aboutsummaryrefslogtreecommitdiff
path: root/lvm.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2002-01-03 15:42:57 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2002-01-03 15:42:57 -0200
commitfacfec0687ff20351d3c7520344a722b9149c9ea (patch)
tree142f5863ac2663f6714a712eca9be2407e7aaf0a /lvm.c
parent34df9976a9fe9a94a4ee96d7ff0ebceac025172d (diff)
downloadlua-facfec0687ff20351d3c7520344a722b9149c9ea.tar.gz
lua-facfec0687ff20351d3c7520344a722b9149c9ea.tar.bz2
lua-facfec0687ff20351d3c7520344a722b9149c9ea.zip
small optimizations
Diffstat (limited to 'lvm.c')
-rw-r--r--lvm.c27
1 files changed, 15 insertions, 12 deletions
diff --git a/lvm.c b/lvm.c
index b56622e7..a073d39d 100644
--- a/lvm.c
+++ b/lvm.c
@@ -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);