From c9b5c7bd986f15114df7dcfc405c4eca11cbf25f Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sun, 22 Dec 2024 20:31:03 +0000 Subject: Support Wasm block types with multiple results --- .../binary/WasmBinaryFormatInstructionsTests.java | 27 +++++++++++++++++----- 1 file changed, 21 insertions(+), 6 deletions(-) (limited to 'src/test/java/org/shedlang/compiler/backends') diff --git a/src/test/java/org/shedlang/compiler/backends/wasm/structure/binary/WasmBinaryFormatInstructionsTests.java b/src/test/java/org/shedlang/compiler/backends/wasm/structure/binary/WasmBinaryFormatInstructionsTests.java index a14763d5..b9f2d9c2 100644 --- a/src/test/java/org/shedlang/compiler/backends/wasm/structure/binary/WasmBinaryFormatInstructionsTests.java +++ b/src/test/java/org/shedlang/compiler/backends/wasm/structure/binary/WasmBinaryFormatInstructionsTests.java @@ -1,10 +1,10 @@ package org.shedlang.compiler.backends.wasm.structure.binary; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.shedlang.compiler.backends.wasm.structure.ast.instructions.*; import org.shedlang.compiler.backends.wasm.structure.ast.modules.*; +import org.shedlang.compiler.backends.wasm.structure.ast.types.WasmFuncType; import org.shedlang.compiler.backends.wasm.structure.ast.types.WasmLimits; import org.shedlang.compiler.backends.wasm.structure.ast.types.WasmMemoryType; import org.shedlang.compiler.backends.wasm.structure.ast.types.WasmValueType; @@ -55,12 +55,16 @@ public class WasmBinaryFormatInstructionsTests { } @Test - @Disabled("WIP") public void canSerializeBlockTypeMultipleValues(Snapshotter snapshotter) throws IOException, InterruptedException { + var funcType = new WasmFuncType( + List.of(), + List.of(WasmValueType.I64, WasmValueType.I32) + ); + var instructions = List.of( new WasmI32Const(0), new WasmIf( - WasmBlockType.of(WasmValueType.I64, WasmValueType.I32), + WasmBlockType.of(funcType), List.of( new WasmI64Const(0), new WasmI32Const(0) @@ -70,10 +74,21 @@ public class WasmBinaryFormatInstructionsTests { new WasmI32Const(1) ) ), + new WasmDrop(), new WasmDrop() ); - var result = serializeInstructions(instructions); + var module = WasmModule.EMPTY + .addType(funcType) + .addFunction(new WasmFunction( + "f", + List.of(), + List.of(), + List.of(), + new WasmExpression(instructions) + )); + + var result = serializeModuleWasm32(module); snapshotter.assertSnapshot(result); } @@ -326,7 +341,7 @@ public class WasmBinaryFormatInstructionsTests { List.of(), new WasmExpression(List.of( new WasmTry( - new WasmBlockType(List.of(WasmValueType.I32)), + WasmBlockType.of(WasmValueType.I32), List.of(), List.of( new WasmI32Const(42) @@ -361,7 +376,7 @@ public class WasmBinaryFormatInstructionsTests { List.of(), new WasmExpression(List.of( new WasmTry( - new WasmBlockType(List.of(WasmValueType.I32)), + WasmBlockType.of(WasmValueType.I32), List.of( new WasmCatchBlock( new WasmTagName("Error1"), -- cgit v1.2.3