MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / luaK_nil

Function luaK_nil

lib/lua/src/lcode.c:131–147  ·  view source on GitHub ↗

** Create a OP_LOADNIL instruction, but try to optimize: if the previous ** instruction is also OP_LOADNIL and ranges are compatible, adjust ** range of previous instruction instead of emitting a new one. (For ** instance, 'local a; local b' will generate a single opcode.) */

Source from the content-addressed store, hash-verified

129** instance, 'local a; local b' will generate a single opcode.)
130*/
131void luaK_nil (FuncState *fs, int from, int n) {
132 int l = from + n - 1; /* last register to set nil */
133 Instruction *previous = previousinstruction(fs);
134 if (GET_OPCODE(*previous) == OP_LOADNIL) { /* previous is LOADNIL? */
135 int pfrom = GETARG_A(*previous); /* get previous range */
136 int pl = pfrom + GETARG_B(*previous);
137 if ((pfrom <= from && from <= pl + 1) ||
138 (from <= pfrom && pfrom <= l + 1)) { /* can connect both? */
139 if (pfrom < from) from = pfrom; /* from = min(from, pfrom) */
140 if (pl > l) l = pl; /* l = max(l, pl) */
141 SETARG_A(*previous, from);
142 SETARG_B(*previous, l - from);
143 return;
144 } /* else go through */
145 }
146 luaK_codeABC(fs, OP_LOADNIL, from, n - 1, 0); /* else no optimization */
147}
148
149
150/*

Callers 2

adjust_assignFunction · 0.85
discharge2regFunction · 0.85

Calls 1

previousinstructionFunction · 0.85

Tested by

no test coverage detected