diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2019-09-11 10:20:10 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2019-09-11 10:20:10 -0300 |
commit | 40d8832ee05096f9aea8eb54d1cdccf2646aecd0 (patch) | |
tree | a36e3995afcdbddb9d584bad7c1f3c5516135618 | |
parent | 91dad09f65984048ae43c8894d18acb785c7092b (diff) | |
download | lua-40d8832ee05096f9aea8eb54d1cdccf2646aecd0.tar.gz lua-40d8832ee05096f9aea8eb54d1cdccf2646aecd0.tar.bz2 lua-40d8832ee05096f9aea8eb54d1cdccf2646aecd0.zip |
Simplification in the call to 'constfolding'
-rw-r--r-- | lcode.c | 26 | ||||
-rw-r--r-- | lcode.h | 12 |
2 files changed, 21 insertions, 17 deletions
@@ -1630,6 +1630,8 @@ static void codeconcat (FuncState *fs, expdesc *e1, expdesc *e2, int line) { | |||
1630 | void luaK_posfix (FuncState *fs, BinOpr opr, | 1630 | void luaK_posfix (FuncState *fs, BinOpr opr, |
1631 | expdesc *e1, expdesc *e2, int line) { | 1631 | expdesc *e1, expdesc *e2, int line) { |
1632 | luaK_dischargevars(fs, e2); | 1632 | luaK_dischargevars(fs, e2); |
1633 | if (foldbinop(opr) && constfolding(fs, opr + LUA_OPADD, e1, e2)) | ||
1634 | return; /* done by folding */ | ||
1633 | switch (opr) { | 1635 | switch (opr) { |
1634 | case OPR_AND: { | 1636 | case OPR_AND: { |
1635 | lua_assert(e1->t == NO_JUMP); /* list closed by 'luaK_infix' */ | 1637 | lua_assert(e1->t == NO_JUMP); /* list closed by 'luaK_infix' */ |
@@ -1649,35 +1651,29 @@ void luaK_posfix (FuncState *fs, BinOpr opr, | |||
1649 | break; | 1651 | break; |
1650 | } | 1652 | } |
1651 | case OPR_ADD: case OPR_MUL: { | 1653 | case OPR_ADD: case OPR_MUL: { |
1652 | if (!constfolding(fs, opr + LUA_OPADD, e1, e2)) | 1654 | codecommutative(fs, opr, e1, e2, line); |
1653 | codecommutative(fs, opr, e1, e2, line); | ||
1654 | break; | 1655 | break; |
1655 | } | 1656 | } |
1656 | case OPR_SUB: case OPR_DIV: | 1657 | case OPR_SUB: case OPR_DIV: |
1657 | case OPR_IDIV: case OPR_MOD: case OPR_POW: { | 1658 | case OPR_IDIV: case OPR_MOD: case OPR_POW: { |
1658 | if (!constfolding(fs, opr + LUA_OPADD, e1, e2)) | 1659 | codearith(fs, opr, e1, e2, 0, line); |
1659 | codearith(fs, opr, e1, e2, 0, line); | ||
1660 | break; | 1660 | break; |
1661 | } | 1661 | } |
1662 | case OPR_BAND: case OPR_BOR: case OPR_BXOR: { | 1662 | case OPR_BAND: case OPR_BOR: case OPR_BXOR: { |
1663 | if (!constfolding(fs, opr + LUA_OPADD, e1, e2)) | 1663 | codebitwise(fs, opr, e1, e2, line); |
1664 | codebitwise(fs, opr, e1, e2, line); | ||
1665 | break; | 1664 | break; |
1666 | } | 1665 | } |
1667 | case OPR_SHL: { | 1666 | case OPR_SHL: { |
1668 | if (!constfolding(fs, LUA_OPSHL, e1, e2)) { | 1667 | if (isSCint(e1)) { |
1669 | if (isSCint(e1)) { | 1668 | swapexps(e1, e2); |
1670 | swapexps(e1, e2); | 1669 | codebini(fs, OP_SHLI, e1, e2, 1, line, TM_SHL); |
1671 | codebini(fs, OP_SHLI, e1, e2, 1, line, TM_SHL); | ||
1672 | } | ||
1673 | else | ||
1674 | codeshift(fs, OP_SHL, e1, e2, line); | ||
1675 | } | 1670 | } |
1671 | else | ||
1672 | codeshift(fs, OP_SHL, e1, e2, line); | ||
1676 | break; | 1673 | break; |
1677 | } | 1674 | } |
1678 | case OPR_SHR: { | 1675 | case OPR_SHR: { |
1679 | if (!constfolding(fs, LUA_OPSHR, e1, e2)) | 1676 | codeshift(fs, OP_SHR, e1, e2, line); |
1680 | codeshift(fs, OP_SHR, e1, e2, line); | ||
1681 | break; | 1677 | break; |
1682 | } | 1678 | } |
1683 | case OPR_EQ: case OPR_NE: { | 1679 | case OPR_EQ: case OPR_NE: { |
@@ -24,19 +24,27 @@ | |||
24 | ** grep "ORDER OPR" if you change these enums (ORDER OP) | 24 | ** grep "ORDER OPR" if you change these enums (ORDER OP) |
25 | */ | 25 | */ |
26 | typedef enum BinOpr { | 26 | typedef enum BinOpr { |
27 | /* arithmetic operators */ | ||
27 | OPR_ADD, OPR_SUB, OPR_MUL, OPR_MOD, OPR_POW, | 28 | OPR_ADD, OPR_SUB, OPR_MUL, OPR_MOD, OPR_POW, |
28 | OPR_DIV, | 29 | OPR_DIV, OPR_IDIV, |
29 | OPR_IDIV, | 30 | /* bitwise operators */ |
30 | OPR_BAND, OPR_BOR, OPR_BXOR, | 31 | OPR_BAND, OPR_BOR, OPR_BXOR, |
31 | OPR_SHL, OPR_SHR, | 32 | OPR_SHL, OPR_SHR, |
33 | /* string operator */ | ||
32 | OPR_CONCAT, | 34 | OPR_CONCAT, |
35 | /* comparison operators */ | ||
33 | OPR_EQ, OPR_LT, OPR_LE, | 36 | OPR_EQ, OPR_LT, OPR_LE, |
34 | OPR_NE, OPR_GT, OPR_GE, | 37 | OPR_NE, OPR_GT, OPR_GE, |
38 | /* logical operators */ | ||
35 | OPR_AND, OPR_OR, | 39 | OPR_AND, OPR_OR, |
36 | OPR_NOBINOPR | 40 | OPR_NOBINOPR |
37 | } BinOpr; | 41 | } BinOpr; |
38 | 42 | ||
39 | 43 | ||
44 | /* true if operation is foldable (that is, it is arithmetic or bitwise) */ | ||
45 | #define foldbinop(op) ((op) <= OPR_SHR) | ||
46 | |||
47 | |||
40 | #define luaK_codeABC(fs,o,a,b,c) luaK_codeABCk(fs,o,a,b,c,0) | 48 | #define luaK_codeABC(fs,o,a,b,c) luaK_codeABCk(fs,o,a,b,c,0) |
41 | 49 | ||
42 | 50 | ||