Fix upvalue processing.
This commit is contained in:
@@ -274,7 +274,7 @@ public class JavaBytecodeGenerator {
|
|||||||
// initialize locals
|
// initialize locals
|
||||||
isup = new boolean[nl];
|
isup = new boolean[nl];
|
||||||
isinited = new boolean[nl];
|
isinited = new boolean[nl];
|
||||||
markups(p, isup, code, 0, 0);
|
markups(p, isup, code);
|
||||||
|
|
||||||
// find first branch or jump-back-to
|
// find first branch or jump-back-to
|
||||||
firstbranch = findfirstbranch();
|
firstbranch = findfirstbranch();
|
||||||
@@ -847,9 +847,13 @@ public class JavaBytecodeGenerator {
|
|||||||
ih[pc] = il.append(InstructionConstants.NOP); // for branching
|
ih[pc] = il.append(InstructionConstants.NOP); // for branching
|
||||||
for ( int j=nl; --j>=a; ) {
|
for ( int j=nl; --j>=a; ) {
|
||||||
isinited[j] = true;
|
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;
|
break;
|
||||||
|
|
||||||
case Lua.OP_CLOSURE: /* A Bx R(A):= closure(KPROTO[Bx], R(A), ... ,R(A+n)) */
|
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
|
// find the upvalues implied by the subsequent instructions
|
||||||
private void markups(Prototype p, boolean[] isup, int[] code, int startpc, int startregister) {
|
private void markups(Prototype p, boolean[] isup, int[] code) {
|
||||||
int last = isup.length;
|
for ( int pc=0; pc<code.length; ++pc ) {
|
||||||
for ( int j=startregister; j<last; j++ )
|
|
||||||
isup[j] = false;
|
|
||||||
for ( int pc=startpc; pc<code.length; ++pc ) {
|
|
||||||
switch ( OP(code[pc]) ) {
|
switch ( OP(code[pc]) ) {
|
||||||
case Lua.OP_CLOSURE:
|
case Lua.OP_CLOSURE:
|
||||||
int b = Bx(code[pc]);
|
int b = Bx(code[pc]);
|
||||||
@@ -1174,14 +1175,6 @@ public class JavaBytecodeGenerator {
|
|||||||
isup[B(i)] = true;
|
isup[B(i)] = true;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case Lua.OP_CLOSE:
|
|
||||||
int a = A(code[pc]);
|
|
||||||
if ( a < last ) {
|
|
||||||
last = a;
|
|
||||||
if ( last <= 0 )
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1225,7 +1218,7 @@ public class JavaBytecodeGenerator {
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
// create variable
|
// create variable
|
||||||
String name = toLegalJavaName( getlocalname(p.locvars, j) ) + (isup[j]? "$u": "");
|
String name = toLegalJavaName( getlocalname(p.locvars, j) );
|
||||||
locals[j] = mg.addLocalVariable(name, isup[j] ? TYPE_LOCALUPVALUE : TYPE_LUAVALUE, null, null);
|
locals[j] = mg.addLocalVariable(name, isup[j] ? TYPE_LOCALUPVALUE : TYPE_LUAVALUE, null, null);
|
||||||
|
|
||||||
// upvalue storage
|
// upvalue storage
|
||||||
|
|||||||
@@ -57,6 +57,20 @@ public class FragmentsTest extends TestCase {
|
|||||||
fail(e.toString());
|
fail(e.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testForloopParamUpvalues() {
|
||||||
|
runFragment( LuaValue.varargsOf(new LuaValue[] {
|
||||||
|
LuaValue.valueOf(77),
|
||||||
|
LuaValue.valueOf(1) } ),
|
||||||
|
"for n,p in ipairs({77}) do\n"+
|
||||||
|
" print('n,p',n,p)\n"+
|
||||||
|
" foo = function()\n"+
|
||||||
|
" return p,n\n"+
|
||||||
|
" end\n"+
|
||||||
|
" return foo()\n"+
|
||||||
|
"end\n");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public void testVarVarargsUseArg() {
|
public void testVarVarargsUseArg() {
|
||||||
runFragment( LuaValue.varargsOf( new LuaValue[] {
|
runFragment( LuaValue.varargsOf( new LuaValue[] {
|
||||||
|
|||||||
Reference in New Issue
Block a user