diff --git a/src/de/inetsoftware/jwebassembly/module/TypeManager.java b/src/de/inetsoftware/jwebassembly/module/TypeManager.java index 95ecf3f..9d8a7c0 100644 --- a/src/de/inetsoftware/jwebassembly/module/TypeManager.java +++ b/src/de/inetsoftware/jwebassembly/module/TypeManager.java @@ -97,7 +97,7 @@ public class TypeManager { if( isFinish ) { throw new WasmException( "Register needed type after scanning: " + name, -1 ); } - type = new StructType( name ); + type = new StructType( name, structTypes.size() ); structTypes.put( name, type ); } return type; @@ -132,6 +132,8 @@ public class TypeManager { private final String name; + private final int classIndex; + private int code = Integer.MAX_VALUE; private HashSet neededFields = new HashSet<>(); @@ -150,9 +152,12 @@ public class TypeManager { * * @param name * the Java class name + * @param classIndex + * the running index of the class/type */ - StructType( String name ) { + StructType( String name, int classIndex ) { this.name = name; + this.classIndex = classIndex; } /** @@ -281,6 +286,15 @@ public class TypeManager { return name; } + /** + * The running index of the class/type for class meta data, instanceof and interface calls. + * + * @return the unique index + */ + public int getClassIndex() { + return classIndex; + } + /** * Get the fields of this struct * @return the fields diff --git a/src/de/inetsoftware/jwebassembly/module/WasmCallInstruction.java b/src/de/inetsoftware/jwebassembly/module/WasmCallInstruction.java index 6a20cce..5e10953 100644 --- a/src/de/inetsoftware/jwebassembly/module/WasmCallInstruction.java +++ b/src/de/inetsoftware/jwebassembly/module/WasmCallInstruction.java @@ -37,6 +37,7 @@ class WasmCallInstruction extends WasmInstruction { private int paramCount = -1; + @Nonnull private final TypeManager types; private final boolean needThisParameter; @@ -55,7 +56,7 @@ class WasmCallInstruction extends WasmInstruction { * @param needThisParameter * true, if this function need additional to the parameter of the signature an extra "this" parameter */ - WasmCallInstruction( FunctionName name, int javaCodePos, int lineNumber, TypeManager types, boolean needThisParameter ) { + WasmCallInstruction( FunctionName name, int javaCodePos, int lineNumber, @Nonnull TypeManager types, boolean needThisParameter ) { super( javaCodePos, lineNumber ); this.name = name; this.types = types; @@ -80,6 +81,14 @@ class WasmCallInstruction extends WasmInstruction { return name; } + /** + * Get the type manager. + * @return the manager + */ + TypeManager getTypeManager() { + return types; + } + /** * Mark the function as needed in the functions manager and replace the function name with a possible super name. * diff --git a/src/de/inetsoftware/jwebassembly/module/WasmCallInterfaceInstruction.java b/src/de/inetsoftware/jwebassembly/module/WasmCallInterfaceInstruction.java index 221d5d6..4b0c4cb 100644 --- a/src/de/inetsoftware/jwebassembly/module/WasmCallInterfaceInstruction.java +++ b/src/de/inetsoftware/jwebassembly/module/WasmCallInterfaceInstruction.java @@ -21,6 +21,7 @@ import java.io.IOException; import javax.annotation.Nonnull; import de.inetsoftware.jwebassembly.WasmException; +import de.inetsoftware.jwebassembly.module.TypeManager.StructType; /** * WasmInstruction for a function call. @@ -58,6 +59,8 @@ class WasmCallInterfaceInstruction extends WasmCallInstruction { * {@inheritDoc} */ public void writeTo( @Nonnull ModuleWriter writer ) throws IOException { + StructType type = getTypeManager().valueOf( getFunctionName().className ); + int classIndex = type.getClassIndex(); throw new WasmException( "Interface calls are not supported.", getLineNumber() ); } }