More integration of 'nresults' into 'callstatus'
This commit is contained in:
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) \
|
#define checkresults(L,na,nr) \
|
||||||
(api_check(L, (nr) == LUA_MULTRET \
|
(api_check(L, (nr) == LUA_MULTRET \
|
||||||
|| (L->ci->top.p - L->top.p >= (nr) - (na)), \
|
|| (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))
|
#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_sinline CallInfo *prepCallInfo (lua_State *L, StkId func, unsigned status,
|
||||||
l_uint32 mask, StkId top) {
|
StkId top) {
|
||||||
CallInfo *ci = L->ci = next_ci(L); /* new frame */
|
CallInfo *ci = L->ci = next_ci(L); /* new frame */
|
||||||
ci->func.p = func;
|
ci->func.p = func;
|
||||||
lua_assert(((nresults + 1) & ~CIST_NRESULTS) == 0);
|
lua_assert((status & ~(CIST_NRESULTS | CIST_C)) == 0);
|
||||||
ci->callstatus = mask | cast(l_uint32, nresults + 1);
|
ci->callstatus = status;
|
||||||
ci->top.p = top;
|
ci->top.p = top;
|
||||||
return ci;
|
return ci;
|
||||||
}
|
}
|
||||||
@@ -578,12 +578,12 @@ l_sinline CallInfo *prepCallInfo (lua_State *L, StkId func, int nresults,
|
|||||||
/*
|
/*
|
||||||
** precall for C functions
|
** 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) {
|
lua_CFunction f) {
|
||||||
int n; /* number of returns */
|
int n; /* number of returns */
|
||||||
CallInfo *ci;
|
CallInfo *ci;
|
||||||
checkstackp(L, LUA_MINSTACK, func); /* ensure minimum stack size */
|
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);
|
L->top.p + LUA_MINSTACK);
|
||||||
lua_assert(ci->top.p <= L->stack_last.p);
|
lua_assert(ci->top.p <= L->stack_last.p);
|
||||||
if (l_unlikely(L->hookmask & LUA_MASKCALL)) {
|
if (l_unlikely(L->hookmask & LUA_MASKCALL)) {
|
||||||
@@ -610,9 +610,9 @@ int luaD_pretailcall (lua_State *L, CallInfo *ci, StkId func,
|
|||||||
retry:
|
retry:
|
||||||
switch (ttypetag(s2v(func))) {
|
switch (ttypetag(s2v(func))) {
|
||||||
case LUA_VCCL: /* C closure */
|
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 */
|
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 */
|
case LUA_VLCL: { /* Lua function */
|
||||||
Proto *p = clLvalue(s2v(func))->p;
|
Proto *p = clLvalue(s2v(func))->p;
|
||||||
int fsize = p->maxstacksize; /* frame size */
|
int fsize = p->maxstacksize; /* frame size */
|
||||||
@@ -651,13 +651,15 @@ int luaD_pretailcall (lua_State *L, CallInfo *ci, StkId func,
|
|||||||
** original function position.
|
** original function position.
|
||||||
*/
|
*/
|
||||||
CallInfo *luaD_precall (lua_State *L, StkId func, int nresults) {
|
CallInfo *luaD_precall (lua_State *L, StkId func, int nresults) {
|
||||||
|
unsigned status = cast_uint(nresults + 1);
|
||||||
|
lua_assert(status <= MAXRESULTS + 1);
|
||||||
retry:
|
retry:
|
||||||
switch (ttypetag(s2v(func))) {
|
switch (ttypetag(s2v(func))) {
|
||||||
case LUA_VCCL: /* C closure */
|
case LUA_VCCL: /* C closure */
|
||||||
precallC(L, func, nresults, clCvalue(s2v(func))->f);
|
precallC(L, func, status, clCvalue(s2v(func))->f);
|
||||||
return NULL;
|
return NULL;
|
||||||
case LUA_VLCF: /* light C function */
|
case LUA_VLCF: /* light C function */
|
||||||
precallC(L, func, nresults, fvalue(s2v(func)));
|
precallC(L, func, status, fvalue(s2v(func)));
|
||||||
return NULL;
|
return NULL;
|
||||||
case LUA_VLCL: { /* Lua function */
|
case LUA_VLCL: { /* Lua function */
|
||||||
CallInfo *ci;
|
CallInfo *ci;
|
||||||
@@ -666,7 +668,7 @@ CallInfo *luaD_precall (lua_State *L, StkId func, int nresults) {
|
|||||||
int nfixparams = p->numparams;
|
int nfixparams = p->numparams;
|
||||||
int fsize = p->maxstacksize; /* frame size */
|
int fsize = p->maxstacksize; /* frame size */
|
||||||
checkstackp(L, fsize, func);
|
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 */
|
ci->u.l.savedpc = p->code; /* starting point */
|
||||||
for (; narg < nfixparams; narg++)
|
for (; narg < nfixparams; narg++)
|
||||||
setnilvalue(s2v(L->top.p++)); /* complete missing arguments */
|
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 */
|
default: { /* not a function */
|
||||||
func = tryfuncTM(L, func); /* try to get '__call' metamethod */
|
func = tryfuncTM(L, func); /* try to get '__call' metamethod */
|
||||||
/* return luaD_precall(L, func, nresults); */
|
|
||||||
goto retry; /* try again with metamethod */
|
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 in CallInfo status
|
||||||
*/
|
*/
|
||||||
/* bits 0-7 are the expected number of results from this function + 1 */
|
/* 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' */
|
/* 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 */
|
/* 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 */
|
/* 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 */
|
/* 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 */
|
/* doing a yieldable protected call */
|
||||||
#define CIST_YPCALL (cast(l_uint32, 1) << 12)
|
#define CIST_YPCALL (CIST_HOOKED << 1)
|
||||||
/* call was tail called */
|
/* call was tail called */
|
||||||
#define CIST_TAIL (cast(l_uint32, 1) << 13)
|
#define CIST_TAIL (CIST_YPCALL << 1)
|
||||||
/* last hook called yielded */
|
/* last hook called yielded */
|
||||||
#define CIST_HOOKYIELD (cast(l_uint32, 1) << 14)
|
#define CIST_HOOKYIELD (CIST_TAIL << 1)
|
||||||
/* function "called" a finalizer */
|
/* function "called" a finalizer */
|
||||||
#define CIST_FIN (cast(l_uint32, 1) << 15)
|
#define CIST_FIN (CIST_HOOKYIELD << 1)
|
||||||
/* function is closing tbc variables */
|
/* function is closing tbc variables */
|
||||||
#define CIST_CLSRET (cast(l_uint32, 1) << 16)
|
#define CIST_CLSRET (CIST_FIN << 1)
|
||||||
/* Bits 17-19 are used for CIST_RECST (see below) */
|
|
||||||
#define CIST_RECST 17 /* the offset, not the mask */
|
|
||||||
#if defined(LUA_COMPAT_LT_LE)
|
#if defined(LUA_COMPAT_LT_LE)
|
||||||
/* using __lt for __le */
|
/* using __lt for __le */
|
||||||
#define CIST_LEQ (cast(l_uint32, 1) << 20)
|
#define CIST_LEQ (CIST_CLSRET << 1)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user