aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2002-08-21 15:56:33 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2002-08-21 15:56:33 -0300
commitfbc23d02456929a24bbad4eee2bd9d6ed8526ba7 (patch)
treea3951cb50721e882b605561a4fa29b8824991577
parent81a8845e4f10851693cbe438520a4c07d347a731 (diff)
downloadlua-fbc23d02456929a24bbad4eee2bd9d6ed8526ba7.tar.gz
lua-fbc23d02456929a24bbad4eee2bd9d6ed8526ba7.tar.bz2
lua-fbc23d02456929a24bbad4eee2bd9d6ed8526ba7.zip
details
-rw-r--r--lcode.c45
-rw-r--r--lopcodes.h7
-rw-r--r--lvm.c4
3 files changed, 22 insertions, 34 deletions
diff --git a/lcode.c b/lcode.c
index 61ff0701..118f16b3 100644
--- a/lcode.c
+++ b/lcode.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lcode.c,v 1.109 2002/08/05 14:07:34 roberto Exp roberto $ 2** $Id: lcode.c,v 1.110 2002/08/20 20:03:05 roberto Exp roberto $
3** Code generator for Lua 3** Code generator for Lua
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -616,38 +616,21 @@ void luaK_infix (FuncState *fs, BinOpr op, expdesc *v) {
616 616
617static void codebinop (FuncState *fs, expdesc *res, BinOpr op, 617static void codebinop (FuncState *fs, expdesc *res, BinOpr op,
618 int o1, int o2) { 618 int o1, int o2) {
619 switch (op) { 619 if (op <= OPR_POW) { /* arithmetic operator? */
620 case OPR_SUB: 620 OpCode opc = cast(OpCode, (op - OPR_ADD) + OP_ADD); /* ORDER OP */
621 case OPR_DIV: 621 res->info = luaK_codeABC(fs, opc, 0, o1, o2);
622 case OPR_POW: 622 res->k = VRELOCABLE;
623 case OPR_ADD: 623 }
624 case OPR_MULT: { /* ORDER OPR */ 624 else { /* test operator */
625 OpCode opc = cast(OpCode, (op - OPR_ADD) + OP_ADD); 625 static const OpCode ops[] = {OP_EQ, OP_EQ, OP_LT, OP_LE, OP_LT, OP_LE};
626 res->info = luaK_codeABC(fs, opc, 0, o1, o2); 626 int cond = 1;
627 res->k = VRELOCABLE; 627 if (op >= OPR_GT) { /* `>' or `>='? */
628 break; 628 int temp; /* exchange args and replace by `<' or `<=' */
629 }
630 case OPR_NE:
631 case OPR_EQ: {
632 res->info = luaK_condjump(fs, OP_EQ, (op == OPR_EQ), o1, o2);
633 res->k = VJMP;
634 break;
635 }
636 case OPR_GT:
637 case OPR_GE: { /* ORDER OPR */
638 int temp;
639 temp = o1; o1 = o2; o2 = temp; /* o1 <==> o2 */ 629 temp = o1; o1 = o2; o2 = temp; /* o1 <==> o2 */
640 op -= 2; /* GT -> LT, GE -> LE */
641 /* go through */
642 }
643 case OPR_LT:
644 case OPR_LE: {
645 OpCode opc = cast(OpCode, (op - OPR_LT) + OP_LT);
646 res->info = luaK_condjump(fs, opc, 1, o1, o2);
647 res->k = VJMP;
648 break;
649 } 630 }
650 default: lua_assert(0); 631 else if (op == OPR_NE) cond = 0;
632 res->info = luaK_condjump(fs, ops[op - OPR_NE], cond, o1, o2);
633 res->k = VJMP;
651 } 634 }
652} 635}
653 636
diff --git a/lopcodes.h b/lopcodes.h
index 7c695324..5386bb21 100644
--- a/lopcodes.h
+++ b/lopcodes.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lopcodes.h,v 1.100 2002/08/05 14:46:43 roberto Exp roberto $ 2** $Id: lopcodes.h,v 1.101 2002/08/20 20:03:05 roberto Exp roberto $
3** Opcodes for Lua virtual machine 3** Opcodes for Lua virtual machine
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -123,6 +123,11 @@ enum OpMode {iABC, iABx, iAsBx}; /* basic instruction format */
123** RK(x) == if x < MAXSTACK then R(x) else Kst(x-MAXSTACK) 123** RK(x) == if x < MAXSTACK then R(x) else Kst(x-MAXSTACK)
124*/ 124*/
125 125
126
127/*
128** grep "ORDER OP" if you change these enums
129*/
130
126typedef enum { 131typedef enum {
127/*---------------------------------------------------------------------- 132/*----------------------------------------------------------------------
128name args description 133name args description
diff --git a/lvm.c b/lvm.c
index b0184b46..4487802e 100644
--- a/lvm.c
+++ b/lvm.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lvm.c,v 1.252 2002/08/12 17:23:12 roberto Exp roberto $ 2** $Id: lvm.c,v 1.253 2002/08/20 20:03:05 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*/
@@ -555,7 +555,7 @@ StkId luaV_execute (lua_State *L) {
555 dojump(pc, GETARG_sBx(i)); 555 dojump(pc, GETARG_sBx(i));
556 break; 556 break;
557 } 557 }
558 case OP_EQ: { /* skip next instruction if test fails */ 558 case OP_EQ: {
559 if (equalobj(L, RKB(i), RKC(i)) != GETARG_A(i)) pc++; 559 if (equalobj(L, RKB(i), RKC(i)) != GETARG_A(i)) pc++;
560 else dojump(pc, GETARG_sBx(*pc) + 1); 560 else dojump(pc, GETARG_sBx(*pc) + 1);
561 break; 561 break;