Start to add branching
This commit is contained in:
@@ -45,7 +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()";
|
program = "f(); if v then a(); elseif w then c(); 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 );
|
||||||
@@ -220,6 +220,10 @@ public class LuaJit extends Lua implements LuaCompiler {
|
|||||||
// get instruction
|
// get instruction
|
||||||
i = code[pc];
|
i = code[pc];
|
||||||
|
|
||||||
|
// close if-related jump bodies
|
||||||
|
while ( jumpdeltas[pc]++ < 0 )
|
||||||
|
ps.println("\t\t}");
|
||||||
|
|
||||||
// get opcode and first arg
|
// get opcode and first arg
|
||||||
o = (i >> POS_OP) & MAX_OP;
|
o = (i >> POS_OP) & MAX_OP;
|
||||||
a = (i >> POS_A) & MAXARG_A;
|
a = (i >> POS_A) & MAXARG_A;
|
||||||
@@ -404,11 +408,12 @@ public class LuaJit extends Lua implements LuaCompiler {
|
|||||||
ps.println("\t\ts"+a+" = new LString( baos.toByteArray() );");
|
ps.println("\t\ts"+a+" = new LString( baos.toByteArray() );");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
case LuaState.OP_JMP: {
|
case LuaState.OP_JMP: {
|
||||||
ci.pc += LuaState.GETARG_sBx(i);
|
//ci.pc += LuaState.GETARG_sBx(i);
|
||||||
continue;
|
//continue;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
case LuaState.OP_EQ:
|
case LuaState.OP_EQ:
|
||||||
case LuaState.OP_LT:
|
case LuaState.OP_LT:
|
||||||
case LuaState.OP_LE: {
|
case LuaState.OP_LE: {
|
||||||
@@ -419,12 +424,20 @@ public class LuaJit extends Lua implements LuaCompiler {
|
|||||||
ci.pc++;
|
ci.pc++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
case LuaState.OP_TEST: {
|
case LuaState.OP_TEST: {
|
||||||
|
//c = LuaState.GETARG_C(i);
|
||||||
|
//if (this.stack[base + a].toJavaBoolean() != (c != 0))
|
||||||
|
// ci.pc++;
|
||||||
|
//continue;
|
||||||
c = LuaState.GETARG_C(i);
|
c = LuaState.GETARG_C(i);
|
||||||
if (this.stack[base + a].toJavaBoolean() != (c != 0))
|
ps.println("\t\tif ( "+(c!=0?"!":"")+" s"+a+".toJavaBoolean())");
|
||||||
ci.pc++;
|
ps.println("\t\t{");
|
||||||
continue;
|
int jump = LuaState.GETARG_sBx(code[++pc]);
|
||||||
|
jumpdeltas[pc+jump]--;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
case LuaState.OP_TESTSET: {
|
case LuaState.OP_TESTSET: {
|
||||||
rkb = GETARG_RKB(k, i);
|
rkb = GETARG_RKB(k, i);
|
||||||
c = LuaState.GETARG_C(i);
|
c = LuaState.GETARG_C(i);
|
||||||
|
|||||||
Reference in New Issue
Block a user