'nresults' is saved in CallInfo from the caller, not the called

This commit is contained in:
Roberto Ierusalimschy 2009-04-15 13:53:39 -03:00
parent 8775f25830
commit 311e9f3ceb
1 changed files with 4 additions and 5 deletions

9
ldo.c
View File

@ -1,5 +1,5 @@
/* /*
** $Id: ldo.c,v 2.57 2009/03/26 12:56:38 roberto Exp roberto $ ** $Id: ldo.c,v 2.58 2009/04/08 18:04:33 roberto Exp roberto $
** Stack and Call structure of Lua ** Stack and Call structure of Lua
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -251,6 +251,7 @@ int luaD_precall (lua_State *L, StkId func, int nresults) {
funcr = savestack(L, func); funcr = savestack(L, func);
cl = &clvalue(func)->l; cl = &clvalue(func)->l;
L->ci->savedpc = L->savedpc; L->ci->savedpc = L->savedpc;
L->ci->nresults = nresults;
if (!cl->isC) { /* Lua function? prepare its call */ if (!cl->isC) { /* Lua function? prepare its call */
CallInfo *ci; CallInfo *ci;
StkId st, base; StkId st, base;
@ -272,7 +273,6 @@ int luaD_precall (lua_State *L, StkId func, int nresults) {
L->savedpc = p->code; /* starting point */ L->savedpc = p->code; /* starting point */
ci->u.l.tailcalls = 0; ci->u.l.tailcalls = 0;
ci->callstatus = CIST_LUA; ci->callstatus = CIST_LUA;
ci->nresults = nresults;
for (st = L->top; st < ci->top; st++) for (st = L->top; st < ci->top; st++)
setnilvalue(st); setnilvalue(st);
L->top = ci->top; L->top = ci->top;
@ -292,7 +292,6 @@ int luaD_precall (lua_State *L, StkId func, int nresults) {
L->base = ci->base = ci->func + 1; L->base = ci->base = ci->func + 1;
ci->top = L->top + LUA_MINSTACK; ci->top = L->top + LUA_MINSTACK;
lua_assert(ci->top <= L->stack_last); lua_assert(ci->top <= L->stack_last);
ci->nresults = nresults;
ci->callstatus = 0; ci->callstatus = 0;
if (L->hookmask & LUA_MASKCALL) if (L->hookmask & LUA_MASKCALL)
luaD_callhook(L, LUA_HOOKCALL, -1); luaD_callhook(L, LUA_HOOKCALL, -1);
@ -327,7 +326,7 @@ int luaD_poscall (lua_State *L, StkId firstResult) {
} }
ci = L->ci--; ci = L->ci--;
res = ci->func; /* res == final position of 1st result */ res = ci->func; /* res == final position of 1st result */
wanted = ci->nresults; wanted = (ci - 1)->nresults;
L->base = (ci - 1)->base; /* restore base */ L->base = (ci - 1)->base; /* restore base */
L->savedpc = (ci - 1)->savedpc; /* restore savedpc */ L->savedpc = (ci - 1)->savedpc; /* restore savedpc */
/* move results to correct place */ /* move results to correct place */
@ -370,7 +369,7 @@ static void finishCcall (lua_State *L) {
/* finish 'luaD_call' */ /* finish 'luaD_call' */
G(L)->nCcalls--; G(L)->nCcalls--;
/* finish 'lua_callk' */ /* finish 'lua_callk' */
adjustresults(L, (L->ci + 1)->nresults); adjustresults(L, L->ci->nresults);
/* call continuation function */ /* call continuation function */
if (!(L->ci->callstatus & CIST_STAT)) /* no call status? */ if (!(L->ci->callstatus & CIST_STAT)) /* no call status? */
L->ci->u.c.status = LUA_YIELD; /* 'default' status */ L->ci->u.c.status = LUA_YIELD; /* 'default' status */