mirror of
https://github.com/i-net-software/JWebAssembly.git
synced 2025-03-15 02:44:47 +01:00
declare the native array type with GC enabled
This commit is contained in:
parent
6b6e6843cb
commit
c96b27a12e
@ -345,7 +345,11 @@ public class TypeManager {
|
||||
componentClassIndex = ((StructType)arrayType).classIndex;
|
||||
}
|
||||
|
||||
type = new ArrayType( arrayType, this, componentClassIndex );
|
||||
type = new ArrayType( arrayType, this, componentClassIndex, options );
|
||||
if( options.useGC() ) {
|
||||
StructType nativeArrayType = (StructType)type.getNativeArrayType();
|
||||
structTypes.put( nativeArrayType.getName(), nativeArrayType );
|
||||
}
|
||||
structTypes.put( arrayType, type );
|
||||
}
|
||||
return type;
|
||||
@ -584,17 +588,24 @@ public class TypeManager {
|
||||
instanceOFs = new LinkedHashSet<>(); // remembers the order from bottom to top class.
|
||||
instanceOFs.add( this );
|
||||
interfaceMethods = new LinkedHashMap<>();
|
||||
if( classIndex < PRIMITIVE_CLASSES.length ) {
|
||||
// nothing
|
||||
} else if( this instanceof ArrayType ) {
|
||||
HashSet<String> allNeededFields = new HashSet<>();
|
||||
listStructFields( "java/lang/Object", functions, types, classFileLoader, allNeededFields );
|
||||
} else {
|
||||
// add all interfaces to the instanceof set
|
||||
listInterfaces( functions, types, classFileLoader );
|
||||
switch( kind ) {
|
||||
case primitive:
|
||||
// nothing
|
||||
break;
|
||||
case array:
|
||||
HashSet<String> allNeededFields = new HashSet<>();
|
||||
listStructFields( "java/lang/Object", functions, types, classFileLoader, allNeededFields );
|
||||
fields.add( new NamedStorageType( ((ArrayType)this).getNativeArrayType(), null, FIELD_VALUE ) );
|
||||
break;
|
||||
case array_native:
|
||||
fields.add( new NamedStorageType( ((ArrayType)this).getArrayType(), null, null ) );
|
||||
break;
|
||||
default:
|
||||
// add all interfaces to the instanceof set
|
||||
listInterfaces( functions, types, classFileLoader );
|
||||
|
||||
HashSet<String> allNeededFields = new HashSet<>();
|
||||
listStructFields( name, functions, types, classFileLoader, allNeededFields );
|
||||
allNeededFields = new HashSet<>();
|
||||
listStructFields( name, functions, types, classFileLoader, allNeededFields );
|
||||
}
|
||||
}
|
||||
|
||||
@ -661,9 +672,6 @@ public class TypeManager {
|
||||
} else {
|
||||
fields.add( new NamedStorageType( ValueType.i32, className, FIELD_VTABLE ) );
|
||||
fields.add( new NamedStorageType( ValueType.i32, className, FIELD_HASHCODE ) );
|
||||
if( getComponentClassIndex() >= 0 ) {
|
||||
fields.add( new NamedStorageType( this, className, FIELD_VALUE ) );
|
||||
}
|
||||
}
|
||||
|
||||
// list all fields
|
||||
|
@ -207,7 +207,8 @@ public class TextModuleWriter extends ModuleWriter {
|
||||
inset = 1;
|
||||
newline( output );
|
||||
String typeName = normalizeName( type.getName() );
|
||||
output.append( "(type $" ).append( typeName ).append( " (struct" );
|
||||
String kind = type.getKind() == StructTypeKind.array_native ? "array" : "struct";
|
||||
output.append( "(type $" ).append( typeName ).append( " (" ).append( kind );
|
||||
inset++;
|
||||
for( NamedStorageType field : type.getFields() ) {
|
||||
newline( output );
|
||||
|
@ -19,6 +19,7 @@ import javax.annotation.Nonnull;
|
||||
|
||||
import de.inetsoftware.jwebassembly.WasmException;
|
||||
import de.inetsoftware.jwebassembly.module.TypeManager;
|
||||
import de.inetsoftware.jwebassembly.module.WasmOptions;
|
||||
import de.inetsoftware.jwebassembly.module.TypeManager.StructType;
|
||||
import de.inetsoftware.jwebassembly.module.TypeManager.StructTypeKind;
|
||||
|
||||
@ -32,6 +33,8 @@ public class ArrayType extends StructType {
|
||||
|
||||
private AnyType arrayType;
|
||||
|
||||
private AnyType nativeArrayType;
|
||||
|
||||
private int componentClassIndex;
|
||||
|
||||
/**
|
||||
@ -43,11 +46,36 @@ public class ArrayType extends StructType {
|
||||
* the manager which hold all StructTypes
|
||||
* @param componentClassIndex
|
||||
* the running index of the component/array class/type
|
||||
* @param options
|
||||
* compiler properties
|
||||
*/
|
||||
public ArrayType( AnyType arrayType, @Nonnull TypeManager manager, int componentClassIndex ) {
|
||||
super( getJavaClassName( arrayType ), StructTypeKind.array, manager );
|
||||
this.arrayType = arrayType;
|
||||
public ArrayType( AnyType arrayType, @Nonnull TypeManager manager, int componentClassIndex, WasmOptions options ) {
|
||||
this( getJavaClassName( arrayType ), StructTypeKind.array, manager, arrayType );
|
||||
this.componentClassIndex = componentClassIndex;
|
||||
if( options.useGC() ) {
|
||||
String nativeName = '_' + getName();
|
||||
this.nativeArrayType = new ArrayType( nativeName, StructTypeKind.array_native, manager, arrayType );
|
||||
//structTypes.put( name, nativeArrayType );
|
||||
} else {
|
||||
this.nativeArrayType = arrayType;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new instance
|
||||
*
|
||||
* @param name
|
||||
* the type name
|
||||
* @param kind
|
||||
* the kind, array or array_native
|
||||
* @param manager
|
||||
* the manager which hold all StructTypes
|
||||
* @param arrayType
|
||||
* the type of the array
|
||||
*/
|
||||
private ArrayType( @Nonnull String name, @Nonnull StructTypeKind kind, @Nonnull TypeManager manager, AnyType arrayType ) {
|
||||
super( name, kind, manager );
|
||||
this.arrayType = arrayType;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -57,6 +85,7 @@ public class ArrayType extends StructType {
|
||||
* the type of the array
|
||||
* @return the name
|
||||
*/
|
||||
@Nonnull
|
||||
private static String getJavaClassName( AnyType arrayType ) {
|
||||
if( !arrayType.isRefType() ) {
|
||||
switch( (ValueType)arrayType ) {
|
||||
@ -97,6 +126,10 @@ public class ArrayType extends StructType {
|
||||
return arrayType;
|
||||
}
|
||||
|
||||
public AnyType getNativeArrayType() {
|
||||
return nativeArrayType;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user