Add control flow extraction to jit compiler.

This commit is contained in:
James Roseborough
2008-06-29 18:34:22 +00:00
parent a3b939352d
commit 88770a3630
2 changed files with 125 additions and 141 deletions

View File

@@ -0,0 +1,53 @@
package org.luaj.jit;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import junit.framework.TestCase;
import org.luaj.compiler.LuaC;
import org.luaj.platform.J2sePlatform;
import org.luaj.vm.LClosure;
import org.luaj.vm.LPrototype;
import org.luaj.vm.LuaState;
import org.luaj.vm.Platform;
/**
* Simple test cases for lua jit basic functional test
*/
public class LuaJitBasicTest extends TestCase {
static {
Platform.setInstance(new J2sePlatform());
LuaC.install();
}
public void testPrintHelloWorld() throws IOException {
stringTest( "print( 'hello, world' )" );
}
public void testForLoop() throws IOException {
stringTest( "print 'starting'\n" +
"for i=1,3 do\n" +
" print( 'i', i )\n" +
"end");
}
private void stringTest(String program) throws IOException {
InputStream is = new ByteArrayInputStream(program.getBytes());
LPrototype p = LuaC.compile(is, "program");
run( p );
LPrototype q = LuaJit.jitCompile( p );
assertTrue(p!=q);
run( q );
}
private static void run(LPrototype p) {
LuaState vm = Platform.newLuaState();
LClosure c = p.newClosure(vm._G);
vm.pushlvalue(c);
vm.call(0, 0);
}
}