MCPcopy Create free account
hub / github.com/Cubitect/cubiomes-viewer / luaK_finish

Function luaK_finish

lua/src/lcode.c:1804–1832  ·  view source on GitHub ↗

** Do a final pass over the code of a function, doing small peephole ** optimizations and adjustments. */

Source from the content-addressed store, hash-verified

1802** optimizations and adjustments.
1803*/
1804void luaK_finish (FuncState *fs) {
1805 int i;
1806 Proto *p = fs->f;
1807 for (i = 0; i < fs->pc; i++) {
1808 Instruction *pc = &p->code[i];
1809 lua_assert(i == 0 || isOT(*(pc - 1)) == isIT(*pc));
1810 switch (GET_OPCODE(*pc)) {
1811 case OP_RETURN0: case OP_RETURN1: {
1812 if (!(fs->needclose || p->is_vararg))
1813 break; /* no extra work */
1814 /* else use OP_RETURN to do the extra work */
1815 SET_OPCODE(*pc, OP_RETURN);
1816 } /* FALLTHROUGH */
1817 case OP_RETURN: case OP_TAILCALL: {
1818 if (fs->needclose)
1819 SETARG_k(*pc, 1); /* signal that it needs to close */
1820 if (p->is_vararg)
1821 SETARG_C(*pc, p->numparams + 1); /* signal that it is vararg */
1822 break;
1823 }
1824 case OP_JMP: {
1825 int target = finaltarget(p->code, i);
1826 fixjump(fs, i, target);
1827 break;
1828 }
1829 default: break;
1830 }
1831 }
1832}

Callers 1

close_funcFunction · 0.85

Calls 2

finaltargetFunction · 0.85
fixjumpFunction · 0.85

Tested by

no test coverage detected