array.len needs a match between variable type and given type. Thats wee needs a cast in WASM to come from Object to a specific array type.

This commit is contained in:
Volker Berlin 2021-02-14 11:22:21 +01:00
parent c1e8191ee0
commit fb7e3e2468

View File

@ -1,5 +1,5 @@
/* /*
Copyright 2020 Volker Berlin (i-net software) Copyright 2020 - 2021 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.
@ -70,66 +70,26 @@ public class ReplacementForArray {
case -1: case -1:
throw new java.lang.IllegalArgumentException( "Argument is not an array" ); throw new java.lang.IllegalArgumentException( "Argument is not an array" );
case BOOLEAN: case BOOLEAN:
return getLengthOfBooleans( obj ); return ((boolean[])obj).length;
case BYTE: case BYTE:
return getLengthOfBytes( obj ); return ((byte[])obj).length;
case CHAR: case CHAR:
return getLengthOfChars( obj ); return ((char[])obj).length;
case DOUBLE: case DOUBLE:
return getLengthOfDoubles( obj ); return ((double[])obj).length;
case FLOAT: case FLOAT:
return getLengthOfFloats( obj ); return ((float[])obj).length;
case INT: case INT:
return getLengthOfInts( obj ); return ((int[])obj).length;
case LONG: case LONG:
return getLengthOfLongs( obj ); return ((long[])obj).length;
case SHORT: case SHORT:
return getLengthOfShorts( obj ); return ((short[])obj).length;
default: default:
return ((Object[])obj).length; return ((Object[])obj).length;
} }
} }
@WasmTextCode( "local.get 0 " // THIS
+ "array.len [Z " //
+ "return " )
private static native int getLengthOfBooleans( Object obj );
@WasmTextCode( "local.get 0 " // THIS
+ "array.len [B " //
+ "return " )
private static native int getLengthOfBytes( Object obj );
@WasmTextCode( "local.get 0 " // THIS
+ "array.len [C " //
+ "return " )
private static native int getLengthOfChars( Object obj );
@WasmTextCode( "local.get 0 " // THIS
+ "array.len [D " //
+ "return " )
private static native int getLengthOfDoubles( Object obj );
@WasmTextCode( "local.get 0 " // THIS
+ "array.len [F " //
+ "return " )
private static native int getLengthOfFloats( Object obj );
@WasmTextCode( "local.get 0 " // THIS
+ "array.len [I " //
+ "return " )
private static native int getLengthOfInts( Object obj );
@WasmTextCode( "local.get 0 " // THIS
+ "array.len [J " //
+ "return " )
private static native int getLengthOfLongs( Object obj );
@WasmTextCode( "local.get 0 " // THIS
+ "array.len [S " //
+ "return " )
private static native int getLengthOfShorts( Object obj );
/** /**
* Replacement of the native Java methods Array.newInstance(c,l) * Replacement of the native Java methods Array.newInstance(c,l)
* *