aboutsummaryrefslogtreecommitdiff
path: root/lcode.c
diff options
context:
space:
mode:
Diffstat (limited to 'lcode.c')
-rw-r--r--lcode.c30
1 files changed, 12 insertions, 18 deletions
diff --git a/lcode.c b/lcode.c
index c182794e..30bf13d8 100644
--- a/lcode.c
+++ b/lcode.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lcode.c,v 2.155 2018/02/17 19:20:00 roberto Exp roberto $ 2** $Id: lcode.c,v 2.156 2018/02/21 12:54: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*/
@@ -171,8 +171,8 @@ void luaK_ret (FuncState *fs, int first, int nret) {
171** Code a "conditional jump", that is, a test or comparison opcode 171** Code a "conditional jump", that is, a test or comparison opcode
172** followed by a jump. Return jump position. 172** followed by a jump. Return jump position.
173*/ 173*/
174static int condjump (FuncState *fs, OpCode op, int A, int B, int C, int k) { 174static int condjump (FuncState *fs, OpCode op, int A, int B, int k) {
175 luaK_codeABCk(fs, op, A, B, C, k); 175 luaK_codeABCk(fs, op, A, B, 0, k);
176 return luaK_jump(fs); 176 return luaK_jump(fs);
177} 177}
178 178
@@ -979,13 +979,13 @@ static int jumponcond (FuncState *fs, expdesc *e, int cond) {
979 Instruction ie = getinstruction(fs, e); 979 Instruction ie = getinstruction(fs, e);
980 if (GET_OPCODE(ie) == OP_NOT) { 980 if (GET_OPCODE(ie) == OP_NOT) {
981 fs->pc--; /* remove previous OP_NOT */ 981 fs->pc--; /* remove previous OP_NOT */
982 return condjump(fs, OP_TEST, GETARG_B(ie), 0, 0, !cond); 982 return condjump(fs, OP_TEST, GETARG_B(ie), 0, !cond);
983 } 983 }
984 /* else go through */ 984 /* else go through */
985 } 985 }
986 discharge2anyreg(fs, e); 986 discharge2anyreg(fs, e);
987 freeexp(fs, e); 987 freeexp(fs, e);
988 return condjump(fs, OP_TESTSET, NO_REG, e->u.info, 0, cond); 988 return condjump(fs, OP_TESTSET, NO_REG, e->u.info, cond);
989} 989}
990 990
991 991
@@ -1338,16 +1338,12 @@ static void codeshift (FuncState *fs, OpCode op,
1338 1338
1339/* 1339/*
1340** Emit code for order comparisons. 1340** Emit code for order comparisons.
1341** When the first operand is an integral value in the proper range, 1341** When the first operand A is an integral value in the proper range,
1342** change (A < B) to (!(B <= A)) and (A <= B) to (!(B < A)) so that 1342** change (A < B) to (B > A) and (A <= B) to (B >= A) so that
1343** it can use an immediate operand. In this case, C indicates this 1343** it can use an immediate operand.
1344** change, for cases that cannot assume a total order (NaN and
1345** metamethods).
1346*/ 1344*/
1347static void codeorder (FuncState *fs, OpCode op, expdesc *e1, expdesc *e2) { 1345static void codeorder (FuncState *fs, OpCode op, expdesc *e1, expdesc *e2) {
1348 int r1, r2; 1346 int r1, r2;
1349 int cond = 1;
1350 int C = 0;
1351 lua_Integer im; 1347 lua_Integer im;
1352 if (isSCnumber(e2, &im)) { 1348 if (isSCnumber(e2, &im)) {
1353 /* use immediate operand */ 1349 /* use immediate operand */
@@ -1356,19 +1352,17 @@ static void codeorder (FuncState *fs, OpCode op, expdesc *e1, expdesc *e2) {
1356 op = cast(OpCode, (op - OP_LT) + OP_LTI); 1352 op = cast(OpCode, (op - OP_LT) + OP_LTI);
1357 } 1353 }
1358 else if (isSCnumber(e1, &im)) { 1354 else if (isSCnumber(e1, &im)) {
1359 /* transform (A < B) to (!(B <= A)) and (A <= B) to (!(B < A)) */ 1355 /* transform (A < B) to (B > A) and (A <= B) to (B >= A) */
1360 r1 = luaK_exp2anyreg(fs, e2); 1356 r1 = luaK_exp2anyreg(fs, e2);
1361 r2 = cast_int(im); 1357 r2 = cast_int(im);
1362 op = (op == OP_LT) ? OP_LEI : OP_LTI; 1358 op = (op == OP_LT) ? OP_GTI : OP_GEI;
1363 cond = 0; /* negate original test */
1364 C = 1; /* indication that it used the transformations */
1365 } 1359 }
1366 else { /* regular case, compare two registers */ 1360 else { /* regular case, compare two registers */
1367 r1 = luaK_exp2anyreg(fs, e1); 1361 r1 = luaK_exp2anyreg(fs, e1);
1368 r2 = luaK_exp2anyreg(fs, e2); 1362 r2 = luaK_exp2anyreg(fs, e2);
1369 } 1363 }
1370 freeexps(fs, e1, e2); 1364 freeexps(fs, e1, e2);
1371 e1->u.info = condjump(fs, op, r1, r2, C, cond); 1365 e1->u.info = condjump(fs, op, r1, r2, 1);
1372 e1->k = VJMP; 1366 e1->k = VJMP;
1373} 1367}
1374 1368
@@ -1399,7 +1393,7 @@ static void codeeq (FuncState *fs, BinOpr opr, expdesc *e1, expdesc *e2) {
1399 r2 = luaK_exp2anyreg(fs, e2); 1393 r2 = luaK_exp2anyreg(fs, e2);
1400 } 1394 }
1401 freeexps(fs, e1, e2); 1395 freeexps(fs, e1, e2);
1402 e1->u.info = condjump(fs, op, r1, r2, 0, (opr == OPR_EQ)); 1396 e1->u.info = condjump(fs, op, r1, r2, (opr == OPR_EQ));
1403 e1->k = VJMP; 1397 e1->k = VJMP;
1404} 1398}
1405 1399