aboutsummaryrefslogtreecommitdiff
path: root/ldo.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2024-11-15 15:25:11 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2024-11-15 15:25:11 -0300
commitf12ce4029dfbce7b89ec136e6b7ba5f6bca039da (patch)
tree6f395f013dcd0841efe00ebbf73c18d855c9fd28 /ldo.c
parenta4762b6ffe74f5878882ef238d37bfa92d90e418 (diff)
downloadlua-f12ce4029dfbce7b89ec136e6b7ba5f6bca039da.tar.gz
lua-f12ce4029dfbce7b89ec136e6b7ba5f6bca039da.tar.bz2
lua-f12ce4029dfbce7b89ec136e6b7ba5f6bca039da.zip
More integration of 'nresults' into 'callstatus'
Diffstat (limited to 'ldo.c')
-rw-r--r--ldo.c25
1 files changed, 13 insertions, 12 deletions
diff --git a/ldo.c b/ldo.c
index e75a79ab..72a1e306 100644
--- a/ldo.c
+++ b/ldo.c
@@ -564,12 +564,12 @@ void luaD_poscall (lua_State *L, CallInfo *ci, int nres) {
564#define next_ci(L) (L->ci->next ? L->ci->next : luaE_extendCI(L)) 564#define next_ci(L) (L->ci->next ? L->ci->next : luaE_extendCI(L))
565 565
566 566
567l_sinline CallInfo *prepCallInfo (lua_State *L, StkId func, int nresults, 567l_sinline CallInfo *prepCallInfo (lua_State *L, StkId func, unsigned status,
568 l_uint32 mask, StkId top) { 568 StkId top) {
569 CallInfo *ci = L->ci = next_ci(L); /* new frame */ 569 CallInfo *ci = L->ci = next_ci(L); /* new frame */
570 ci->func.p = func; 570 ci->func.p = func;
571 lua_assert(((nresults + 1) & ~CIST_NRESULTS) == 0); 571 lua_assert((status & ~(CIST_NRESULTS | CIST_C)) == 0);
572 ci->callstatus = mask | cast(l_uint32, nresults + 1); 572 ci->callstatus = status;
573 ci->top.p = top; 573 ci->top.p = top;
574 return ci; 574 return ci;
575} 575}
@@ -578,12 +578,12 @@ l_sinline CallInfo *prepCallInfo (lua_State *L, StkId func, int nresults,
578/* 578/*
579** precall for C functions 579** precall for C functions
580*/ 580*/
581l_sinline int precallC (lua_State *L, StkId func, int nresults, 581l_sinline int precallC (lua_State *L, StkId func, unsigned status,
582 lua_CFunction f) { 582 lua_CFunction f) {
583 int n; /* number of returns */ 583 int n; /* number of returns */
584 CallInfo *ci; 584 CallInfo *ci;
585 checkstackp(L, LUA_MINSTACK, func); /* ensure minimum stack size */ 585 checkstackp(L, LUA_MINSTACK, func); /* ensure minimum stack size */
586 L->ci = ci = prepCallInfo(L, func, nresults, CIST_C, 586 L->ci = ci = prepCallInfo(L, func, status | CIST_C,
587 L->top.p + LUA_MINSTACK); 587 L->top.p + LUA_MINSTACK);
588 lua_assert(ci->top.p <= L->stack_last.p); 588 lua_assert(ci->top.p <= L->stack_last.p);
589 if (l_unlikely(L->hookmask & LUA_MASKCALL)) { 589 if (l_unlikely(L->hookmask & LUA_MASKCALL)) {
@@ -610,9 +610,9 @@ int luaD_pretailcall (lua_State *L, CallInfo *ci, StkId func,
610 retry: 610 retry:
611 switch (ttypetag(s2v(func))) { 611 switch (ttypetag(s2v(func))) {
612 case LUA_VCCL: /* C closure */ 612 case LUA_VCCL: /* C closure */
613 return precallC(L, func, LUA_MULTRET, clCvalue(s2v(func))->f); 613 return precallC(L, func, LUA_MULTRET + 1, clCvalue(s2v(func))->f);
614 case LUA_VLCF: /* light C function */ 614 case LUA_VLCF: /* light C function */
615 return precallC(L, func, LUA_MULTRET, fvalue(s2v(func))); 615 return precallC(L, func, LUA_MULTRET + 1, fvalue(s2v(func)));
616 case LUA_VLCL: { /* Lua function */ 616 case LUA_VLCL: { /* Lua function */
617 Proto *p = clLvalue(s2v(func))->p; 617 Proto *p = clLvalue(s2v(func))->p;
618 int fsize = p->maxstacksize; /* frame size */ 618 int fsize = p->maxstacksize; /* frame size */
@@ -651,13 +651,15 @@ int luaD_pretailcall (lua_State *L, CallInfo *ci, StkId func,
651** original function position. 651** original function position.
652*/ 652*/
653CallInfo *luaD_precall (lua_State *L, StkId func, int nresults) { 653CallInfo *luaD_precall (lua_State *L, StkId func, int nresults) {
654 unsigned status = cast_uint(nresults + 1);
655 lua_assert(status <= MAXRESULTS + 1);
654 retry: 656 retry:
655 switch (ttypetag(s2v(func))) { 657 switch (ttypetag(s2v(func))) {
656 case LUA_VCCL: /* C closure */ 658 case LUA_VCCL: /* C closure */
657 precallC(L, func, nresults, clCvalue(s2v(func))->f); 659 precallC(L, func, status, clCvalue(s2v(func))->f);
658 return NULL; 660 return NULL;
659 case LUA_VLCF: /* light C function */ 661 case LUA_VLCF: /* light C function */
660 precallC(L, func, nresults, fvalue(s2v(func))); 662 precallC(L, func, status, fvalue(s2v(func)));
661 return NULL; 663 return NULL;
662 case LUA_VLCL: { /* Lua function */ 664 case LUA_VLCL: { /* Lua function */
663 CallInfo *ci; 665 CallInfo *ci;
@@ -666,7 +668,7 @@ CallInfo *luaD_precall (lua_State *L, StkId func, int nresults) {
666 int nfixparams = p->numparams; 668 int nfixparams = p->numparams;
667 int fsize = p->maxstacksize; /* frame size */ 669 int fsize = p->maxstacksize; /* frame size */
668 checkstackp(L, fsize, func); 670 checkstackp(L, fsize, func);
669 L->ci = ci = prepCallInfo(L, func, nresults, 0, func + 1 + fsize); 671 L->ci = ci = prepCallInfo(L, func, status, func + 1 + fsize);
670 ci->u.l.savedpc = p->code; /* starting point */ 672 ci->u.l.savedpc = p->code; /* starting point */
671 for (; narg < nfixparams; narg++) 673 for (; narg < nfixparams; narg++)
672 setnilvalue(s2v(L->top.p++)); /* complete missing arguments */ 674 setnilvalue(s2v(L->top.p++)); /* complete missing arguments */
@@ -675,7 +677,6 @@ CallInfo *luaD_precall (lua_State *L, StkId func, int nresults) {
675 } 677 }
676 default: { /* not a function */ 678 default: { /* not a function */
677 func = tryfuncTM(L, func); /* try to get '__call' metamethod */ 679 func = tryfuncTM(L, func); /* try to get '__call' metamethod */
678 /* return luaD_precall(L, func, nresults); */
679 goto retry; /* try again with metamethod */ 680 goto retry; /* try again with metamethod */
680 } 681 }
681 } 682 }