Update bytecode-to-bytecode compiler to handle upvalues in numeric for loops.
This commit is contained in:
@@ -457,7 +457,6 @@ and LuaForge:
|
|||||||
<li>tail calls are not tracked in debug information
|
<li>tail calls are not tracked in debug information
|
||||||
<li>using both version 1 and 2 libraries together in the same java vm has not been tested
|
<li>using both version 1 and 2 libraries together in the same java vm has not been tested
|
||||||
<li>module() and setfenv() only partially supported for lau2java or luajc compiled lua
|
<li>module() and setfenv() only partially supported for lau2java or luajc compiled lua
|
||||||
<li>luajc can produce invalid class files in some cases
|
|
||||||
<li>values associated with weak keys may linger longer than expected
|
<li>values associated with weak keys may linger longer than expected
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
|
|||||||
@@ -356,6 +356,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) {
|
private static String upvalueName(int upindex) {
|
||||||
return PREFIX_UPVALUE+upindex;
|
return PREFIX_UPVALUE+upindex;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ public class JavaGen {
|
|||||||
for ( int pc=0, n=p.code.length; pc<n; pc++ ) {
|
for ( int pc=0, n=p.code.length; pc<n; pc++ ) {
|
||||||
int pc0 = pc; // closure changes pc
|
int pc0 = pc; // closure changes pc
|
||||||
int ins = p.code[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 a = Lua.GETARG_A(ins);
|
||||||
int b = Lua.GETARG_B(ins);
|
int b = Lua.GETARG_B(ins);
|
||||||
int bx = Lua.GETARG_Bx(ins);
|
int bx = Lua.GETARG_Bx(ins);
|
||||||
@@ -410,6 +410,13 @@ public class JavaGen {
|
|||||||
|
|
||||||
// let builder process branch instructions
|
// let builder process branch instructions
|
||||||
builder.onEndOfLuaInstruction( pc0 );
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -38,9 +38,10 @@ public class TestLuaJC {
|
|||||||
public static String name = "script";
|
public static String name = "script";
|
||||||
public static String script =
|
public static String script =
|
||||||
"for i = 1,2 do\n" +
|
"for i = 1,2 do\n" +
|
||||||
" t[i] = function()\n"+
|
" i = i + 5\n"+
|
||||||
|
" return (function()\n"+
|
||||||
" return i\n"+
|
" return i\n"+
|
||||||
" end\n"+
|
" end)()\n"+
|
||||||
"end\n";
|
"end\n";
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
|
|||||||
@@ -58,6 +58,10 @@ public class AllTests {
|
|||||||
table.addTestSuite(WeakKeyValueTableTest.class);
|
table.addTestSuite(WeakKeyValueTableTest.class);
|
||||||
suite.addTest(table);
|
suite.addTest(table);
|
||||||
|
|
||||||
|
// bytecode compilers regression tests
|
||||||
|
TestSuite bytecodetests = FragmentsTest.suite();
|
||||||
|
suite.addTest(bytecodetests);
|
||||||
|
|
||||||
// prototype compiler
|
// prototype compiler
|
||||||
TestSuite compiler = new TestSuite("Lua Compiler Tests");
|
TestSuite compiler = new TestSuite("Lua Compiler Tests");
|
||||||
compiler.addTestSuite(CompilerUnitTests.class);
|
compiler.addTestSuite(CompilerUnitTests.class);
|
||||||
@@ -73,16 +77,11 @@ public class AllTests {
|
|||||||
suite.addTest(lib);
|
suite.addTest(lib);
|
||||||
|
|
||||||
// compatiblity tests
|
// compatiblity tests
|
||||||
TestSuite compat = (TestSuite) CompatibiltyTest.suite();
|
TestSuite compat = CompatibiltyTest.suite();
|
||||||
suite.addTest( compat );
|
suite.addTest( compat );
|
||||||
compat.addTestSuite(ErrorsTest.class);
|
compat.addTestSuite(ErrorsTest.class);
|
||||||
compat.addTestSuite(Luajvm1CompatibilityTest.class);
|
compat.addTestSuite(Luajvm1CompatibilityTest.class);
|
||||||
|
|
||||||
// luajc regression tests
|
|
||||||
TestSuite luajc = new TestSuite("Java Compiler Tests");
|
|
||||||
luajc.addTestSuite(FragmentsTest.class);
|
|
||||||
suite.addTest(luajc);
|
|
||||||
|
|
||||||
return suite;
|
return suite;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -59,11 +59,11 @@ public class CompatibiltyTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static Test suite() {
|
public static TestSuite suite() {
|
||||||
TestSuite suite = new TestSuite("Compatibility Tests");
|
TestSuite suite = new TestSuite("Compatibility Tests");
|
||||||
suite.addTest( new TestSuite( JseCompatibilityTest.class, "JSE Tests" ) );
|
suite.addTest( new TestSuite( JseCompatibilityTest.class, "JSE Tests" ) );
|
||||||
suite.addTest( new TestSuite( JmeCompatibilityTest.class, "JME Tests" ) );
|
suite.addTest( new TestSuite( JmeCompatibilityTest.class, "JME Tests" ) );
|
||||||
suite.addTest( new TestSuite( JseBytecodeTest.class, "JSE Bytecode Tests" ) );
|
suite.addTest( new TestSuite( LuaJCTest.class, "JSE Bytecode Tests" ) );
|
||||||
suite.addTest( new TestSuite( Lua2JavaTest.class, "Lua2Java Tests" ) );
|
suite.addTest( new TestSuite( Lua2JavaTest.class, "Lua2Java Tests" ) );
|
||||||
return suite;
|
return suite;
|
||||||
}
|
}
|
||||||
@@ -74,7 +74,7 @@ public class CompatibiltyTest {
|
|||||||
}
|
}
|
||||||
protected void setUp() throws Exception {
|
protected void setUp() throws Exception {
|
||||||
super.setUp();
|
super.setUp();
|
||||||
System.setProperty("Lua2Java", "false");
|
System.setProperty("JME", "false");
|
||||||
Lua2Java.install();
|
Lua2Java.install();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -97,8 +97,8 @@ public class CompatibiltyTest {
|
|||||||
System.setProperty("JME", "false");
|
System.setProperty("JME", "false");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public static class JseBytecodeTest extends CompatibiltyTestSuite {
|
public static class LuaJCTest extends CompatibiltyTestSuite {
|
||||||
public JseBytecodeTest() {
|
public LuaJCTest() {
|
||||||
super(ScriptDrivenTest.PlatformType.LUAJIT);
|
super(ScriptDrivenTest.PlatformType.LUAJIT);
|
||||||
}
|
}
|
||||||
protected void setUp() throws Exception {
|
protected void setUp() throws Exception {
|
||||||
|
|||||||
@@ -24,8 +24,14 @@ package org.luaj.vm2;
|
|||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
|
||||||
|
import junit.framework.Test;
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
import junit.framework.TestSuite;
|
||||||
|
|
||||||
|
import org.luaj.vm2.CompatibiltyTest.JmeCompatibilityTest;
|
||||||
|
import org.luaj.vm2.CompatibiltyTest.JseCompatibilityTest;
|
||||||
|
import org.luaj.vm2.CompatibiltyTest.Lua2JavaTest;
|
||||||
|
import org.luaj.vm2.CompatibiltyTest.LuaJCTest;
|
||||||
import org.luaj.vm2.compiler.LuaC;
|
import org.luaj.vm2.compiler.LuaC;
|
||||||
import org.luaj.vm2.lua2java.Lua2Java;
|
import org.luaj.vm2.lua2java.Lua2Java;
|
||||||
import org.luaj.vm2.luajc.LuaJC;
|
import org.luaj.vm2.luajc.LuaJC;
|
||||||
@@ -35,12 +41,37 @@ import org.luaj.vm2.luajc.LuaJC;
|
|||||||
* caused problems for jit compiling during development.
|
* caused problems for jit compiling during development.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class FragmentsTest extends TestCase {
|
public class FragmentsTest extends TestSuite {
|
||||||
|
|
||||||
static final int TEST_TYPE_LUAC = 0;
|
static final int TEST_TYPE_LUAC = 0;
|
||||||
static final int TEST_TYPE_LUAJC = 1;
|
static final int TEST_TYPE_LUAJC = 1;
|
||||||
static final int TEST_TYPE_LUA2JAVA = 2;
|
static final int TEST_TYPE_LUA2JAVA = 2;
|
||||||
static final int TEST_TYPE = TEST_TYPE_LUA2JAVA;
|
|
||||||
|
public static class JseFragmentsTest extends FragmentsTestCase {
|
||||||
|
public JseFragmentsTest() { super( TEST_TYPE_LUAC ); }
|
||||||
|
}
|
||||||
|
public static class LuaJCFragmentsTest extends FragmentsTestCase {
|
||||||
|
public LuaJCFragmentsTest() { super( TEST_TYPE_LUAJC ); }
|
||||||
|
}
|
||||||
|
public static class Lua2JavaFragmentsTest extends FragmentsTestCase {
|
||||||
|
public Lua2JavaFragmentsTest() { super( TEST_TYPE_LUA2JAVA ); }
|
||||||
|
}
|
||||||
|
|
||||||
|
public static TestSuite suite() {
|
||||||
|
TestSuite suite = new TestSuite("Compiler Fragments Tests");
|
||||||
|
suite.addTest( new TestSuite( JseFragmentsTest.class, "JSE Fragments Tests" ) );
|
||||||
|
suite.addTest( new TestSuite( LuaJCFragmentsTest.class, "LuaJC Fragments Tests" ) );
|
||||||
|
suite.addTest( new TestSuite( Lua2JavaFragmentsTest.class, "Lua2Java Fragments Tests" ) );
|
||||||
|
return suite;
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract protected static class FragmentsTestCase extends TestCase {
|
||||||
|
|
||||||
|
final int TEST_TYPE;
|
||||||
|
|
||||||
|
protected FragmentsTestCase(int testType) {
|
||||||
|
this.TEST_TYPE = testType;
|
||||||
|
}
|
||||||
|
|
||||||
public void runFragment( Varargs expected, String script ) {
|
public void runFragment( Varargs expected, String script ) {
|
||||||
try {
|
try {
|
||||||
@@ -362,3 +393,4 @@ public class FragmentsTest extends TestCase {
|
|||||||
"end\n");
|
"end\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user