MCPcopy Create free account
hub / github.com/ArduPilot/ardupilot / luaK_nil

Function luaK_nil

libraries/AP_Scripting/lua/src/lcode.c:71–90  ·  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

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

Callers 2

adjust_assignFunction · 0.85
discharge2regFunction · 0.85

Calls 1

luaK_codeABCFunction · 0.85

Tested by

no test coverage detected