diff --git a/src/core/org/luaj/vm2/LoadState.java b/src/core/org/luaj/vm2/LoadState.java index 6dc072db..5eb69fec 100644 --- a/src/core/org/luaj/vm2/LoadState.java +++ b/src/core/org/luaj/vm2/LoadState.java @@ -312,9 +312,8 @@ public class LoadState { } n = loadInt(); - f.upvalues = n>0? new Upvaldesc[n]: NOUPVALDESCS; for ( int i=0; i this.lasttarget) { /* no jumps to current position? */ - if (this.pc == 0) { /* function start? */ - if (from >= this.nactvar) - return; /* positions are already clean */ - } else { - previous = new InstructionPtr(this.f.code, this.pc - 1); - if (GET_OPCODE(previous.get()) == OP_LOADNIL) { - int pfrom = GETARG_A(previous.get()); - int pto = GETARG_B(previous.get()); - if (pfrom <= from && from <= pto + 1) { /* can connect both? */ - if (from + n - 1 > pto) - SETARG_B(previous, from + n - 1); - return; - } - } + final int code_prev = f.code[pc - 1]; + if (pc > 0 && GET_OPCODE(code_prev) == OP_LOADNIL) { + int l = from + n - 1; /* last register to set nil */ + int pfrom = GETARG_A(code_prev); + int pl = pfrom + GETARG_B(code_prev); + if ((pfrom <= from && from <= pl + 1) + || (from <= pfrom && pfrom <= l + 1)) { /* can connect both? */ + if (pfrom < from) + from = pfrom; /* from = min(from, pfrom) */ + if (pl > l) + l = pl; /* l = max(l, pl) */ + InstructionPtr previous = new InstructionPtr(this.f.code, this.pc - 1); + SETARG_A(previous, from); + SETARG_B(previous, l - from); + return; } - } - /* else no optimization */ - this.codeABC(OP_LOADNIL, from, from + n - 1, 0); + } /* else go through */ + this.codeABC(OP_LOADNIL, from, n - 1, 0); } diff --git a/src/core/org/luaj/vm2/compiler/LexState.java b/src/core/org/luaj/vm2/compiler/LexState.java index 6d270d23..fc3ef1aa 100644 --- a/src/core/org/luaj/vm2/compiler/LexState.java +++ b/src/core/org/luaj/vm2/compiler/LexState.java @@ -1065,7 +1065,6 @@ public class LexState { } void open_func (FuncState fs, BlockCnt bl) { - Prototype f = new Prototype(); fs.prev = this.fs; /* linked list of funcstates */ fs.ls = this; this.fs = fs; @@ -1080,7 +1079,8 @@ public class LexState { fs.nactvar = 0; fs.firstlocal = dyd.n_actvar; fs.bl = null; - f.maxstacksize = 2; /* registers 0/1 are always valid */ + fs.f.source = this.source; + fs.f.maxstacksize = 2; /* registers 0/1 are always valid */ fs.enterblock(bl, false); }