Update bytecode-to-bytecode compiler to handle upvalues in numeric for loops.

This commit is contained in:
James Roseborough
2010-07-29 21:28:13 +00:00
parent cd35ad7cbd
commit dce6007569
7 changed files with 372 additions and 323 deletions

View File

@@ -355,6 +355,17 @@ public class JavaBuilder {
}
}
}
public void convertToUpvalue(int pc, int slot) {
boolean isupassign = slots.isUpvalueAssign(pc, slot);
if ( isupassign ) {
int index = findSlotIndex( slot, false );
append(new ALOAD(index));
append(factory.createInvoke(classname, "newupl", TYPE_LOCALUPVALUE, new Type[] { TYPE_LUAVALUE }, Constants.INVOKESTATIC));
int upindex = findSlotIndex( slot, true );
append(new ASTORE(upindex));
}
}
private static String upvalueName(int upindex) {
return PREFIX_UPVALUE+upindex;

View File

@@ -60,7 +60,7 @@ public class JavaGen {
for ( int pc=0, n=p.code.length; pc<n; pc++ ) {
int pc0 = pc; // closure changes pc
int ins = p.code[pc];
int o = Lua.GET_OPCODE(ins);
final int o = Lua.GET_OPCODE(ins);
int a = Lua.GETARG_A(ins);
int b = Lua.GETARG_B(ins);
int bx = Lua.GETARG_Bx(ins);
@@ -410,6 +410,13 @@ public class JavaGen {
// let builder process branch instructions
builder.onEndOfLuaInstruction( pc0 );
// for-loops have upvalue created at top of loop
switch ( o ) {
case Lua.OP_FORPREP:
builder.convertToUpvalue(pc+1, a+3);
break;
}
}
}