implements byte code ifne

This commit is contained in:
Volker Berlin 2018-03-25 21:06:18 +02:00
parent 07c18fac6b
commit 8d7ea08f64
3 changed files with 18 additions and 2 deletions

View File

@ -453,6 +453,7 @@ public class BinaryModuleWriter extends ModuleWriter implements InstructionOpcod
op = F64_EQ;
break;
}
break;
case ne:
switch( valueType ) {
case i32:
@ -468,6 +469,7 @@ public class BinaryModuleWriter extends ModuleWriter implements InstructionOpcod
op = F64_NE;
break;
}
break;
}
if( op == 0 ) {
throw new Error( valueType + "." + numOp );

View File

@ -499,6 +499,9 @@ public abstract class ModuleWriter implements Closeable {
case 153: // ifeq
opIfCondition( NumericOperator.ne, byteCode );
break;
case 154: // ifne
opIfCondition( NumericOperator.eq, byteCode );
break;
case 167: // goto
int baseCodePosition = byteCode.getCodePosition() - 1;
int offset = byteCode.readUnsignedShort();

View File

@ -24,7 +24,8 @@ public class ControlFlowOperators extends AbstractBaseTest {
ArrayList<Object[]> list = new ArrayList<>();
for( ScriptEngine[] val : ScriptEngine.testParams() ) {
ScriptEngine script = val[0];
addParam( list, script, "ifThenElse_Int0" );
addParam( list, script, "ifeq" );
addParam( list, script, "ifne" );
addParam( list, script, "forLoop" );
}
return list;
@ -33,7 +34,7 @@ public class ControlFlowOperators extends AbstractBaseTest {
static class TestClass {
@Export
static int ifThenElse_Int0() {
static int ifeq() {
int condition = 0;
if( condition != 0 ) {
return 13;
@ -42,6 +43,16 @@ public class ControlFlowOperators extends AbstractBaseTest {
}
}
@Export
static int ifne() {
int condition = 3;
if( condition == 0 ) {
return 13;
} else {
return 76;
}
}
@Export
static int forLoop() {
int a = 0;