** Finalize code for binary operation, after reading 2nd operand. */
| 1640 | ** Finalize code for binary operation, after reading 2nd operand. |
| 1641 | */ |
| 1642 | void luaK_posfix (FuncState *fs, BinOpr opr, |
| 1643 | expdesc *e1, expdesc *e2, int line) { |
| 1644 | luaK_dischargevars(fs, e2); |
| 1645 | if (foldbinop(opr) && constfolding(fs, opr + LUA_OPADD, e1, e2)) |
| 1646 | return; /* done by folding */ |
| 1647 | switch (opr) { |
| 1648 | case OPR_AND: { |
| 1649 | lua_assert(e1->t == NO_JUMP); /* list closed by 'luaK_infix' */ |
| 1650 | luaK_concat(fs, &e2->f, e1->f); |
| 1651 | *e1 = *e2; |
| 1652 | break; |
| 1653 | } |
| 1654 | case OPR_OR: { |
| 1655 | lua_assert(e1->f == NO_JUMP); /* list closed by 'luaK_infix' */ |
| 1656 | luaK_concat(fs, &e2->t, e1->t); |
| 1657 | *e1 = *e2; |
| 1658 | break; |
| 1659 | } |
| 1660 | case OPR_CONCAT: { /* e1 .. e2 */ |
| 1661 | luaK_exp2nextreg(fs, e2); |
| 1662 | codeconcat(fs, e1, e2, line); |
| 1663 | break; |
| 1664 | } |
| 1665 | case OPR_ADD: case OPR_MUL: { |
| 1666 | codecommutative(fs, opr, e1, e2, line); |
| 1667 | break; |
| 1668 | } |
| 1669 | case OPR_SUB: { |
| 1670 | if (finishbinexpneg(fs, e1, e2, OP_ADDI, line, TM_SUB)) |
| 1671 | break; /* coded as (r1 + -I) */ |
| 1672 | /* ELSE */ |
| 1673 | } /* FALLTHROUGH */ |
| 1674 | case OPR_DIV: case OPR_IDIV: case OPR_MOD: case OPR_POW: { |
| 1675 | codearith(fs, opr, e1, e2, 0, line); |
| 1676 | break; |
| 1677 | } |
| 1678 | case OPR_BAND: case OPR_BOR: case OPR_BXOR: { |
| 1679 | codebitwise(fs, opr, e1, e2, line); |
| 1680 | break; |
| 1681 | } |
| 1682 | case OPR_SHL: { |
| 1683 | if (isSCint(e1)) { |
| 1684 | swapexps(e1, e2); |
| 1685 | codebini(fs, OP_SHLI, e1, e2, 1, line, TM_SHL); /* I << r2 */ |
| 1686 | } |
| 1687 | else if (finishbinexpneg(fs, e1, e2, OP_SHRI, line, TM_SHL)) { |
| 1688 | /* coded as (r1 >> -I) */; |
| 1689 | } |
| 1690 | else /* regular case (two registers) */ |
| 1691 | codebinexpval(fs, OP_SHL, e1, e2, line); |
| 1692 | break; |
| 1693 | } |
| 1694 | case OPR_SHR: { |
| 1695 | if (isSCint(e2)) |
| 1696 | codebini(fs, OP_SHRI, e1, e2, 0, line, TM_SHR); /* r1 >> I */ |
| 1697 | else /* regular case (two registers) */ |
| 1698 | codebinexpval(fs, OP_SHR, e1, e2, line); |
| 1699 | break; |
no test coverage detected