aboutsummaryrefslogtreecommitdiff
path: root/lvm.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2000-04-07 10:13:11 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2000-04-07 10:13:11 -0300
commit031978798cc404c2c6757c564675d43a7da129ee (patch)
tree993e59994258f1a9176d7d260214b132d0b2baa9 /lvm.c
parent14251c5a5640f73f8f98d2445900a3c3a8d472fb (diff)
downloadlua-031978798cc404c2c6757c564675d43a7da129ee.tar.gz
lua-031978798cc404c2c6757c564675d43a7da129ee.tar.bz2
lua-031978798cc404c2c6757c564675d43a7da129ee.zip
more optimizations
Diffstat (limited to 'lvm.c')
-rw-r--r--lvm.c44
1 files changed, 24 insertions, 20 deletions
diff --git a/lvm.c b/lvm.c
index 2a8e2484..fc8cb262 100644
--- a/lvm.c
+++ b/lvm.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lvm.c,v 1.98 2000/03/29 20:19:20 roberto Exp roberto $ 2** $Id: lvm.c,v 1.99 2000/04/04 20:48:44 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*/
@@ -231,6 +231,13 @@ static void call_arith (lua_State *L, StkId top, IMS event) {
231} 231}
232 232
233 233
234static void addK (lua_State *L, StkId top, int k) {
235 ttype(top) = TAG_NUMBER;
236 nvalue(top) = (Number)k;
237 call_arith(L, top+1, IM_ADD);
238}
239
240
234static int luaV_strcomp (const TString *ls, const TString *rs) { 241static int luaV_strcomp (const TString *ls, const TString *rs) {
235 const char *l = ls->str; 242 const char *l = ls->str;
236 long ll = ls->u.s.len; 243 long ll = ls->u.s.len;
@@ -403,7 +410,7 @@ StkId luaV_execute (lua_State *L, const Closure *cl, register StkId base) {
403 *top++ = cl->consts[GETARG_U(i)]; 410 *top++ = cl->consts[GETARG_U(i)];
404 break; 411 break;
405 412
406 case OP_PUSHLOCAL: 413 case OP_GETLOCAL:
407 *top++ = *(base+GETARG_U(i)); 414 *top++ = *(base+GETARG_U(i));
408 break; 415 break;
409 416
@@ -424,6 +431,12 @@ StkId luaV_execute (lua_State *L, const Closure *cl, register StkId base) {
424 top--; 431 top--;
425 break; 432 break;
426 433
434 case OP_GETINDEXED:
435 *top++ = *(base+GETARG_U(i));
436 luaV_gettable(L, top);
437 top--;
438 break;
439
427 case OP_PUSHSELF: { 440 case OP_PUSHSELF: {
428 TObject receiver; 441 TObject receiver;
429 receiver = *(top-1); 442 receiver = *(top-1);
@@ -443,7 +456,8 @@ StkId luaV_execute (lua_State *L, const Closure *cl, register StkId base) {
443 break; 456 break;
444 457
445 case OP_SETLOCAL: 458 case OP_SETLOCAL:
446 *(base+GETARG_U(i)) = *(--top); 459 *(base+GETARG_A(i)) = *(top-1);
460 top -= GETARG_B(i);
447 break; 461 break;
448 462
449 case OP_SETGLOBAL: 463 case OP_SETGLOBAL:
@@ -451,14 +465,9 @@ StkId luaV_execute (lua_State *L, const Closure *cl, register StkId base) {
451 top--; 465 top--;
452 break; 466 break;
453 467
454 case OP_SETTABLEPOP:
455 luaV_settable(L, top-3, top);
456 top -= 3; /* pop table, index, and value */
457 break;
458
459 case OP_SETTABLE: 468 case OP_SETTABLE:
460 luaV_settable(L, top-3-GETARG_U(i), top); 469 luaV_settable(L, top-GETARG_A(i), top);
461 top--; /* pop value */ 470 top -= GETARG_B(i); /* pop values */
462 break; 471 break;
463 472
464 case OP_SETLIST: { 473 case OP_SETLIST: {
@@ -496,9 +505,7 @@ StkId luaV_execute (lua_State *L, const Closure *cl, register StkId base) {
496 int n = GETARG_sA(i); 505 int n = GETARG_sA(i);
497 if (tonumber(var)) { 506 if (tonumber(var)) {
498 *top = *var; /* PUSHLOCAL */ 507 *top = *var; /* PUSHLOCAL */
499 ttype(top+1) = TAG_NUMBER; 508 addK(L, top+1, n);
500 nvalue(top+1) = (Number)n; /* PUSHINT */
501 call_arith(L, top+2, IM_ADD);
502 *var = *top; /* SETLOCAL */ 509 *var = *top; /* SETLOCAL */
503 } 510 }
504 else 511 else
@@ -507,11 +514,8 @@ StkId luaV_execute (lua_State *L, const Closure *cl, register StkId base) {
507 } 514 }
508 515
509 case OP_ADDI: 516 case OP_ADDI:
510 if (tonumber(top-1)) { 517 if (tonumber(top-1))
511 ttype(top) = TAG_NUMBER; 518 addK(L, top, GETARG_S(i));
512 nvalue(top) = (Number)GETARG_S(i);
513 call_arith(L, top+1, IM_ADD);
514 }
515 else 519 else
516 nvalue(top-1) += (Number)GETARG_S(i); 520 nvalue(top-1) += (Number)GETARG_S(i);
517 break; 521 break;
@@ -545,7 +549,7 @@ StkId luaV_execute (lua_State *L, const Closure *cl, register StkId base) {
545 top--; 549 top--;
546 break; 550 break;
547 551
548 case OP_CONC: { 552 case OP_CONCAT: {
549 int n = GETARG_U(i); 553 int n = GETARG_U(i);
550 strconc(L, n, top); 554 strconc(L, n, top);
551 top -= n-1; 555 top -= n-1;
@@ -569,7 +573,7 @@ StkId luaV_execute (lua_State *L, const Closure *cl, register StkId base) {
569 nvalue(top-1) = 1; 573 nvalue(top-1) = 1;
570 break; 574 break;
571 575
572 case OP_JMPNEQ: 576 case OP_JMPNE:
573 top -= 2; 577 top -= 2;
574 if (!luaO_equalObj(top, top+1)) pc += GETARG_S(i); 578 if (!luaO_equalObj(top, top+1)) pc += GETARG_S(i);
575 break; 579 break;