diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2009-04-17 19:00:01 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2009-04-17 19:00:01 -0300 |
commit | d3037d97ec192e7719de485f15dacb473bf96528 (patch) | |
tree | ea9f837cc64d9df82ae4324f2c7ea447b5c4582f /ldo.c | |
parent | c6b442bd369ce05b3d4bfb95ba64451521aa1b31 (diff) | |
download | lua-d3037d97ec192e7719de485f15dacb473bf96528.tar.gz lua-d3037d97ec192e7719de485f15dacb473bf96528.tar.bz2 lua-d3037d97ec192e7719de485f15dacb473bf96528.zip |
several small improvements based on 'ci' being fixed now (including
erasing savedpc from lua_State)
Diffstat (limited to 'ldo.c')
-rw-r--r-- | ldo.c | 52 |
1 files changed, 25 insertions, 27 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ldo.c,v 2.59 2009/04/15 16:53:39 roberto Exp roberto $ | 2 | ** $Id: ldo.c,v 2.60 2009/04/17 14:28:06 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 | */ |
@@ -151,28 +151,29 @@ void luaD_growstack (lua_State *L, int n) { | |||
151 | void luaD_callhook (lua_State *L, int event, int line) { | 151 | void luaD_callhook (lua_State *L, int event, int line) { |
152 | lua_Hook hook = L->hook; | 152 | lua_Hook hook = L->hook; |
153 | if (hook && L->allowhook) { | 153 | if (hook && L->allowhook) { |
154 | CallInfo *ci = L->ci; | ||
154 | ptrdiff_t top = savestack(L, L->top); | 155 | ptrdiff_t top = savestack(L, L->top); |
155 | ptrdiff_t ci_top = savestack(L, L->ci->top); | 156 | ptrdiff_t ci_top = savestack(L, ci->top); |
156 | lua_Debug ar; | 157 | lua_Debug ar; |
157 | ar.event = event; | 158 | ar.event = event; |
158 | ar.currentline = line; | 159 | ar.currentline = line; |
159 | if (event == LUA_HOOKTAILRET) | 160 | if (event == LUA_HOOKTAILRET) |
160 | ar.i_ci = NULL; /* tail call; no debug information about it */ | 161 | ar.i_ci = NULL; /* tail call; no debug information about it */ |
161 | else | 162 | else |
162 | ar.i_ci = L->ci; | 163 | ar.i_ci = ci; |
163 | luaD_checkstack(L, LUA_MINSTACK); /* ensure minimum stack size */ | 164 | luaD_checkstack(L, LUA_MINSTACK); /* ensure minimum stack size */ |
164 | L->ci->top = L->top + LUA_MINSTACK; | 165 | ci->top = L->top + LUA_MINSTACK; |
165 | lua_assert(L->ci->top <= L->stack_last); | 166 | lua_assert(ci->top <= L->stack_last); |
166 | L->allowhook = 0; /* cannot call hooks inside a hook */ | 167 | L->allowhook = 0; /* cannot call hooks inside a hook */ |
167 | L->ci->callstatus |= CIST_HOOKED; | 168 | ci->callstatus |= CIST_HOOKED; |
168 | lua_unlock(L); | 169 | lua_unlock(L); |
169 | (*hook)(L, &ar); | 170 | (*hook)(L, &ar); |
170 | lua_lock(L); | 171 | lua_lock(L); |
171 | lua_assert(!L->allowhook); | 172 | lua_assert(!L->allowhook); |
172 | L->allowhook = 1; | 173 | L->allowhook = 1; |
173 | L->ci->top = restorestack(L, ci_top); | 174 | ci->top = restorestack(L, ci_top); |
174 | L->top = restorestack(L, top); | 175 | L->top = restorestack(L, top); |
175 | L->ci->callstatus &= ~CIST_HOOKED; | 176 | ci->callstatus &= ~CIST_HOOKED; |
176 | } | 177 | } |
177 | } | 178 | } |
178 | 179 | ||
@@ -223,7 +224,6 @@ int luaD_precall (lua_State *L, StkId func, int nresults) { | |||
223 | func = tryfuncTM(L, func); /* check the `function' tag method */ | 224 | func = tryfuncTM(L, func); /* check the `function' tag method */ |
224 | funcr = savestack(L, func); | 225 | funcr = savestack(L, func); |
225 | cl = &clvalue(func)->l; | 226 | cl = &clvalue(func)->l; |
226 | L->ci->savedpc = L->savedpc; | ||
227 | L->ci->nresults = nresults; | 227 | L->ci->nresults = nresults; |
228 | if (!cl->isC) { /* Lua function? prepare its call */ | 228 | if (!cl->isC) { /* Lua function? prepare its call */ |
229 | CallInfo *ci; | 229 | CallInfo *ci; |
@@ -243,16 +243,16 @@ int luaD_precall (lua_State *L, StkId func, int nresults) { | |||
243 | L->base = ci->base = base; | 243 | L->base = ci->base = base; |
244 | ci->top = L->base + p->maxstacksize; | 244 | ci->top = L->base + p->maxstacksize; |
245 | lua_assert(ci->top <= L->stack_last); | 245 | lua_assert(ci->top <= L->stack_last); |
246 | L->savedpc = p->code; /* starting point */ | 246 | ci->u.l.savedpc = p->code; /* starting point */ |
247 | ci->u.l.tailcalls = 0; | 247 | ci->u.l.tailcalls = 0; |
248 | ci->callstatus = CIST_LUA; | 248 | ci->callstatus = CIST_LUA; |
249 | for (st = L->top; st < ci->top; st++) | 249 | for (st = L->top; st < ci->top; st++) |
250 | setnilvalue(st); | 250 | setnilvalue(st); |
251 | L->top = ci->top; | 251 | L->top = ci->top; |
252 | if (L->hookmask & LUA_MASKCALL) { | 252 | if (L->hookmask & LUA_MASKCALL) { |
253 | L->savedpc++; /* hooks assume 'pc' is already incremented */ | 253 | ci->u.l.savedpc++; /* hooks assume 'pc' is already incremented */ |
254 | luaD_callhook(L, LUA_HOOKCALL, -1); | 254 | luaD_callhook(L, LUA_HOOKCALL, -1); |
255 | L->savedpc--; /* correct 'pc' */ | 255 | ci->u.l.savedpc--; /* correct 'pc' */ |
256 | } | 256 | } |
257 | return 0; | 257 | return 0; |
258 | } | 258 | } |
@@ -295,13 +295,12 @@ int luaD_poscall (lua_State *L, StkId firstResult) { | |||
295 | if (L->hookmask & (LUA_MASKRET | LUA_MASKLINE)) { | 295 | if (L->hookmask & (LUA_MASKRET | LUA_MASKLINE)) { |
296 | if (L->hookmask & LUA_MASKRET) | 296 | if (L->hookmask & LUA_MASKRET) |
297 | firstResult = callrethooks(L, firstResult); | 297 | firstResult = callrethooks(L, firstResult); |
298 | L->oldpc = L->ci->previous->savedpc; /* 'oldpc' for returning function */ | 298 | L->oldpc = ci->previous->u.l.savedpc; /* 'oldpc' for returning function */ |
299 | } | 299 | } |
300 | res = ci->func; /* res == final position of 1st result */ | 300 | res = ci->func; /* res == final position of 1st result */ |
301 | L->ci = ci = L->ci->previous; /* back to caller */ | 301 | L->ci = ci = ci->previous; /* back to caller */ |
302 | wanted = ci->nresults; | 302 | wanted = ci->nresults; |
303 | L->base = ci->base; /* restore base */ | 303 | L->base = ci->base; /* restore base */ |
304 | L->savedpc = ci->savedpc; /* restore savedpc */ | ||
305 | /* move results to correct place */ | 304 | /* move results to correct place */ |
306 | for (i = wanted; i != 0 && firstResult < L->top; i--) | 305 | for (i = wanted; i != 0 && firstResult < L->top; i--) |
307 | setobjs2s(L, res++, firstResult++); | 306 | setobjs2s(L, res++, firstResult++); |
@@ -336,21 +335,21 @@ void luaD_call (lua_State *L, StkId func, int nResults, int allowyield) { | |||
336 | 335 | ||
337 | 336 | ||
338 | static void finishCcall (lua_State *L) { | 337 | static void finishCcall (lua_State *L) { |
338 | CallInfo *ci = L->ci; | ||
339 | int n; | 339 | int n; |
340 | lua_assert(L->ci->u.c.k != NULL); /* must have a continuation */ | 340 | lua_assert(ci->u.c.k != NULL); /* must have a continuation */ |
341 | lua_assert(L->nny == 0); | 341 | lua_assert(L->nny == 0); |
342 | /* finish 'luaD_call' */ | 342 | /* finish 'luaD_call' */ |
343 | G(L)->nCcalls--; | 343 | G(L)->nCcalls--; |
344 | /* finish 'lua_callk' */ | 344 | /* finish 'lua_callk' */ |
345 | adjustresults(L, L->ci->nresults); | 345 | adjustresults(L, ci->nresults); |
346 | /* call continuation function */ | 346 | /* call continuation function */ |
347 | if (!(L->ci->callstatus & CIST_STAT)) /* no call status? */ | 347 | if (!(ci->callstatus & CIST_STAT)) /* no call status? */ |
348 | L->ci->u.c.status = LUA_YIELD; /* 'default' status */ | 348 | ci->u.c.status = LUA_YIELD; /* 'default' status */ |
349 | lua_assert(L->ci->u.c.status != LUA_OK); | 349 | lua_assert(ci->u.c.status != LUA_OK); |
350 | L->ci->callstatus = (L->ci->callstatus & ~(CIST_YPCALL | CIST_STAT)) | 350 | ci->callstatus = (ci->callstatus & ~(CIST_YPCALL | CIST_STAT)) | CIST_YIELDED; |
351 | | CIST_YIELDED; | ||
352 | lua_unlock(L); | 351 | lua_unlock(L); |
353 | n = (*L->ci->u.c.k)(L); | 352 | n = (*ci->u.c.k)(L); |
354 | lua_lock(L); | 353 | lua_lock(L); |
355 | /* finish 'luaD_precall' */ | 354 | /* finish 'luaD_precall' */ |
356 | luaD_poscall(L, L->top - n); | 355 | luaD_poscall(L, L->top - n); |
@@ -384,7 +383,7 @@ static void resume (lua_State *L, void *ud) { | |||
384 | lua_assert(L->status == LUA_YIELD); | 383 | lua_assert(L->status == LUA_YIELD); |
385 | L->status = LUA_OK; | 384 | L->status = LUA_OK; |
386 | if (isLua(ci)) { /* yielded inside a hook? */ | 385 | if (isLua(ci)) { /* yielded inside a hook? */ |
387 | L->base = L->ci->base; /* just continue its execution */ | 386 | L->base = ci->base; /* just continue its execution */ |
388 | luaV_execute(L); | 387 | luaV_execute(L); |
389 | } | 388 | } |
390 | else { /* 'common' yield */ | 389 | else { /* 'common' yield */ |
@@ -427,7 +426,7 @@ static int recover (lua_State *L, int status) { | |||
427 | luaF_close(L, oldtop); | 426 | luaF_close(L, oldtop); |
428 | luaD_seterrorobj(L, status, oldtop); | 427 | luaD_seterrorobj(L, status, oldtop); |
429 | L->ci = ci; | 428 | L->ci = ci; |
430 | L->base = L->ci->base; | 429 | L->base = ci->base; |
431 | L->allowhook = ci->u.c.old_allowhook; | 430 | L->allowhook = ci->u.c.old_allowhook; |
432 | L->nny = 0; /* should be zero to be yieldable */ | 431 | L->nny = 0; /* should be zero to be yieldable */ |
433 | restore_stack_limit(L); | 432 | restore_stack_limit(L); |
@@ -499,8 +498,7 @@ int luaD_pcall (lua_State *L, Pfunc func, void *u, | |||
499 | luaF_close(L, oldtop); /* close possible pending closures */ | 498 | luaF_close(L, oldtop); /* close possible pending closures */ |
500 | luaD_seterrorobj(L, status, oldtop); | 499 | luaD_seterrorobj(L, status, oldtop); |
501 | L->ci = old_ci; | 500 | L->ci = old_ci; |
502 | L->base = L->ci->base; | 501 | L->base = old_ci->base; |
503 | L->savedpc = L->ci->savedpc; | ||
504 | L->allowhook = old_allowhooks; | 502 | L->allowhook = old_allowhooks; |
505 | L->nny = old_nny; | 503 | L->nny = old_nny; |
506 | restore_stack_limit(L); | 504 | restore_stack_limit(L); |