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

Function luaK_finish

third-party/lua-5.5.0/src/lcode.c:1929–1971  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1927*/
1928#include "lopnames.h"
1929void luaK_finish (FuncState *fs) {
1930 int i;
1931 Proto *p = fs->f;
1932 if (p->flag & PF_VATAB) /* will it use a vararg table? */
1933 p->flag &= cast_byte(~PF_VAHID); /* then it will not use hidden args. */
1934 for (i = 0; i < fs->pc; i++) {
1935 Instruction *pc = &p->code[i];
1936 /* avoid "not used" warnings when assert is off (for 'onelua.c') */
1937 (void)luaP_isOT; (void)luaP_isIT;
1938 lua_assert(i == 0 || luaP_isOT(*(pc - 1)) == luaP_isIT(*pc));
1939 switch (GET_OPCODE(*pc)) {
1940 case OP_RETURN0: case OP_RETURN1: {
1941 if (!(fs->needclose || (p->flag & PF_VAHID)))
1942 break; /* no extra work */
1943 /* else use OP_RETURN to do the extra work */
1944 SET_OPCODE(*pc, OP_RETURN);
1945 } /* FALLTHROUGH */
1946 case OP_RETURN: case OP_TAILCALL: {
1947 if (fs->needclose)
1948 SETARG_k(*pc, 1); /* signal that it needs to close */
1949 if (p->flag & PF_VAHID) /* does it use hidden arguments? */
1950 SETARG_C(*pc, p->numparams + 1); /* signal that */
1951 break;
1952 }
1953 case OP_GETVARG: {
1954 if (p->flag & PF_VATAB) /* function has a vararg table? */
1955 SET_OPCODE(*pc, OP_GETTABLE); /* must get vararg there */
1956 break;
1957 }
1958 case OP_VARARG: {
1959 if (p->flag & PF_VATAB) /* function has a vararg table? */
1960 SETARG_k(*pc, 1); /* must get vararg there */
1961 break;
1962 }
1963 case OP_JMP: { /* to optimize jumps to jumps */
1964 int target = finaltarget(p->code, i);
1965 fixjump(fs, i, target); /* jump directly to final target */
1966 break;
1967 }
1968 default: break;
1969 }
1970 }
1971}

Callers 1

close_funcFunction · 0.70

Calls 4

luaP_isOTFunction · 0.85
luaP_isITFunction · 0.85
finaltargetFunction · 0.70
fixjumpFunction · 0.70

Tested by

no test coverage detected