diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2002-11-21 13:16:04 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2002-11-21 13:16:04 -0200 |
commit | ddc144e4d297e5e008f5693a568a1c74ac3e4f54 (patch) | |
tree | 273211ca4e0add6f5aa9e28b494e94d3267fbcc3 /ldo.c | |
parent | b48c6e768035a44ced1af0affa4b8c0970f1bdfd (diff) | |
download | lua-ddc144e4d297e5e008f5693a568a1c74ac3e4f54.tar.gz lua-ddc144e4d297e5e008f5693a568a1c74ac3e4f54.tar.bz2 lua-ddc144e4d297e5e008f5693a568a1c74ac3e4f54.zip |
keep L->ci->base in L->base for faster access
Diffstat (limited to 'ldo.c')
-rw-r--r-- | ldo.c | 28 |
1 files changed, 16 insertions, 12 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ldo.c,v 1.203 2002/11/18 15:24:11 roberto Exp roberto $ | 2 | ** $Id: ldo.c,v 1.204 2002/11/18 18:45:38 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 | */ |
@@ -115,6 +115,7 @@ static void correctstack (lua_State *L, TObject *oldstack) { | |||
115 | } | 115 | } |
116 | ci->base = newbase; | 116 | ci->base = newbase; |
117 | } | 117 | } |
118 | L->base = L->ci->base; | ||
118 | } | 119 | } |
119 | 120 | ||
120 | 121 | ||
@@ -230,8 +231,8 @@ StkId luaD_precall (lua_State *L, StkId func) { | |||
230 | adjust_varargs(L, p->numparams, func+1); | 231 | adjust_varargs(L, p->numparams, func+1); |
231 | luaD_checkstack(L, p->maxstacksize); | 232 | luaD_checkstack(L, p->maxstacksize); |
232 | ci = ++L->ci; /* now `enter' new function */ | 233 | ci = ++L->ci; /* now `enter' new function */ |
233 | ci->base = restorestack(L, funcr) + 1; | 234 | L->base = L->ci->base = restorestack(L, funcr) + 1; |
234 | ci->top = ci->base + p->maxstacksize; | 235 | ci->top = L->base + p->maxstacksize; |
235 | ci->u.l.savedpc = p->code; /* starting point */ | 236 | ci->u.l.savedpc = p->code; /* starting point */ |
236 | ci->state = CI_SAVEDPC; | 237 | ci->state = CI_SAVEDPC; |
237 | while (L->top < ci->top) | 238 | while (L->top < ci->top) |
@@ -244,7 +245,7 @@ StkId luaD_precall (lua_State *L, StkId func) { | |||
244 | int n; | 245 | int n; |
245 | luaD_checkstack(L, LUA_MINSTACK); /* ensure minimum stack size */ | 246 | luaD_checkstack(L, LUA_MINSTACK); /* ensure minimum stack size */ |
246 | ci = ++L->ci; /* now `enter' new function */ | 247 | ci = ++L->ci; /* now `enter' new function */ |
247 | ci->base = restorestack(L, funcr) + 1; | 248 | L->base = L->ci->base = restorestack(L, funcr) + 1; |
248 | ci->top = L->top + LUA_MINSTACK; | 249 | ci->top = L->top + LUA_MINSTACK; |
249 | ci->state = CI_C; /* a C function */ | 250 | ci->state = CI_C; /* a C function */ |
250 | if (L->hookmask & LUA_MASKCALL) { | 251 | if (L->hookmask & LUA_MASKCALL) { |
@@ -255,7 +256,7 @@ StkId luaD_precall (lua_State *L, StkId func) { | |||
255 | #ifdef LUA_COMPATUPVALUES | 256 | #ifdef LUA_COMPATUPVALUES |
256 | lua_pushupvalues(L); | 257 | lua_pushupvalues(L); |
257 | #endif | 258 | #endif |
258 | n = (*clvalue(ci->base-1)->c.f)(L); /* do the actual call */ | 259 | n = (*clvalue(L->base - 1)->c.f)(L); /* do the actual call */ |
259 | lua_lock(L); | 260 | lua_lock(L); |
260 | return L->top - n; | 261 | return L->top - n; |
261 | } | 262 | } |
@@ -269,8 +270,9 @@ void luaD_poscall (lua_State *L, int wanted, StkId firstResult) { | |||
269 | luaD_callhook(L, LUA_HOOKRET, -1); | 270 | luaD_callhook(L, LUA_HOOKRET, -1); |
270 | firstResult = restorestack(L, fr); | 271 | firstResult = restorestack(L, fr); |
271 | } | 272 | } |
272 | res = L->ci->base - 1; /* res == final position of 1st result */ | 273 | res = L->base - 1; /* res == final position of 1st result */ |
273 | L->ci--; | 274 | L->ci--; |
275 | L->base = L->ci->base; /* restore base */ | ||
274 | /* move results to correct place */ | 276 | /* move results to correct place */ |
275 | while (wanted != 0 && firstResult < L->top) { | 277 | while (wanted != 0 && firstResult < L->top) { |
276 | setobjs2s(res++, firstResult++); | 278 | setobjs2s(res++, firstResult++); |
@@ -307,7 +309,7 @@ static void resume (lua_State *L, void *ud) { | |||
307 | int nargs = *cast(int *, ud); | 309 | int nargs = *cast(int *, ud); |
308 | CallInfo *ci = L->ci; | 310 | CallInfo *ci = L->ci; |
309 | if (ci == L->base_ci) { /* no activation record? */ | 311 | if (ci == L->base_ci) { /* no activation record? */ |
310 | if (nargs >= L->top - L->ci->base) | 312 | if (nargs >= L->top - L->base) |
311 | luaG_runerror(L, "cannot resume dead coroutine"); | 313 | luaG_runerror(L, "cannot resume dead coroutine"); |
312 | luaD_precall(L, L->top - (nargs + 1)); /* start coroutine */ | 314 | luaD_precall(L, L->top - (nargs + 1)); /* start coroutine */ |
313 | } | 315 | } |
@@ -343,8 +345,9 @@ LUA_API int lua_resume (lua_State *L, int nargs) { | |||
343 | status = luaD_rawrunprotected(L, resume, &nargs); | 345 | status = luaD_rawrunprotected(L, resume, &nargs); |
344 | if (status != 0) { /* error? */ | 346 | if (status != 0) { /* error? */ |
345 | L->ci = L->base_ci; /* go back to initial level */ | 347 | L->ci = L->base_ci; /* go back to initial level */ |
346 | luaF_close(L, L->ci->base); /* close eventual pending closures */ | 348 | L->base = L->ci->base; |
347 | seterrorobj(L, status, L->ci->base); | 349 | luaF_close(L, L->base); /* close eventual pending closures */ |
350 | seterrorobj(L, status, L->base); | ||
348 | L->allowhook = old_allowhooks; | 351 | L->allowhook = old_allowhooks; |
349 | restore_stack_limit(L); | 352 | restore_stack_limit(L); |
350 | } | 353 | } |
@@ -360,11 +363,11 @@ LUA_API int lua_yield (lua_State *L, int nresults) { | |||
360 | if (ci->state & CI_C) { /* usual yield */ | 363 | if (ci->state & CI_C) { /* usual yield */ |
361 | if ((ci-1)->state & CI_C) | 364 | if ((ci-1)->state & CI_C) |
362 | luaG_runerror(L, "cannot yield a C function"); | 365 | luaG_runerror(L, "cannot yield a C function"); |
363 | if (L->top - nresults > ci->base) { /* is there garbage in the stack? */ | 366 | if (L->top - nresults > L->base) { /* is there garbage in the stack? */ |
364 | int i; | 367 | int i; |
365 | for (i=0; i<nresults; i++) /* move down results */ | 368 | for (i=0; i<nresults; i++) /* move down results */ |
366 | setobjs2s(ci->base + i, L->top - nresults + i); | 369 | setobjs2s(L->base + i, L->top - nresults + i); |
367 | L->top = ci->base + nresults; | 370 | L->top = L->base + nresults; |
368 | } | 371 | } |
369 | } | 372 | } |
370 | /* else it's an yield inside a hook: nothing to do */ | 373 | /* else it's an yield inside a hook: nothing to do */ |
@@ -405,6 +408,7 @@ int luaD_pcall (lua_State *L, int nargs, int nresults, ptrdiff_t errfunc) { | |||
405 | luaF_close(L, oldtop); /* close eventual pending closures */ | 408 | luaF_close(L, oldtop); /* close eventual pending closures */ |
406 | seterrorobj(L, status, oldtop); | 409 | seterrorobj(L, status, oldtop); |
407 | L->ci = restoreci(L, old_ci); | 410 | L->ci = restoreci(L, old_ci); |
411 | L->base = L->ci->base; | ||
408 | L->allowhook = old_allowhooks; | 412 | L->allowhook = old_allowhooks; |
409 | restore_stack_limit(L); | 413 | restore_stack_limit(L); |
410 | } | 414 | } |