mirror of
https://github.com/i-net-software/JWebAssembly.git
synced 2025-03-15 10:44:47 +01:00
experimental code for structs
This commit is contained in:
parent
6f64f957b2
commit
c6800a895b
@ -37,6 +37,7 @@ import de.inetsoftware.jwebassembly.module.ValueTypeConvertion;
|
||||
import de.inetsoftware.jwebassembly.wasm.ArrayOperator;
|
||||
import de.inetsoftware.jwebassembly.wasm.NumericOperator;
|
||||
import de.inetsoftware.jwebassembly.wasm.StorageType;
|
||||
import de.inetsoftware.jwebassembly.wasm.StructOperator;
|
||||
import de.inetsoftware.jwebassembly.wasm.ValueType;
|
||||
import de.inetsoftware.jwebassembly.wasm.WasmBlockOperator;
|
||||
|
||||
@ -806,4 +807,28 @@ public class BinaryModuleWriter extends ModuleWriter implements InstructionOpcod
|
||||
codeStream.writeOpCode( opCode );
|
||||
codeStream.writeValueType( type );
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected void writeStructOperator( StructOperator op, StorageType type ) throws IOException {
|
||||
int opCode;
|
||||
switch(op) {
|
||||
case NEW:
|
||||
case NEW_DEFAULT:
|
||||
opCode = STRUCT_NEW;
|
||||
break;
|
||||
case GET:
|
||||
opCode = STRUCT_GET;
|
||||
break;
|
||||
case SET:
|
||||
opCode = STRUCT_SET;
|
||||
break;
|
||||
default:
|
||||
throw new Error( "Unknown operator: " + op );
|
||||
}
|
||||
codeStream.writeOpCode( opCode );
|
||||
codeStream.writeValueType( type );
|
||||
}
|
||||
}
|
||||
|
@ -22,11 +22,14 @@ import javax.annotation.Nonnull;
|
||||
|
||||
import de.inetsoftware.classparser.Code;
|
||||
import de.inetsoftware.classparser.CodeInputStream;
|
||||
import de.inetsoftware.classparser.ConstantClass;
|
||||
import de.inetsoftware.classparser.ConstantPool;
|
||||
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.StructOperator;
|
||||
import de.inetsoftware.jwebassembly.wasm.ValueType;
|
||||
import de.inetsoftware.jwebassembly.wasm.WasmBlockOperator;
|
||||
|
||||
@ -534,7 +537,11 @@ class JavaMethodWasmCodeBuilder extends WasmCodeBuilder {
|
||||
break;
|
||||
//TODO case 185: // invokeinterface
|
||||
//TODO case 186: // invokedynamic
|
||||
//TODO case 187: // new
|
||||
case 187: // new
|
||||
String name = ((ConstantClass)constantPool.get( byteCode.readUnsignedShort() )).getName();
|
||||
StorageType storageType = ValueType.anyref;
|
||||
addStructInstruction( StructOperator.NEW_DEFAULT, storageType, codePos );
|
||||
break;
|
||||
case 188: // newarray
|
||||
int typeValue = byteCode.readByte();
|
||||
switch( typeValue ) {
|
||||
|
@ -25,6 +25,7 @@ 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.StructOperator;
|
||||
import de.inetsoftware.jwebassembly.wasm.ValueType;
|
||||
import de.inetsoftware.jwebassembly.wasm.WasmBlockOperator;
|
||||
|
||||
@ -220,4 +221,16 @@ public abstract class ModuleWriter implements Closeable {
|
||||
* if any I/O error occur
|
||||
*/
|
||||
protected abstract void writeArrayOperator( @Nonnull ArrayOperator op, StorageType type ) throws IOException;
|
||||
|
||||
/**
|
||||
* Write a struct operation
|
||||
*
|
||||
* @param op
|
||||
* the operation
|
||||
* @param type
|
||||
* the type of the struct
|
||||
* @throws IOException
|
||||
* if any I/O error occur
|
||||
*/
|
||||
protected abstract void writeStructOperator( StructOperator op, StorageType type ) throws IOException;
|
||||
}
|
||||
|
@ -25,6 +25,8 @@ 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.StructOperator;
|
||||
import de.inetsoftware.jwebassembly.wasm.ValueType;
|
||||
import de.inetsoftware.jwebassembly.wasm.WasmBlockOperator;
|
||||
|
||||
@ -220,7 +222,21 @@ public abstract class WasmCodeBuilder {
|
||||
* @param javaCodePos
|
||||
* the code position/offset in the Java method
|
||||
*/
|
||||
protected void addArrayInstruction( ArrayOperator op, ValueType type, int javaCodePos ) {
|
||||
protected void addArrayInstruction( ArrayOperator op, StorageType type, int javaCodePos ) {
|
||||
instructions.add( new WasmArrayInstruction( op, type, javaCodePos ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an array operation to the instruction list as marker on the code position.
|
||||
*
|
||||
* @param op
|
||||
* the operation
|
||||
* @param type
|
||||
* the array type
|
||||
* @param javaCodePos
|
||||
* the code position/offset in the Java method
|
||||
*/
|
||||
protected void addStructInstruction( StructOperator op, StorageType type, int javaCodePos ) {
|
||||
instructions.add( new WasmStructInstruction( op, type, javaCodePos ) );
|
||||
}
|
||||
}
|
||||
|
@ -30,6 +30,7 @@ import de.inetsoftware.jwebassembly.module.ValueTypeConvertion;
|
||||
import de.inetsoftware.jwebassembly.wasm.ArrayOperator;
|
||||
import de.inetsoftware.jwebassembly.wasm.NumericOperator;
|
||||
import de.inetsoftware.jwebassembly.wasm.StorageType;
|
||||
import de.inetsoftware.jwebassembly.wasm.StructOperator;
|
||||
import de.inetsoftware.jwebassembly.wasm.ValueType;
|
||||
import de.inetsoftware.jwebassembly.wasm.WasmBlockOperator;
|
||||
|
||||
@ -365,6 +366,9 @@ public class TextModuleWriter extends ModuleWriter {
|
||||
inset += insetAfter;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected void writeArrayOperator( @Nonnull ArrayOperator op, StorageType type ) throws IOException {
|
||||
String operation;
|
||||
@ -387,4 +391,30 @@ public class TextModuleWriter extends ModuleWriter {
|
||||
newline( methodOutput );
|
||||
methodOutput.append( "array." ).append( operation ).append( ' ' ).append( type );
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected void writeStructOperator( StructOperator op, StorageType type ) throws IOException {
|
||||
String operation;
|
||||
switch( op ) {
|
||||
case NEW:
|
||||
operation = "new";
|
||||
break;
|
||||
case NEW_DEFAULT:
|
||||
operation = "new_default";
|
||||
break;
|
||||
case GET:
|
||||
operation = "get";
|
||||
break;
|
||||
case SET:
|
||||
operation = "set";
|
||||
break;
|
||||
default:
|
||||
throw new Error( "Unknown operator: " + op );
|
||||
}
|
||||
newline( methodOutput );
|
||||
methodOutput.append( "struct." ).append( operation ).append( ' ' ).append( type );
|
||||
}
|
||||
}
|
||||
|
29
src/de/inetsoftware/jwebassembly/wasm/StructOperator.java
Normal file
29
src/de/inetsoftware/jwebassembly/wasm/StructOperator.java
Normal file
@ -0,0 +1,29 @@
|
||||
/*
|
||||
Copyright 2018 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.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
*/
|
||||
package de.inetsoftware.jwebassembly.wasm;
|
||||
|
||||
/**
|
||||
* Operation on Arrays.
|
||||
*
|
||||
* @author Volker Berlin
|
||||
*/
|
||||
public enum StructOperator {
|
||||
NEW,
|
||||
NEW_DEFAULT,
|
||||
GET,
|
||||
SET,
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user