diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2002-01-03 15:42:57 -0200 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2002-01-03 15:42:57 -0200 |
| commit | facfec0687ff20351d3c7520344a722b9149c9ea (patch) | |
| tree | 142f5863ac2663f6714a712eca9be2407e7aaf0a | |
| parent | 34df9976a9fe9a94a4ee96d7ff0ebceac025172d (diff) | |
| download | lua-facfec0687ff20351d3c7520344a722b9149c9ea.tar.gz lua-facfec0687ff20351d3c7520344a722b9149c9ea.tar.bz2 lua-facfec0687ff20351d3c7520344a722b9149c9ea.zip | |
small optimizations
| -rw-r--r-- | ldo.c | 4 | ||||
| -rw-r--r-- | lstate.h | 3 | ||||
| -rw-r--r-- | lvm.c | 27 |
3 files changed, 18 insertions, 16 deletions
| @@ -49,7 +49,6 @@ void luaD_init (lua_State *L, int stacksize) { | |||
| 49 | L->ci = L->base_ci; | 49 | L->ci = L->base_ci; |
| 50 | L->ci->base = L->top; | 50 | L->ci->base = L->top; |
| 51 | L->ci->savedpc = NULL; | 51 | L->ci->savedpc = NULL; |
| 52 | L->ci->pc = NULL; | ||
| 53 | L->size_ci = 20; | 52 | L->size_ci = 20; |
| 54 | L->end_ci = L->base_ci + L->size_ci; | 53 | L->end_ci = L->base_ci + L->size_ci; |
| 55 | } | 54 | } |
| @@ -107,6 +106,7 @@ void luaD_callHook (lua_State *L, lua_Hook callhook, const char *event) { | |||
| 107 | lua_Debug ar; | 106 | lua_Debug ar; |
| 108 | ar.event = event; | 107 | ar.event = event; |
| 109 | ar._ci = L->ci - L->base_ci; | 108 | ar._ci = L->ci - L->base_ci; |
| 109 | L->ci->pc = NULL; /* function is not active */ | ||
| 110 | dohook(L, &ar, callhook); | 110 | dohook(L, &ar, callhook); |
| 111 | } | 111 | } |
| 112 | } | 112 | } |
| @@ -135,11 +135,9 @@ StkId luaD_precall (lua_State *L, StkId func) { | |||
| 135 | luaD_openstack(L, func); | 135 | luaD_openstack(L, func); |
| 136 | setobj(func, tm); /* tag method is the new function to be called */ | 136 | setobj(func, tm); /* tag method is the new function to be called */ |
| 137 | } | 137 | } |
| 138 | lua_assert(ttype(func) == LUA_TFUNCTION); | ||
| 139 | ci = newci(L); | 138 | ci = newci(L); |
| 140 | ci->base = func+1; | 139 | ci->base = func+1; |
| 141 | ci->savedpc = NULL; | 140 | ci->savedpc = NULL; |
| 142 | ci->pc = NULL; | ||
| 143 | if (L->callhook) | 141 | if (L->callhook) |
| 144 | luaD_callHook(L, L->callhook, "call"); | 142 | luaD_callHook(L, L->callhook, "call"); |
| 145 | if (!clvalue(func)->c.isC) return NULL; | 143 | if (!clvalue(func)->c.isC) return NULL; |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lstate.h,v 1.1 2001/11/29 22:14:34 rieru Exp rieru $ | 2 | ** $Id: lstate.h,v 1.68 2001/12/18 20:52:30 roberto Exp $ |
| 3 | ** Global State | 3 | ** Global State |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -76,6 +76,7 @@ typedef struct CallInfo { | |||
| 76 | StkId base; /* base for called function */ | 76 | StkId base; /* base for called function */ |
| 77 | const Instruction *savedpc; | 77 | const Instruction *savedpc; |
| 78 | lua_Hook linehook; | 78 | lua_Hook linehook; |
| 79 | StkId top; /* top for this function (when it's a Lua function) */ | ||
| 79 | /* extra information for debugging */ | 80 | /* extra information for debugging */ |
| 80 | const Instruction **pc; | 81 | const Instruction **pc; |
| 81 | int lastpc; /* last pc traced */ | 82 | int lastpc; /* last pc traced */ |
| @@ -105,7 +105,6 @@ static void callTM (lua_State *L, const TObject *f, | |||
| 105 | } | 105 | } |
| 106 | 106 | ||
| 107 | 107 | ||
| 108 | |||
| 109 | /* | 108 | /* |
| 110 | ** Function to index a table. | 109 | ** Function to index a table. |
| 111 | ** Receives the table at `t' and the key at `key'. | 110 | ** Receives the table at `t' and the key at `key'. |
| @@ -141,7 +140,6 @@ void luaV_gettable (lua_State *L, StkId t, TObject *key, StkId res) { | |||
| 141 | } | 140 | } |
| 142 | 141 | ||
| 143 | 142 | ||
| 144 | |||
| 145 | /* | 143 | /* |
| 146 | ** Receives table at `t', key at `key' and value at `val'. | 144 | ** Receives table at `t', key at `key' and value at `val'. |
| 147 | */ | 145 | */ |
| @@ -285,7 +283,7 @@ static void powOp (lua_State *L, StkId ra, StkId rb, StkId rc) { | |||
| 285 | TObject tempb, tempc; | 283 | TObject tempb, tempc; |
| 286 | if ((b = luaV_tonumber(b, &tempb)) != NULL && | 284 | if ((b = luaV_tonumber(b, &tempb)) != NULL && |
| 287 | (c = luaV_tonumber(c, &tempc)) != NULL) { | 285 | (c = luaV_tonumber(c, &tempc)) != NULL) { |
| 288 | TObject o, f; | 286 | TObject f, o; |
| 289 | setsvalue(&o, luaS_newliteral(L, "pow")); | 287 | setsvalue(&o, luaS_newliteral(L, "pow")); |
| 290 | luaV_gettable(L, gt(L), &o, &f); | 288 | luaV_gettable(L, gt(L), &o, &f); |
| 291 | if (ttype(&f) != LUA_TFUNCTION) | 289 | if (ttype(&f) != LUA_TFUNCTION) |
| @@ -323,10 +321,10 @@ static void powOp (lua_State *L, StkId ra, StkId rb, StkId rc) { | |||
| 323 | } | 321 | } |
| 324 | 322 | ||
| 325 | 323 | ||
| 326 | #define luaV_poscall(L,c,f) \ | 324 | #define luaV_poscall(L,c,f,ci) \ |
| 327 | if (c != NO_REG) { \ | 325 | if (c != NO_REG) { \ |
| 328 | luaD_poscall(L, c, f); \ | 326 | luaD_poscall(L, c, f); \ |
| 329 | L->top = base + cl->p->maxstacksize; \ | 327 | L->top = ci->top; \ |
| 330 | } \ | 328 | } \ |
| 331 | else { \ | 329 | else { \ |
| 332 | luaD_poscall(L, LUA_MULTRET, f); \ | 330 | luaD_poscall(L, LUA_MULTRET, f); \ |
| @@ -344,14 +342,15 @@ StkId luaV_execute (lua_State *L, const LClosure *cl, StkId base) { | |||
| 344 | lua_Hook linehook; | 342 | lua_Hook linehook; |
| 345 | reinit: | 343 | reinit: |
| 346 | lua_assert(L->ci->savedpc == NULL); | 344 | lua_assert(L->ci->savedpc == NULL); |
| 345 | L->ci->pc = &pc; | ||
| 346 | L->ci->top = base + cl->p->maxstacksize; | ||
| 347 | if (cl->p->is_vararg) /* varargs? */ | 347 | if (cl->p->is_vararg) /* varargs? */ |
| 348 | adjust_varargs(L, base, cl->p->numparams); | 348 | adjust_varargs(L, base, cl->p->numparams); |
| 349 | if (base > L->stack_last - cl->p->maxstacksize) | 349 | if (base > L->stack_last - cl->p->maxstacksize) |
| 350 | luaD_stackerror(L); | 350 | luaD_stackerror(L); |
| 351 | while (L->top < base + cl->p->maxstacksize) | 351 | while (L->top < L->ci->top) |
| 352 | setnilvalue(L->top++); | 352 | setnilvalue(L->top++); |
| 353 | L->top = base + cl->p->maxstacksize; | 353 | L->top = L->ci->top; |
| 354 | L->ci->pc = &pc; | ||
| 355 | linehook = L->ci->linehook = L->linehook; | 354 | linehook = L->ci->linehook = L->linehook; |
| 356 | pc = cl->p->code; | 355 | pc = cl->p->code; |
| 357 | /* main loop of interpreter */ | 356 | /* main loop of interpreter */ |
| @@ -360,6 +359,8 @@ StkId luaV_execute (lua_State *L, const LClosure *cl, StkId base) { | |||
| 360 | const StkId ra = RA(i); | 359 | const StkId ra = RA(i); |
| 361 | if (linehook) | 360 | if (linehook) |
| 362 | traceexec(L, linehook); | 361 | traceexec(L, linehook); |
| 362 | lua_assert(L->top == L->ci->top || GET_OPCODE(i) == OP_CALL || | ||
| 363 | GET_OPCODE(i) == OP_RETURN || GET_OPCODE(i) == OP_SETLISTO); | ||
| 363 | switch (GET_OPCODE(i)) { | 364 | switch (GET_OPCODE(i)) { |
| 364 | case OP_MOVE: { | 365 | case OP_MOVE: { |
| 365 | setobj(ra, RB(i)); | 366 | setobj(ra, RB(i)); |
| @@ -539,7 +540,7 @@ StkId luaV_execute (lua_State *L, const LClosure *cl, StkId base) { | |||
| 539 | firstResult = luaD_precall(L, ra); | 540 | firstResult = luaD_precall(L, ra); |
| 540 | if (firstResult) { | 541 | if (firstResult) { |
| 541 | /* it was a C function (`precall' called it); adjust results */ | 542 | /* it was a C function (`precall' called it); adjust results */ |
| 542 | luaV_poscall(L, GETARG_C(i), firstResult); | 543 | luaV_poscall(L, GETARG_C(i), firstResult, L->ci); |
| 543 | } | 544 | } |
| 544 | else { /* it is a Lua function: `call' it */ | 545 | else { /* it is a Lua function: `call' it */ |
| 545 | CallInfo *ci = L->ci; | 546 | CallInfo *ci = L->ci; |
| @@ -553,7 +554,7 @@ StkId luaV_execute (lua_State *L, const LClosure *cl, StkId base) { | |||
| 553 | case OP_RETURN: { | 554 | case OP_RETURN: { |
| 554 | CallInfo *ci; | 555 | CallInfo *ci; |
| 555 | int b; | 556 | int b; |
| 556 | luaF_close(L, base); | 557 | if (L->openupval) luaF_close(L, base); |
| 557 | b = GETARG_B(i); | 558 | b = GETARG_B(i); |
| 558 | if (b != NO_REG) L->top = ra+b; | 559 | if (b != NO_REG) L->top = ra+b; |
| 559 | ci = L->ci - 1; | 560 | ci = L->ci - 1; |
| @@ -567,7 +568,7 @@ StkId luaV_execute (lua_State *L, const LClosure *cl, StkId base) { | |||
| 567 | pc = ci->savedpc; | 568 | pc = ci->savedpc; |
| 568 | ci->savedpc = NULL; | 569 | ci->savedpc = NULL; |
| 569 | lua_assert(GET_OPCODE(*(pc-1)) == OP_CALL); | 570 | lua_assert(GET_OPCODE(*(pc-1)) == OP_CALL); |
| 570 | luaV_poscall(L, GETARG_C(*(pc-1)), ra); | 571 | luaV_poscall(L, GETARG_C(*(pc-1)), ra, ci); |
| 571 | } | 572 | } |
| 572 | break; | 573 | break; |
| 573 | } | 574 | } |
| @@ -630,8 +631,10 @@ StkId luaV_execute (lua_State *L, const LClosure *cl, StkId base) { | |||
| 630 | bc = GETARG_Bc(i); | 631 | bc = GETARG_Bc(i); |
| 631 | if (GET_OPCODE(i) == OP_SETLIST) | 632 | if (GET_OPCODE(i) == OP_SETLIST) |
| 632 | n = (bc&(LFIELDS_PER_FLUSH-1)) + 1; | 633 | n = (bc&(LFIELDS_PER_FLUSH-1)) + 1; |
| 633 | else | 634 | else { |
| 634 | n = L->top - ra - 1; | 635 | n = L->top - ra - 1; |
| 636 | L->top = L->ci->top; | ||
| 637 | } | ||
| 635 | bc &= ~(LFIELDS_PER_FLUSH-1); /* bc = bc - bc%FPF */ | 638 | bc &= ~(LFIELDS_PER_FLUSH-1); /* bc = bc - bc%FPF */ |
| 636 | for (; n > 0; n--) | 639 | for (; n > 0; n--) |
| 637 | luaH_setnum(L, h, bc+n, ra+n); | 640 | luaH_setnum(L, h, bc+n, ra+n); |
