mirror of
https://github.com/i-net-software/JWebAssembly.git
synced 2025-03-15 10:44:47 +01:00
Rename StorageType to AnyType.
This commit is contained in:
parent
522f25c326
commit
1376af2f3f
@ -37,7 +37,7 @@ import de.inetsoftware.jwebassembly.module.ValueTypeConvertion;
|
||||
import de.inetsoftware.jwebassembly.wasm.ArrayOperator;
|
||||
import de.inetsoftware.jwebassembly.wasm.NamedStorageType;
|
||||
import de.inetsoftware.jwebassembly.wasm.NumericOperator;
|
||||
import de.inetsoftware.jwebassembly.wasm.StorageType;
|
||||
import de.inetsoftware.jwebassembly.wasm.AnyType;
|
||||
import de.inetsoftware.jwebassembly.wasm.StructOperator;
|
||||
import de.inetsoftware.jwebassembly.wasm.ValueType;
|
||||
import de.inetsoftware.jwebassembly.wasm.WasmBlockOperator;
|
||||
@ -63,7 +63,7 @@ public class BinaryModuleWriter extends ModuleWriter implements InstructionOpcod
|
||||
|
||||
private Map<String, Function> functions = new LinkedHashMap<>();
|
||||
|
||||
private List<StorageType> locals = new ArrayList<>();
|
||||
private List<AnyType> locals = new ArrayList<>();
|
||||
|
||||
private Map<String, Global> globals = new LinkedHashMap<>();
|
||||
|
||||
@ -287,7 +287,7 @@ public class BinaryModuleWriter extends ModuleWriter implements InstructionOpcod
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected void writeMethodParam( String kind, StorageType valueType, @Nullable String name ) throws IOException {
|
||||
protected void writeMethodParam( String kind, AnyType valueType, @Nullable String name ) throws IOException {
|
||||
switch( kind ) {
|
||||
case "param":
|
||||
functionType.params.add( valueType );
|
||||
@ -327,7 +327,7 @@ public class BinaryModuleWriter extends ModuleWriter implements InstructionOpcod
|
||||
protected void writeMethodFinish() throws IOException {
|
||||
WasmOutputStream localsStream = new WasmOutputStream();
|
||||
localsStream.writeVaruint32( locals.size() );
|
||||
for( StorageType valueType : locals ) {
|
||||
for( AnyType valueType : locals ) {
|
||||
localsStream.writeVaruint32( 1 ); // TODO optimize, write the count of same types.
|
||||
localsStream.writeValueType( valueType );
|
||||
}
|
||||
@ -812,7 +812,7 @@ public class BinaryModuleWriter extends ModuleWriter implements InstructionOpcod
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected void writeArrayOperator( @Nonnull ArrayOperator op, StorageType type ) throws IOException {
|
||||
protected void writeArrayOperator( @Nonnull ArrayOperator op, AnyType type ) throws IOException {
|
||||
int opCode;
|
||||
switch(op) {
|
||||
case NEW:
|
||||
@ -838,7 +838,7 @@ public class BinaryModuleWriter extends ModuleWriter implements InstructionOpcod
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected void writeStructOperator( StructOperator op, StorageType type, String fieldName ) throws IOException {
|
||||
protected void writeStructOperator( StructOperator op, AnyType type, String fieldName ) throws IOException {
|
||||
int opCode;
|
||||
switch(op) {
|
||||
case NEW:
|
||||
|
@ -19,7 +19,7 @@ import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import de.inetsoftware.jwebassembly.wasm.StorageType;
|
||||
import de.inetsoftware.jwebassembly.wasm.AnyType;
|
||||
import de.inetsoftware.jwebassembly.wasm.ValueType;
|
||||
|
||||
/**
|
||||
@ -29,9 +29,9 @@ import de.inetsoftware.jwebassembly.wasm.ValueType;
|
||||
*/
|
||||
class FunctionTypeEntry extends TypeEntry {
|
||||
|
||||
final List<StorageType> params = new ArrayList<>();
|
||||
final List<AnyType> params = new ArrayList<>();
|
||||
|
||||
final List<StorageType> results = new ArrayList<>();
|
||||
final List<AnyType> results = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
@ -47,11 +47,11 @@ class FunctionTypeEntry extends TypeEntry {
|
||||
@Override
|
||||
void writeSectionEntryDetails( WasmOutputStream stream ) throws IOException {
|
||||
stream.writeVaruint32( this.params.size() );
|
||||
for( StorageType valueType : this.params ) {
|
||||
for( AnyType valueType : this.params ) {
|
||||
stream.writeValueType( valueType );
|
||||
}
|
||||
stream.writeVaruint32( this.results.size() );
|
||||
for( StorageType valueType : this.results ) {
|
||||
for( AnyType valueType : this.results ) {
|
||||
stream.writeValueType( valueType );
|
||||
}
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ import java.nio.charset.StandardCharsets;
|
||||
import javax.annotation.Nonnegative;
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import de.inetsoftware.jwebassembly.wasm.StorageType;
|
||||
import de.inetsoftware.jwebassembly.wasm.AnyType;
|
||||
import de.inetsoftware.jwebassembly.wasm.ValueType;
|
||||
|
||||
/**
|
||||
@ -72,7 +72,7 @@ class WasmOutputStream extends FilterOutputStream {
|
||||
* @throws IOException
|
||||
* if an I/O error occurs.
|
||||
*/
|
||||
public void writeValueType( StorageType type ) throws IOException {
|
||||
public void writeValueType( AnyType type ) throws IOException {
|
||||
writeVarint( type.getCode() );
|
||||
}
|
||||
|
||||
|
@ -28,7 +28,7 @@ import de.inetsoftware.classparser.ConstantRef;
|
||||
import de.inetsoftware.jwebassembly.WasmException;
|
||||
import de.inetsoftware.jwebassembly.wasm.ArrayOperator;
|
||||
import de.inetsoftware.jwebassembly.wasm.NumericOperator;
|
||||
import de.inetsoftware.jwebassembly.wasm.StorageType;
|
||||
import de.inetsoftware.jwebassembly.wasm.AnyType;
|
||||
import de.inetsoftware.jwebassembly.wasm.StructOperator;
|
||||
import de.inetsoftware.jwebassembly.wasm.ValueType;
|
||||
import de.inetsoftware.jwebassembly.wasm.WasmBlockOperator;
|
||||
@ -186,7 +186,7 @@ class JavaMethodWasmCodeBuilder extends WasmCodeBuilder {
|
||||
addArrayInstruction( ArrayOperator.GET, ValueType.f64, codePos );
|
||||
break;
|
||||
case 50: // aaload
|
||||
StorageType storeType = findPreviousPushInstructionPushValueType();
|
||||
AnyType storeType = findPreviousPushInstructionPushValueType();
|
||||
addArrayInstruction( ArrayOperator.GET, storeType, codePos );
|
||||
break;
|
||||
case 51: // baload
|
||||
|
@ -37,7 +37,7 @@ import de.inetsoftware.jwebassembly.JWebAssembly;
|
||||
import de.inetsoftware.jwebassembly.WasmException;
|
||||
import de.inetsoftware.jwebassembly.module.TypeManager.StructType;
|
||||
import de.inetsoftware.jwebassembly.wasm.NamedStorageType;
|
||||
import de.inetsoftware.jwebassembly.wasm.StorageType;
|
||||
import de.inetsoftware.jwebassembly.wasm.AnyType;
|
||||
import de.inetsoftware.jwebassembly.wasm.ValueType;
|
||||
import de.inetsoftware.jwebassembly.wasm.ValueTypeParser;
|
||||
import de.inetsoftware.jwebassembly.watparser.WatParser;
|
||||
@ -179,7 +179,7 @@ public class ModuleGenerator {
|
||||
if( field.isStatic() ) {
|
||||
continue;
|
||||
}
|
||||
StorageType fieldtype = new ValueTypeParser( field.getType(), types ).next();
|
||||
AnyType fieldtype = new ValueTypeParser( field.getType(), types ).next();
|
||||
list.add( new NamedStorageType( fieldtype, field.getName() ) );
|
||||
}
|
||||
int id = writer.writeStruct( className, list );
|
||||
@ -355,7 +355,7 @@ public class ModuleGenerator {
|
||||
writer.writeMethodParam( "param", ValueType.anyref, "this" );
|
||||
}
|
||||
ValueTypeParser parser = new ValueTypeParser( signature );
|
||||
StorageType type;
|
||||
AnyType type;
|
||||
for( String kind : new String[] {"param","result"}) {
|
||||
while( (type = parser.next()) != null ) {
|
||||
String paramName = null;
|
||||
|
@ -26,7 +26,7 @@ import de.inetsoftware.classparser.Member;
|
||||
import de.inetsoftware.jwebassembly.wasm.ArrayOperator;
|
||||
import de.inetsoftware.jwebassembly.wasm.NamedStorageType;
|
||||
import de.inetsoftware.jwebassembly.wasm.NumericOperator;
|
||||
import de.inetsoftware.jwebassembly.wasm.StorageType;
|
||||
import de.inetsoftware.jwebassembly.wasm.AnyType;
|
||||
import de.inetsoftware.jwebassembly.wasm.StructOperator;
|
||||
import de.inetsoftware.jwebassembly.wasm.ValueType;
|
||||
import de.inetsoftware.jwebassembly.wasm.WasmBlockOperator;
|
||||
@ -107,7 +107,7 @@ public abstract class ModuleWriter implements Closeable {
|
||||
* @throws IOException
|
||||
* if any I/O error occur
|
||||
*/
|
||||
protected abstract void writeMethodParam( String kind, StorageType valueType, @Nullable String name ) throws IOException;
|
||||
protected abstract void writeMethodParam( String kind, AnyType valueType, @Nullable String name ) throws IOException;
|
||||
|
||||
/**
|
||||
* Finish the function parameter.
|
||||
@ -227,7 +227,7 @@ public abstract class ModuleWriter implements Closeable {
|
||||
* @throws IOException
|
||||
* if any I/O error occur
|
||||
*/
|
||||
protected abstract void writeArrayOperator( @Nonnull ArrayOperator op, StorageType type ) throws IOException;
|
||||
protected abstract void writeArrayOperator( @Nonnull ArrayOperator op, AnyType type ) throws IOException;
|
||||
|
||||
/**
|
||||
* Write a struct operation
|
||||
@ -240,5 +240,5 @@ public abstract class ModuleWriter implements Closeable {
|
||||
* @throws IOException
|
||||
* if any I/O error occur
|
||||
*/
|
||||
protected abstract void writeStructOperator( StructOperator op, StorageType type, String fieldName ) throws IOException;
|
||||
protected abstract void writeStructOperator( StructOperator op, AnyType type, String fieldName ) throws IOException;
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ import java.util.Map;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import de.inetsoftware.jwebassembly.wasm.StorageType;
|
||||
import de.inetsoftware.jwebassembly.wasm.AnyType;
|
||||
|
||||
/**
|
||||
* Manage the written and to write types (classes)
|
||||
@ -76,7 +76,7 @@ public class TypeManager {
|
||||
*
|
||||
* @author Volker Berlin
|
||||
*/
|
||||
static class StructType implements StorageType {
|
||||
static class StructType implements AnyType {
|
||||
|
||||
private final String name;
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright 2018 Volker Berlin (i-net software)
|
||||
Copyright 2018 - 2019 Volker Berlin (i-net software)
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
@ -22,9 +22,8 @@ import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import de.inetsoftware.jwebassembly.WasmException;
|
||||
import de.inetsoftware.jwebassembly.module.WasmInstruction.Type;
|
||||
import de.inetsoftware.jwebassembly.wasm.ArrayOperator;
|
||||
import de.inetsoftware.jwebassembly.wasm.StorageType;
|
||||
import de.inetsoftware.jwebassembly.wasm.AnyType;
|
||||
import de.inetsoftware.jwebassembly.wasm.ValueType;
|
||||
|
||||
/**
|
||||
@ -37,7 +36,7 @@ class WasmArrayInstruction extends WasmInstruction {
|
||||
|
||||
private final ArrayOperator op;
|
||||
|
||||
private final StorageType type;
|
||||
private final AnyType type;
|
||||
|
||||
/**
|
||||
* Create an instance of an array operation.
|
||||
@ -49,7 +48,7 @@ class WasmArrayInstruction extends WasmInstruction {
|
||||
* @param javaCodePos
|
||||
* the code position/offset in the Java method
|
||||
*/
|
||||
WasmArrayInstruction( @Nullable ArrayOperator op, @Nullable StorageType type, int javaCodePos ) {
|
||||
WasmArrayInstruction( @Nullable ArrayOperator op, @Nullable AnyType type, int javaCodePos ) {
|
||||
super( javaCodePos );
|
||||
this.op = op;
|
||||
this.type = type;
|
||||
|
@ -25,7 +25,7 @@ import javax.annotation.Nullable;
|
||||
import de.inetsoftware.classparser.Member;
|
||||
import de.inetsoftware.jwebassembly.wasm.ArrayOperator;
|
||||
import de.inetsoftware.jwebassembly.wasm.NumericOperator;
|
||||
import de.inetsoftware.jwebassembly.wasm.StorageType;
|
||||
import de.inetsoftware.jwebassembly.wasm.AnyType;
|
||||
import de.inetsoftware.jwebassembly.wasm.StructOperator;
|
||||
import de.inetsoftware.jwebassembly.wasm.ValueType;
|
||||
import de.inetsoftware.jwebassembly.wasm.WasmBlockOperator;
|
||||
@ -222,7 +222,7 @@ public abstract class WasmCodeBuilder {
|
||||
* @param javaCodePos
|
||||
* the code position/offset in the Java method
|
||||
*/
|
||||
protected void addArrayInstruction( ArrayOperator op, StorageType type, int javaCodePos ) {
|
||||
protected void addArrayInstruction( ArrayOperator op, AnyType type, int javaCodePos ) {
|
||||
instructions.add( new WasmArrayInstruction( op, type, javaCodePos ) );
|
||||
}
|
||||
|
||||
|
@ -23,7 +23,7 @@ import javax.annotation.Nullable;
|
||||
|
||||
import de.inetsoftware.jwebassembly.WasmException;
|
||||
import de.inetsoftware.jwebassembly.module.TypeManager.StructType;
|
||||
import de.inetsoftware.jwebassembly.wasm.StorageType;
|
||||
import de.inetsoftware.jwebassembly.wasm.AnyType;
|
||||
import de.inetsoftware.jwebassembly.wasm.StructOperator;
|
||||
import de.inetsoftware.jwebassembly.wasm.ValueType;
|
||||
|
||||
@ -39,7 +39,7 @@ class WasmStructInstruction extends WasmInstruction {
|
||||
|
||||
private final String typeName;
|
||||
|
||||
private StorageType type;
|
||||
private AnyType type;
|
||||
|
||||
private final String fieldName;
|
||||
|
||||
|
@ -31,7 +31,7 @@ import de.inetsoftware.jwebassembly.module.ValueTypeConvertion;
|
||||
import de.inetsoftware.jwebassembly.wasm.ArrayOperator;
|
||||
import de.inetsoftware.jwebassembly.wasm.NamedStorageType;
|
||||
import de.inetsoftware.jwebassembly.wasm.NumericOperator;
|
||||
import de.inetsoftware.jwebassembly.wasm.StorageType;
|
||||
import de.inetsoftware.jwebassembly.wasm.AnyType;
|
||||
import de.inetsoftware.jwebassembly.wasm.StructOperator;
|
||||
import de.inetsoftware.jwebassembly.wasm.ValueType;
|
||||
import de.inetsoftware.jwebassembly.wasm.WasmBlockOperator;
|
||||
@ -101,7 +101,7 @@ public class TextModuleWriter extends ModuleWriter {
|
||||
output.append( " $" ).append( field.name );
|
||||
}
|
||||
output.append( " (mut " );
|
||||
StorageType type = field.type;
|
||||
AnyType type = field.type;
|
||||
if( type.getCode() < 0 ) {
|
||||
output.append( type.toString() );
|
||||
} else {
|
||||
@ -152,7 +152,7 @@ public class TextModuleWriter extends ModuleWriter {
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected void writeMethodParam( String kind, StorageType valueType, @Nullable String name ) throws IOException {
|
||||
protected void writeMethodParam( String kind, AnyType valueType, @Nullable String name ) throws IOException {
|
||||
methodOutput.append( " (" ).append( kind );
|
||||
if( debugNames && name != null ) {
|
||||
methodOutput.append( " $" ).append( name );
|
||||
@ -423,7 +423,7 @@ public class TextModuleWriter extends ModuleWriter {
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected void writeArrayOperator( @Nonnull ArrayOperator op, StorageType type ) throws IOException {
|
||||
protected void writeArrayOperator( @Nonnull ArrayOperator op, AnyType type ) throws IOException {
|
||||
String operation;
|
||||
switch( op ) {
|
||||
case NEW:
|
||||
@ -449,7 +449,7 @@ public class TextModuleWriter extends ModuleWriter {
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected void writeStructOperator( StructOperator op, StorageType type, String fieldName ) throws IOException {
|
||||
protected void writeStructOperator( StructOperator op, AnyType type, String fieldName ) throws IOException {
|
||||
String operation;
|
||||
switch( op ) {
|
||||
case NEW:
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2018 Volker Berlin (i-net software)
|
||||
* Copyright 2018 - 2019 Volker Berlin (i-net software)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -16,20 +16,22 @@
|
||||
package de.inetsoftware.jwebassembly.wasm;
|
||||
|
||||
/**
|
||||
* Interface of all possible types in WebAssembly. This are predefined (native) types and custom types in the type section.
|
||||
* <pre><code>
|
||||
* numtype ::= i32 | i64 | f32 | f64
|
||||
* packedtype ::= i8 | i16
|
||||
* reftype ::= anyref | anyfunc | nullref
|
||||
* valtype ::= numtype | reftype
|
||||
* deftype ::= functype | structtype | arraytype
|
||||
*
|
||||
* storagetype ::= valtype | packedtype
|
||||
* </code></pre>
|
||||
* @author Volker Berlin
|
||||
*/
|
||||
public interface StorageType {
|
||||
public interface AnyType {
|
||||
|
||||
/**
|
||||
* The operation code in WebAssembly.
|
||||
* The type code(typeidx) in WebAssembly. Predefined types have an negative typeidx. Custom types have the positive index in the type section.
|
||||
*
|
||||
* @return the code
|
||||
*/
|
@ -22,7 +22,7 @@ package de.inetsoftware.jwebassembly.wasm;
|
||||
*/
|
||||
public class NamedStorageType {
|
||||
|
||||
public final StorageType type;
|
||||
public final AnyType type;
|
||||
|
||||
public final String name;
|
||||
|
||||
@ -31,7 +31,7 @@ public class NamedStorageType {
|
||||
* @param type the type
|
||||
* @param name the name
|
||||
*/
|
||||
public NamedStorageType( StorageType type, String name ) {
|
||||
public NamedStorageType( AnyType type, String name ) {
|
||||
this.type = type;
|
||||
this.name = name;
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ package de.inetsoftware.jwebassembly.wasm;
|
||||
/**
|
||||
* @author Volker Berlin
|
||||
*/
|
||||
public enum ValueType implements StorageType {
|
||||
public enum ValueType implements AnyType {
|
||||
i32(-0x01),
|
||||
i64(-0x02),
|
||||
f32(-0x03),
|
||||
|
@ -61,7 +61,7 @@ public class ValueTypeParser {
|
||||
*
|
||||
* @return next type or null
|
||||
*/
|
||||
public StorageType next() {
|
||||
public AnyType next() {
|
||||
if( idx >= sig.length() ) {
|
||||
return null;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user