implement CAST operation, WIP

This commit is contained in:
Volker Berlin 2020-02-01 20:29:29 +01:00
parent 8c12f5a3c9
commit 5410764249
4 changed files with 21 additions and 5 deletions

View File

@ -653,10 +653,12 @@ class JavaMethodWasmCodeBuilder extends WasmCodeBuilder {
case 191: // athrow
addBlockInstruction( WasmBlockOperator.THROW, null, codePos, lineNumber );
break;
//TODO case 192: // checkcast
case 192: // checkcast
name = ((ConstantClass)constantPool.get( byteCode.readUnsignedShort() )).getName();
addStructInstruction( StructOperator.CAST, name, null, codePos, lineNumber );
break;
case 193: // instanceof
idx = byteCode.readUnsignedShort();
name = ((ConstantClass)constantPool.get( idx )).getName();
name = ((ConstantClass)constantPool.get( byteCode.readUnsignedShort() )).getName();
addStructInstruction( StructOperator.INSTANCEOF, name, null, codePos, lineNumber );
break;
case 194: // monitorenter

View File

@ -203,6 +203,7 @@ class WasmStructInstruction extends WasmInstruction {
return ValueType.anyref;
case NEW:
case NEW_DEFAULT:
case CAST:
return type;
case GET:
return fieldName.getType();
@ -223,6 +224,7 @@ class WasmStructInstruction extends WasmInstruction {
switch( op ) {
case GET:
case INSTANCEOF:
case CAST:
return 1;
case SET:
return 2;

View File

@ -27,5 +27,6 @@ public enum StructOperator {
GET,
SET,
NULL,
CAST,
INSTANCEOF,
}

View File

@ -76,7 +76,6 @@ public class RuntimeErrors {
}
}
@Test
public void nonStaticImport() throws IOException {
compileErrorTest( "Import method must be static:", NonStaticImport.class );
@ -127,7 +126,6 @@ public class RuntimeErrors {
}
}
@Test
public void instanceofCall() throws IOException {
compileErrorTest( "Unknown operator: INSTANCEOF", InstanceofMethod.class );
@ -140,4 +138,17 @@ public class RuntimeErrors {
return obj instanceof Integer;
}
}
@Test
public void checkcast() throws IOException {
compileErrorTest( "Unknown operator: CAST", CheckcastMethod.class );
}
static class CheckcastMethod {
@Export
static Integer runnable() {
Object obj = new Integer(0);
return (Integer)obj;
}
}
}