implement "instanceof", WIP

This commit is contained in:
Volker Berlin 2020-02-01 16:49:52 +01:00
parent 3d8b759a2d
commit 8c12f5a3c9
4 changed files with 25 additions and 4 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright 2018 - 2019 Volker Berlin (i-net software)
* Copyright 2018 - 2020 Volker Berlin (i-net software)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -654,7 +654,11 @@ class JavaMethodWasmCodeBuilder extends WasmCodeBuilder {
addBlockInstruction( WasmBlockOperator.THROW, null, codePos, lineNumber );
break;
//TODO case 192: // checkcast
//TODO case 193: // instanceof
case 193: // instanceof
idx = byteCode.readUnsignedShort();
name = ((ConstantClass)constantPool.get( idx )).getName();
addStructInstruction( StructOperator.INSTANCEOF, name, null, codePos, lineNumber );
break;
case 194: // monitorenter
addBlockInstruction( WasmBlockOperator.MONITOR_ENTER, null, codePos, lineNumber );
break;

View File

@ -208,6 +208,8 @@ class WasmStructInstruction extends WasmInstruction {
return fieldName.getType();
case SET:
return null;
case INSTANCEOF:
return ValueType.i32; // a boolean value
default:
throw new WasmException( "Unknown array operation: " + op, -1 );
}
@ -220,6 +222,7 @@ class WasmStructInstruction extends WasmInstruction {
int getPopCount() {
switch( op ) {
case GET:
case INSTANCEOF:
return 1;
case SET:
return 2;

View File

@ -1,5 +1,5 @@
/*
Copyright 2018 Volker Berlin (i-net software)
Copyright 2018 - 2020 Volker Berlin (i-net software)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@ -27,4 +27,5 @@ public enum StructOperator {
GET,
SET,
NULL,
INSTANCEOF,
}

View File

@ -114,7 +114,6 @@ public class RuntimeErrors {
}
}
@Test
public void interfaceCall() throws IOException {
compileErrorTest( "Interface calls are not supported.", InterfaceMethod.class );
@ -127,4 +126,18 @@ public class RuntimeErrors {
return list.size();
}
}
@Test
public void instanceofCall() throws IOException {
compileErrorTest( "Unknown operator: INSTANCEOF", InstanceofMethod.class );
}
static class InstanceofMethod {
@Export
static boolean runnable() {
Object obj = new Object();
return obj instanceof Integer;
}
}
}