** Do a final pass over the code of a function, doing small peephole ** optimizations and adjustments. */
| 1784 | ** optimizations and adjustments. |
| 1785 | */ |
| 1786 | void luaK_finish (FuncState *fs) { |
| 1787 | int i; |
| 1788 | Proto *p = fs->f; |
| 1789 | for (i = 0; i < fs->pc; i++) { |
| 1790 | Instruction *pc = &p->code[i]; |
| 1791 | lua_assert(i == 0 || isOT(*(pc - 1)) == isIT(*pc)); |
| 1792 | switch (GET_OPCODE(*pc)) { |
| 1793 | case OP_RETURN0: case OP_RETURN1: { |
| 1794 | if (!(fs->needclose || p->is_vararg)) |
| 1795 | break; /* no extra work */ |
| 1796 | /* else use OP_RETURN to do the extra work */ |
| 1797 | SET_OPCODE(*pc, OP_RETURN); |
| 1798 | } /* FALLTHROUGH */ |
| 1799 | case OP_RETURN: case OP_TAILCALL: { |
| 1800 | if (fs->needclose) |
| 1801 | SETARG_k(*pc, 1); /* signal that it needs to close */ |
| 1802 | if (p->is_vararg) |
| 1803 | SETARG_C(*pc, p->numparams + 1); /* signal that it is vararg */ |
| 1804 | break; |
| 1805 | } |
| 1806 | case OP_JMP: { |
| 1807 | int target = finaltarget(p->code, i); |
| 1808 | fixjump(fs, i, target); |
| 1809 | break; |
| 1810 | } |
| 1811 | default: break; |
| 1812 | } |
| 1813 | } |
| 1814 | } |
no test coverage detected