diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2017-10-31 15:54:35 -0200 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2017-10-31 15:54:35 -0200 |
| commit | c5482468fde11c6c169da3b331a0653455f8fc94 (patch) | |
| tree | 2a48592c73f5a94f1615793d66cb7fcf1c5b8946 | |
| parent | ad5dcdcf0f1e139c8cc5b1aafd11db69f54010de (diff) | |
| download | lua-c5482468fde11c6c169da3b331a0653455f8fc94.tar.gz lua-c5482468fde11c6c169da3b331a0653455f8fc94.tar.bz2 lua-c5482468fde11c6c169da3b331a0653455f8fc94.zip | |
baby steps to remove 'CallInfo': keeping 'L->func' correct
| -rw-r--r-- | ldo.c | 14 | ||||
| -rw-r--r-- | lobject.h | 6 | ||||
| -rw-r--r-- | lstate.c | 9 | ||||
| -rw-r--r-- | lstate.h | 3 | ||||
| -rw-r--r-- | lvm.c | 3 |
5 files changed, 26 insertions, 9 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ldo.c,v 2.161 2017/06/29 15:06:44 roberto Exp roberto $ | 2 | ** $Id: ldo.c,v 2.162 2017/07/27 13:50:16 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 | */ |
| @@ -160,6 +160,7 @@ static void correctstack (lua_State *L, StkId oldstack) { | |||
| 160 | CallInfo *ci; | 160 | CallInfo *ci; |
| 161 | UpVal *up; | 161 | UpVal *up; |
| 162 | L->top = (L->top - oldstack) + L->stack; | 162 | L->top = (L->top - oldstack) + L->stack; |
| 163 | L->func = (L->func - oldstack) + L->stack; | ||
| 163 | for (up = L->openupval; up != NULL; up = up->u.open.next) | 164 | for (up = L->openupval; up != NULL; up = up->u.open.next) |
| 164 | up->v = s2v((uplevel(up) - oldstack) + L->stack); | 165 | up->v = s2v((uplevel(up) - oldstack) + L->stack); |
| 165 | for (ci = L->ci; ci != NULL; ci = ci->previous) { | 166 | for (ci = L->ci; ci != NULL; ci = ci->previous) { |
| @@ -369,6 +370,8 @@ int luaD_poscall (lua_State *L, CallInfo *ci, StkId firstResult, int nres) { | |||
| 369 | } | 370 | } |
| 370 | res = ci->func; /* res == final position of 1st result */ | 371 | res = ci->func; /* res == final position of 1st result */ |
| 371 | L->ci = ci->previous; /* back to caller */ | 372 | L->ci = ci->previous; /* back to caller */ |
| 373 | L->func -= L->func->stkci.previous; | ||
| 374 | lua_assert(L->func == L->ci->func); | ||
| 372 | /* move results to proper place */ | 375 | /* move results to proper place */ |
| 373 | return moveresults(L, firstResult, res, nres, wanted); | 376 | return moveresults(L, firstResult, res, nres, wanted); |
| 374 | } | 377 | } |
| @@ -400,7 +403,8 @@ int luaD_precall (lua_State *L, StkId func, int nresults) { | |||
| 400 | checkstackp(L, LUA_MINSTACK, func); /* ensure minimum stack size */ | 403 | checkstackp(L, LUA_MINSTACK, func); /* ensure minimum stack size */ |
| 401 | ci = next_ci(L); /* now 'enter' new function */ | 404 | ci = next_ci(L); /* now 'enter' new function */ |
| 402 | ci->nresults = nresults; | 405 | ci->nresults = nresults; |
| 403 | ci->func = func; | 406 | func->stkci.previous = func - L->func; |
| 407 | L->func = ci->func = func; | ||
| 404 | ci->top = L->top + LUA_MINSTACK; | 408 | ci->top = L->top + LUA_MINSTACK; |
| 405 | lua_assert(ci->top <= L->stack_last); | 409 | lua_assert(ci->top <= L->stack_last); |
| 406 | ci->callstatus = 0; | 410 | ci->callstatus = 0; |
| @@ -424,7 +428,8 @@ int luaD_precall (lua_State *L, StkId func, int nresults) { | |||
| 424 | luaT_adjustvarargs(L, p, n); | 428 | luaT_adjustvarargs(L, p, n); |
| 425 | ci = next_ci(L); /* now 'enter' new function */ | 429 | ci = next_ci(L); /* now 'enter' new function */ |
| 426 | ci->nresults = nresults; | 430 | ci->nresults = nresults; |
| 427 | ci->func = func; | 431 | func->stkci.previous = func - L->func; |
| 432 | L->func = ci->func = func; | ||
| 428 | L->top = ci->top = func + 1 + fsize; | 433 | L->top = ci->top = func + 1 + fsize; |
| 429 | lua_assert(ci->top <= L->stack_last); | 434 | lua_assert(ci->top <= L->stack_last); |
| 430 | ci->u.l.savedpc = p->code; /* starting point */ | 435 | ci->u.l.savedpc = p->code; /* starting point */ |
| @@ -558,6 +563,7 @@ static int recover (lua_State *L, int status) { | |||
| 558 | luaF_close(L, oldtop); | 563 | luaF_close(L, oldtop); |
| 559 | seterrorobj(L, status, oldtop); | 564 | seterrorobj(L, status, oldtop); |
| 560 | L->ci = ci; | 565 | L->ci = ci; |
| 566 | L->func = ci->func; | ||
| 561 | L->allowhook = getoah(ci->callstatus); /* restore original 'allowhook' */ | 567 | L->allowhook = getoah(ci->callstatus); /* restore original 'allowhook' */ |
| 562 | L->nny = 0; /* should be zero to be yieldable */ | 568 | L->nny = 0; /* should be zero to be yieldable */ |
| 563 | luaD_shrinkstack(L); | 569 | luaD_shrinkstack(L); |
| @@ -693,6 +699,7 @@ int luaD_pcall (lua_State *L, Pfunc func, void *u, | |||
| 693 | ptrdiff_t old_top, ptrdiff_t ef) { | 699 | ptrdiff_t old_top, ptrdiff_t ef) { |
| 694 | int status; | 700 | int status; |
| 695 | CallInfo *old_ci = L->ci; | 701 | CallInfo *old_ci = L->ci; |
| 702 | ptrdiff_t oldfunc = savestack(L, L->func); | ||
| 696 | lu_byte old_allowhooks = L->allowhook; | 703 | lu_byte old_allowhooks = L->allowhook; |
| 697 | unsigned short old_nny = L->nny; | 704 | unsigned short old_nny = L->nny; |
| 698 | ptrdiff_t old_errfunc = L->errfunc; | 705 | ptrdiff_t old_errfunc = L->errfunc; |
| @@ -703,6 +710,7 @@ int luaD_pcall (lua_State *L, Pfunc func, void *u, | |||
| 703 | luaF_close(L, oldtop); /* close possible pending closures */ | 710 | luaF_close(L, oldtop); /* close possible pending closures */ |
| 704 | seterrorobj(L, status, oldtop); | 711 | seterrorobj(L, status, oldtop); |
| 705 | L->ci = old_ci; | 712 | L->ci = old_ci; |
| 713 | L->func = restorestack(L, oldfunc); | ||
| 706 | L->allowhook = old_allowhooks; | 714 | L->allowhook = old_allowhooks; |
| 707 | L->nny = old_nny; | 715 | L->nny = old_nny; |
| 708 | luaD_shrinkstack(L); | 716 | luaD_shrinkstack(L); |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lobject.h,v 2.124 2017/06/27 11:35:31 roberto Exp roberto $ | 2 | ** $Id: lobject.h,v 2.125 2017/06/29 15:06:44 roberto Exp roberto $ |
| 3 | ** Type definitions for Lua objects | 3 | ** Type definitions for Lua objects |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -311,6 +311,10 @@ typedef struct TValue { | |||
| 311 | 311 | ||
| 312 | typedef union StackValue { | 312 | typedef union StackValue { |
| 313 | TValue val; | 313 | TValue val; |
| 314 | struct { | ||
| 315 | TValuefields; | ||
| 316 | unsigned short previous; /* difference to previous 'func' */ | ||
| 317 | } stkci; | ||
| 314 | } StackValue; | 318 | } StackValue; |
| 315 | 319 | ||
| 316 | 320 | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lstate.c,v 2.141 2017/06/29 15:06:44 roberto Exp roberto $ | 2 | ** $Id: lstate.c,v 2.142 2017/10/11 12:38:45 roberto Exp roberto $ |
| 3 | ** Global State | 3 | ** Global State |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -153,8 +153,10 @@ static void stack_init (lua_State *L1, lua_State *L) { | |||
| 153 | ci = &L1->base_ci; | 153 | ci = &L1->base_ci; |
| 154 | ci->next = ci->previous = NULL; | 154 | ci->next = ci->previous = NULL; |
| 155 | ci->callstatus = 0; | 155 | ci->callstatus = 0; |
| 156 | ci->func = L1->top; | 156 | L1->func = ci->func = L1->top; |
| 157 | setnilvalue(s2v(L1->top++)); /* 'function' entry for this 'ci' */ | 157 | L1->func->stkci.previous = 0; /* end of linked list */ |
| 158 | setnilvalue(s2v(L1->top)); /* 'function' entry for this 'ci' */ | ||
| 159 | L1->top++; | ||
| 158 | ci->top = L1->top + LUA_MINSTACK; | 160 | ci->top = L1->top + LUA_MINSTACK; |
| 159 | L1->ci = ci; | 161 | L1->ci = ci; |
| 160 | } | 162 | } |
| @@ -215,6 +217,7 @@ static void preinit_thread (lua_State *L, global_State *g) { | |||
| 215 | G(L) = g; | 217 | G(L) = g; |
| 216 | L->stack = NULL; | 218 | L->stack = NULL; |
| 217 | L->ci = NULL; | 219 | L->ci = NULL; |
| 220 | L->func = NULL; | ||
| 218 | L->nci = 0; | 221 | L->nci = 0; |
| 219 | L->stacksize = 0; | 222 | L->stacksize = 0; |
| 220 | L->twups = L; /* thread has no upvalues */ | 223 | L->twups = L; /* thread has no upvalues */ |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lstate.h,v 2.143 2017/06/12 14:21:44 roberto Exp roberto $ | 2 | ** $Id: lstate.h,v 2.144 2017/07/27 13:50:16 roberto Exp roberto $ |
| 3 | ** Global State | 3 | ** Global State |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -192,6 +192,7 @@ struct lua_State { | |||
| 192 | StkId top; /* first free slot in the stack */ | 192 | StkId top; /* first free slot in the stack */ |
| 193 | global_State *l_G; | 193 | global_State *l_G; |
| 194 | CallInfo *ci; /* call info for current function */ | 194 | CallInfo *ci; /* call info for current function */ |
| 195 | StkId func; /* current function */ | ||
| 195 | const Instruction *oldpc; /* last pc traced */ | 196 | const Instruction *oldpc; /* last pc traced */ |
| 196 | StkId stack_last; /* last free slot in the stack */ | 197 | StkId stack_last; /* last free slot in the stack */ |
| 197 | StkId stack; /* stack base */ | 198 | StkId stack; /* stack base */ |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lvm.c,v 2.298 2017/10/04 15:49:24 roberto Exp roberto $ | 2 | ** $Id: lvm.c,v 2.299 2017/10/04 21:56:32 roberto Exp roberto $ |
| 3 | ** Lua virtual machine | 3 | ** Lua virtual machine |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -1390,6 +1390,7 @@ void luaV_execute (lua_State *L) { | |||
| 1390 | oci->u.l.savedpc = nci->u.l.savedpc; | 1390 | oci->u.l.savedpc = nci->u.l.savedpc; |
| 1391 | oci->callstatus |= CIST_TAIL; /* function was tail called */ | 1391 | oci->callstatus |= CIST_TAIL; /* function was tail called */ |
| 1392 | ci = L->ci = oci; /* remove new frame */ | 1392 | ci = L->ci = oci; /* remove new frame */ |
| 1393 | L->func = ofunc; | ||
| 1393 | lua_assert(L->top == | 1394 | lua_assert(L->top == |
| 1394 | oci->func + 1 + getproto(s2v(ofunc))->maxstacksize); | 1395 | oci->func + 1 + getproto(s2v(ofunc))->maxstacksize); |
| 1395 | goto newframe; /* restart luaV_execute over new Lua function */ | 1396 | goto newframe; /* restart luaV_execute over new Lua function */ |
