MCPcopy Create free account
hub / github.com/Overload-Technologies/Overload / luaK_finish

Function luaK_finish

Dependencies/lua/src/lcode.c:1846–1874  ·  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

1844** optimizations and adjustments.
1845*/
1846void luaK_finish (FuncState *fs) {
1847 int i;
1848 Proto *p = fs->f;
1849 for (i = 0; i < fs->pc; i++) {
1850 Instruction *pc = &p->code[i];
1851 lua_assert(i == 0 || isOT(*(pc - 1)) == isIT(*pc));
1852 switch (GET_OPCODE(*pc)) {
1853 case OP_RETURN0: case OP_RETURN1: {
1854 if (!(fs->needclose || p->is_vararg))
1855 break; /* no extra work */
1856 /* else use OP_RETURN to do the extra work */
1857 SET_OPCODE(*pc, OP_RETURN);
1858 } /* FALLTHROUGH */
1859 case OP_RETURN: case OP_TAILCALL: {
1860 if (fs->needclose)
1861 SETARG_k(*pc, 1); /* signal that it needs to close */
1862 if (p->is_vararg)
1863 SETARG_C(*pc, p->numparams + 1); /* signal that it is vararg */
1864 break;
1865 }
1866 case OP_JMP: {
1867 int target = finaltarget(p->code, i);
1868 fixjump(fs, i, target);
1869 break;
1870 }
1871 default: break;
1872 }
1873 }
1874}

Callers 1

close_funcFunction · 0.85

Calls 2

finaltargetFunction · 0.85
fixjumpFunction · 0.85

Tested by

no test coverage detected