mirror of
https://github.com/i-net-software/JWebAssembly.git
synced 2025-03-25 15:37:52 +01:00
implement CAST operation, WIP
This commit is contained in:
parent
8c12f5a3c9
commit
5410764249
@ -653,10 +653,12 @@ class JavaMethodWasmCodeBuilder extends WasmCodeBuilder {
|
|||||||
case 191: // athrow
|
case 191: // athrow
|
||||||
addBlockInstruction( WasmBlockOperator.THROW, null, codePos, lineNumber );
|
addBlockInstruction( WasmBlockOperator.THROW, null, codePos, lineNumber );
|
||||||
break;
|
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
|
case 193: // instanceof
|
||||||
idx = byteCode.readUnsignedShort();
|
name = ((ConstantClass)constantPool.get( byteCode.readUnsignedShort() )).getName();
|
||||||
name = ((ConstantClass)constantPool.get( idx )).getName();
|
|
||||||
addStructInstruction( StructOperator.INSTANCEOF, name, null, codePos, lineNumber );
|
addStructInstruction( StructOperator.INSTANCEOF, name, null, codePos, lineNumber );
|
||||||
break;
|
break;
|
||||||
case 194: // monitorenter
|
case 194: // monitorenter
|
||||||
|
@ -203,6 +203,7 @@ class WasmStructInstruction extends WasmInstruction {
|
|||||||
return ValueType.anyref;
|
return ValueType.anyref;
|
||||||
case NEW:
|
case NEW:
|
||||||
case NEW_DEFAULT:
|
case NEW_DEFAULT:
|
||||||
|
case CAST:
|
||||||
return type;
|
return type;
|
||||||
case GET:
|
case GET:
|
||||||
return fieldName.getType();
|
return fieldName.getType();
|
||||||
@ -223,6 +224,7 @@ class WasmStructInstruction extends WasmInstruction {
|
|||||||
switch( op ) {
|
switch( op ) {
|
||||||
case GET:
|
case GET:
|
||||||
case INSTANCEOF:
|
case INSTANCEOF:
|
||||||
|
case CAST:
|
||||||
return 1;
|
return 1;
|
||||||
case SET:
|
case SET:
|
||||||
return 2;
|
return 2;
|
||||||
|
@ -27,5 +27,6 @@ public enum StructOperator {
|
|||||||
GET,
|
GET,
|
||||||
SET,
|
SET,
|
||||||
NULL,
|
NULL,
|
||||||
|
CAST,
|
||||||
INSTANCEOF,
|
INSTANCEOF,
|
||||||
}
|
}
|
@ -76,7 +76,6 @@ public class RuntimeErrors {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void nonStaticImport() throws IOException {
|
public void nonStaticImport() throws IOException {
|
||||||
compileErrorTest( "Import method must be static:", NonStaticImport.class );
|
compileErrorTest( "Import method must be static:", NonStaticImport.class );
|
||||||
@ -127,7 +126,6 @@ public class RuntimeErrors {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void instanceofCall() throws IOException {
|
public void instanceofCall() throws IOException {
|
||||||
compileErrorTest( "Unknown operator: INSTANCEOF", InstanceofMethod.class );
|
compileErrorTest( "Unknown operator: INSTANCEOF", InstanceofMethod.class );
|
||||||
@ -140,4 +138,17 @@ public class RuntimeErrors {
|
|||||||
return obj instanceof Integer;
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user