aboutsummaryrefslogtreecommitdiff
path: root/ldo.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2008-08-26 10:27:42 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2008-08-26 10:27:42 -0300
commitf94cd2201c3a8d341db448f2719dfb0ae4338adf (patch)
tree34f49a3e607098699b1f9e3af9358c062ec8425e /ldo.c
parentfdbb243ff9980870c54676f3b2597b110ab82864 (diff)
downloadlua-f94cd2201c3a8d341db448f2719dfb0ae4338adf.tar.gz
lua-f94cd2201c3a8d341db448f2719dfb0ae4338adf.tar.bz2
lua-f94cd2201c3a8d341db448f2719dfb0ae4338adf.zip
better control of call status through CallInfo
Diffstat (limited to 'ldo.c')
-rw-r--r--ldo.c19
1 files changed, 10 insertions, 9 deletions
diff --git a/ldo.c b/ldo.c
index c984dd09..6df778bc 100644
--- a/ldo.c
+++ b/ldo.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ldo.c,v 2.46 2008/01/18 22:36:50 roberto Exp roberto $ 2** $Id: ldo.c,v 2.47 2008/08/13 17:02:42 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*/
@@ -193,9 +193,9 @@ void luaD_callhook (lua_State *L, int event, int line) {
193 ar.i_ci = cast_int(L->ci - L->base_ci); 193 ar.i_ci = cast_int(L->ci - L->base_ci);
194 luaD_checkstack(L, LUA_MINSTACK); /* ensure minimum stack size */ 194 luaD_checkstack(L, LUA_MINSTACK); /* ensure minimum stack size */
195 L->ci->top = L->top + LUA_MINSTACK; 195 L->ci->top = L->top + LUA_MINSTACK;
196 L->ci->status |= 1; /* this level is running a hook */
197 lua_assert(L->ci->top <= L->stack_last); 196 lua_assert(L->ci->top <= L->stack_last);
198 L->allowhook = 0; /* cannot call hooks inside a hook */ 197 L->allowhook = 0; /* cannot call hooks inside a hook */
198 L->ci->callstatus |= CIST_HOOKED;
199 lua_unlock(L); 199 lua_unlock(L);
200 (*hook)(L, &ar); 200 (*hook)(L, &ar);
201 lua_lock(L); 201 lua_lock(L);
@@ -203,7 +203,7 @@ void luaD_callhook (lua_State *L, int event, int line) {
203 L->allowhook = 1; 203 L->allowhook = 1;
204 L->ci->top = restorestack(L, ci_top); 204 L->ci->top = restorestack(L, ci_top);
205 L->top = restorestack(L, top); 205 L->top = restorestack(L, top);
206 L->ci->status &= ~1; /* this level is not running a hook anymore */ 206 L->ci->callstatus &= ~CIST_HOOKED;
207 } 207 }
208} 208}
209 209
@@ -297,7 +297,7 @@ int luaD_precall (lua_State *L, StkId func, int nresults) {
297 lua_assert(ci->top <= L->stack_last); 297 lua_assert(ci->top <= L->stack_last);
298 L->savedpc = p->code; /* starting point */ 298 L->savedpc = p->code; /* starting point */
299 ci->tailcalls = 0; 299 ci->tailcalls = 0;
300 ci->status = 0; 300 ci->callstatus = CIST_LUA;
301 ci->nresults = nresults; 301 ci->nresults = nresults;
302 for (st = L->top; st < ci->top; st++) 302 for (st = L->top; st < ci->top; st++)
303 setnilvalue(st); 303 setnilvalue(st);
@@ -319,6 +319,7 @@ int luaD_precall (lua_State *L, StkId func, int nresults) {
319 ci->top = L->top + LUA_MINSTACK; 319 ci->top = L->top + LUA_MINSTACK;
320 lua_assert(ci->top <= L->stack_last); 320 lua_assert(ci->top <= L->stack_last);
321 ci->nresults = nresults; 321 ci->nresults = nresults;
322 ci->callstatus = 0;
322 if (L->hookmask & LUA_MASKCALL) 323 if (L->hookmask & LUA_MASKCALL)
323 luaD_callhook(L, LUA_HOOKCALL, -1); 324 luaD_callhook(L, LUA_HOOKCALL, -1);
324 lua_unlock(L); 325 lua_unlock(L);
@@ -333,7 +334,7 @@ int luaD_precall (lua_State *L, StkId func, int nresults) {
333static StkId callrethooks (lua_State *L, StkId firstResult) { 334static StkId callrethooks (lua_State *L, StkId firstResult) {
334 ptrdiff_t fr = savestack(L, firstResult); /* next call may change stack */ 335 ptrdiff_t fr = savestack(L, firstResult); /* next call may change stack */
335 luaD_callhook(L, LUA_HOOKRET, -1); 336 luaD_callhook(L, LUA_HOOKRET, -1);
336 if (f_isLua(L->ci)) { /* Lua function? */ 337 if (isLua(L->ci)) { /* Lua function? */
337 while ((L->hookmask & LUA_MASKRET) && L->ci->tailcalls--) /* tail calls */ 338 while ((L->hookmask & LUA_MASKRET) && L->ci->tailcalls--) /* tail calls */
338 luaD_callhook(L, LUA_HOOKTAILRET, -1); 339 luaD_callhook(L, LUA_HOOKTAILRET, -1);
339 } 340 }
@@ -381,7 +382,7 @@ void luaD_call (lua_State *L, StkId func, int nResults) {
381 luaD_throw(L, LUA_ERRERR); /* error while handing stack error */ 382 luaD_throw(L, LUA_ERRERR); /* error while handing stack error */
382 } 383 }
383 if (!luaD_precall(L, func, nResults)) /* is a Lua function? */ 384 if (!luaD_precall(L, func, nResults)) /* is a Lua function? */
384 luaV_execute(L, 1); /* call it */ 385 luaV_execute(L); /* call it */
385 g->nCcalls--; 386 g->nCcalls--;
386 luaC_checkGC(L); 387 luaC_checkGC(L);
387} 388}
@@ -398,7 +399,7 @@ static void resume (lua_State *L, void *ud) {
398 else { /* resuming from previous yield */ 399 else { /* resuming from previous yield */
399 lua_assert(L->status == LUA_YIELD); 400 lua_assert(L->status == LUA_YIELD);
400 L->status = LUA_OK; 401 L->status = LUA_OK;
401 if (!f_isLua(ci)) { /* `common' yield? */ 402 if (!isLua(ci)) { /* `common' yield? */
402 /* finish interrupted execution of `OP_CALL' */ 403 /* finish interrupted execution of `OP_CALL' */
403 lua_assert(GET_OPCODE(*((ci-1)->savedpc - 1)) == OP_CALL || 404 lua_assert(GET_OPCODE(*((ci-1)->savedpc - 1)) == OP_CALL ||
404 GET_OPCODE(*((ci-1)->savedpc - 1)) == OP_TAILCALL); 405 GET_OPCODE(*((ci-1)->savedpc - 1)) == OP_TAILCALL);
@@ -408,7 +409,7 @@ static void resume (lua_State *L, void *ud) {
408 else /* yielded inside a hook: just continue its execution */ 409 else /* yielded inside a hook: just continue its execution */
409 L->base = L->ci->base; 410 L->base = L->ci->base;
410 } 411 }
411 luaV_execute(L, cast_int(L->ci - L->base_ci)); 412 luaV_execute(L);
412} 413}
413 414
414 415
@@ -461,7 +462,7 @@ LUA_API int lua_yield (lua_State *L, int nresults) {
461 L->status = LUA_YIELD; 462 L->status = LUA_YIELD;
462 if (!isLua(L->ci)) /* not inside a hook? */ 463 if (!isLua(L->ci)) /* not inside a hook? */
463 luaD_throw(L, LUA_YIELD); 464 luaD_throw(L, LUA_YIELD);
464 lua_assert(L->ci->status & 1); /* must be inside a hook */ 465 lua_assert(L->ci->callstatus & CIST_HOOKED); /* must be inside a hook */
465 lua_unlock(L); 466 lua_unlock(L);
466 return 0; /* otherwise, return to 'luaD_callhook' */ 467 return 0; /* otherwise, return to 'luaD_callhook' */
467} 468}