Improve bytecode generation.
This commit is contained in:
@@ -574,16 +574,26 @@ public class JavaBuilder {
|
||||
private Map<LuaValue,String> constants = new HashMap<LuaValue,String>();
|
||||
|
||||
public void loadConstant(LuaValue value) {
|
||||
String name = constants.get(value);
|
||||
if ( name == null ) {
|
||||
name = value.type() == LuaValue.TNUMBER?
|
||||
value.isinttype()?
|
||||
createLuaIntegerField(value.checkint()):
|
||||
createLuaDoubleField(value.checkdouble()):
|
||||
createLuaStringField(value.checkstring());
|
||||
constants.put(value, name);
|
||||
switch ( value.type() ) {
|
||||
case LuaValue.TNIL:
|
||||
loadNil();
|
||||
break;
|
||||
case LuaValue.TNUMBER:
|
||||
case LuaValue.TSTRING:
|
||||
String name = constants.get(value);
|
||||
if ( name == null ) {
|
||||
name = value.type() == LuaValue.TNUMBER?
|
||||
value.isinttype()?
|
||||
createLuaIntegerField(value.checkint()):
|
||||
createLuaDoubleField(value.checkdouble()):
|
||||
createLuaStringField(value.checkstring());
|
||||
constants.put(value, name);
|
||||
}
|
||||
append(factory.createGetStatic(classname, name, TYPE_LUAVALUE));
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException("bad constant type: "+value.type());
|
||||
}
|
||||
append(factory.createGetStatic(classname, name, TYPE_LUAVALUE));
|
||||
}
|
||||
|
||||
private String createLuaIntegerField(int value) {
|
||||
|
||||
@@ -172,7 +172,8 @@ public class JavaGen {
|
||||
case Lua.OP_LOADBOOL:/* A B C R(A):= (Bool)B: if (C) pc++ */
|
||||
builder.loadBoolean( b!=0 );
|
||||
builder.storeLocal( pc, a );
|
||||
//if ( c != 0 ) branchdest[index+2] = true;
|
||||
if ( c!=0 )
|
||||
builder.addBranch(pc, JavaBuilder.BRANCH_GOTO, pc+2);
|
||||
break;
|
||||
|
||||
case Lua.OP_JMP: /* sBx pc+=sBx */
|
||||
|
||||
@@ -383,7 +383,7 @@ public class Slots {
|
||||
private int prevUndefined(int index, int j) {
|
||||
for ( ; index>=0; --index )
|
||||
if ( ((slots[index][j] & BIT_INVALID) != 0) )
|
||||
return 0;
|
||||
return index;
|
||||
return index;
|
||||
}
|
||||
|
||||
|
||||
@@ -333,5 +333,10 @@ public class FragmentsTest extends TestCase {
|
||||
"end\n" +
|
||||
"return foo()\n" );
|
||||
}
|
||||
|
||||
public void testTestSimpleBinops() {
|
||||
runFragment( LuaValue.varargsOf(new LuaValue[] {
|
||||
LuaValue.FALSE, LuaValue.FALSE, LuaValue.TRUE, LuaValue.TRUE, LuaValue.FALSE }),
|
||||
"local a,b,c = 2,-2.5,0\n" +
|
||||
"return (a==c), (b==c), (a==a), (a>c), (b>0)\n" );
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user