additional jit implementations
This commit is contained in:
@@ -45,6 +45,7 @@ public class LuaJit extends Lua implements LuaCompiler {
|
|||||||
"for i=1,10 do\n" +
|
"for i=1,10 do\n" +
|
||||||
" print 'hello, world'\n" +
|
" print 'hello, world'\n" +
|
||||||
"end";
|
"end";
|
||||||
|
program = "f(); if v then a(); else b(); end; g()";
|
||||||
InputStream is = new ByteArrayInputStream(program.getBytes());
|
InputStream is = new ByteArrayInputStream(program.getBytes());
|
||||||
LPrototype p = LuaC.compile(is, "program");
|
LPrototype p = LuaC.compile(is, "program");
|
||||||
test( p );
|
test( p );
|
||||||
@@ -143,6 +144,7 @@ public class LuaJit extends Lua implements LuaCompiler {
|
|||||||
ps.print(
|
ps.print(
|
||||||
"import org.luaj.vm.*;\n"+
|
"import org.luaj.vm.*;\n"+
|
||||||
"import org.luaj.jit.*;\n"+
|
"import org.luaj.jit.*;\n"+
|
||||||
|
"import java.io.*;\n"+
|
||||||
"\n"+
|
"\n"+
|
||||||
"public class "+name+" extends JitPrototype {\n" );
|
"public class "+name+" extends JitPrototype {\n" );
|
||||||
|
|
||||||
@@ -176,6 +178,7 @@ public class LuaJit extends Lua implements LuaCompiler {
|
|||||||
for (; is<ns; is++ )
|
for (; is<ns; is++ )
|
||||||
ps.println( "\t\tLValue s"+is+" = LNil.NIL;" );
|
ps.println( "\t\tLValue s"+is+" = LNil.NIL;" );
|
||||||
ps.println("\t\tLClosure newcl;");
|
ps.println("\t\tLClosure newcl;");
|
||||||
|
ps.println("\t\tByteArrayOutputStream baos;");
|
||||||
ps.println();
|
ps.println();
|
||||||
|
|
||||||
// save var args
|
// save var args
|
||||||
@@ -383,18 +386,25 @@ public class LuaJit extends Lua implements LuaCompiler {
|
|||||||
bs = GETARG_RKB_jit(i);
|
bs = GETARG_RKB_jit(i);
|
||||||
ps.println("\t\ts"+a+" = LInteger.valueOf("+bs+".luaLength());");
|
ps.println("\t\ts"+a+" = LInteger.valueOf("+bs+".luaLength());");
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
case LuaState.OP_CONCAT: {
|
case LuaState.OP_CONCAT: {
|
||||||
b = LuaState.GETARG_B(i);
|
//b = LuaState.GETARG_B(i);
|
||||||
c = LuaState.GETARG_C(i);
|
//c = LuaState.GETARG_C(i);
|
||||||
int numValues = c - b + 1;
|
//int numValues = c - b + 1;
|
||||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
//ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
for (int j = b, l = 0; j <= c; j++, l++) {
|
//for (int j = b, l = 0; j <= c; j++, l++) {
|
||||||
this.stack[base + j].luaConcatTo( baos );
|
// this.stack[base + j].luaConcatTo( baos );
|
||||||
}
|
//}
|
||||||
this.stack[base + a] = new LString( baos.toByteArray() );
|
//this.stack[base + a] = new LString( baos.toByteArray() );
|
||||||
continue;
|
//continue;
|
||||||
|
b = LuaState.GETARG_B(i);
|
||||||
|
c = LuaState.GETARG_C(i);
|
||||||
|
ps.println("\t\tbaos = new ByteArrayOutputStream();");
|
||||||
|
for (int j = b; j <= c; j++)
|
||||||
|
ps.println("\t\ts"+j+".luaConcatTo( baos );");
|
||||||
|
ps.println("\t\ts"+a+" = new LString( baos.toByteArray() );");
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
case LuaState.OP_JMP: {
|
case LuaState.OP_JMP: {
|
||||||
ci.pc += LuaState.GETARG_sBx(i);
|
ci.pc += LuaState.GETARG_sBx(i);
|
||||||
continue;
|
continue;
|
||||||
@@ -619,24 +629,39 @@ public class LuaJit extends Lua implements LuaCompiler {
|
|||||||
//}
|
//}
|
||||||
//continue;
|
//continue;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
case LuaState.OP_SETLIST: {
|
case LuaState.OP_SETLIST: {
|
||||||
b = LuaState.GETARG_B(i);
|
//b = LuaState.GETARG_B(i);
|
||||||
c = LuaState.GETARG_C(i);
|
//c = LuaState.GETARG_C(i);
|
||||||
int listBase = base + a;
|
//int listBase = base + a;
|
||||||
if (b == 0) {
|
//if (b == 0) {
|
||||||
b = top - listBase - 1;
|
// b = top - listBase - 1;
|
||||||
}
|
//}
|
||||||
if (c == 0) {
|
//if (c == 0) {
|
||||||
c = code[ci.pc++];
|
// c = code[ci.pc++];
|
||||||
}
|
//}
|
||||||
int offset = (c-1) * LFIELDS_PER_FLUSH;
|
//int offset = (c-1) * LFIELDS_PER_FLUSH;
|
||||||
LTable tbl = (LTable) this.stack[base + a];
|
//LTable tbl = (LTable) this.stack[base + a];
|
||||||
for (int j=1; j<=b; j++) {
|
//for (int j=1; j<=b; j++) {
|
||||||
tbl.put(offset+j, stack[listBase + j]);
|
// tbl.put(offset+j, stack[listBase + j]);
|
||||||
}
|
//}
|
||||||
top = base + a - 1;
|
//top = base + a - 1;
|
||||||
continue;
|
//continue;
|
||||||
|
b = LuaState.GETARG_B(i);
|
||||||
|
c = LuaState.GETARG_C(i);
|
||||||
|
if (c == 0)
|
||||||
|
c = code[++pc];
|
||||||
|
int offset = (c-1) * LFIELDS_PER_FLUSH;
|
||||||
|
if ( b == 0 ) {
|
||||||
|
ps.println("\t\tfor ( int j=0, nj=vm.top-base-"+(a+1)+"; j<nj; j++ )");
|
||||||
|
ps.println("\t\t\ts"+(a)+".put("+offset+"+j,vm.stack[base+"+a+"+j]);");
|
||||||
|
} else {
|
||||||
|
for (int j=1; j<=b; j++)
|
||||||
|
ps.println("\t\ts"+(a)+".put("+(offset+j)+",s"+(a+j)+");");
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
case LuaState.OP_CLOSE: {
|
case LuaState.OP_CLOSE: {
|
||||||
closeUpVals( base + a ); // close upvals higher in the stack than position a
|
closeUpVals( base + a ); // close upvals higher in the stack than position a
|
||||||
continue;
|
continue;
|
||||||
|
|||||||
Reference in New Issue
Block a user