diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2024-11-15 15:25:11 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2024-11-15 15:25:11 -0300 |
commit | f12ce4029dfbce7b89ec136e6b7ba5f6bca039da (patch) | |
tree | 6f395f013dcd0841efe00ebbf73c18d855c9fd28 | |
parent | a4762b6ffe74f5878882ef238d37bfa92d90e418 (diff) | |
download | lua-f12ce4029dfbce7b89ec136e6b7ba5f6bca039da.tar.gz lua-f12ce4029dfbce7b89ec136e6b7ba5f6bca039da.tar.bz2 lua-f12ce4029dfbce7b89ec136e6b7ba5f6bca039da.zip |
More integration of 'nresults' into 'callstatus'
-rw-r--r-- | lapi.c | 3 | ||||
-rw-r--r-- | ldo.c | 25 | ||||
-rw-r--r-- | lstate.h | 33 |
3 files changed, 33 insertions, 28 deletions
@@ -1023,9 +1023,6 @@ LUA_API int lua_setiuservalue (lua_State *L, int idx, int n) { | |||
1023 | */ | 1023 | */ |
1024 | 1024 | ||
1025 | 1025 | ||
1026 | #define MAXRESULTS 250 | ||
1027 | |||
1028 | |||
1029 | #define checkresults(L,na,nr) \ | 1026 | #define checkresults(L,na,nr) \ |
1030 | (api_check(L, (nr) == LUA_MULTRET \ | 1027 | (api_check(L, (nr) == LUA_MULTRET \ |
1031 | || (L->ci->top.p - L->top.p >= (nr) - (na)), \ | 1028 | || (L->ci->top.p - L->top.p >= (nr) - (na)), \ |
@@ -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 | ||
567 | l_sinline CallInfo *prepCallInfo (lua_State *L, StkId func, int nresults, | 567 | l_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 | */ |
581 | l_sinline int precallC (lua_State *L, StkId func, int nresults, | 581 | l_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 | */ |
653 | CallInfo *luaD_precall (lua_State *L, StkId func, int nresults) { | 653 | CallInfo *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 | } |
@@ -210,33 +210,40 @@ struct CallInfo { | |||
210 | 210 | ||
211 | 211 | ||
212 | /* | 212 | /* |
213 | ** Maximum expected number of results from a function | ||
214 | ** (must fit in CIST_NRESULTS). | ||
215 | */ | ||
216 | #define MAXRESULTS 250 | ||
217 | |||
218 | |||
219 | /* | ||
213 | ** Bits in CallInfo status | 220 | ** Bits in CallInfo status |
214 | */ | 221 | */ |
215 | /* bits 0-7 are the expected number of results from this function + 1 */ | 222 | /* bits 0-7 are the expected number of results from this function + 1 */ |
216 | #define CIST_NRESULTS 0xff | 223 | #define CIST_NRESULTS 0xffu |
224 | /* Bits 8-10 are used for CIST_RECST (see below) */ | ||
225 | #define CIST_RECST 8 /* the offset, not the mask */ | ||
217 | /* original value of 'allowhook' */ | 226 | /* original value of 'allowhook' */ |
218 | #define CIST_OAH (cast(l_uint32, 1) << 8) | 227 | #define CIST_OAH (cast(l_uint32, 1) << 11) |
219 | /* call is running a C function */ | 228 | /* call is running a C function */ |
220 | #define CIST_C (cast(l_uint32, 1) << 9) | 229 | #define CIST_C (CIST_OAH << 1) |
221 | /* call is on a fresh "luaV_execute" frame */ | 230 | /* call is on a fresh "luaV_execute" frame */ |
222 | #define CIST_FRESH (cast(l_uint32, 1) << 10) | 231 | #define CIST_FRESH (CIST_C << 1) |
223 | /* call is running a debug hook */ | 232 | /* call is running a debug hook */ |
224 | #define CIST_HOOKED (cast(l_uint32, 1) << 11) | 233 | #define CIST_HOOKED (CIST_FRESH << 1) |
225 | /* doing a yieldable protected call */ | 234 | /* doing a yieldable protected call */ |
226 | #define CIST_YPCALL (cast(l_uint32, 1) << 12) | 235 | #define CIST_YPCALL (CIST_HOOKED << 1) |
227 | /* call was tail called */ | 236 | /* call was tail called */ |
228 | #define CIST_TAIL (cast(l_uint32, 1) << 13) | 237 | #define CIST_TAIL (CIST_YPCALL << 1) |
229 | /* last hook called yielded */ | 238 | /* last hook called yielded */ |
230 | #define CIST_HOOKYIELD (cast(l_uint32, 1) << 14) | 239 | #define CIST_HOOKYIELD (CIST_TAIL << 1) |
231 | /* function "called" a finalizer */ | 240 | /* function "called" a finalizer */ |
232 | #define CIST_FIN (cast(l_uint32, 1) << 15) | 241 | #define CIST_FIN (CIST_HOOKYIELD << 1) |
233 | /* function is closing tbc variables */ | 242 | /* function is closing tbc variables */ |
234 | #define CIST_CLSRET (cast(l_uint32, 1) << 16) | 243 | #define CIST_CLSRET (CIST_FIN << 1) |
235 | /* Bits 17-19 are used for CIST_RECST (see below) */ | ||
236 | #define CIST_RECST 17 /* the offset, not the mask */ | ||
237 | #if defined(LUA_COMPAT_LT_LE) | 244 | #if defined(LUA_COMPAT_LT_LE) |
238 | /* using __lt for __le */ | 245 | /* using __lt for __le */ |
239 | #define CIST_LEQ (cast(l_uint32, 1) << 20) | 246 | #define CIST_LEQ (CIST_CLSRET << 1) |
240 | #endif | 247 | #endif |
241 | 248 | ||
242 | 249 | ||