MCPcopy Create free account
hub / github.com/EmmyLua/EmmyLuaDebugger / luaK_finish

Function luaK_finish

third-party/lua-5.4.6/src/lcode.c:1847–1875  ·  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

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

Callers 1

close_funcFunction · 0.70

Calls 2

finaltargetFunction · 0.70
fixjumpFunction · 0.70

Tested by

no test coverage detected