add interface calls, WIP

This commit is contained in:
Volker Berlin 2020-02-24 11:46:00 +01:00
parent a535c48363
commit cb71374f57
3 changed files with 29 additions and 3 deletions

View File

@ -97,7 +97,7 @@ public class TypeManager {
if( isFinish ) { if( isFinish ) {
throw new WasmException( "Register needed type after scanning: " + name, -1 ); throw new WasmException( "Register needed type after scanning: " + name, -1 );
} }
type = new StructType( name ); type = new StructType( name, structTypes.size() );
structTypes.put( name, type ); structTypes.put( name, type );
} }
return type; return type;
@ -132,6 +132,8 @@ public class TypeManager {
private final String name; private final String name;
private final int classIndex;
private int code = Integer.MAX_VALUE; private int code = Integer.MAX_VALUE;
private HashSet<String> neededFields = new HashSet<>(); private HashSet<String> neededFields = new HashSet<>();
@ -150,9 +152,12 @@ public class TypeManager {
* *
* @param name * @param name
* the Java class 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.name = name;
this.classIndex = classIndex;
} }
/** /**
@ -281,6 +286,15 @@ public class TypeManager {
return name; 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 * Get the fields of this struct
* @return the fields * @return the fields

View File

@ -37,6 +37,7 @@ class WasmCallInstruction extends WasmInstruction {
private int paramCount = -1; private int paramCount = -1;
@Nonnull
private final TypeManager types; private final TypeManager types;
private final boolean needThisParameter; private final boolean needThisParameter;
@ -55,7 +56,7 @@ class WasmCallInstruction extends WasmInstruction {
* @param needThisParameter * @param needThisParameter
* true, if this function need additional to the parameter of the signature an extra "this" parameter * 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 ); super( javaCodePos, lineNumber );
this.name = name; this.name = name;
this.types = types; this.types = types;
@ -80,6 +81,14 @@ class WasmCallInstruction extends WasmInstruction {
return name; 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. * Mark the function as needed in the functions manager and replace the function name with a possible super name.
* *

View File

@ -21,6 +21,7 @@ import java.io.IOException;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import de.inetsoftware.jwebassembly.WasmException; import de.inetsoftware.jwebassembly.WasmException;
import de.inetsoftware.jwebassembly.module.TypeManager.StructType;
/** /**
* WasmInstruction for a function call. * WasmInstruction for a function call.
@ -58,6 +59,8 @@ class WasmCallInterfaceInstruction extends WasmCallInstruction {
* {@inheritDoc} * {@inheritDoc}
*/ */
public void writeTo( @Nonnull ModuleWriter writer ) throws IOException { 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() ); throw new WasmException( "Interface calls are not supported.", getLineNumber() );
} }
} }