** Finalize code for binary operation, after reading 2nd operand. */
| 1703 | ** Finalize code for binary operation, after reading 2nd operand. |
| 1704 | */ |
| 1705 | void luaK_posfix (FuncState *fs, BinOpr opr, |
| 1706 | expdesc *e1, expdesc *e2, int line) { |
| 1707 | luaK_dischargevars(fs, e2); |
| 1708 | if (foldbinop(opr) && constfolding(fs, opr + LUA_OPADD, e1, e2)) |
| 1709 | return; /* done by folding */ |
| 1710 | switch (opr) { |
| 1711 | case OPR_AND: { |
| 1712 | lua_assert(e1->t == NO_JUMP); /* list closed by 'luaK_infix' */ |
| 1713 | luaK_concat(fs, &e2->f, e1->f); |
| 1714 | *e1 = *e2; |
| 1715 | break; |
| 1716 | } |
| 1717 | case OPR_OR: { |
| 1718 | lua_assert(e1->f == NO_JUMP); /* list closed by 'luaK_infix' */ |
| 1719 | luaK_concat(fs, &e2->t, e1->t); |
| 1720 | *e1 = *e2; |
| 1721 | break; |
| 1722 | } |
| 1723 | case OPR_CONCAT: { /* e1 .. e2 */ |
| 1724 | luaK_exp2nextreg(fs, e2); |
| 1725 | codeconcat(fs, e1, e2, line); |
| 1726 | break; |
| 1727 | } |
| 1728 | case OPR_ADD: case OPR_MUL: { |
| 1729 | codecommutative(fs, opr, e1, e2, line); |
| 1730 | break; |
| 1731 | } |
| 1732 | case OPR_SUB: { |
| 1733 | if (finishbinexpneg(fs, e1, e2, OP_ADDI, line, TM_SUB)) |
| 1734 | break; /* coded as (r1 + -I) */ |
| 1735 | /* ELSE */ |
| 1736 | } /* FALLTHROUGH */ |
| 1737 | case OPR_DIV: case OPR_IDIV: case OPR_MOD: case OPR_POW: { |
| 1738 | codearith(fs, opr, e1, e2, 0, line); |
| 1739 | break; |
| 1740 | } |
| 1741 | case OPR_BAND: case OPR_BOR: case OPR_BXOR: { |
| 1742 | codebitwise(fs, opr, e1, e2, line); |
| 1743 | break; |
| 1744 | } |
| 1745 | case OPR_SHL: { |
| 1746 | if (isSCint(e1)) { |
| 1747 | swapexps(e1, e2); |
| 1748 | codebini(fs, OP_SHLI, e1, e2, 1, line, TM_SHL); /* I << r2 */ |
| 1749 | } |
| 1750 | else if (finishbinexpneg(fs, e1, e2, OP_SHRI, line, TM_SHL)) { |
| 1751 | /* coded as (r1 >> -I) */; |
| 1752 | } |
| 1753 | else /* regular case (two registers) */ |
| 1754 | codebinexpval(fs, opr, e1, e2, line); |
| 1755 | break; |
| 1756 | } |
| 1757 | case OPR_SHR: { |
| 1758 | if (isSCint(e2)) |
| 1759 | codebini(fs, OP_SHRI, e1, e2, 0, line, TM_SHR); /* r1 >> I */ |
| 1760 | else /* regular case (two registers) */ |
| 1761 | codebinexpval(fs, opr, e1, e2, line); |
| 1762 | break; |
no test coverage detected