aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2005-04-04 15:12:51 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2005-04-04 15:12:51 -0300
commit0316308c0d8ee9834641dacf81b43bcfd396095d (patch)
treef2a66cb6080fe432ede5d17911d3766d37ad5fb6
parent409ee99900216d4a64a9a7029099bc7ae67a4d8e (diff)
downloadlua-0316308c0d8ee9834641dacf81b43bcfd396095d.tar.gz
lua-0316308c0d8ee9834641dacf81b43bcfd396095d.tar.bz2
lua-0316308c0d8ee9834641dacf81b43bcfd396095d.zip
removed dirt optimizations that gave small gains
-rw-r--r--lapi.c10
-rw-r--r--ldebug.c36
-rw-r--r--lvm.c89
-rw-r--r--lvm.h8
4 files changed, 54 insertions, 89 deletions
diff --git a/lapi.c b/lapi.c
index b336014f..b1b13124 100644
--- a/lapi.c
+++ b/lapi.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lapi.c,v 2.35 2005/03/21 18:12:21 roberto Exp roberto $ 2** $Id: lapi.c,v 2.36 2005/03/22 16:04:29 roberto Exp roberto $
3** Lua API 3** Lua API
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -526,7 +526,7 @@ LUA_API void lua_gettable (lua_State *L, int idx) {
526 lua_lock(L); 526 lua_lock(L);
527 t = index2adr(L, idx); 527 t = index2adr(L, idx);
528 api_checkvalidindex(L, t); 528 api_checkvalidindex(L, t);
529 luaV_gettable(L, t, L->top - 1, L->top - 1, NULL); 529 luaV_gettable(L, t, L->top - 1, L->top - 1);
530 lua_unlock(L); 530 lua_unlock(L);
531} 531}
532 532
@@ -538,7 +538,7 @@ LUA_API void lua_getfield (lua_State *L, int idx, const char *k) {
538 t = index2adr(L, idx); 538 t = index2adr(L, idx);
539 api_checkvalidindex(L, t); 539 api_checkvalidindex(L, t);
540 setsvalue(L, &key, luaS_new(L, k)); 540 setsvalue(L, &key, luaS_new(L, k));
541 luaV_gettable(L, t, &key, L->top, NULL); 541 luaV_gettable(L, t, &key, L->top);
542 api_incr_top(L); 542 api_incr_top(L);
543 lua_unlock(L); 543 lua_unlock(L);
544} 544}
@@ -632,7 +632,7 @@ LUA_API void lua_settable (lua_State *L, int idx) {
632 api_checknelems(L, 2); 632 api_checknelems(L, 2);
633 t = index2adr(L, idx); 633 t = index2adr(L, idx);
634 api_checkvalidindex(L, t); 634 api_checkvalidindex(L, t);
635 luaV_settable(L, t, L->top - 2, L->top - 1, NULL); 635 luaV_settable(L, t, L->top - 2, L->top - 1);
636 L->top -= 2; /* pop index and value */ 636 L->top -= 2; /* pop index and value */
637 lua_unlock(L); 637 lua_unlock(L);
638} 638}
@@ -646,7 +646,7 @@ LUA_API void lua_setfield (lua_State *L, int idx, const char *k) {
646 t = index2adr(L, idx); 646 t = index2adr(L, idx);
647 api_checkvalidindex(L, t); 647 api_checkvalidindex(L, t);
648 setsvalue(L, &key, luaS_new(L, k)); 648 setsvalue(L, &key, luaS_new(L, k));
649 luaV_settable(L, t, &key, L->top - 1, NULL); 649 luaV_settable(L, t, &key, L->top - 1);
650 L->top--; /* pop value */ 650 L->top--; /* pop value */
651 lua_unlock(L); 651 lua_unlock(L);
652} 652}
diff --git a/ldebug.c b/ldebug.c
index ca1f5410..19a1453e 100644
--- a/ldebug.c
+++ b/ldebug.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ldebug.c,v 2.11 2004/12/03 20:35:33 roberto Exp roberto $ 2** $Id: ldebug.c,v 2.12 2004/12/20 15:50:00 roberto Exp roberto $
3** Debug Interface 3** Debug Interface
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -30,17 +30,18 @@
30 30
31 31
32 32
33static const char *getfuncname (CallInfo *ci, const char **name); 33static const char *getfuncname (lua_State *L, CallInfo *ci, const char **name);
34 34
35 35
36static int currentpc (CallInfo *ci) { 36static int currentpc (lua_State *L, CallInfo *ci) {
37 UNUSED(L);
37 if (!isLua(ci)) return -1; /* function is not a Lua function? */ 38 if (!isLua(ci)) return -1; /* function is not a Lua function? */
38 return pcRel(ci->savedpc, ci_func(ci)->l.p); 39 return pcRel(ci->savedpc, ci_func(ci)->l.p);
39} 40}
40 41
41 42
42static int currentline (CallInfo *ci) { 43static int currentline (lua_State *L, CallInfo *ci) {
43 int pc = currentpc(ci); 44 int pc = currentpc(L, ci);
44 if (pc < 0) 45 if (pc < 0)
45 return -1; /* only active lua functions have current-line information */ 46 return -1; /* only active lua functions have current-line information */
46 else 47 else
@@ -116,7 +117,7 @@ LUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n) {
116 ci = L->base_ci + ar->i_ci; 117 ci = L->base_ci + ar->i_ci;
117 fp = getluaproto(ci); 118 fp = getluaproto(ci);
118 if (fp) { /* is a Lua function? */ 119 if (fp) { /* is a Lua function? */
119 name = luaF_getlocalname(fp, n, currentpc(ci)); 120 name = luaF_getlocalname(fp, n, currentpc(L, ci));
120 if (name) 121 if (name)
121 luaA_pushobject(L, ci->base+(n-1)); /* push value */ 122 luaA_pushobject(L, ci->base+(n-1)); /* push value */
122 } 123 }
@@ -135,7 +136,7 @@ LUA_API const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n) {
135 fp = getluaproto(ci); 136 fp = getluaproto(ci);
136 L->top--; /* pop new value */ 137 L->top--; /* pop new value */
137 if (fp) { /* is a Lua function? */ 138 if (fp) { /* is a Lua function? */
138 name = luaF_getlocalname(fp, n, currentpc(ci)); 139 name = luaF_getlocalname(fp, n, currentpc(L, ci));
139 if (!name || name[0] == '(') /* `(' starts private locals */ 140 if (!name || name[0] == '(') /* `(' starts private locals */
140 name = NULL; 141 name = NULL;
141 else 142 else
@@ -183,7 +184,7 @@ static int auxgetinfo (lua_State *L, const char *what, lua_Debug *ar,
183 break; 184 break;
184 } 185 }
185 case 'l': { 186 case 'l': {
186 ar->currentline = (ci) ? currentline(ci) : -1; 187 ar->currentline = (ci) ? currentline(L, ci) : -1;
187 break; 188 break;
188 } 189 }
189 case 'u': { 190 case 'u': {
@@ -191,7 +192,7 @@ static int auxgetinfo (lua_State *L, const char *what, lua_Debug *ar,
191 break; 192 break;
192 } 193 }
193 case 'n': { 194 case 'n': {
194 ar->namewhat = (ci) ? getfuncname(ci, &ar->name) : NULL; 195 ar->namewhat = (ci) ? getfuncname(L, ci, &ar->name) : NULL;
195 if (ar->namewhat == NULL) { 196 if (ar->namewhat == NULL) {
196 ar->namewhat = ""; /* not found */ 197 ar->namewhat = ""; /* not found */
197 ar->name = NULL; 198 ar->name = NULL;
@@ -446,10 +447,11 @@ static const char *kname (Proto *p, int c) {
446} 447}
447 448
448 449
449static const char *getobjname (CallInfo *ci, int stackpos, const char **name) { 450static const char *getobjname (lua_State *L, CallInfo *ci, int stackpos,
451 const char **name) {
450 if (isLua(ci)) { /* a Lua function? */ 452 if (isLua(ci)) { /* a Lua function? */
451 Proto *p = ci_func(ci)->l.p; 453 Proto *p = ci_func(ci)->l.p;
452 int pc = currentpc(ci); 454 int pc = currentpc(L, ci);
453 Instruction i; 455 Instruction i;
454 *name = luaF_getlocalname(p, stackpos+1, pc); 456 *name = luaF_getlocalname(p, stackpos+1, pc);
455 if (*name) /* is a local? */ 457 if (*name) /* is a local? */
@@ -467,7 +469,7 @@ static const char *getobjname (CallInfo *ci, int stackpos, const char **name) {
467 int a = GETARG_A(i); 469 int a = GETARG_A(i);
468 int b = GETARG_B(i); /* move from `b' to `a' */ 470 int b = GETARG_B(i); /* move from `b' to `a' */
469 if (b < a) 471 if (b < a)
470 return getobjname(ci, b, name); /* get name for `b' */ 472 return getobjname(L, ci, b, name); /* get name for `b' */
471 break; 473 break;
472 } 474 }
473 case OP_GETTABLE: { 475 case OP_GETTABLE: {
@@ -492,15 +494,15 @@ static const char *getobjname (CallInfo *ci, int stackpos, const char **name) {
492} 494}
493 495
494 496
495static const char *getfuncname (CallInfo *ci, const char **name) { 497static const char *getfuncname (lua_State *L, CallInfo *ci, const char **name) {
496 Instruction i; 498 Instruction i;
497 if ((isLua(ci) && ci->tailcalls > 0) || !isLua(ci - 1)) 499 if ((isLua(ci) && ci->tailcalls > 0) || !isLua(ci - 1))
498 return NULL; /* calling function is not Lua (or is unknown) */ 500 return NULL; /* calling function is not Lua (or is unknown) */
499 ci--; /* calling function */ 501 ci--; /* calling function */
500 i = ci_func(ci)->l.p->code[currentpc(ci)]; 502 i = ci_func(ci)->l.p->code[currentpc(L, ci)];
501 if (GET_OPCODE(i) == OP_CALL || GET_OPCODE(i) == OP_TAILCALL || 503 if (GET_OPCODE(i) == OP_CALL || GET_OPCODE(i) == OP_TAILCALL ||
502 GET_OPCODE(i) == OP_TFORLOOP) 504 GET_OPCODE(i) == OP_TFORLOOP)
503 return getobjname(ci, GETARG_A(i), name); 505 return getobjname(L, ci, GETARG_A(i), name);
504 else 506 else
505 return NULL; /* no useful name can be found */ 507 return NULL; /* no useful name can be found */
506} 508}
@@ -519,7 +521,7 @@ void luaG_typeerror (lua_State *L, const TValue *o, const char *op) {
519 const char *name = NULL; 521 const char *name = NULL;
520 const char *t = luaT_typenames[ttype(o)]; 522 const char *t = luaT_typenames[ttype(o)];
521 const char *kind = (isinstack(L->ci, o)) ? 523 const char *kind = (isinstack(L->ci, o)) ?
522 getobjname(L->ci, o - L->base, &name) : NULL; 524 getobjname(L, L->ci, o - L->base, &name) : NULL;
523 if (kind) 525 if (kind)
524 luaG_runerror(L, "attempt to %s %s `%s' (a %s value)", 526 luaG_runerror(L, "attempt to %s %s `%s' (a %s value)",
525 op, kind, name, t); 527 op, kind, name, t);
@@ -558,7 +560,7 @@ static void addinfo (lua_State *L, const char *msg) {
558 CallInfo *ci = L->ci; 560 CallInfo *ci = L->ci;
559 if (isLua(ci)) { /* is Lua code? */ 561 if (isLua(ci)) { /* is Lua code? */
560 char buff[LUA_IDSIZE]; /* add file:line information */ 562 char buff[LUA_IDSIZE]; /* add file:line information */
561 int line = currentline(ci); 563 int line = currentline(L, ci);
562 luaO_chunkid(buff, getstr(getluaproto(ci)->source), LUA_IDSIZE); 564 luaO_chunkid(buff, getstr(getluaproto(ci)->source), LUA_IDSIZE);
563 luaO_pushfstring(L, "%s:%d: %s", buff, line, msg); 565 luaO_pushfstring(L, "%s:%d: %s", buff, line, msg);
564 } 566 }
diff --git a/lvm.c b/lvm.c
index 5456e74d..6f3e6d05 100644
--- a/lvm.c
+++ b/lvm.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lvm.c,v 2.34 2005/03/18 18:01:37 roberto Exp roberto $ 2** $Id: lvm.c,v 2.35 2005/03/28 17:17:53 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*/
@@ -108,8 +108,7 @@ static void callTM (lua_State *L) {
108} 108}
109 109
110 110
111StkId luaV_gettable (lua_State *L, const TValue *t, TValue *key, StkId val, 111void luaV_gettable (lua_State *L, const TValue *t, TValue *key, StkId val) {
112 const Instruction *pc) {
113 int loop; 112 int loop;
114 for (loop = 0; loop < MAXTAGLOOP; loop++) { 113 for (loop = 0; loop < MAXTAGLOOP; loop++) {
115 const TValue *tm; 114 const TValue *tm;
@@ -119,30 +118,24 @@ StkId luaV_gettable (lua_State *L, const TValue *t, TValue *key, StkId val,
119 if (!ttisnil(res) || /* result is no nil? */ 118 if (!ttisnil(res) || /* result is no nil? */
120 (tm = fasttm(L, h->metatable, TM_INDEX)) == NULL) { /* or no TM? */ 119 (tm = fasttm(L, h->metatable, TM_INDEX)) == NULL) { /* or no TM? */
121 setobj2s(L, val, res); 120 setobj2s(L, val, res);
122 return L->base; 121 return;
123 } 122 }
124 /* else will try the tag method */ 123 /* else will try the tag method */
125 } 124 }
126 else if (ttisnil(tm = luaT_gettmbyobj(L, t, TM_INDEX))) { 125 else if (ttisnil(tm = luaT_gettmbyobj(L, t, TM_INDEX)))
127 L->ci->savedpc = pc;
128 luaG_typeerror(L, t, "index"); 126 luaG_typeerror(L, t, "index");
129 }
130 if (ttisfunction(tm)) { 127 if (ttisfunction(tm)) {
131 L->ci->savedpc = pc;
132 prepTMcall(L, tm, t, key); 128 prepTMcall(L, tm, t, key);
133 callTMres(L, val); 129 callTMres(L, val);
134 return L->base; 130 return;
135 } 131 }
136 t = tm; /* else repeat with `tm' */ 132 t = tm; /* else repeat with `tm' */
137 } 133 }
138 L->ci->savedpc = pc;
139 luaG_runerror(L, "loop in gettable"); 134 luaG_runerror(L, "loop in gettable");
140 return NULL; /* to avoid warnings */
141} 135}
142 136
143 137
144StkId luaV_settable (lua_State *L, const TValue *t, TValue *key, StkId val, 138void luaV_settable (lua_State *L, const TValue *t, TValue *key, StkId val) {
145 const Instruction *pc) {
146 int loop; 139 int loop;
147 for (loop = 0; loop < MAXTAGLOOP; loop++) { 140 for (loop = 0; loop < MAXTAGLOOP; loop++) {
148 const TValue *tm; 141 const TValue *tm;
@@ -153,26 +146,21 @@ StkId luaV_settable (lua_State *L, const TValue *t, TValue *key, StkId val,
153 (tm = fasttm(L, h->metatable, TM_NEWINDEX)) == NULL) { /* or no TM? */ 146 (tm = fasttm(L, h->metatable, TM_NEWINDEX)) == NULL) { /* or no TM? */
154 setobj2t(L, oldval, val); 147 setobj2t(L, oldval, val);
155 luaC_barriert(L, h, val); 148 luaC_barriert(L, h, val);
156 return L->base; 149 return;
157 } 150 }
158 /* else will try the tag method */ 151 /* else will try the tag method */
159 } 152 }
160 else if (ttisnil(tm = luaT_gettmbyobj(L, t, TM_NEWINDEX))) { 153 else if (ttisnil(tm = luaT_gettmbyobj(L, t, TM_NEWINDEX)))
161 L->ci->savedpc = pc;
162 luaG_typeerror(L, t, "index"); 154 luaG_typeerror(L, t, "index");
163 }
164 if (ttisfunction(tm)) { 155 if (ttisfunction(tm)) {
165 L->ci->savedpc = pc;
166 prepTMcall(L, tm, t, key); 156 prepTMcall(L, tm, t, key);
167 setobj2s(L, L->top+3, val); /* 3th argument */ 157 setobj2s(L, L->top+3, val); /* 3th argument */
168 callTM(L); 158 callTM(L);
169 return L->base; 159 return;
170 } 160 }
171 t = tm; /* else repeat with `tm' */ 161 t = tm; /* else repeat with `tm' */
172 } 162 }
173 L->ci->savedpc = pc;
174 luaG_runerror(L, "loop in settable"); 163 luaG_runerror(L, "loop in settable");
175 return NULL; /* to avoid warnings */
176} 164}
177 165
178 166
@@ -330,10 +318,9 @@ void luaV_concat (lua_State *L, int total, int last) {
330 318
331 319
332static StkId Arith (lua_State *L, StkId ra, const TValue *rb, 320static StkId Arith (lua_State *L, StkId ra, const TValue *rb,
333 const TValue *rc, TMS op, const Instruction *pc) { 321 const TValue *rc, TMS op) {
334 TValue tempb, tempc; 322 TValue tempb, tempc;
335 const TValue *b, *c; 323 const TValue *b, *c;
336 L->ci->savedpc = pc;
337 if ((b = luaV_tonumber(rb, &tempb)) != NULL && 324 if ((b = luaV_tonumber(rb, &tempb)) != NULL &&
338 (c = luaV_tonumber(rc, &tempc)) != NULL) { 325 (c = luaV_tonumber(rc, &tempc)) != NULL) {
339 lua_Number nb = nvalue(b), nc = nvalue(c); 326 lua_Number nb = nvalue(b), nc = nvalue(c);
@@ -377,7 +364,6 @@ static StkId Arith (lua_State *L, StkId ra, const TValue *rb,
377StkId luaV_execute (lua_State *L, int nexeccalls) { 364StkId luaV_execute (lua_State *L, int nexeccalls) {
378 LClosure *cl; 365 LClosure *cl;
379 TValue *k; 366 TValue *k;
380 StkId base;
381 const Instruction *pc; 367 const Instruction *pc;
382 callentry: /* entry point when calling new functions */ 368 callentry: /* entry point when calling new functions */
383 if (L->hookmask & LUA_MASKCALL) 369 if (L->hookmask & LUA_MASKCALL)
@@ -385,10 +371,10 @@ StkId luaV_execute (lua_State *L, int nexeccalls) {
385 retentry: /* entry point when returning to old functions */ 371 retentry: /* entry point when returning to old functions */
386 pc = L->ci->savedpc; 372 pc = L->ci->savedpc;
387 cl = &clvalue(L->ci->func)->l; 373 cl = &clvalue(L->ci->func)->l;
388 base = L->base;
389 k = cl->p->k; 374 k = cl->p->k;
390 /* main loop of interpreter */ 375 /* main loop of interpreter */
391 for (;;) { 376 for (;;) {
377 StkId base;
392 const Instruction i = *pc++; 378 const Instruction i = *pc++;
393 StkId ra; 379 StkId ra;
394 if ((L->hookmask & (LUA_MASKLINE | LUA_MASKCOUNT)) && 380 if ((L->hookmask & (LUA_MASKLINE | LUA_MASKCOUNT)) &&
@@ -398,11 +384,12 @@ StkId luaV_execute (lua_State *L, int nexeccalls) {
398 L->ci->savedpc = pc - 1; 384 L->ci->savedpc = pc - 1;
399 return NULL; 385 return NULL;
400 } 386 }
401 base = L->base;
402 } 387 }
403 /* warning!! several calls may realloc the stack and invalidate `ra' */ 388 /* warning!! several calls may realloc the stack and invalidate `ra' */
389 base = L->base;
404 ra = RA(i); 390 ra = RA(i);
405 lua_assert(base == L->ci->base && base == L->base); 391 L->ci->savedpc = pc;
392 lua_assert(base == L->ci->base);
406 lua_assert(base <= L->top && L->top <= L->stack + L->stacksize); 393 lua_assert(base <= L->top && L->top <= L->stack + L->stacksize);
407 lua_assert(L->top == L->ci->top || luaG_checkopenop(i)); 394 lua_assert(L->top == L->ci->top || luaG_checkopenop(i));
408 switch (GET_OPCODE(i)) { 395 switch (GET_OPCODE(i)) {
@@ -436,18 +423,18 @@ StkId luaV_execute (lua_State *L, int nexeccalls) {
436 TValue *rb = KBx(i); 423 TValue *rb = KBx(i);
437 sethvalue(L, &g, cl->env); 424 sethvalue(L, &g, cl->env);
438 lua_assert(ttisstring(rb)); 425 lua_assert(ttisstring(rb));
439 base = luaV_gettable(L, &g, rb, ra, pc); /***/ 426 luaV_gettable(L, &g, rb, ra); /***/
440 continue; 427 continue;
441 } 428 }
442 case OP_GETTABLE: { 429 case OP_GETTABLE: {
443 base = luaV_gettable(L, RB(i), RKC(i), ra, pc); /***/ 430 luaV_gettable(L, RB(i), RKC(i), ra); /***/
444 continue; 431 continue;
445 } 432 }
446 case OP_SETGLOBAL: { 433 case OP_SETGLOBAL: {
447 TValue g; 434 TValue g;
448 sethvalue(L, &g, cl->env); 435 sethvalue(L, &g, cl->env);
449 lua_assert(ttisstring(KBx(i))); 436 lua_assert(ttisstring(KBx(i)));
450 base = luaV_settable(L, &g, KBx(i), ra, pc); /***/ 437 luaV_settable(L, &g, KBx(i), ra); /***/
451 continue; 438 continue;
452 } 439 }
453 case OP_SETUPVAL: { 440 case OP_SETUPVAL: {
@@ -457,22 +444,20 @@ StkId luaV_execute (lua_State *L, int nexeccalls) {
457 continue; 444 continue;
458 } 445 }
459 case OP_SETTABLE: { 446 case OP_SETTABLE: {
460 base = luaV_settable(L, ra, RKB(i), RKC(i), pc); /***/ 447 luaV_settable(L, ra, RKB(i), RKC(i)); /***/
461 continue; 448 continue;
462 } 449 }
463 case OP_NEWTABLE: { 450 case OP_NEWTABLE: {
464 int b = GETARG_B(i); 451 int b = GETARG_B(i);
465 int c = GETARG_C(i); 452 int c = GETARG_C(i);
466 sethvalue(L, ra, luaH_new(L, luaO_fb2int(b), luaO_fb2int(c))); 453 sethvalue(L, ra, luaH_new(L, luaO_fb2int(b), luaO_fb2int(c)));
467 L->ci->savedpc = pc;
468 luaC_checkGC(L); /***/ 454 luaC_checkGC(L); /***/
469 base = L->base;
470 continue; 455 continue;
471 } 456 }
472 case OP_SELF: { 457 case OP_SELF: {
473 StkId rb = RB(i); 458 StkId rb = RB(i);
474 setobjs2s(L, ra+1, rb); 459 setobjs2s(L, ra+1, rb);
475 base = luaV_gettable(L, rb, RKC(i), ra, pc); /***/ 460 luaV_gettable(L, rb, RKC(i), ra); /***/
476 continue; 461 continue;
477 } 462 }
478 case OP_ADD: { 463 case OP_ADD: {
@@ -483,7 +468,7 @@ StkId luaV_execute (lua_State *L, int nexeccalls) {
483 setnvalue(ra, luai_numadd(nb, nc)); 468 setnvalue(ra, luai_numadd(nb, nc));
484 } 469 }
485 else 470 else
486 base = Arith(L, ra, rb, rc, TM_ADD, pc); /***/ 471 Arith(L, ra, rb, rc, TM_ADD); /***/
487 continue; 472 continue;
488 } 473 }
489 case OP_SUB: { 474 case OP_SUB: {
@@ -494,7 +479,7 @@ StkId luaV_execute (lua_State *L, int nexeccalls) {
494 setnvalue(ra, luai_numsub(nb, nc)); 479 setnvalue(ra, luai_numsub(nb, nc));
495 } 480 }
496 else 481 else
497 base = Arith(L, ra, rb, rc, TM_SUB, pc); /***/ 482 Arith(L, ra, rb, rc, TM_SUB); /***/
498 continue; 483 continue;
499 } 484 }
500 case OP_MUL: { 485 case OP_MUL: {
@@ -505,7 +490,7 @@ StkId luaV_execute (lua_State *L, int nexeccalls) {
505 setnvalue(ra, luai_nummul(nb, nc)); 490 setnvalue(ra, luai_nummul(nb, nc));
506 } 491 }
507 else 492 else
508 base = Arith(L, ra, rb, rc, TM_MUL, pc); /***/ 493 Arith(L, ra, rb, rc, TM_MUL); /***/
509 continue; 494 continue;
510 } 495 }
511 case OP_DIV: { 496 case OP_DIV: {
@@ -516,7 +501,7 @@ StkId luaV_execute (lua_State *L, int nexeccalls) {
516 setnvalue(ra, luai_numdiv(nb, nc)); 501 setnvalue(ra, luai_numdiv(nb, nc));
517 } 502 }
518 else 503 else
519 base = Arith(L, ra, rb, rc, TM_DIV, pc); /***/ 504 Arith(L, ra, rb, rc, TM_DIV); /***/
520 continue; 505 continue;
521 } 506 }
522 case OP_MOD: { 507 case OP_MOD: {
@@ -527,7 +512,7 @@ StkId luaV_execute (lua_State *L, int nexeccalls) {
527 setnvalue(ra, luai_nummod(nb, nc)); 512 setnvalue(ra, luai_nummod(nb, nc));
528 } 513 }
529 else 514 else
530 base = Arith(L, ra, rb, rc, TM_MOD, pc); /***/ 515 Arith(L, ra, rb, rc, TM_MOD); /***/
531 continue; 516 continue;
532 } 517 }
533 case OP_POW: { 518 case OP_POW: {
@@ -538,7 +523,7 @@ StkId luaV_execute (lua_State *L, int nexeccalls) {
538 setnvalue(ra, luai_numpow(nb, nc)); 523 setnvalue(ra, luai_numpow(nb, nc));
539 } 524 }
540 else 525 else
541 base = Arith(L, ra, rb, rc, TM_POW, pc); /***/ 526 Arith(L, ra, rb, rc, TM_POW); /***/
542 continue; 527 continue;
543 } 528 }
544 case OP_UNM: { 529 case OP_UNM: {
@@ -550,10 +535,8 @@ StkId luaV_execute (lua_State *L, int nexeccalls) {
550 } 535 }
551 else { 536 else {
552 setnilvalue(&temp); 537 setnilvalue(&temp);
553 L->ci->savedpc = pc;
554 if (!call_binTM(L, RB(i), &temp, ra, TM_UNM)) /***/ 538 if (!call_binTM(L, RB(i), &temp, ra, TM_UNM)) /***/
555 luaG_aritherror(L, RB(i), &temp); 539 luaG_aritherror(L, RB(i), &temp);
556 base = L->base;
557 } 540 }
558 continue; 541 continue;
559 } 542 }
@@ -572,7 +555,6 @@ StkId luaV_execute (lua_State *L, int nexeccalls) {
572 setnvalue(ra, cast(lua_Number, tsvalue(rb)->len)); 555 setnvalue(ra, cast(lua_Number, tsvalue(rb)->len));
573 break; 556 break;
574 default: /* no metamethod?? */ 557 default: /* no metamethod?? */
575 L->ci->savedpc = pc;
576 luaG_typeerror(L, rb, "get the size of"); 558 luaG_typeerror(L, rb, "get the size of");
577 } 559 }
578 continue; 560 continue;
@@ -580,7 +562,6 @@ StkId luaV_execute (lua_State *L, int nexeccalls) {
580 case OP_CONCAT: { 562 case OP_CONCAT: {
581 int b = GETARG_B(i); 563 int b = GETARG_B(i);
582 int c = GETARG_C(i); 564 int c = GETARG_C(i);
583 L->ci->savedpc = pc;
584 luaV_concat(L, c-b+1, c); /* may change `base' (and `ra') */ /***/ 565 luaV_concat(L, c-b+1, c); /* may change `base' (and `ra') */ /***/
585 luaC_checkGC(L); /***/ 566 luaC_checkGC(L); /***/
586 base = L->base; 567 base = L->base;
@@ -592,24 +573,18 @@ StkId luaV_execute (lua_State *L, int nexeccalls) {
592 continue; 573 continue;
593 } 574 }
594 case OP_EQ: { 575 case OP_EQ: {
595 L->ci->savedpc = pc;
596 if (equalobj(L, RKB(i), RKC(i)) != GETARG_A(i)) pc++; /***/ 576 if (equalobj(L, RKB(i), RKC(i)) != GETARG_A(i)) pc++; /***/
597 else dojump(L, pc, GETARG_sBx(*pc) + 1); 577 else dojump(L, pc, GETARG_sBx(*pc) + 1);
598 base = L->base;
599 continue; 578 continue;
600 } 579 }
601 case OP_LT: { 580 case OP_LT: {
602 L->ci->savedpc = pc;
603 if (luaV_lessthan(L, RKB(i), RKC(i)) != GETARG_A(i)) pc++; /***/ 581 if (luaV_lessthan(L, RKB(i), RKC(i)) != GETARG_A(i)) pc++; /***/
604 else dojump(L, pc, GETARG_sBx(*pc) + 1); 582 else dojump(L, pc, GETARG_sBx(*pc) + 1);
605 base = L->base;
606 continue; 583 continue;
607 } 584 }
608 case OP_LE: { 585 case OP_LE: {
609 L->ci->savedpc = pc;
610 if (lessequal(L, RKB(i), RKC(i)) != GETARG_A(i)) pc++; /***/ 586 if (lessequal(L, RKB(i), RKC(i)) != GETARG_A(i)) pc++; /***/
611 else dojump(L, pc, GETARG_sBx(*pc) + 1); 587 else dojump(L, pc, GETARG_sBx(*pc) + 1);
612 base = L->base;
613 continue; 588 continue;
614 } 589 }
615 case OP_TEST: { 590 case OP_TEST: {
@@ -626,7 +601,6 @@ StkId luaV_execute (lua_State *L, int nexeccalls) {
626 int b = GETARG_B(i); 601 int b = GETARG_B(i);
627 int nresults = GETARG_C(i) - 1; 602 int nresults = GETARG_C(i) - 1;
628 if (b != 0) L->top = ra+b; /* else previous instruction set top */ 603 if (b != 0) L->top = ra+b; /* else previous instruction set top */
629 L->ci->savedpc = pc;
630 pcr = luaD_precall(L, ra, nresults); 604 pcr = luaD_precall(L, ra, nresults);
631 if (pcr == PCRLUA) { 605 if (pcr == PCRLUA) {
632 nexeccalls++; 606 nexeccalls++;
@@ -635,7 +609,6 @@ StkId luaV_execute (lua_State *L, int nexeccalls) {
635 else if (pcr == PCRC) { 609 else if (pcr == PCRC) {
636 /* it was a C function (`precall' called it); adjust results */ 610 /* it was a C function (`precall' called it); adjust results */
637 if (nresults >= 0) L->top = L->ci->top; 611 if (nresults >= 0) L->top = L->ci->top;
638 base = L->base;
639 continue; 612 continue;
640 } 613 }
641 else { 614 else {
@@ -647,7 +620,6 @@ StkId luaV_execute (lua_State *L, int nexeccalls) {
647 int pcr; 620 int pcr;
648 int b = GETARG_B(i); 621 int b = GETARG_B(i);
649 if (b != 0) L->top = ra+b; /* else previous instruction set top */ 622 if (b != 0) L->top = ra+b; /* else previous instruction set top */
650 L->ci->savedpc = pc;
651 lua_assert(GETARG_C(i) - 1 == LUA_MULTRET); 623 lua_assert(GETARG_C(i) - 1 == LUA_MULTRET);
652 pcr = luaD_precall(L, ra, LUA_MULTRET); 624 pcr = luaD_precall(L, ra, LUA_MULTRET);
653 if (pcr == PCRLUA) { 625 if (pcr == PCRLUA) {
@@ -657,20 +629,18 @@ StkId luaV_execute (lua_State *L, int nexeccalls) {
657 StkId func = ci->func; 629 StkId func = ci->func;
658 StkId pfunc = (ci+1)->func; /* previous function index */ 630 StkId pfunc = (ci+1)->func; /* previous function index */
659 if (L->openupval) luaF_close(L, ci->base); 631 if (L->openupval) luaF_close(L, ci->base);
660 base = ci->base = ci->func + ((ci+1)->base - pfunc); 632 L->base = ci->base = ci->func + ((ci+1)->base - pfunc);
661 L->base = base;
662 for (aux = 0; pfunc+aux < L->top; aux++) /* move frame down */ 633 for (aux = 0; pfunc+aux < L->top; aux++) /* move frame down */
663 setobjs2s(L, func+aux, pfunc+aux); 634 setobjs2s(L, func+aux, pfunc+aux);
664 ci->top = L->top = func+aux; /* correct top */ 635 ci->top = L->top = func+aux; /* correct top */
665 lua_assert(L->top == L->base + clvalue(func)->l.p->maxstacksize); 636 lua_assert(L->top == L->base + clvalue(func)->l.p->maxstacksize);
666 ci->savedpc = L->ci->savedpc; 637 ci->savedpc = (ci+1)->savedpc;
667 ci->tailcalls++; /* one more call lost */ 638 ci->tailcalls++; /* one more call lost */
668 L->ci--; /* remove new frame */ 639 L->ci--; /* remove new frame */
669 goto callentry; 640 goto callentry;
670 } 641 }
671 else if (pcr == PCRC) { 642 else if (pcr == PCRC) {
672 /* it was a C function (`precall' called it) */ 643 /* it was a C function (`precall' called it) */
673 base = L->base;
674 continue; 644 continue;
675 } 645 }
676 else { 646 else {
@@ -683,7 +653,6 @@ StkId luaV_execute (lua_State *L, int nexeccalls) {
683 int b = GETARG_B(i); 653 int b = GETARG_B(i);
684 if (b != 0) L->top = ra+b-1; 654 if (b != 0) L->top = ra+b-1;
685 if (L->openupval) luaF_close(L, base); 655 if (L->openupval) luaF_close(L, base);
686 L->ci->savedpc = pc;
687 if (--nexeccalls == 0) /* was previous function running `here'? */ 656 if (--nexeccalls == 0) /* was previous function running `here'? */
688 return ra; /* no: return */ 657 return ra; /* no: return */
689 else { /* yes: continue its execution */ 658 else { /* yes: continue its execution */
@@ -710,7 +679,6 @@ StkId luaV_execute (lua_State *L, int nexeccalls) {
710 const TValue *init = ra; 679 const TValue *init = ra;
711 const TValue *plimit = ra+1; 680 const TValue *plimit = ra+1;
712 const TValue *pstep = ra+2; 681 const TValue *pstep = ra+2;
713 L->ci->savedpc = pc;
714 if (!tonumber(init, ra)) 682 if (!tonumber(init, ra))
715 luaG_runerror(L, "`for' initial value must be a number"); 683 luaG_runerror(L, "`for' initial value must be a number");
716 else if (!tonumber(plimit, ra+1)) 684 else if (!tonumber(plimit, ra+1))
@@ -727,7 +695,6 @@ StkId luaV_execute (lua_State *L, int nexeccalls) {
727 setobjs2s(L, cb+1, ra+1); 695 setobjs2s(L, cb+1, ra+1);
728 setobjs2s(L, cb, ra); 696 setobjs2s(L, cb, ra);
729 L->top = cb+3; /* func. + 2 args (state and index) */ 697 L->top = cb+3; /* func. + 2 args (state and index) */
730 L->ci->savedpc = pc;
731 luaD_call(L, cb, GETARG_C(i)); /***/ 698 luaD_call(L, cb, GETARG_C(i)); /***/
732 L->top = L->ci->top; 699 L->top = L->ci->top;
733 base = L->base; 700 base = L->base;
@@ -791,9 +758,7 @@ StkId luaV_execute (lua_State *L, int nexeccalls) {
791 } 758 }
792 } 759 }
793 setclvalue(L, ra, ncl); 760 setclvalue(L, ra, ncl);
794 L->ci->savedpc = pc;
795 luaC_checkGC(L); /***/ 761 luaC_checkGC(L); /***/
796 base = L->base;
797 continue; 762 continue;
798 } 763 }
799 case OP_VARARG: { 764 case OP_VARARG: {
diff --git a/lvm.h b/lvm.h
index 0cae36c9..0e096c96 100644
--- a/lvm.h
+++ b/lvm.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lvm.h,v 2.1 2003/12/10 12:13:36 roberto Exp roberto $ 2** $Id: lvm.h,v 2.2 2004/05/14 19:25:09 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*/
@@ -26,10 +26,8 @@ int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r);
26int luaV_equalval (lua_State *L, const TValue *t1, const TValue *t2); 26int luaV_equalval (lua_State *L, const TValue *t1, const TValue *t2);
27const TValue *luaV_tonumber (const TValue *obj, TValue *n); 27const TValue *luaV_tonumber (const TValue *obj, TValue *n);
28int luaV_tostring (lua_State *L, StkId obj); 28int luaV_tostring (lua_State *L, StkId obj);
29StkId luaV_gettable (lua_State *L, const TValue *t, TValue *key, StkId val, 29void luaV_gettable (lua_State *L, const TValue *t, TValue *key, StkId val);
30 const Instruction *pc); 30void luaV_settable (lua_State *L, const TValue *t, TValue *key, StkId val);
31StkId luaV_settable (lua_State *L, const TValue *t, TValue *key, StkId val,
32 const Instruction *pc);
33StkId luaV_execute (lua_State *L, int nexeccalls); 31StkId luaV_execute (lua_State *L, int nexeccalls);
34void luaV_concat (lua_State *L, int total, int last); 32void luaV_concat (lua_State *L, int total, int last);
35 33