mirror of
https://github.com/i-net-software/JWebAssembly.git
synced 2025-03-25 07:27:52 +01:00
implement "instanceof", WIP
This commit is contained in:
parent
3d8b759a2d
commit
8c12f5a3c9
@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with 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 );
|
addBlockInstruction( WasmBlockOperator.THROW, null, codePos, lineNumber );
|
||||||
break;
|
break;
|
||||||
//TODO case 192: // checkcast
|
//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
|
case 194: // monitorenter
|
||||||
addBlockInstruction( WasmBlockOperator.MONITOR_ENTER, null, codePos, lineNumber );
|
addBlockInstruction( WasmBlockOperator.MONITOR_ENTER, null, codePos, lineNumber );
|
||||||
break;
|
break;
|
||||||
|
@ -208,6 +208,8 @@ class WasmStructInstruction extends WasmInstruction {
|
|||||||
return fieldName.getType();
|
return fieldName.getType();
|
||||||
case SET:
|
case SET:
|
||||||
return null;
|
return null;
|
||||||
|
case INSTANCEOF:
|
||||||
|
return ValueType.i32; // a boolean value
|
||||||
default:
|
default:
|
||||||
throw new WasmException( "Unknown array operation: " + op, -1 );
|
throw new WasmException( "Unknown array operation: " + op, -1 );
|
||||||
}
|
}
|
||||||
@ -220,6 +222,7 @@ class WasmStructInstruction extends WasmInstruction {
|
|||||||
int getPopCount() {
|
int getPopCount() {
|
||||||
switch( op ) {
|
switch( op ) {
|
||||||
case GET:
|
case GET:
|
||||||
|
case INSTANCEOF:
|
||||||
return 1;
|
return 1;
|
||||||
case SET:
|
case SET:
|
||||||
return 2;
|
return 2;
|
||||||
|
@ -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");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
@ -27,4 +27,5 @@ public enum StructOperator {
|
|||||||
GET,
|
GET,
|
||||||
SET,
|
SET,
|
||||||
NULL,
|
NULL,
|
||||||
|
INSTANCEOF,
|
||||||
}
|
}
|
@ -114,7 +114,6 @@ public class RuntimeErrors {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void interfaceCall() throws IOException {
|
public void interfaceCall() throws IOException {
|
||||||
compileErrorTest( "Interface calls are not supported.", InterfaceMethod.class );
|
compileErrorTest( "Interface calls are not supported.", InterfaceMethod.class );
|
||||||
@ -127,4 +126,18 @@ public class RuntimeErrors {
|
|||||||
return list.size();
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user