mirror of
https://github.com/i-net-software/JWebAssembly.git
synced 2025-03-15 10:44:47 +01:00
add support for objects equals/not equals (if_acmpeq,if_acmpne)
This commit is contained in:
parent
9ba680848a
commit
6196648cc0
@ -635,6 +635,13 @@ public class BinaryModuleWriter extends ModuleWriter implements InstructionOpcod
|
||||
codeStream.writeOpCode( REF_ISNULL );
|
||||
op = I32_EQZ;
|
||||
break;
|
||||
case ref_eq:
|
||||
op = REF_EQ;
|
||||
break;
|
||||
case ref_ne:
|
||||
codeStream.writeOpCode( REF_EQ );
|
||||
op = I32_EQZ;
|
||||
break;
|
||||
}
|
||||
if( op == 0 ) {
|
||||
throw new Error( valueType + "." + numOp );
|
||||
|
@ -379,6 +379,8 @@ interface InstructionOpcodes {
|
||||
|
||||
static final int REF_ISNULL = 0xD1;
|
||||
|
||||
static final int REF_EQ = 0xD2;
|
||||
|
||||
// === Non-trapping float-to-int conversions ====== https://github.com/WebAssembly/design/issues/1143
|
||||
|
||||
static final int I32_TRUNC_S_SAT_F32 = 0xFC00;
|
||||
|
@ -702,6 +702,12 @@ class BranchManger {
|
||||
case ifnonnull:
|
||||
newOp = NumericOperator.ifnull;
|
||||
break;
|
||||
case ref_eq:
|
||||
newOp = NumericOperator.ref_ne;
|
||||
break;
|
||||
case ref_ne:
|
||||
newOp = NumericOperator.ref_eq;
|
||||
break;
|
||||
default:
|
||||
throw new WasmException( "Not a compare operation: " + instr.numOp, null, null, lineNumber );
|
||||
}
|
||||
|
@ -480,8 +480,12 @@ class JavaMethodWasmCodeBuilder extends WasmCodeBuilder {
|
||||
case 164: // if_icmple
|
||||
opIfCompareCondition( NumericOperator.le, byteCode, codePos );
|
||||
break;
|
||||
//TODO case 165: // if_acmpeq
|
||||
//TODO case 166: // if_acmpne
|
||||
case 165: // if_acmpeq
|
||||
opIfCompareCondition( NumericOperator.ref_eq, byteCode, codePos );
|
||||
break;
|
||||
case 166: // if_acmpne
|
||||
opIfCompareCondition( NumericOperator.ref_ne, byteCode, codePos );
|
||||
break;
|
||||
case 167: // goto
|
||||
int offset = byteCode.readShort();
|
||||
branchManager.addGotoOperator( codePos, offset, byteCode.getLineNumber() );
|
||||
|
@ -217,6 +217,13 @@ public class TextModuleWriter extends ModuleWriter {
|
||||
case ifnull:
|
||||
methodOutput.append( "ref.isnull" );
|
||||
return;
|
||||
case ref_ne:
|
||||
methodOutput.append( "ref.eq" );
|
||||
writeNumericOperator( NumericOperator.eqz, ValueType.i32 );
|
||||
return;
|
||||
case ref_eq:
|
||||
methodOutput.append( "ref.eq" );
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -41,4 +41,6 @@ public enum NumericOperator {
|
||||
max,
|
||||
ifnull,
|
||||
ifnonnull,
|
||||
ref_eq,
|
||||
ref_ne,
|
||||
}
|
||||
|
@ -43,6 +43,8 @@ public class Structs extends AbstractBaseTest {
|
||||
ScriptEngine script = val[0];
|
||||
addParam( list, script, "isNull" );
|
||||
addParam( list, script, "isNotNull" );
|
||||
addParam( list, script, "isSame" );
|
||||
addParam( list, script, "isNotSame" );
|
||||
addParam( list, script, "simple" );
|
||||
}
|
||||
return list;
|
||||
@ -68,6 +70,20 @@ public class Structs extends AbstractBaseTest {
|
||||
return val != null;
|
||||
}
|
||||
|
||||
@Export
|
||||
static boolean isSame() {
|
||||
Object val1 = null;
|
||||
Object val2 = null;
|
||||
return val1 == val2;
|
||||
}
|
||||
|
||||
@Export
|
||||
static boolean isNotSame() {
|
||||
Object val1 = null;
|
||||
Object val2 = null;
|
||||
return val1 != val2;
|
||||
}
|
||||
|
||||
@Export
|
||||
static int simple() {
|
||||
Object val = new Abc();
|
||||
|
Loading…
x
Reference in New Issue
Block a user