aboutsummaryrefslogtreecommitdiff
path: root/lcode.c
diff options
context:
space:
mode:
Diffstat (limited to 'lcode.c')
-rw-r--r--lcode.c35
1 files changed, 10 insertions, 25 deletions
diff --git a/lcode.c b/lcode.c
index af2a0838..174c826a 100644
--- a/lcode.c
+++ b/lcode.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lcode.c,v 1.105 2002/05/27 20:35:40 roberto Exp roberto $ 2** $Id: lcode.c,v 1.106 2002/06/03 12:59:26 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*/
@@ -460,19 +460,8 @@ void luaK_self (FuncState *fs, expdesc *e, expdesc *key) {
460 460
461static void invertjump (FuncState *fs, expdesc *e) { 461static void invertjump (FuncState *fs, expdesc *e) {
462 Instruction *pc = getjumpcontrol(fs, e->info); 462 Instruction *pc = getjumpcontrol(fs, e->info);
463 OpCode op = GET_OPCODE(*pc); 463 lua_assert(testOpMode(GET_OPCODE(*pc), OpModeT));
464 switch (op) { 464 SETARG_B(*pc, !(GETARG_B(*pc)));
465 case OP_EQ: {
466 SETARG_B(*pc, !(GETARG_B(*pc)));
467 return;
468 }
469 case OP_CMP: {
470 SETARG_B(*pc, ~(GETARG_B(*pc)));
471 return;
472 }
473 default: lua_assert(0); /* invalid jump instruction */
474 }
475 SET_OPCODE(*pc, op);
476} 465}
477 466
478 467
@@ -629,12 +618,6 @@ void luaK_infix (FuncState *fs, BinOpr op, expdesc *v) {
629} 618}
630 619
631 620
632
633static const int cmp_masks[] = { /* ORDER OPR */
634 CMP_LT, (CMP_LT | CMP_EQ), CMP_GT, (CMP_GT | CMP_EQ)
635};
636
637
638static void codebinop (FuncState *fs, expdesc *res, BinOpr op, 621static void codebinop (FuncState *fs, expdesc *res, BinOpr op,
639 int o1, int o2, int ic) { 622 int o1, int o2, int ic) {
640 switch (op) { 623 switch (op) {
@@ -644,7 +627,7 @@ static void codebinop (FuncState *fs, expdesc *res, BinOpr op,
644 lua_assert(!ic); 627 lua_assert(!ic);
645 /* go through */ 628 /* go through */
646 case OPR_ADD: 629 case OPR_ADD:
647 case OPR_MULT: { 630 case OPR_MULT: { /* ORDER OPR */
648 OpCode opc = cast(OpCode, (op - OPR_ADD) + OP_ADD); 631 OpCode opc = cast(OpCode, (op - OPR_ADD) + OP_ADD);
649 res->info = luaK_codeABC(fs, opc, 0, o1, o2); 632 res->info = luaK_codeABC(fs, opc, 0, o1, o2);
650 res->k = VRELOCABLE; 633 res->k = VRELOCABLE;
@@ -659,11 +642,13 @@ static void codebinop (FuncState *fs, expdesc *res, BinOpr op,
659 case OPR_LT: 642 case OPR_LT:
660 case OPR_LE: 643 case OPR_LE:
661 case OPR_GT: 644 case OPR_GT:
662 case OPR_GE: { 645 case OPR_GE: { /* ORDER OPR */
663 int mask = cmp_masks[op - OPR_LT]; 646 OpCode opc;
647 int i = op - OPR_LT;
664 if (ic) /* operands were interchanged? */ 648 if (ic) /* operands were interchanged? */
665 mask ^= (CMP_LT | CMP_GT); /* correct condition */ 649 i = (i+2)&3; /* correct operator */
666 res->info = luaK_condjump(fs, OP_CMP, o1, mask, o2); 650 opc = cast(OpCode, i + OP_LT);
651 res->info = luaK_condjump(fs, opc, o1, 1, o2);
667 res->k = VJMP; 652 res->k = VJMP;
668 break; 653 break;
669 } 654 }