diff --git a/lcode.c b/lcode.c index 08e92ea1..f2c9de7b 100644 --- a/lcode.c +++ b/lcode.c @@ -1,5 +1,5 @@ /* -** $Id: lcode.c,v 2.133 2017/11/16 12:59:14 roberto Exp roberto $ +** $Id: lcode.c,v 2.134 2017/11/22 18:41:20 roberto Exp roberto $ ** Code generator for Lua ** See Copyright Notice in lua.h */ @@ -969,7 +969,7 @@ static void negatecondition (FuncState *fs, expdesc *e) { Instruction *pc = getjumpcontrol(fs, e->u.info); lua_assert(testTMode(GET_OPCODE(*pc)) && GET_OPCODE(*pc) != OP_TESTSET && GET_OPCODE(*pc) != OP_TEST); - SETARG_A(*pc, !(GETARG_A(*pc))); + SETARG_B(*pc, !(GETARG_B(*pc))); } @@ -1286,12 +1286,12 @@ static void codeorder (FuncState *fs, BinOpr opr, expdesc *e1, expdesc *e2) { case OPR_GT: case OPR_GE: { /* '(a > b)' ==> '(b < a)'; '(a >= b)' ==> '(b <= a)' */ OpCode op = cast(OpCode, (opr - OPR_NE) + OP_EQ); - e1->u.info = condjump(fs, op, 1, rk2, rk1); /* invert operands */ + e1->u.info = condjump(fs, op, rk2, 1, rk1); /* invert operands */ break; } default: { /* '==', '<', '<=' use their own opcodes */ OpCode op = cast(OpCode, (opr - OPR_EQ) + OP_EQ); - e1->u.info = condjump(fs, op, 1, rk1, rk2); + e1->u.info = condjump(fs, op, rk1, 1, rk2); break; } } @@ -1325,7 +1325,7 @@ static void codeeq (FuncState *fs, BinOpr opr, expdesc *e1, expdesc *e2) { r2 = luaK_exp2anyreg(fs, e2); } freeexps(fs, e1, e2); - e1->u.info = condjump(fs, op, (opr == OPR_EQ), r1, r2); + e1->u.info = condjump(fs, op, r1, (opr == OPR_EQ), r2); e1->k = VJMP; } diff --git a/lopcodes.h b/lopcodes.h index 6829711c..a9645620 100644 --- a/lopcodes.h +++ b/lopcodes.h @@ -1,5 +1,5 @@ /* -** $Id: lopcodes.h,v 1.168 2017/11/16 12:59:14 roberto Exp roberto $ +** $Id: lopcodes.h,v 1.169 2017/11/22 18:41:20 roberto Exp roberto $ ** Opcodes for Lua virtual machine ** See Copyright Notice in lua.h */ @@ -236,12 +236,12 @@ OP_CONCAT,/* A B C R(A) := R(B).. ... ..R(C) */ OP_CLOSE,/* A close all upvalues >= R(A) */ OP_JMP,/* k sJ pc += sJ (k is used in code generation) */ -OP_EQ,/* A B C if ((R(B) == R(C)) ~= A) then pc++ */ -OP_LT,/* A B C if ((R(B) < R(C)) ~= A) then pc++ */ -OP_LE,/* A B C if ((R(B) <= R(C)) ~= A) then pc++ */ +OP_EQ,/* A B C if ((R(A) == R(C)) ~= B) then pc++ */ +OP_LT,/* A B C if ((R(A) < R(C)) ~= B) then pc++ */ +OP_LE,/* A B C if ((R(A) <= R(C)) ~= B) then pc++ */ -OP_EQK,/* A B C if ((R(B) == K(C)) ~= A) then pc++ */ -OP_EQI,/* A B C if ((R(B) == C) ~= A) then pc++ */ +OP_EQK,/* A B C if ((R(A) == K(C)) ~= B) then pc++ */ +OP_EQI,/* A B C if ((R(A) == C) ~= B) then pc++ */ OP_TEST,/* A C if not (R(A) <=> C) then pc++ */ OP_TESTSET,/* A B C if (R(B) <=> C) then R(A) := R(B) else pc++ */ diff --git a/lvm.c b/lvm.c index 6c4bab08..457da1dd 100644 --- a/lvm.c +++ b/lvm.c @@ -1,5 +1,5 @@ /* -** $Id: lvm.c,v 2.313 2017/11/21 14:17:35 roberto Exp $ +** $Id: lvm.c,v 2.314 2017/11/22 18:41:20 roberto Exp roberto $ ** Lua virtual machine ** See Copyright Notice in lua.h */ @@ -715,7 +715,7 @@ void luaV_finishOp (lua_State *L) { res = !res; /* negate result */ } lua_assert(GET_OPCODE(*ci->u.l.savedpc) == OP_JMP); - if (res != GETARG_A(inst)) /* condition failed? */ + if (res != GETARG_B(inst)) /* condition failed? */ ci->u.l.savedpc++; /* skip jump instruction */ break; } @@ -1340,64 +1340,59 @@ void luaV_execute (lua_State *L) { vmbreak; } vmcase(OP_EQ) { - TValue *rb = vRB(i); TValue *rc = vRC(i); int res; - Protect(res = luaV_equalobj(L, rb, rc)); - if (res != GETARG_A(i)) + Protect(res = luaV_equalobj(L, s2v(ra), rc)); + if (res != GETARG_B(i)) pc++; else donextjump(ci); vmbreak; } vmcase(OP_LT) { - TValue *rb = vRB(i); TValue *rc = vRC(i); int res; - if (ttisinteger(rb) && ttisinteger(rc)) - res = (ivalue(rb) < ivalue(rc)); - else if (ttisnumber(rb) && ttisnumber(rc)) - res = LTnum(rb, rc); + if (ttisinteger(s2v(ra)) && ttisinteger(rc)) + res = (ivalue(s2v(ra)) < ivalue(rc)); + else if (ttisnumber(s2v(ra)) && ttisnumber(rc)) + res = LTnum(s2v(ra), rc); else - Protect(res = lessthanothers(L, rb, rc)); - if (res != GETARG_A(i)) + Protect(res = lessthanothers(L, s2v(ra), rc)); + if (res != GETARG_B(i)) pc++; else donextjump(ci); vmbreak; } vmcase(OP_LE) { - TValue *rb = vRB(i); TValue *rc = vRC(i); int res; - if (ttisinteger(rb) && ttisinteger(rc)) - res = (ivalue(rb) <= ivalue(rc)); - else if (ttisnumber(rb) && ttisnumber(rc)) - res = LEnum(rb, rc); + if (ttisinteger(s2v(ra)) && ttisinteger(rc)) + res = (ivalue(s2v(ra)) <= ivalue(rc)); + else if (ttisnumber(s2v(ra)) && ttisnumber(rc)) + res = LEnum(s2v(ra), rc); else - Protect(res = lessequalothers(L, rb, rc)); - if (res != GETARG_A(i)) + Protect(res = lessequalothers(L, s2v(ra), rc)); + if (res != GETARG_B(i)) pc++; else donextjump(ci); vmbreak; } vmcase(OP_EQK) { - TValue *rb = vRB(i); TValue *rc = KC(i); /* basic types do not use '__eq'; we can use raw equality */ - if (luaV_equalobj(NULL, rb, rc) != GETARG_A(i)) + if (luaV_equalobj(NULL, s2v(ra), rc) != GETARG_B(i)) pc++; else donextjump(ci); vmbreak; } vmcase(OP_EQI) { - TValue *rb = vRB(i); int ic = GETARG_sC(i); - if ((ttisinteger(rb) ? (ivalue(rb) == ic) - :ttisfloat(rb) ? luai_numeq(fltvalue(rb), cast_num(ic)) - : 0) != GETARG_A(i)) + if ((ttisinteger(s2v(ra)) ? (ivalue(s2v(ra)) == ic) + :ttisfloat(s2v(ra)) ? luai_numeq(fltvalue(s2v(ra)), cast_num(ic)) + : 0) != GETARG_B(i)) pc++; else donextjump(ci);