mirror of
https://github.com/lua/lua.git
synced 2024-11-23 02:03:55 +08:00
More integration of 'nresults' into 'callstatus'
This commit is contained in:
parent
a4762b6ffe
commit
f12ce4029d
3
lapi.c
3
lapi.c
@ -1023,9 +1023,6 @@ LUA_API int lua_setiuservalue (lua_State *L, int idx, int n) {
|
||||
*/
|
||||
|
||||
|
||||
#define MAXRESULTS 250
|
||||
|
||||
|
||||
#define checkresults(L,na,nr) \
|
||||
(api_check(L, (nr) == LUA_MULTRET \
|
||||
|| (L->ci->top.p - L->top.p >= (nr) - (na)), \
|
||||
|
25
ldo.c
25
ldo.c
@ -564,12 +564,12 @@ void luaD_poscall (lua_State *L, CallInfo *ci, int nres) {
|
||||
#define next_ci(L) (L->ci->next ? L->ci->next : luaE_extendCI(L))
|
||||
|
||||
|
||||
l_sinline CallInfo *prepCallInfo (lua_State *L, StkId func, int nresults,
|
||||
l_uint32 mask, StkId top) {
|
||||
l_sinline CallInfo *prepCallInfo (lua_State *L, StkId func, unsigned status,
|
||||
StkId top) {
|
||||
CallInfo *ci = L->ci = next_ci(L); /* new frame */
|
||||
ci->func.p = func;
|
||||
lua_assert(((nresults + 1) & ~CIST_NRESULTS) == 0);
|
||||
ci->callstatus = mask | cast(l_uint32, nresults + 1);
|
||||
lua_assert((status & ~(CIST_NRESULTS | CIST_C)) == 0);
|
||||
ci->callstatus = status;
|
||||
ci->top.p = top;
|
||||
return ci;
|
||||
}
|
||||
@ -578,12 +578,12 @@ l_sinline CallInfo *prepCallInfo (lua_State *L, StkId func, int nresults,
|
||||
/*
|
||||
** precall for C functions
|
||||
*/
|
||||
l_sinline int precallC (lua_State *L, StkId func, int nresults,
|
||||
l_sinline int precallC (lua_State *L, StkId func, unsigned status,
|
||||
lua_CFunction f) {
|
||||
int n; /* number of returns */
|
||||
CallInfo *ci;
|
||||
checkstackp(L, LUA_MINSTACK, func); /* ensure minimum stack size */
|
||||
L->ci = ci = prepCallInfo(L, func, nresults, CIST_C,
|
||||
L->ci = ci = prepCallInfo(L, func, status | CIST_C,
|
||||
L->top.p + LUA_MINSTACK);
|
||||
lua_assert(ci->top.p <= L->stack_last.p);
|
||||
if (l_unlikely(L->hookmask & LUA_MASKCALL)) {
|
||||
@ -610,9 +610,9 @@ int luaD_pretailcall (lua_State *L, CallInfo *ci, StkId func,
|
||||
retry:
|
||||
switch (ttypetag(s2v(func))) {
|
||||
case LUA_VCCL: /* C closure */
|
||||
return precallC(L, func, LUA_MULTRET, clCvalue(s2v(func))->f);
|
||||
return precallC(L, func, LUA_MULTRET + 1, clCvalue(s2v(func))->f);
|
||||
case LUA_VLCF: /* light C function */
|
||||
return precallC(L, func, LUA_MULTRET, fvalue(s2v(func)));
|
||||
return precallC(L, func, LUA_MULTRET + 1, fvalue(s2v(func)));
|
||||
case LUA_VLCL: { /* Lua function */
|
||||
Proto *p = clLvalue(s2v(func))->p;
|
||||
int fsize = p->maxstacksize; /* frame size */
|
||||
@ -651,13 +651,15 @@ int luaD_pretailcall (lua_State *L, CallInfo *ci, StkId func,
|
||||
** original function position.
|
||||
*/
|
||||
CallInfo *luaD_precall (lua_State *L, StkId func, int nresults) {
|
||||
unsigned status = cast_uint(nresults + 1);
|
||||
lua_assert(status <= MAXRESULTS + 1);
|
||||
retry:
|
||||
switch (ttypetag(s2v(func))) {
|
||||
case LUA_VCCL: /* C closure */
|
||||
precallC(L, func, nresults, clCvalue(s2v(func))->f);
|
||||
precallC(L, func, status, clCvalue(s2v(func))->f);
|
||||
return NULL;
|
||||
case LUA_VLCF: /* light C function */
|
||||
precallC(L, func, nresults, fvalue(s2v(func)));
|
||||
precallC(L, func, status, fvalue(s2v(func)));
|
||||
return NULL;
|
||||
case LUA_VLCL: { /* Lua function */
|
||||
CallInfo *ci;
|
||||
@ -666,7 +668,7 @@ CallInfo *luaD_precall (lua_State *L, StkId func, int nresults) {
|
||||
int nfixparams = p->numparams;
|
||||
int fsize = p->maxstacksize; /* frame size */
|
||||
checkstackp(L, fsize, func);
|
||||
L->ci = ci = prepCallInfo(L, func, nresults, 0, func + 1 + fsize);
|
||||
L->ci = ci = prepCallInfo(L, func, status, func + 1 + fsize);
|
||||
ci->u.l.savedpc = p->code; /* starting point */
|
||||
for (; narg < nfixparams; narg++)
|
||||
setnilvalue(s2v(L->top.p++)); /* complete missing arguments */
|
||||
@ -675,7 +677,6 @@ CallInfo *luaD_precall (lua_State *L, StkId func, int nresults) {
|
||||
}
|
||||
default: { /* not a function */
|
||||
func = tryfuncTM(L, func); /* try to get '__call' metamethod */
|
||||
/* return luaD_precall(L, func, nresults); */
|
||||
goto retry; /* try again with metamethod */
|
||||
}
|
||||
}
|
||||
|
33
lstate.h
33
lstate.h
@ -209,34 +209,41 @@ struct CallInfo {
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
** Maximum expected number of results from a function
|
||||
** (must fit in CIST_NRESULTS).
|
||||
*/
|
||||
#define MAXRESULTS 250
|
||||
|
||||
|
||||
/*
|
||||
** Bits in CallInfo status
|
||||
*/
|
||||
/* bits 0-7 are the expected number of results from this function + 1 */
|
||||
#define CIST_NRESULTS 0xff
|
||||
#define CIST_NRESULTS 0xffu
|
||||
/* Bits 8-10 are used for CIST_RECST (see below) */
|
||||
#define CIST_RECST 8 /* the offset, not the mask */
|
||||
/* original value of 'allowhook' */
|
||||
#define CIST_OAH (cast(l_uint32, 1) << 8)
|
||||
#define CIST_OAH (cast(l_uint32, 1) << 11)
|
||||
/* call is running a C function */
|
||||
#define CIST_C (cast(l_uint32, 1) << 9)
|
||||
#define CIST_C (CIST_OAH << 1)
|
||||
/* call is on a fresh "luaV_execute" frame */
|
||||
#define CIST_FRESH (cast(l_uint32, 1) << 10)
|
||||
#define CIST_FRESH (CIST_C << 1)
|
||||
/* call is running a debug hook */
|
||||
#define CIST_HOOKED (cast(l_uint32, 1) << 11)
|
||||
#define CIST_HOOKED (CIST_FRESH << 1)
|
||||
/* doing a yieldable protected call */
|
||||
#define CIST_YPCALL (cast(l_uint32, 1) << 12)
|
||||
#define CIST_YPCALL (CIST_HOOKED << 1)
|
||||
/* call was tail called */
|
||||
#define CIST_TAIL (cast(l_uint32, 1) << 13)
|
||||
#define CIST_TAIL (CIST_YPCALL << 1)
|
||||
/* last hook called yielded */
|
||||
#define CIST_HOOKYIELD (cast(l_uint32, 1) << 14)
|
||||
#define CIST_HOOKYIELD (CIST_TAIL << 1)
|
||||
/* function "called" a finalizer */
|
||||
#define CIST_FIN (cast(l_uint32, 1) << 15)
|
||||
#define CIST_FIN (CIST_HOOKYIELD << 1)
|
||||
/* function is closing tbc variables */
|
||||
#define CIST_CLSRET (cast(l_uint32, 1) << 16)
|
||||
/* Bits 17-19 are used for CIST_RECST (see below) */
|
||||
#define CIST_RECST 17 /* the offset, not the mask */
|
||||
#define CIST_CLSRET (CIST_FIN << 1)
|
||||
#if defined(LUA_COMPAT_LT_LE)
|
||||
/* using __lt for __le */
|
||||
#define CIST_LEQ (cast(l_uint32, 1) << 20)
|
||||
#define CIST_LEQ (CIST_CLSRET << 1)
|
||||
#endif
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user