| 2142 | */ |
| 2143 | #include "lopnames.h" |
| 2144 | void luaK_finish (FuncState *fs) { |
| 2145 | int i; |
| 2146 | Proto *p = fs->f; |
| 2147 | if (p->flag & PF_VATAB) /* will it use a vararg table? */ |
| 2148 | p->flag &= cast_byte(~PF_VAHID); /* then it will not use hidden args. */ |
| 2149 | for (i = 0; i < fs->pc; i++) { |
| 2150 | Instruction *pc = &p->code[i]; |
| 2151 | /* avoid "not used" warnings when assert is off (for 'onelua.c') */ |
| 2152 | (void)luaP_isOT; (void)luaP_isIT; |
| 2153 | lua_assert(i == 0 || luaP_isOT(*(pc - 1)) == luaP_isIT(*pc)); |
| 2154 | switch (GET_OPCODE(*pc)) { |
| 2155 | case OP_RETURN0: case OP_RETURN1: { |
| 2156 | if (!(fs->needclose || (p->flag & PF_VAHID))) |
| 2157 | break; /* no extra work */ |
| 2158 | /* else use OP_RETURN to do the extra work */ |
| 2159 | SET_OPCODE(*pc, OP_RETURN); |
| 2160 | } /* FALLTHROUGH */ |
| 2161 | case OP_RETURN: case OP_TAILCALL: { |
| 2162 | if (fs->needclose) |
| 2163 | SETARG_k(*pc, 1); /* signal that it needs to close */ |
| 2164 | if (p->flag & PF_VAHID) /* does it use hidden arguments? */ |
| 2165 | SETARG_C(*pc, p->numparams + 1); /* signal that */ |
| 2166 | break; |
| 2167 | } |
| 2168 | case OP_GETVARG: { |
| 2169 | if (p->flag & PF_VATAB) /* function has a vararg table? */ |
| 2170 | SET_OPCODE(*pc, OP_GETTABLE); /* must get vararg there */ |
| 2171 | break; |
| 2172 | } |
| 2173 | case OP_VARARG: { |
| 2174 | if (p->flag & PF_VATAB) /* function has a vararg table? */ |
| 2175 | SETARG_k(*pc, 1); /* must get vararg there */ |
| 2176 | break; |
| 2177 | } |
| 2178 | case OP_JMP: { /* to optimize jumps to jumps */ |
| 2179 | int target = finaltarget(p->code, i); |
| 2180 | fixjump(fs, i, target); /* jump directly to final target */ |
| 2181 | break; |
| 2182 | } |
| 2183 | default: break; |
| 2184 | } |
| 2185 | } |
| 2186 | } |
| 2187 | |
| 2188 | |
| 2189 | void luaK_exp2reg (FuncState *fs, expdesc *e, int reg) { |
no test coverage detected