Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ testing {
suites {
val integrationTest by
registering(JvmTestSuite::class) {
testType.set(TestSuiteType.INTEGRATION_TEST)
dependencies {
implementation(project())
implementation(libs.apacheCommonsLang)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ public enum Opcode {
REF_FUNC((byte) 0xD2),
REF_AS_NON_NULL((byte) 0xD3),
BR_ON_NULL((byte) 0xD4),
// RESERVED((byte) 0xD5),
REF_EQ((byte) 0xD5),
BR_ON_NON_NULL((byte) 0xD6),
// RESERVED((byte) 0xD7),
// RESERVED((byte) 0xD8),
Expand Down Expand Up @@ -257,6 +257,54 @@ public enum Opcode {
// RESERVED((byte) 0xF9),
// RESERVED((byte) 0xFA),
// RESERVED((byte) 0xFB),
// FB Extensions (GC Spec)
STRUCT_NEW_CANON(new byte[]{(byte) 0xFB, (byte) 0x01}),
STRUCT_NEW_CANON_DEFAULT(new byte[]{(byte) 0xFB, (byte) 0x02}),
STRUCT_GET(new byte[]{(byte) 0xFB, (byte) 0x03}),
STRUCT_GET_S(new byte[]{(byte) 0xFB, (byte) 0x04}),
STRUCT_GET_U(new byte[]{(byte) 0xFB, (byte) 0x05}),
STRUCT_SET(new byte[]{(byte) 0xFB, (byte) 0x06}),
// RESERVED(new byte[]{(byte) 0xFB, (byte) 0x07}),
// RESERVED(new byte[]{(byte) 0xFB, (byte) 0x08}),
// RESERVED(new byte[]{(byte) 0xFB, (byte) 0x09}),
// RESERVED(new byte[]{(byte) 0xFB, (byte) 0x0A}),
// RESERVED(new byte[]{(byte) 0xFB, (byte) 0x0B}),
// RESERVED(new byte[]{(byte) 0xFB, (byte) 0x0C}),
// RESERVED(new byte[]{(byte) 0xFB, (byte) 0x0D}),
// RESERVED(new byte[]{(byte) 0xFB, (byte) 0x0E}),
// RESERVED(new byte[]{(byte) 0xFB, (byte) 0x0F}),
// RESERVED(new byte[]{(byte) 0xFB, (byte) 0x10}),
ARRAY_NEW_CANON(new byte[]{(byte) 0xFB, (byte) 0x11}),
ARRAY_NEW_CANON_DEFAULT(new byte[]{(byte) 0xFB, (byte) 0x12}),
ARRAY_GET(new byte[]{(byte) 0xFB, (byte) 0x13}),
ARRAY_GET_S(new byte[]{(byte) 0xFB, (byte) 0x14}),
ARRAY_GET_U(new byte[]{(byte) 0xFB, (byte) 0x15}),
ARRAY_SET(new byte[]{(byte) 0xFB, (byte) 0x16}),
ARRAY_LEN(new byte[]{(byte) 0xFB, (byte) 0x17}),
// RESERVED(new byte[]{(byte) 0xFB, (byte) 0x18}),
ARRAY_NEW_CANON_FIXED(new byte[]{(byte) 0xFB, (byte) 0x19}),
// RESERVED(new byte[]{(byte) 0xFB, (byte) 0x1A}),
ARRAY_NEW_CANON_DATA(new byte[]{(byte) 0xFB, (byte) 0x1B}),
ARRAY_NEW_CANON_ELEM(new byte[]{(byte) 0xFB, (byte) 0x1C}),
// RESERVED(new byte[]{(byte) 0xFB, (byte) 0x1D}),
// RESERVED(new byte[]{(byte) 0xFB, (byte) 0x1E}),
// RESERVED(new byte[]{(byte) 0xFB, (byte) 0x1F}),
I31_NEW(new byte[]{(byte) 0xFB, (byte) 0x20}),
I31_GET_S(new byte[]{(byte) 0xFB, (byte) 0x21}),
I31_GET_U(new byte[]{(byte) 0xFB, (byte) 0x22}),
// 0xFB23 .. 0xFB3F reserved
REF_TEST(new byte[]{(byte) 0xFB, (byte) 0x40}),
REF_CAST(new byte[]{(byte) 0xFB, (byte) 0x41}),
BR_ON_CAST(new byte[]{(byte) 0xFB, (byte) 0x42}),
BR_ON_CAST_FAIL(new byte[]{(byte) 0xFB, (byte) 0x43}),
// 0xFB44 .. 0xFB47 reserved
REF_TEST_NULL(new byte[]{(byte) 0xFB, (byte) 0x48}),
REF_CAST_NULL(new byte[]{(byte) 0xFB, (byte) 0x49}),
BR_ON_CAST_NULL(new byte[]{(byte) 0xFB, (byte) 0x4A}),
BR_ON_CAST_FAIL_NULL(new byte[]{(byte) 0xFB, (byte) 0x4B}),
// 0xFB4C .. 0xFB6F reserved
EXTERN_INTERNALIZE(new byte[]{(byte) 0xFB, (byte) 0x70}),
EXTERN_EXTERNALIZE(new byte[]{(byte) 0xFB, (byte) 0x71}),
// FC Extensions
I32_TRUNC_SAT_F32_S(new byte[]{(byte) 0xFC, (byte) 0x00}),
I32_TRUNC_SAT_F32_U(new byte[]{(byte) 0xFC, (byte) 0x01}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,29 @@ public enum TypeOpcode {
F32((byte) 0x7D),
F64((byte) 0x7C),
V128((byte) 0x7B),
// 0x7A .. 0x71 reserved
I8((byte) 0x7A),
I16((byte) 0x79),
// 0x78 .. 0x77 reserved
HEAP_FUNC((byte) 0x70),
HEAP_EXTERN((byte) 0x6F),
// 0x6E .. 0x6D reserved
ANY((byte) 0x6E),
EQ((byte) 0x6D),
REF_NULLABLE((byte) 0x6C),
REF((byte) 0x6B),
// 0x6A .. 0x61 reserved
I31((byte) 0x6A),
NOFUNC((byte) 0x69),
NOEXTERN((byte) 0x68),
STRUCT((byte) 0x67),
ARRAY((byte) 0x66),
NONE((byte) 0x65),
// 0x64 .. 0x5F reserved
FUNC((byte) 0x60),
// 0x5F .. 0x41 reserved
STRUCT_FIELDS((byte) 0x5F),
ARRAY_FIELDS((byte) 0x5E),
// 0x5D .. 0x51 reserved
SUB((byte) 0x50),
REC((byte) 0x4F),
SUB_FINAL((byte) 0x4E),
// Apparently unused
// RESULT((byte) 0x40)
;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,46 @@ public void visitHeapExtern(HeapExternType heapExtern) throws IOException {
output.write(TypeOpcode.HEAP_EXTERN.opcode());
}

@Override
public void visitAnyType(AnyType any) throws IOException {
output.write(TypeOpcode.ANY.opcode());
}

@Override
public void visitNoneType(NoneType none) throws IOException {
output.write(TypeOpcode.NONE.opcode());
}

@Override
public void visitNoExternType(NoExternType noExtern) throws IOException {
output.write(TypeOpcode.NOEXTERN.opcode());
}

@Override
public void visitNoFuncType(NoFuncType noFunc) throws IOException {
output.write(TypeOpcode.NOFUNC.opcode());
}

@Override
public void visitEqType(EqType eq) throws IOException {
output.write(TypeOpcode.EQ.opcode());
}

@Override
public void visitStructType(StructType struct) throws IOException {
output.write(TypeOpcode.STRUCT.opcode());
}

@Override
public void visitArrayType(ArrayType array) throws IOException {
output.write(TypeOpcode.ARRAY.opcode());
}

@Override
public void visitI31Type(I31Type i31) throws IOException {
output.write(TypeOpcode.I31.opcode());
}

@Override
public void visitLimits(Limits limits) throws IOException {
if (limits.max() == null) {
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/com/opencastsoftware/wasm4j/types/AnyType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* SPDX-FileCopyrightText: Copyright 2023 Opencast Software Europe Ltd
* SPDX-License-Identifier: Apache-2.0
*/
package com.opencastsoftware.wasm4j.types;

public enum AnyType implements HeapType {
INSTANCE;

@Override
public <T extends Exception> void accept(WasmTypeVisitor<T> visitor) throws T {
visitor.visitAnyType(this);
}
}
14 changes: 14 additions & 0 deletions src/main/java/com/opencastsoftware/wasm4j/types/ArrayType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* SPDX-FileCopyrightText: Copyright 2023 Opencast Software Europe Ltd
* SPDX-License-Identifier: Apache-2.0
*/
package com.opencastsoftware.wasm4j.types;

public enum ArrayType implements HeapType {
INSTANCE;

@Override
public <T extends Exception> void accept(WasmTypeVisitor<T> visitor) throws T {
visitor.visitArrayType(this);
}
}
14 changes: 14 additions & 0 deletions src/main/java/com/opencastsoftware/wasm4j/types/EqType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* SPDX-FileCopyrightText: Copyright 2023 Opencast Software Europe Ltd
* SPDX-License-Identifier: Apache-2.0
*/
package com.opencastsoftware.wasm4j.types;

public enum EqType implements HeapType {
INSTANCE;

@Override
public <T extends Exception> void accept(WasmTypeVisitor<T> visitor) throws T {
visitor.visitEqType(this);
}
}
33 changes: 33 additions & 0 deletions src/main/java/com/opencastsoftware/wasm4j/types/HeapType.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/
package com.opencastsoftware.wasm4j.types;


public interface HeapType extends WasmType {
static HeapFuncType func() {
return HeapFuncType.INSTANCE;
Expand All @@ -13,6 +14,38 @@ static HeapExternType extern() {
return HeapExternType.INSTANCE;
}

static AnyType any() {
return AnyType.INSTANCE;
}

static NoneType none() {
return NoneType.INSTANCE;
}

static NoExternType noExtern() {
return NoExternType.INSTANCE;
}

static NoFuncType noFunc() {
return NoFuncType.INSTANCE;
}

static EqType eq() {
return EqType.INSTANCE;
}

static StructType struct() {
return StructType.INSTANCE;
}

static ArrayType array() {
return ArrayType.INSTANCE;
}

static I31Type i31() {
return I31Type.INSTANCE;
}

static TypeId typeId(int typeIndex) {
return new TypeId(typeIndex);
}
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/com/opencastsoftware/wasm4j/types/I31Type.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* SPDX-FileCopyrightText: Copyright 2023 Opencast Software Europe Ltd
* SPDX-License-Identifier: Apache-2.0
*/
package com.opencastsoftware.wasm4j.types;

public enum I31Type implements HeapType {
INSTANCE;

@Override
public <T extends Exception> void accept(WasmTypeVisitor<T> visitor) throws T {
visitor.visitI31Type(this);
}
}
14 changes: 14 additions & 0 deletions src/main/java/com/opencastsoftware/wasm4j/types/NoExternType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* SPDX-FileCopyrightText: Copyright 2023 Opencast Software Europe Ltd
* SPDX-License-Identifier: Apache-2.0
*/
package com.opencastsoftware.wasm4j.types;

public enum NoExternType implements HeapType {
INSTANCE;

@Override
public <T extends Exception> void accept(WasmTypeVisitor<T> visitor) throws T {
visitor.visitNoExternType(this);
}
}
14 changes: 14 additions & 0 deletions src/main/java/com/opencastsoftware/wasm4j/types/NoFuncType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* SPDX-FileCopyrightText: Copyright 2023 Opencast Software Europe Ltd
* SPDX-License-Identifier: Apache-2.0
*/
package com.opencastsoftware.wasm4j.types;

public enum NoFuncType implements HeapType {
INSTANCE;

@Override
public <T extends Exception> void accept(WasmTypeVisitor<T> visitor) throws T {
visitor.visitNoFuncType(this);
}
}
14 changes: 14 additions & 0 deletions src/main/java/com/opencastsoftware/wasm4j/types/NoneType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* SPDX-FileCopyrightText: Copyright 2023 Opencast Software Europe Ltd
* SPDX-License-Identifier: Apache-2.0
*/
package com.opencastsoftware.wasm4j.types;

public enum NoneType implements HeapType {
INSTANCE;

@Override
public <T extends Exception> void accept(WasmTypeVisitor<T> visitor) throws T {
visitor.visitNoneType(this);
}
}
40 changes: 36 additions & 4 deletions src/main/java/com/opencastsoftware/wasm4j/types/RefType.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,44 @@ public static RefType nonNullable(HeapType heapType) {
return new RefType(false, heapType);
}

public static RefType heapFunc() {
return new RefType(false, HeapType.func());
public static RefType funcRef() {
return new RefType(true, HeapType.func());
}

public static RefType heapExtern() {
return new RefType(false, HeapType.extern());
public static RefType externRef() {
return new RefType(true, HeapType.extern());
}

public static RefType anyRef() {
return new RefType(true, HeapType.any());
}

public static RefType nullRef() {
return new RefType(true, HeapType.none());
}

public static RefType nullExternRef() {
return new RefType(true, HeapType.noExtern());
}

public static RefType nullFuncRef() {
return new RefType(true, HeapType.noFunc());
}

public static RefType eqRef() {
return new RefType(true, HeapType.eq());
}

public static RefType structRef() {
return new RefType(true, HeapType.struct());
}

public static RefType arrayRef() {
return new RefType(true, HeapType.array());
}

public static RefType i31Ref() {
return new RefType(true, HeapType.i31());
}

@Override
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/com/opencastsoftware/wasm4j/types/StructType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* SPDX-FileCopyrightText: Copyright 2023 Opencast Software Europe Ltd
* SPDX-License-Identifier: Apache-2.0
*/
package com.opencastsoftware.wasm4j.types;

public enum StructType implements HeapType {
INSTANCE;

@Override
public <T extends Exception> void accept(WasmTypeVisitor<T> visitor) throws T {
visitor.visitStructType(this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/
package com.opencastsoftware.wasm4j.types;


public interface WasmTypeVisitor<T extends Exception> {

default void visitType(WasmType type) throws T {
Expand All @@ -21,6 +22,22 @@ default void visitHeapType(HeapType heap) throws T {

void visitHeapExtern(HeapExternType heapExtern) throws T;

void visitAnyType(AnyType any) throws T;

void visitNoneType(NoneType none) throws T;

void visitNoExternType(NoExternType noExtern) throws T;

void visitNoFuncType(NoFuncType noFunc) throws T;

void visitEqType(EqType eq) throws T;

void visitStructType(StructType struct) throws T;

void visitArrayType(ArrayType array) throws T;

void visitI31Type(I31Type i31) throws T;

// Extern types
default void visitExternType(ExternType extern) throws T {
extern.accept(this);
Expand Down
Loading