** Finalize code for binary operation, after reading 2nd operand. */
| 1785 | ** Finalize code for binary operation, after reading 2nd operand. |
| 1786 | */ |
| 1787 | void luaK_posfix (FuncState *fs, BinOpr opr, |
| 1788 | expdesc *e1, expdesc *e2, int line) { |
| 1789 | luaK_dischargevars(fs, e2); |
| 1790 | if (foldbinop(opr) && constfolding(fs, cast_int(opr + LUA_OPADD), e1, e2)) |
| 1791 | return; /* done by folding */ |
| 1792 | switch (opr) { |
| 1793 | case OPR_AND: { |
| 1794 | lua_assert(e1->t == NO_JUMP); /* list closed by 'luaK_infix' */ |
| 1795 | luaK_concat(fs, &e2->f, e1->f); |
| 1796 | *e1 = *e2; |
| 1797 | break; |
| 1798 | } |
| 1799 | case OPR_OR: { |
| 1800 | lua_assert(e1->f == NO_JUMP); /* list closed by 'luaK_infix' */ |
| 1801 | luaK_concat(fs, &e2->t, e1->t); |
| 1802 | *e1 = *e2; |
| 1803 | break; |
| 1804 | } |
| 1805 | case OPR_CONCAT: { /* e1 .. e2 */ |
| 1806 | luaK_exp2nextreg(fs, e2); |
| 1807 | codeconcat(fs, e1, e2, line); |
| 1808 | break; |
| 1809 | } |
| 1810 | case OPR_ADD: case OPR_MUL: { |
| 1811 | codecommutative(fs, opr, e1, e2, line); |
| 1812 | break; |
| 1813 | } |
| 1814 | case OPR_SUB: { |
| 1815 | if (finishbinexpneg(fs, e1, e2, OP_ADDI, line, TM_SUB)) |
| 1816 | break; /* coded as (r1 + -I) */ |
| 1817 | /* ELSE */ |
| 1818 | } /* FALLTHROUGH */ |
| 1819 | case OPR_DIV: case OPR_IDIV: case OPR_MOD: case OPR_POW: { |
| 1820 | codearith(fs, opr, e1, e2, 0, line); |
| 1821 | break; |
| 1822 | } |
| 1823 | case OPR_BAND: case OPR_BOR: case OPR_BXOR: { |
| 1824 | codebitwise(fs, opr, e1, e2, line); |
| 1825 | break; |
| 1826 | } |
| 1827 | case OPR_SHL: { |
| 1828 | if (isSCint(e1)) { |
| 1829 | swapexps(e1, e2); |
| 1830 | codebini(fs, OP_SHLI, e1, e2, 1, line, TM_SHL); /* I << r2 */ |
| 1831 | } |
| 1832 | else if (finishbinexpneg(fs, e1, e2, OP_SHRI, line, TM_SHL)) { |
| 1833 | /* coded as (r1 >> -I) */; |
| 1834 | } |
| 1835 | else /* regular case (two registers) */ |
| 1836 | codebinexpval(fs, opr, e1, e2, line); |
| 1837 | break; |
| 1838 | } |
| 1839 | case OPR_SHR: { |
| 1840 | if (isSCint(e2)) |
| 1841 | codebini(fs, OP_SHRI, e1, e2, 0, line, TM_SHR); /* r1 >> I */ |
| 1842 | else /* regular case (two registers) */ |
| 1843 | codebinexpval(fs, opr, e1, e2, line); |
| 1844 | break; |
no test coverage detected