aboutsummaryrefslogtreecommitdiff
path: root/ldo.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2002-08-07 16:22:39 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2002-08-07 16:22:39 -0300
commit5016f43aa439662ca35a5d78e820c617c517f60a (patch)
tree167aabeccb5a2307c3de7d20542ecf7d99769d3c /ldo.c
parentc1c100a0c04bc77623b32269f37df49e7a2457d2 (diff)
downloadlua-5016f43aa439662ca35a5d78e820c617c517f60a.tar.gz
lua-5016f43aa439662ca35a5d78e820c617c517f60a.tar.bz2
lua-5016f43aa439662ca35a5d78e820c617c517f60a.zip
(much) cleaner way to control function states
Diffstat (limited to 'ldo.c')
-rw-r--r--ldo.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/ldo.c b/ldo.c
index 85561e06..8f125372 100644
--- a/ldo.c
+++ b/ldo.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ldo.c,v 1.189 2002/08/05 17:36:24 roberto Exp roberto $ 2** $Id: ldo.c,v 1.190 2002/08/06 15:32:22 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*/
@@ -108,7 +108,7 @@ static void correctstack (lua_State *L, TObject *oldstack) {
108 for (ci = L->base_ci; ci <= L->ci; ci++) { 108 for (ci = L->base_ci; ci <= L->ci; ci++) {
109 ci->base = (ci->base - oldstack) + L->stack; 109 ci->base = (ci->base - oldstack) + L->stack;
110 ci->top = (ci->top - oldstack) + L->stack; 110 ci->top = (ci->top - oldstack) + L->stack;
111 if (ci->pc && ci->pc != &luaV_callingmark) /* function has a frame? */ 111 if (ci->state & CI_HASFRAME) /* Lua function with active frame? */
112 *ci->u.l.pb = (*ci->u.l.pb - oldstack) + L->stack; /* correct frame */ 112 *ci->u.l.pb = (*ci->u.l.pb - oldstack) + L->stack; /* correct frame */
113 } 113 }
114} 114}
@@ -229,6 +229,7 @@ StkId luaD_precall (lua_State *L, StkId func) {
229 ci->base = restorestack(L, funcr) + 1; 229 ci->base = restorestack(L, funcr) + 1;
230 ci->top = ci->base + p->maxstacksize; 230 ci->top = ci->base + p->maxstacksize;
231 ci->u.l.savedpc = p->code; /* starting point */ 231 ci->u.l.savedpc = p->code; /* starting point */
232 ci->state = CI_SAVEDPC;
232 while (L->top < ci->top) 233 while (L->top < ci->top)
233 setnilvalue(L->top++); 234 setnilvalue(L->top++);
234 L->top = ci->top; 235 L->top = ci->top;
@@ -241,7 +242,7 @@ StkId luaD_precall (lua_State *L, StkId func) {
241 ci = ++L->ci; /* now `enter' new function */ 242 ci = ++L->ci; /* now `enter' new function */
242 ci->base = restorestack(L, funcr) + 1; 243 ci->base = restorestack(L, funcr) + 1;
243 ci->top = L->top + LUA_MINSTACK; 244 ci->top = L->top + LUA_MINSTACK;
244 ci->pc = NULL; /* not a Lua function */ 245 ci->state = CI_C; /* a C function */
245 if (L->hookmask & LUA_MASKCALL) { 246 if (L->hookmask & LUA_MASKCALL) {
246 luaD_callhook(L, LUA_HOOKCALL, -1); 247 luaD_callhook(L, LUA_HOOKCALL, -1);
247 ci = L->ci; /* previous call may realocate `ci' */ 248 ci = L->ci; /* previous call may realocate `ci' */
@@ -300,7 +301,6 @@ void luaD_call (lua_State *L, StkId func, int nResults) {
300LUA_API void lua_cobegin (lua_State *L, int nargs) { 301LUA_API void lua_cobegin (lua_State *L, int nargs) {
301 lua_lock(L); 302 lua_lock(L);
302 luaD_precall(L, L->top - (nargs+1)); 303 luaD_precall(L, L->top - (nargs+1));
303 L->ci->pc = &luaV_callingmark; /* function is not active (yet) */
304 lua_unlock(L); 304 lua_unlock(L);
305} 305}
306 306
@@ -317,10 +317,10 @@ static void move_results (lua_State *L, TObject *from, TObject *to) {
317static void resume (lua_State *L, void *ud) { 317static void resume (lua_State *L, void *ud) {
318 StkId firstResult; 318 StkId firstResult;
319 CallInfo *ci = L->ci; 319 CallInfo *ci = L->ci;
320 if (ci->pc == NULL) { /* not first time? */ 320 if (ci->state & CI_C) { /* not first time (i.e. inside a yield)? */
321 /* finish interrupted execution of `OP_CALL' */ 321 /* finish interrupted execution of `OP_CALL' */
322 int nresults; 322 int nresults;
323 lua_assert((ci - 1)->pc == &luaV_callingmark); 323 lua_assert((ci-1)->state & CI_SAVEDPC);
324 lua_assert(GET_OPCODE(*((ci-1)->u.l.savedpc - 1)) == OP_CALL || 324 lua_assert(GET_OPCODE(*((ci-1)->u.l.savedpc - 1)) == OP_CALL ||
325 GET_OPCODE(*((ci-1)->u.l.savedpc - 1)) == OP_TAILCALL); 325 GET_OPCODE(*((ci-1)->u.l.savedpc - 1)) == OP_TAILCALL);
326 nresults = GETARG_C(*((ci-1)->u.l.savedpc - 1)) - 1; 326 nresults = GETARG_C(*((ci-1)->u.l.savedpc - 1)) - 1;
@@ -363,9 +363,9 @@ LUA_API int lua_yield (lua_State *L, int nresults) {
363 CallInfo *ci; 363 CallInfo *ci;
364 lua_lock(L); 364 lua_lock(L);
365 ci = L->ci; 365 ci = L->ci;
366 if ((ci-1)->pc == NULL) 366 if ((ci-1)->state & CI_C)
367 luaG_runerror(L, "cannot yield a C function"); 367 luaG_runerror(L, "cannot yield a C function");
368 lua_assert(ci->pc == NULL); /* current function is not Lua */ 368 lua_assert(ci->state & CI_C); /* current function is not Lua */
369 ci->u.c.yield_results = nresults; 369 ci->u.c.yield_results = nresults;
370 lua_unlock(L); 370 lua_unlock(L);
371 return -1; 371 return -1;