diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2009-06-01 16:09:26 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2009-06-01 16:09:26 -0300 |
| commit | 9423e22aa35f47b392fc52a1b93c1be4c69f2aee (patch) | |
| tree | 4d466663bc69a342941ea9830b17014aa76acfb2 /ldo.c | |
| parent | 57f8414de1968b6f9f212140f2da14cba3b6dacb (diff) | |
| download | lua-9423e22aa35f47b392fc52a1b93c1be4c69f2aee.tar.gz lua-9423e22aa35f47b392fc52a1b93c1be4c69f2aee.tar.bz2 lua-9423e22aa35f47b392fc52a1b93c1be4c69f2aee.zip | |
no more L->base + ci->base only for Lua functions (C functions may use
'func')
Diffstat (limited to 'ldo.c')
| -rw-r--r-- | ldo.c | 27 |
1 files changed, 11 insertions, 16 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ldo.c,v 2.63 2009/04/28 19:04:36 roberto Exp roberto $ | 2 | ** $Id: ldo.c,v 2.64 2009/05/21 20:06:11 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 | */ |
| @@ -123,10 +123,10 @@ static void correctstack (lua_State *L, TValue *oldstack) { | |||
| 123 | gco2uv(up)->v = (gco2uv(up)->v - oldstack) + L->stack; | 123 | gco2uv(up)->v = (gco2uv(up)->v - oldstack) + L->stack; |
| 124 | for (ci = L->ci; ci != NULL; ci = ci->previous) { | 124 | for (ci = L->ci; ci != NULL; ci = ci->previous) { |
| 125 | ci->top = (ci->top - oldstack) + L->stack; | 125 | ci->top = (ci->top - oldstack) + L->stack; |
| 126 | ci->base = (ci->base - oldstack) + L->stack; | ||
| 127 | ci->func = (ci->func - oldstack) + L->stack; | 126 | ci->func = (ci->func - oldstack) + L->stack; |
| 127 | if (isLua(ci)) | ||
| 128 | ci->u.l.base = (ci->u.l.base - oldstack) + L->stack; | ||
| 128 | } | 129 | } |
| 129 | L->base = (L->base - oldstack) + L->stack; | ||
| 130 | } | 130 | } |
| 131 | 131 | ||
| 132 | 132 | ||
| @@ -245,8 +245,8 @@ int luaD_precall (lua_State *L, StkId func, int nresults) { | |||
| 245 | base = adjust_varargs(L, p, nargs); | 245 | base = adjust_varargs(L, p, nargs); |
| 246 | ci = next_ci(L); /* now 'enter' new function */ | 246 | ci = next_ci(L); /* now 'enter' new function */ |
| 247 | ci->func = func; | 247 | ci->func = func; |
| 248 | L->base = ci->base = base; | 248 | ci->u.l.base = base; |
| 249 | ci->top = L->base + p->maxstacksize; | 249 | ci->top = base + p->maxstacksize; |
| 250 | lua_assert(ci->top <= L->stack_last); | 250 | lua_assert(ci->top <= L->stack_last); |
| 251 | ci->u.l.savedpc = p->code; /* starting point */ | 251 | ci->u.l.savedpc = p->code; /* starting point */ |
| 252 | ci->u.l.tailcalls = 0; | 252 | ci->u.l.tailcalls = 0; |
| @@ -265,7 +265,6 @@ int luaD_precall (lua_State *L, StkId func, int nresults) { | |||
| 265 | luaD_checkstack(L, LUA_MINSTACK); /* ensure minimum stack size */ | 265 | luaD_checkstack(L, LUA_MINSTACK); /* ensure minimum stack size */ |
| 266 | ci = next_ci(L); /* now 'enter' new function */ | 266 | ci = next_ci(L); /* now 'enter' new function */ |
| 267 | ci->func = restorestack(L, funcr); | 267 | ci->func = restorestack(L, funcr); |
| 268 | L->base = ci->base = ci->func + 1; | ||
| 269 | ci->top = L->top + LUA_MINSTACK; | 268 | ci->top = L->top + LUA_MINSTACK; |
| 270 | lua_assert(ci->top <= L->stack_last); | 269 | lua_assert(ci->top <= L->stack_last); |
| 271 | ci->callstatus = 0; | 270 | ci->callstatus = 0; |
| @@ -303,7 +302,6 @@ int luaD_poscall (lua_State *L, StkId firstResult) { | |||
| 303 | res = ci->func; /* res == final position of 1st result */ | 302 | res = ci->func; /* res == final position of 1st result */ |
| 304 | L->ci = ci = ci->previous; /* back to caller */ | 303 | L->ci = ci = ci->previous; /* back to caller */ |
| 305 | wanted = ci->nresults; | 304 | wanted = ci->nresults; |
| 306 | L->base = ci->base; /* restore base */ | ||
| 307 | /* move results to correct place */ | 305 | /* move results to correct place */ |
| 308 | for (i = wanted; i != 0 && firstResult < L->top; i--) | 306 | for (i = wanted; i != 0 && firstResult < L->top; i--) |
| 309 | setobjs2s(L, res++, firstResult++); | 307 | setobjs2s(L, res++, firstResult++); |
| @@ -378,17 +376,15 @@ static void resume (lua_State *L, void *ud) { | |||
| 378 | StkId firstArg = cast(StkId, ud); | 376 | StkId firstArg = cast(StkId, ud); |
| 379 | CallInfo *ci = L->ci; | 377 | CallInfo *ci = L->ci; |
| 380 | if (L->status == LUA_OK) { /* start coroutine? */ | 378 | if (L->status == LUA_OK) { /* start coroutine? */ |
| 381 | lua_assert(ci == &L->base_ci && firstArg > L->base); | 379 | lua_assert(ci == &L->base_ci); |
| 382 | if (!luaD_precall(L, firstArg - 1, LUA_MULTRET)) /* Lua function? */ | 380 | if (!luaD_precall(L, firstArg - 1, LUA_MULTRET)) /* Lua function? */ |
| 383 | luaV_execute(L); /* call it */ | 381 | luaV_execute(L); /* call it */ |
| 384 | } | 382 | } |
| 385 | else { /* resuming from previous yield */ | 383 | else { /* resuming from previous yield */ |
| 386 | lua_assert(L->status == LUA_YIELD); | 384 | lua_assert(L->status == LUA_YIELD); |
| 387 | L->status = LUA_OK; | 385 | L->status = LUA_OK; |
| 388 | if (isLua(ci)) { /* yielded inside a hook? */ | 386 | if (isLua(ci)) /* yielded inside a hook? */ |
| 389 | L->base = ci->base; /* just continue its execution */ | ||
| 390 | luaV_execute(L); | 387 | luaV_execute(L); |
| 391 | } | ||
| 392 | else { /* 'common' yield */ | 388 | else { /* 'common' yield */ |
| 393 | G(L)->nCcalls--; /* finish 'luaD_call' */ | 389 | G(L)->nCcalls--; /* finish 'luaD_call' */ |
| 394 | luaD_poscall(L, firstArg); /* finish 'luaD_precall' */ | 390 | luaD_poscall(L, firstArg); /* finish 'luaD_precall' */ |
| @@ -399,7 +395,7 @@ static void resume (lua_State *L, void *ud) { | |||
| 399 | 395 | ||
| 400 | 396 | ||
| 401 | static int resume_error (lua_State *L, const char *msg) { | 397 | static int resume_error (lua_State *L, const char *msg) { |
| 402 | L->top = L->ci->base; | 398 | L->top = L->ci->func + 1; |
| 403 | setsvalue2s(L, L->top, luaS_new(L, msg)); | 399 | setsvalue2s(L, L->top, luaS_new(L, msg)); |
| 404 | incr_top(L); | 400 | incr_top(L); |
| 405 | lua_unlock(L); | 401 | lua_unlock(L); |
| @@ -429,7 +425,6 @@ static int recover (lua_State *L, int status) { | |||
| 429 | luaF_close(L, oldtop); | 425 | luaF_close(L, oldtop); |
| 430 | luaD_seterrorobj(L, status, oldtop); | 426 | luaD_seterrorobj(L, status, oldtop); |
| 431 | L->ci = ci; | 427 | L->ci = ci; |
| 432 | L->base = ci->base; | ||
| 433 | L->allowhook = ci->u.c.old_allowhook; | 428 | L->allowhook = ci->u.c.old_allowhook; |
| 434 | L->nny = 0; /* should be zero to be yieldable */ | 429 | L->nny = 0; /* should be zero to be yieldable */ |
| 435 | restore_stack_limit(L); | 430 | restore_stack_limit(L); |
| @@ -477,10 +472,11 @@ LUA_API int lua_yield (lua_State *L, int nresults) { | |||
| 477 | lua_lock(L); | 472 | lua_lock(L); |
| 478 | if (L->nny > 0) | 473 | if (L->nny > 0) |
| 479 | luaG_runerror(L, "attempt to yield across metamethod/C-call boundary"); | 474 | luaG_runerror(L, "attempt to yield across metamethod/C-call boundary"); |
| 480 | L->base = L->top - nresults; /* protect stack slots below */ | ||
| 481 | L->status = LUA_YIELD; | 475 | L->status = LUA_YIELD; |
| 482 | if (!isLua(L->ci)) /* not inside a hook? */ | 476 | if (!isLua(L->ci)) { /* not inside a hook? */ |
| 477 | L->ci->func = L->top - nresults - 1; /* protect stack slots below ??? */ | ||
| 483 | luaD_throw(L, LUA_YIELD); | 478 | luaD_throw(L, LUA_YIELD); |
| 479 | } | ||
| 484 | lua_assert(L->ci->callstatus & CIST_HOOKED); /* must be inside a hook */ | 480 | lua_assert(L->ci->callstatus & CIST_HOOKED); /* must be inside a hook */ |
| 485 | lua_unlock(L); | 481 | lua_unlock(L); |
| 486 | return 0; /* otherwise, return to 'luaD_callhook' */ | 482 | return 0; /* otherwise, return to 'luaD_callhook' */ |
| @@ -501,7 +497,6 @@ int luaD_pcall (lua_State *L, Pfunc func, void *u, | |||
| 501 | luaF_close(L, oldtop); /* close possible pending closures */ | 497 | luaF_close(L, oldtop); /* close possible pending closures */ |
| 502 | luaD_seterrorobj(L, status, oldtop); | 498 | luaD_seterrorobj(L, status, oldtop); |
| 503 | L->ci = old_ci; | 499 | L->ci = old_ci; |
| 504 | L->base = old_ci->base; | ||
| 505 | L->allowhook = old_allowhooks; | 500 | L->allowhook = old_allowhooks; |
| 506 | L->nny = old_nny; | 501 | L->nny = old_nny; |
| 507 | restore_stack_limit(L); | 502 | restore_stack_limit(L); |
