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 /lcode.c | |
parent | 91dad09f65984048ae43c8894d18acb785c7092b (diff) | |
download | lua-40d8832ee05096f9aea8eb54d1cdccf2646aecd0.tar.gz lua-40d8832ee05096f9aea8eb54d1cdccf2646aecd0.tar.bz2 lua-40d8832ee05096f9aea8eb54d1cdccf2646aecd0.zip |
Simplification in the call to 'constfolding'
Diffstat (limited to 'lcode.c')
-rw-r--r-- | lcode.c | 26 |
1 files changed, 11 insertions, 15 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: { |