summaryrefslogtreecommitdiff
path: root/ldo.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2005-08-09 16:49:04 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2005-08-09 16:49:04 -0300
commit44b19075c0fa4310d312147ee1d74dc11ff36eba (patch)
treeda10448271a24dc9f0f24e5123fdf8918f9c7228 /ldo.c
parentab3dfa55948a670c35152ffd965d218ad48f871a (diff)
downloadlua-44b19075c0fa4310d312147ee1d74dc11ff36eba.tar.gz
lua-44b19075c0fa4310d312147ee1d74dc11ff36eba.tar.bz2
lua-44b19075c0fa4310d312147ee1d74dc11ff36eba.zip
small changes (to easy integration with Coco)
Diffstat (limited to 'ldo.c')
-rw-r--r--ldo.c31
1 files changed, 16 insertions, 15 deletions
diff --git a/ldo.c b/ldo.c
index 87c9a1f7..ecce53d3 100644
--- a/ldo.c
+++ b/ldo.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ldo.c,v 2.27 2005/06/13 21:17:59 roberto Exp roberto $ 2** $Id: ldo.c,v 2.28 2005/07/11 14:00:31 roberto Exp roberto $
3** Stack and Call structure of Lua 3** Stack and Call structure of Lua
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -298,6 +298,11 @@ int luaD_precall (lua_State *L, StkId func, int nresults) {
298 for (st = L->top; st < ci->top; st++) 298 for (st = L->top; st < ci->top; st++)
299 setnilvalue(st); 299 setnilvalue(st);
300 L->top = ci->top; 300 L->top = ci->top;
301 if (L->hookmask & LUA_MASKCALL) {
302 L->savedpc++; /* hooks assume 'pc' is already incremented */
303 luaD_callhook(L, LUA_HOOKCALL, -1);
304 L->savedpc--; /* correct 'pc' */
305 }
301 return PCRLUA; 306 return PCRLUA;
302 } 307 }
303 else { /* if is a C function, call it */ 308 else { /* if is a C function, call it */
@@ -380,11 +385,11 @@ void luaD_call (lua_State *L, StkId func, int nResults) {
380 385
381static void resume (lua_State *L, void *ud) { 386static void resume (lua_State *L, void *ud) {
382 StkId firstResult; 387 StkId firstResult;
383 int nargs = *cast(int *, ud); 388 StkId firstArg = cast(StkId, ud);
384 CallInfo *ci = L->ci; 389 CallInfo *ci = L->ci;
385 if (L->status != LUA_YIELD) { 390 if (L->status != LUA_YIELD) {
386 lua_assert(ci == L->base_ci && nargs < L->top - L->base); 391 lua_assert(ci == L->base_ci && firstArg > L->base);
387 luaD_precall(L, L->top - (nargs + 1), LUA_MULTRET); /* start coroutine */ 392 luaD_precall(L, firstArg - 1, LUA_MULTRET); /* start coroutine */
388 } 393 }
389 else { /* resuming from previous yield */ 394 else { /* resuming from previous yield */
390 if (!f_isLua(ci)) { /* `common' yield? */ 395 if (!f_isLua(ci)) { /* `common' yield? */
@@ -392,9 +397,12 @@ static void resume (lua_State *L, void *ud) {
392 int nresults = ci->nresults; 397 int nresults = ci->nresults;
393 lua_assert(GET_OPCODE(*((ci-1)->savedpc - 1)) == OP_CALL || 398 lua_assert(GET_OPCODE(*((ci-1)->savedpc - 1)) == OP_CALL ||
394 GET_OPCODE(*((ci-1)->savedpc - 1)) == OP_TAILCALL); 399 GET_OPCODE(*((ci-1)->savedpc - 1)) == OP_TAILCALL);
395 luaD_poscall(L, nresults, L->top - nargs); /* complete it */ 400 luaD_poscall(L, nresults, firstArg); /* complete it */
396 if (nresults >= 0) L->top = L->ci->top; 401 if (nresults >= 0) L->top = L->ci->top;
397 } /* else yielded inside a hook: just continue its execution */ 402 }
403 else { /* yielded inside a hook: just continue its execution */
404 L->base = L->ci->base;
405 }
398 } 406 }
399 L->status = 0; 407 L->status = 0;
400 firstResult = luaV_execute(L, cast(int, L->ci - L->base_ci)); 408 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) {
423 else if (L->ci != L->base_ci) 431 else if (L->ci != L->base_ci)
424 return resume_error(L, "cannot resume non-suspended coroutine"); 432 return resume_error(L, "cannot resume non-suspended coroutine");
425 } 433 }
426 status = luaD_rawrunprotected(L, resume, &nargs); 434 status = luaD_rawrunprotected(L, resume, L->top - nargs);
427 if (status != 0) { /* error? */ 435 if (status != 0) { /* error? */
428 L->status = cast(lu_byte, status); /* mark thread as `dead' */ 436 L->status = cast(lu_byte, status); /* mark thread as `dead' */
429 seterrorobj(L, status, L->top); 437 seterrorobj(L, status, L->top);
@@ -441,14 +449,7 @@ LUA_API int lua_yield (lua_State *L, int nresults) {
441 ci = L->ci; 449 ci = L->ci;
442 if (L->nCcalls > 0) 450 if (L->nCcalls > 0)
443 luaG_runerror(L, "attempt to yield across metamethod/C-call boundary"); 451 luaG_runerror(L, "attempt to yield across metamethod/C-call boundary");
444 if (!f_isLua(ci)) { /* usual yield */ 452 L->base = L->top - nresults; /* protect stack slots below */
445 if (L->top - nresults > L->base) { /* is there garbage in the stack? */
446 int i;
447 for (i=0; i<nresults; i++) /* move down results */
448 setobjs2s(L, L->base + i, L->top - nresults + i);
449 L->top = L->base + nresults;
450 }
451 } /* else it's an yield inside a hook: nothing to do */
452 L->status = LUA_YIELD; 453 L->status = LUA_YIELD;
453 lua_unlock(L); 454 lua_unlock(L);
454 return -1; 455 return -1;