aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lcode.c36
1 files changed, 18 insertions, 18 deletions
diff --git a/lcode.c b/lcode.c
index 911dbd5f..236ce05c 100644
--- a/lcode.c
+++ b/lcode.c
@@ -1389,15 +1389,16 @@ static void finishbinexpval (FuncState *fs, expdesc *e1, expdesc *e2,
1389** Emit code for binary expressions that "produce values" over 1389** Emit code for binary expressions that "produce values" over
1390** two registers. 1390** two registers.
1391*/ 1391*/
1392static void codebinexpval (FuncState *fs, OpCode op, 1392static void codebinexpval (FuncState *fs, BinOpr opr,
1393 expdesc *e1, expdesc *e2, int line) { 1393 expdesc *e1, expdesc *e2, int line) {
1394 OpCode op = cast(OpCode, opr + OP_ADD);
1394 int v2 = luaK_exp2anyreg(fs, e2); /* make sure 'e2' is in a register */ 1395 int v2 = luaK_exp2anyreg(fs, e2); /* make sure 'e2' is in a register */
1395 /* 'e1' must be already in a register or it is a constant */ 1396 /* 'e1' must be already in a register or it is a constant */
1396 lua_assert((VNIL <= e1->k && e1->k <= VKSTR) || 1397 lua_assert((VNIL <= e1->k && e1->k <= VKSTR) ||
1397 e1->k == VNONRELOC || e1->k == VRELOC); 1398 e1->k == VNONRELOC || e1->k == VRELOC);
1398 lua_assert(OP_ADD <= op && op <= OP_SHR); 1399 lua_assert(OP_ADD <= op && op <= OP_SHR);
1399 finishbinexpval(fs, e1, e2, op, v2, 0, line, OP_MMBIN, 1400 finishbinexpval(fs, e1, e2, op, v2, 0, line, OP_MMBIN,
1400 cast(TMS, (op - OP_ADD) + TM_ADD)); 1401 cast(TMS, opr + TM_ADD));
1401} 1402}
1402 1403
1403 1404
@@ -1457,10 +1458,9 @@ static void swapexps (expdesc *e1, expdesc *e2) {
1457*/ 1458*/
1458static void codebinNoK (FuncState *fs, BinOpr opr, 1459static void codebinNoK (FuncState *fs, BinOpr opr,
1459 expdesc *e1, expdesc *e2, int flip, int line) { 1460 expdesc *e1, expdesc *e2, int flip, int line) {
1460 OpCode op = cast(OpCode, opr + OP_ADD);
1461 if (flip) 1461 if (flip)
1462 swapexps(e1, e2); /* back to original order */ 1462 swapexps(e1, e2); /* back to original order */
1463 codebinexpval(fs, op, e1, e2, line); /* use standard operators */ 1463 codebinexpval(fs, opr, e1, e2, line); /* use standard operators */
1464} 1464}
1465 1465
1466 1466
@@ -1490,7 +1490,7 @@ static void codecommutative (FuncState *fs, BinOpr op,
1490 flip = 1; 1490 flip = 1;
1491 } 1491 }
1492 if (op == OPR_ADD && isSCint(e2)) /* immediate operand? */ 1492 if (op == OPR_ADD && isSCint(e2)) /* immediate operand? */
1493 codebini(fs, cast(OpCode, OP_ADDI), e1, e2, flip, line, TM_ADD); 1493 codebini(fs, OP_ADDI, e1, e2, flip, line, TM_ADD);
1494 else 1494 else
1495 codearith(fs, op, e1, e2, flip, line); 1495 codearith(fs, op, e1, e2, flip, line);
1496} 1496}
@@ -1518,25 +1518,27 @@ static void codebitwise (FuncState *fs, BinOpr opr,
1518** Emit code for order comparisons. When using an immediate operand, 1518** Emit code for order comparisons. When using an immediate operand,
1519** 'isfloat' tells whether the original value was a float. 1519** 'isfloat' tells whether the original value was a float.
1520*/ 1520*/
1521static void codeorder (FuncState *fs, OpCode op, expdesc *e1, expdesc *e2) { 1521static void codeorder (FuncState *fs, BinOpr opr, expdesc *e1, expdesc *e2) {
1522 int r1, r2; 1522 int r1, r2;
1523 int im; 1523 int im;
1524 int isfloat = 0; 1524 int isfloat = 0;
1525 OpCode op;
1525 if (isSCnumber(e2, &im, &isfloat)) { 1526 if (isSCnumber(e2, &im, &isfloat)) {
1526 /* use immediate operand */ 1527 /* use immediate operand */
1527 r1 = luaK_exp2anyreg(fs, e1); 1528 r1 = luaK_exp2anyreg(fs, e1);
1528 r2 = im; 1529 r2 = im;
1529 op = cast(OpCode, (op - OP_LT) + OP_LTI); 1530 op = cast(OpCode, (opr - OPR_LT) + OP_LTI);
1530 } 1531 }
1531 else if (isSCnumber(e1, &im, &isfloat)) { 1532 else if (isSCnumber(e1, &im, &isfloat)) {
1532 /* transform (A < B) to (B > A) and (A <= B) to (B >= A) */ 1533 /* transform (A < B) to (B > A) and (A <= B) to (B >= A) */
1533 r1 = luaK_exp2anyreg(fs, e2); 1534 r1 = luaK_exp2anyreg(fs, e2);
1534 r2 = im; 1535 r2 = im;
1535 op = (op == OP_LT) ? OP_GTI : OP_GEI; 1536 op = cast(OpCode, (opr - OPR_LT) + OP_GTI);
1536 } 1537 }
1537 else { /* regular case, compare two registers */ 1538 else { /* regular case, compare two registers */
1538 r1 = luaK_exp2anyreg(fs, e1); 1539 r1 = luaK_exp2anyreg(fs, e1);
1539 r2 = luaK_exp2anyreg(fs, e2); 1540 r2 = luaK_exp2anyreg(fs, e2);
1541 op = cast(OpCode, (opr - OPR_EQ) + OP_EQ);
1540 } 1542 }
1541 freeexps(fs, e1, e2); 1543 freeexps(fs, e1, e2);
1542 e1->u.info = condjump(fs, op, r1, r2, isfloat, 1); 1544 e1->u.info = condjump(fs, op, r1, r2, isfloat, 1);
@@ -1579,16 +1581,16 @@ static void codeeq (FuncState *fs, BinOpr opr, expdesc *e1, expdesc *e2) {
1579/* 1581/*
1580** Apply prefix operation 'op' to expression 'e'. 1582** Apply prefix operation 'op' to expression 'e'.
1581*/ 1583*/
1582void luaK_prefix (FuncState *fs, UnOpr op, expdesc *e, int line) { 1584void luaK_prefix (FuncState *fs, UnOpr opr, expdesc *e, int line) {
1583 static const expdesc ef = {VKINT, {0}, NO_JUMP, NO_JUMP}; 1585 static const expdesc ef = {VKINT, {0}, NO_JUMP, NO_JUMP};
1584 luaK_dischargevars(fs, e); 1586 luaK_dischargevars(fs, e);
1585 switch (op) { 1587 switch (opr) {
1586 case OPR_MINUS: case OPR_BNOT: /* use 'ef' as fake 2nd operand */ 1588 case OPR_MINUS: case OPR_BNOT: /* use 'ef' as fake 2nd operand */
1587 if (constfolding(fs, op + LUA_OPUNM, e, &ef)) 1589 if (constfolding(fs, opr + LUA_OPUNM, e, &ef))
1588 break; 1590 break;
1589 /* else */ /* FALLTHROUGH */ 1591 /* else */ /* FALLTHROUGH */
1590 case OPR_LEN: 1592 case OPR_LEN:
1591 codeunexpval(fs, cast(OpCode, op + OP_UNM), e, line); 1593 codeunexpval(fs, cast(OpCode, opr + OP_UNM), e, line);
1592 break; 1594 break;
1593 case OPR_NOT: codenot(fs, e); break; 1595 case OPR_NOT: codenot(fs, e); break;
1594 default: lua_assert(0); 1596 default: lua_assert(0);
@@ -1718,14 +1720,14 @@ void luaK_posfix (FuncState *fs, BinOpr opr,
1718 /* coded as (r1 >> -I) */; 1720 /* coded as (r1 >> -I) */;
1719 } 1721 }
1720 else /* regular case (two registers) */ 1722 else /* regular case (two registers) */
1721 codebinexpval(fs, OP_SHL, e1, e2, line); 1723 codebinexpval(fs, opr, e1, e2, line);
1722 break; 1724 break;
1723 } 1725 }
1724 case OPR_SHR: { 1726 case OPR_SHR: {
1725 if (isSCint(e2)) 1727 if (isSCint(e2))
1726 codebini(fs, OP_SHRI, e1, e2, 0, line, TM_SHR); /* r1 >> I */ 1728 codebini(fs, OP_SHRI, e1, e2, 0, line, TM_SHR); /* r1 >> I */
1727 else /* regular case (two registers) */ 1729 else /* regular case (two registers) */
1728 codebinexpval(fs, OP_SHR, e1, e2, line); 1730 codebinexpval(fs, opr, e1, e2, line);
1729 break; 1731 break;
1730 } 1732 }
1731 case OPR_EQ: case OPR_NE: { 1733 case OPR_EQ: case OPR_NE: {
@@ -1733,15 +1735,13 @@ void luaK_posfix (FuncState *fs, BinOpr opr,
1733 break; 1735 break;
1734 } 1736 }
1735 case OPR_LT: case OPR_LE: { 1737 case OPR_LT: case OPR_LE: {
1736 OpCode op = cast(OpCode, (opr - OPR_EQ) + OP_EQ); 1738 codeorder(fs, opr, e1, e2);
1737 codeorder(fs, op, e1, e2);
1738 break; 1739 break;
1739 } 1740 }
1740 case OPR_GT: case OPR_GE: { 1741 case OPR_GT: case OPR_GE: {
1741 /* '(a > b)' <=> '(b < a)'; '(a >= b)' <=> '(b <= a)' */ 1742 /* '(a > b)' <=> '(b < a)'; '(a >= b)' <=> '(b <= a)' */
1742 OpCode op = cast(OpCode, (opr - OPR_NE) + OP_EQ);
1743 swapexps(e1, e2); 1743 swapexps(e1, e2);
1744 codeorder(fs, op, e1, e2); 1744 codeorder(fs, (opr - OPR_NE) + OPR_EQ, e1, e2);
1745 break; 1745 break;
1746 } 1746 }
1747 default: lua_assert(0); 1747 default: lua_assert(0);