mirror of
https://github.com/i-net-software/JWebAssembly.git
synced 2025-03-25 07:27:52 +01:00
use constants for primitive type IDs
This commit is contained in:
parent
0290a5f8e4
commit
622fd5d63c
@ -19,6 +19,8 @@ package de.inetsoftware.jwebassembly.module;
|
|||||||
import de.inetsoftware.jwebassembly.api.annotation.Replace;
|
import de.inetsoftware.jwebassembly.api.annotation.Replace;
|
||||||
import de.inetsoftware.jwebassembly.api.annotation.WasmTextCode;
|
import de.inetsoftware.jwebassembly.api.annotation.WasmTextCode;
|
||||||
|
|
||||||
|
import static de.inetsoftware.jwebassembly.module.TypeManager.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Replacement for java.lang.Class
|
* Replacement for java.lang.Class
|
||||||
*
|
*
|
||||||
@ -45,7 +47,7 @@ class ReplacementForClass {
|
|||||||
* @return the name
|
* @return the name
|
||||||
*/
|
*/
|
||||||
String getName() {
|
String getName() {
|
||||||
return StringManager.stringConstant( getIntFromMemory( vtable + TypeManager.TYPE_DESCRIPTION_TYPE_NAME ) );
|
return StringManager.stringConstant( getIntFromMemory( vtable + TYPE_DESCRIPTION_TYPE_NAME ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -59,7 +61,7 @@ class ReplacementForClass {
|
|||||||
@WasmTextCode( "local.get 0 " // THIS
|
@WasmTextCode( "local.get 0 " // THIS
|
||||||
+ "struct.get java/lang/Object .vtable " // vtable is on index 0
|
+ "struct.get java/lang/Object .vtable " // vtable is on index 0
|
||||||
+ "local.tee 1 " // save the vtable location
|
+ "local.tee 1 " // save the vtable location
|
||||||
+ "i32.const " + TypeManager.TYPE_DESCRIPTION_INSTANCEOF_OFFSET + " " // vtable is on index 0
|
+ "i32.const " + TYPE_DESCRIPTION_INSTANCEOF_OFFSET + " " // vtable is on index 0
|
||||||
+ "i32.add " //
|
+ "i32.add " //
|
||||||
+ "call $java/lang/Class.getIntFromMemory(I)I " //
|
+ "call $java/lang/Class.getIntFromMemory(I)I " //
|
||||||
+ "local.get 1 " // get the vtable location
|
+ "local.get 1 " // get the vtable location
|
||||||
@ -177,7 +179,7 @@ class ReplacementForClass {
|
|||||||
* Replacement of the native Java methods getComponentType()
|
* Replacement of the native Java methods getComponentType()
|
||||||
*/
|
*/
|
||||||
ReplacementForClass getComponentType() {
|
ReplacementForClass getComponentType() {
|
||||||
int classIdx = getIntFromMemory( vtable + TypeManager.TYPE_DESCRIPTION_ARRAY_TYPE );
|
int classIdx = getIntFromMemory( vtable + TYPE_DESCRIPTION_ARRAY_TYPE );
|
||||||
return classIdx >= 0 ? classConstant( classIdx ) : null;
|
return classIdx >= 0 ? classConstant( classIdx ) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -192,23 +194,23 @@ class ReplacementForClass {
|
|||||||
static ReplacementForClass getPrimitiveClass( String name ) {
|
static ReplacementForClass getPrimitiveClass( String name ) {
|
||||||
switch( name ) {
|
switch( name ) {
|
||||||
case "boolean":
|
case "boolean":
|
||||||
return classConstant( 0 );
|
return classConstant( BOOLEAN );
|
||||||
case "byte":
|
case "byte":
|
||||||
return classConstant( 1 );
|
return classConstant( BYTE );
|
||||||
case "char":
|
case "char":
|
||||||
return classConstant( 2 );
|
return classConstant( CHAR );
|
||||||
case "double":
|
case "double":
|
||||||
return classConstant( 3 );
|
return classConstant( DOUBLE );
|
||||||
case "float":
|
case "float":
|
||||||
return classConstant( 4 );
|
return classConstant( FLOAT );
|
||||||
case "int":
|
case "int":
|
||||||
return classConstant( 5 );
|
return classConstant( INT );
|
||||||
case "long":
|
case "long":
|
||||||
return classConstant( 6 );
|
return classConstant( LONG );
|
||||||
case "short":
|
case "short":
|
||||||
return classConstant( 7 );
|
return classConstant( SHORT );
|
||||||
case "void":
|
case "void":
|
||||||
return classConstant( 8 );
|
return classConstant( VOID );
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -82,7 +82,7 @@ public class TypeManager {
|
|||||||
/**
|
/**
|
||||||
* Byte position in the type description that contains the type of the array (component type). Length 4 bytes.
|
* Byte position in the type description that contains the type of the array (component type). Length 4 bytes.
|
||||||
*/
|
*/
|
||||||
static final int TYPE_DESCRIPTION_ARRAY_TYPE = 12;
|
public static final int TYPE_DESCRIPTION_ARRAY_TYPE = 12;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The reserved position on start of the vtable:
|
* The reserved position on start of the vtable:
|
||||||
@ -94,6 +94,51 @@ public class TypeManager {
|
|||||||
|
|
||||||
private static final FunctionName CLASS_CONSTANT_FUNCTION = new FunctionName( "java/lang/Class.classConstant(I)Ljava/lang/Class;" );
|
private static final FunctionName CLASS_CONSTANT_FUNCTION = new FunctionName( "java/lang/Class.classConstant(I)Ljava/lang/Class;" );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Type id of primitive class
|
||||||
|
*/
|
||||||
|
public static final int BOOLEAN = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Type id of primitive class
|
||||||
|
*/
|
||||||
|
public static final int BYTE = 1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Type id of primitive class
|
||||||
|
*/
|
||||||
|
public static final int CHAR = 2;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Type id of primitive class
|
||||||
|
*/
|
||||||
|
public static final int DOUBLE = 3;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Type id of primitive class
|
||||||
|
*/
|
||||||
|
public static final int FLOAT = 4;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Type id of primitive class
|
||||||
|
*/
|
||||||
|
public static final int INT = 5;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Type id of primitive class
|
||||||
|
*/
|
||||||
|
public static final int LONG = 6;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Type id of primitive class
|
||||||
|
*/
|
||||||
|
public static final int SHORT = 7;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Type id of primitive class
|
||||||
|
*/
|
||||||
|
public static final int VOID = 8;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* the list of primitive types. The order is important and must correlate with getPrimitiveClass.
|
* the list of primitive types. The order is important and must correlate with getPrimitiveClass.
|
||||||
*
|
*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user