/// <summary> /// Equivalent to luaK_nil. </summary> internal void kNil(int from, int n) { int previous; if (pc > lasttarget) // no jumps to current position? { if (pc == 0) // function start? { return; // positions are already clean } previous = pc - 1; int instr = f.code_Renamed[previous]; if (Lua.OPCODE(instr) == Lua.OP_LOADNIL) { int pfrom = Lua.ARGA(instr); int pto = Lua.ARGB(instr); if (pfrom <= from && from <= pto + 1) // can connect both? { if (from + n - 1 > pto) { f.code_Renamed[previous] = Lua.SETARG_B(instr, from + n - 1); } return; } } } kCodeABC(Lua.OP_LOADNIL, from, from + n - 1, 0); }
private int jumponcond(Expdesc e, bool cond) { if (e.k == Expdesc.VRELOCABLE) { int ie = getcode(e); if (Lua.OPCODE(ie) == Lua.OP_NOT) { pc--; // remove previous OP_NOT return(condjump(Lua.OP_TEST, Lua.ARGB(ie), 0, cond ? 0 : 1)); } /* else go through */ } discharge2anyreg(e); freeexp(e); return(condjump(Lua.OP_TESTSET, Lua.NO_REG, e.info_Renamed, cond ? 1 : 0)); }
private bool patchtestreg(int node, int reg) { int i = getjumpcontrol(node); int[] code = f.code_Renamed; int instr = code[i]; if (Lua.OPCODE(instr) != Lua.OP_TESTSET) { return(false); // cannot patch other instructions } if (reg != Lua.NO_REG && reg != Lua.ARGB(instr)) { code[i] = Lua.SETARG_A(instr, reg); } else // no register to put value or register already has the value { code[i] = Lua.CREATE_ABC(Lua.OP_TEST, Lua.ARGB(instr), 0, Lua.ARGC(instr)); } return(true); }