Improve bytecode generation.
This commit is contained in:
@@ -574,16 +574,26 @@ public class JavaBuilder {
|
|||||||
private Map<LuaValue,String> constants = new HashMap<LuaValue,String>();
|
private Map<LuaValue,String> constants = new HashMap<LuaValue,String>();
|
||||||
|
|
||||||
public void loadConstant(LuaValue value) {
|
public void loadConstant(LuaValue value) {
|
||||||
String name = constants.get(value);
|
switch ( value.type() ) {
|
||||||
if ( name == null ) {
|
case LuaValue.TNIL:
|
||||||
name = value.type() == LuaValue.TNUMBER?
|
loadNil();
|
||||||
value.isinttype()?
|
break;
|
||||||
createLuaIntegerField(value.checkint()):
|
case LuaValue.TNUMBER:
|
||||||
createLuaDoubleField(value.checkdouble()):
|
case LuaValue.TSTRING:
|
||||||
createLuaStringField(value.checkstring());
|
String name = constants.get(value);
|
||||||
constants.put(value, name);
|
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) {
|
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++ */
|
case Lua.OP_LOADBOOL:/* A B C R(A):= (Bool)B: if (C) pc++ */
|
||||||
builder.loadBoolean( b!=0 );
|
builder.loadBoolean( b!=0 );
|
||||||
builder.storeLocal( pc, a );
|
builder.storeLocal( pc, a );
|
||||||
//if ( c != 0 ) branchdest[index+2] = true;
|
if ( c!=0 )
|
||||||
|
builder.addBranch(pc, JavaBuilder.BRANCH_GOTO, pc+2);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Lua.OP_JMP: /* sBx pc+=sBx */
|
case Lua.OP_JMP: /* sBx pc+=sBx */
|
||||||
|
|||||||
@@ -383,7 +383,7 @@ public class Slots {
|
|||||||
private int prevUndefined(int index, int j) {
|
private int prevUndefined(int index, int j) {
|
||||||
for ( ; index>=0; --index )
|
for ( ; index>=0; --index )
|
||||||
if ( ((slots[index][j] & BIT_INVALID) != 0) )
|
if ( ((slots[index][j] & BIT_INVALID) != 0) )
|
||||||
return 0;
|
return index;
|
||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -333,5 +333,10 @@ public class FragmentsTest extends TestCase {
|
|||||||
"end\n" +
|
"end\n" +
|
||||||
"return foo()\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