MCPcopy Create free account
hub / github.com/DFHack/dfhack / luaK_nil

Function luaK_nil

depends/lua/src/lcode.c:64–83  ·  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

62** instance, 'local a; local b' will generate a single opcode.)
63*/
64void luaK_nil (FuncState *fs, int from, int n) {
65 Instruction *previous;
66 int l = from + n - 1; /* last register to set nil */
67 if (fs->pc > fs->lasttarget) { /* no jumps to current position? */
68 previous = &fs->f->code[fs->pc-1];
69 if (GET_OPCODE(*previous) == OP_LOADNIL) { /* previous is LOADNIL? */
70 int pfrom = GETARG_A(*previous); /* get previous range */
71 int pl = pfrom + GETARG_B(*previous);
72 if ((pfrom <= from && from <= pl + 1) ||
73 (from <= pfrom && pfrom <= l + 1)) { /* can connect both? */
74 if (pfrom < from) from = pfrom; /* from = min(from, pfrom) */
75 if (pl > l) l = pl; /* l = max(l, pl) */
76 SETARG_A(*previous, from);
77 SETARG_B(*previous, l - from);
78 return;
79 }
80 } /* else go through */
81 }
82 luaK_codeABC(fs, OP_LOADNIL, from, n - 1, 0); /* else no optimization */
83}
84
85
86/*

Callers 2

adjust_assignFunction · 0.85
discharge2regFunction · 0.85

Calls 1

luaK_codeABCFunction · 0.85

Tested by

no test coverage detected