small changes (to easy integration with Coco)
This commit is contained in:
31
ldo.c
31
ldo.c
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
** $Id: ldo.c,v 2.27 2005/06/13 21:17:59 roberto Exp roberto $
|
** $Id: ldo.c,v 2.28 2005/07/11 14:00:31 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
|
||||||
*/
|
*/
|
||||||
@@ -298,6 +298,11 @@ int luaD_precall (lua_State *L, StkId func, int 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;
|
||||||
|
if (L->hookmask & LUA_MASKCALL) {
|
||||||
|
L->savedpc++; /* hooks assume 'pc' is already incremented */
|
||||||
|
luaD_callhook(L, LUA_HOOKCALL, -1);
|
||||||
|
L->savedpc--; /* correct 'pc' */
|
||||||
|
}
|
||||||
return PCRLUA;
|
return PCRLUA;
|
||||||
}
|
}
|
||||||
else { /* if is a C function, call it */
|
else { /* if is a C function, call it */
|
||||||
@@ -380,11 +385,11 @@ void luaD_call (lua_State *L, StkId func, int nResults) {
|
|||||||
|
|
||||||
static void resume (lua_State *L, void *ud) {
|
static void resume (lua_State *L, void *ud) {
|
||||||
StkId firstResult;
|
StkId firstResult;
|
||||||
int nargs = *cast(int *, ud);
|
StkId firstArg = cast(StkId, ud);
|
||||||
CallInfo *ci = L->ci;
|
CallInfo *ci = L->ci;
|
||||||
if (L->status != LUA_YIELD) {
|
if (L->status != LUA_YIELD) {
|
||||||
lua_assert(ci == L->base_ci && nargs < L->top - L->base);
|
lua_assert(ci == L->base_ci && firstArg > L->base);
|
||||||
luaD_precall(L, L->top - (nargs + 1), LUA_MULTRET); /* start coroutine */
|
luaD_precall(L, firstArg - 1, LUA_MULTRET); /* start coroutine */
|
||||||
}
|
}
|
||||||
else { /* resuming from previous yield */
|
else { /* resuming from previous yield */
|
||||||
if (!f_isLua(ci)) { /* `common' yield? */
|
if (!f_isLua(ci)) { /* `common' yield? */
|
||||||
@@ -392,9 +397,12 @@ static void resume (lua_State *L, void *ud) {
|
|||||||
int nresults = ci->nresults;
|
int nresults = ci->nresults;
|
||||||
lua_assert(GET_OPCODE(*((ci-1)->savedpc - 1)) == OP_CALL ||
|
lua_assert(GET_OPCODE(*((ci-1)->savedpc - 1)) == OP_CALL ||
|
||||||
GET_OPCODE(*((ci-1)->savedpc - 1)) == OP_TAILCALL);
|
GET_OPCODE(*((ci-1)->savedpc - 1)) == OP_TAILCALL);
|
||||||
luaD_poscall(L, nresults, L->top - nargs); /* complete it */
|
luaD_poscall(L, nresults, firstArg); /* complete it */
|
||||||
if (nresults >= 0) L->top = L->ci->top;
|
if (nresults >= 0) L->top = L->ci->top;
|
||||||
} /* else yielded inside a hook: just continue its execution */
|
}
|
||||||
|
else { /* yielded inside a hook: just continue its execution */
|
||||||
|
L->base = L->ci->base;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
L->status = 0;
|
L->status = 0;
|
||||||
firstResult = luaV_execute(L, cast(int, L->ci - L->base_ci));
|
firstResult = luaV_execute(L, cast(int, L->ci - L->base_ci));
|
||||||
@@ -423,7 +431,7 @@ LUA_API int lua_resume (lua_State *L, int nargs) {
|
|||||||
else if (L->ci != L->base_ci)
|
else if (L->ci != L->base_ci)
|
||||||
return resume_error(L, "cannot resume non-suspended coroutine");
|
return resume_error(L, "cannot resume non-suspended coroutine");
|
||||||
}
|
}
|
||||||
status = luaD_rawrunprotected(L, resume, &nargs);
|
status = luaD_rawrunprotected(L, resume, L->top - nargs);
|
||||||
if (status != 0) { /* error? */
|
if (status != 0) { /* error? */
|
||||||
L->status = cast(lu_byte, status); /* mark thread as `dead' */
|
L->status = cast(lu_byte, status); /* mark thread as `dead' */
|
||||||
seterrorobj(L, status, L->top);
|
seterrorobj(L, status, L->top);
|
||||||
@@ -441,14 +449,7 @@ LUA_API int lua_yield (lua_State *L, int nresults) {
|
|||||||
ci = L->ci;
|
ci = L->ci;
|
||||||
if (L->nCcalls > 0)
|
if (L->nCcalls > 0)
|
||||||
luaG_runerror(L, "attempt to yield across metamethod/C-call boundary");
|
luaG_runerror(L, "attempt to yield across metamethod/C-call boundary");
|
||||||
if (!f_isLua(ci)) { /* usual yield */
|
L->base = L->top - nresults; /* protect stack slots below */
|
||||||
if (L->top - nresults > L->base) { /* is there garbage in the stack? */
|
|
||||||
int i;
|
|
||||||
for (i=0; i<nresults; i++) /* move down results */
|
|
||||||
setobjs2s(L, L->base + i, L->top - nresults + i);
|
|
||||||
L->top = L->base + nresults;
|
|
||||||
}
|
|
||||||
} /* else it's an yield inside a hook: nothing to do */
|
|
||||||
L->status = LUA_YIELD;
|
L->status = LUA_YIELD;
|
||||||
lua_unlock(L);
|
lua_unlock(L);
|
||||||
return -1;
|
return -1;
|
||||||
|
|||||||
16
lvm.c
16
lvm.c
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
** $Id: lvm.c,v 2.48 2005/07/05 14:31:20 roberto Exp roberto $
|
** $Id: lvm.c,v 2.49 2005/08/09 17:42:02 roberto Exp roberto $
|
||||||
** Lua virtual machine
|
** Lua virtual machine
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
@@ -362,13 +362,7 @@ StkId luaV_execute (lua_State *L, int nexeccalls) {
|
|||||||
StkId base;
|
StkId base;
|
||||||
TValue *k;
|
TValue *k;
|
||||||
const Instruction *pc;
|
const Instruction *pc;
|
||||||
callentry: /* entry point when calling new functions */
|
reentry: /* entry point */
|
||||||
if (L->hookmask & LUA_MASKCALL) {
|
|
||||||
L->savedpc++; /* hooks assume 'pc' is already incremented */
|
|
||||||
luaD_callhook(L, LUA_HOOKCALL, -1);
|
|
||||||
L->savedpc--; /* correct 'pc' */
|
|
||||||
}
|
|
||||||
retentry: /* entry point when returning to old functions */
|
|
||||||
pc = L->savedpc;
|
pc = L->savedpc;
|
||||||
cl = &clvalue(L->ci->func)->l;
|
cl = &clvalue(L->ci->func)->l;
|
||||||
base = L->base;
|
base = L->base;
|
||||||
@@ -618,7 +612,7 @@ StkId luaV_execute (lua_State *L, int nexeccalls) {
|
|||||||
switch (luaD_precall(L, ra, nresults)) {
|
switch (luaD_precall(L, ra, nresults)) {
|
||||||
case PCRLUA: {
|
case PCRLUA: {
|
||||||
nexeccalls++;
|
nexeccalls++;
|
||||||
goto callentry; /* restart luaV_execute over new Lua function */
|
goto reentry; /* restart luaV_execute over new Lua function */
|
||||||
}
|
}
|
||||||
case PCRC: {
|
case PCRC: {
|
||||||
/* it was a C function (`precall' called it); adjust results */
|
/* it was a C function (`precall' called it); adjust results */
|
||||||
@@ -652,7 +646,7 @@ StkId luaV_execute (lua_State *L, int nexeccalls) {
|
|||||||
ci->savedpc = L->savedpc;
|
ci->savedpc = L->savedpc;
|
||||||
ci->tailcalls++; /* one more call lost */
|
ci->tailcalls++; /* one more call lost */
|
||||||
L->ci--; /* remove new frame */
|
L->ci--; /* remove new frame */
|
||||||
goto callentry;
|
goto reentry;
|
||||||
}
|
}
|
||||||
case PCRC: {
|
case PCRC: {
|
||||||
/* it was a C function (`precall' called it) */
|
/* it was a C function (`precall' called it) */
|
||||||
@@ -677,7 +671,7 @@ StkId luaV_execute (lua_State *L, int nexeccalls) {
|
|||||||
lua_assert(GET_OPCODE(*((L->ci - 1)->savedpc - 1)) == OP_CALL);
|
lua_assert(GET_OPCODE(*((L->ci - 1)->savedpc - 1)) == OP_CALL);
|
||||||
luaD_poscall(L, nresults, ra);
|
luaD_poscall(L, nresults, ra);
|
||||||
if (nresults >= 0) L->top = L->ci->top;
|
if (nresults >= 0) L->top = L->ci->top;
|
||||||
goto retentry;
|
goto reentry;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case OP_FORLOOP: {
|
case OP_FORLOOP: {
|
||||||
|
|||||||
Reference in New Issue
Block a user