From 7cc18046ab33a77266070a77886df74f492d78ba Mon Sep 17 00:00:00 2001 From: James Roseborough Date: Wed, 4 Nov 2009 06:33:34 +0000 Subject: [PATCH] Fix upvalue processing. --- .../luaj/vm2/luajc/JavaBytecodeGenerator.java | 27 +++++++------------ test/junit/org/luaj/vm2/FragmentsTest.java | 14 ++++++++++ 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/src/jse/org/luaj/vm2/luajc/JavaBytecodeGenerator.java b/src/jse/org/luaj/vm2/luajc/JavaBytecodeGenerator.java index ad974404..804d8e4a 100644 --- a/src/jse/org/luaj/vm2/luajc/JavaBytecodeGenerator.java +++ b/src/jse/org/luaj/vm2/luajc/JavaBytecodeGenerator.java @@ -274,7 +274,7 @@ public class JavaBytecodeGenerator { // initialize locals isup = new boolean[nl]; isinited = new boolean[nl]; - markups(p, isup, code, 0, 0); + markups(p, isup, code); // find first branch or jump-back-to firstbranch = findfirstbranch(); @@ -847,9 +847,13 @@ public class JavaBytecodeGenerator { ih[pc] = il.append(InstructionConstants.NOP); // for branching for ( int j=nl; --j>=a; ) { isinited[j] = true; - locals[j] = null; + if ( isup[j] ) { + this.initLocal(j, false); + il.append(new PUSH(cp, 1)); + il.append(new ANEWARRAY(cp.addClass(STR_LUAVALUE))); + il.append(new ASTORE(locals[j].getIndex())); + } } - markups( p, isup, code, pc+1, a ); break; case Lua.OP_CLOSURE: /* A Bx R(A):= closure(KPROTO[Bx], R(A), ... ,R(A+n)) */ @@ -1159,11 +1163,8 @@ public class JavaBytecodeGenerator { } // find the upvalues implied by the subsequent instructions - private void markups(Prototype p, boolean[] isup, int[] code, int startpc, int startregister) { - int last = isup.length; - for ( int j=startregister; j