aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2023-11-26 15:47:13 +0000
committerMichael Williamson <mike@zwobble.org>2023-11-26 15:49:33 +0000
commit1b7e1f872b27493895d44d038763cbb20e869d77 (patch)
tree8add52ab2700128e59e4a10771e2ec487a5c97e0 /src/main/java
parent52444b565aa3fa5719df3acf490eb11b9337511c (diff)
Support Wasm try with no catch blocks
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/org/shedlang/compiler/backends/wasm/structure/ast/instructions/WasmCatchBlock.java11
-rw-r--r--src/main/java/org/shedlang/compiler/backends/wasm/structure/ast/instructions/WasmInstruction.java2
-rw-r--r--src/main/java/org/shedlang/compiler/backends/wasm/structure/ast/instructions/WasmTry.java10
-rw-r--r--src/main/java/org/shedlang/compiler/backends/wasm/structure/ast/modules/WasmTagName.java4
-rw-r--r--src/main/java/org/shedlang/compiler/backends/wasm/structure/binary/WasmBinaryFormatExceptions.java12
-rw-r--r--src/main/java/org/shedlang/compiler/backends/wasm/structure/binary/WasmBinaryFormatInstructions.java11
6 files changed, 48 insertions, 2 deletions
diff --git a/src/main/java/org/shedlang/compiler/backends/wasm/structure/ast/instructions/WasmCatchBlock.java b/src/main/java/org/shedlang/compiler/backends/wasm/structure/ast/instructions/WasmCatchBlock.java
new file mode 100644
index 00000000..c0ab485b
--- /dev/null
+++ b/src/main/java/org/shedlang/compiler/backends/wasm/structure/ast/instructions/WasmCatchBlock.java
@@ -0,0 +1,11 @@
+package org.shedlang.compiler.backends.wasm.structure.ast.instructions;
+
+import org.shedlang.compiler.backends.wasm.structure.ast.modules.WasmTag;
+
+import java.util.List;
+
+public record WasmCatchBlock(
+ WasmTag tag,
+ List<WasmInstruction> body
+) {
+}
diff --git a/src/main/java/org/shedlang/compiler/backends/wasm/structure/ast/instructions/WasmInstruction.java b/src/main/java/org/shedlang/compiler/backends/wasm/structure/ast/instructions/WasmInstruction.java
index eef4ec24..155cfdf2 100644
--- a/src/main/java/org/shedlang/compiler/backends/wasm/structure/ast/instructions/WasmInstruction.java
+++ b/src/main/java/org/shedlang/compiler/backends/wasm/structure/ast/instructions/WasmInstruction.java
@@ -1,4 +1,4 @@
package org.shedlang.compiler.backends.wasm.structure.ast.instructions;
-public sealed interface WasmInstruction permits WasmBlock, WasmBr, WasmCall, WasmCallIndirect, WasmDrop, WasmGlobalGet, WasmGlobalSet, WasmI32Add, WasmI32Const, WasmI32Eq, WasmI32Load, WasmI32Ne, WasmI32Store, WasmI32Sub, WasmI64Const, WasmIf, WasmLocalGet, WasmLocalSet, WasmLoop, WasmMemoryAddressConst, WasmMemoryGrow, WasmReturn, WasmTableElementIndexConst, WasmUnreachable {
+public sealed interface WasmInstruction permits WasmBlock, WasmBr, WasmCall, WasmCallIndirect, WasmDrop, WasmGlobalGet, WasmGlobalSet, WasmI32Add, WasmI32Const, WasmI32Eq, WasmI32Load, WasmI32Ne, WasmI32Store, WasmI32Sub, WasmI64Const, WasmIf, WasmLocalGet, WasmLocalSet, WasmLoop, WasmMemoryAddressConst, WasmMemoryGrow, WasmReturn, WasmTableElementIndexConst, WasmTry, WasmUnreachable {
}
diff --git a/src/main/java/org/shedlang/compiler/backends/wasm/structure/ast/instructions/WasmTry.java b/src/main/java/org/shedlang/compiler/backends/wasm/structure/ast/instructions/WasmTry.java
new file mode 100644
index 00000000..15436919
--- /dev/null
+++ b/src/main/java/org/shedlang/compiler/backends/wasm/structure/ast/instructions/WasmTry.java
@@ -0,0 +1,10 @@
+package org.shedlang.compiler.backends.wasm.structure.ast.instructions;
+
+import java.util.List;
+
+public record WasmTry(
+ WasmBlockType blockType,
+ List<WasmCatchBlock> catchBlocks,
+ List<WasmInstruction> body
+) implements WasmInstruction {
+}
diff --git a/src/main/java/org/shedlang/compiler/backends/wasm/structure/ast/modules/WasmTagName.java b/src/main/java/org/shedlang/compiler/backends/wasm/structure/ast/modules/WasmTagName.java
new file mode 100644
index 00000000..02e5d9b3
--- /dev/null
+++ b/src/main/java/org/shedlang/compiler/backends/wasm/structure/ast/modules/WasmTagName.java
@@ -0,0 +1,4 @@
+package org.shedlang.compiler.backends.wasm.structure.ast.modules;
+
+public record WasmTagName(String name) {
+}
diff --git a/src/main/java/org/shedlang/compiler/backends/wasm/structure/binary/WasmBinaryFormatExceptions.java b/src/main/java/org/shedlang/compiler/backends/wasm/structure/binary/WasmBinaryFormatExceptions.java
index fa1dbe9c..d3a66853 100644
--- a/src/main/java/org/shedlang/compiler/backends/wasm/structure/binary/WasmBinaryFormatExceptions.java
+++ b/src/main/java/org/shedlang/compiler/backends/wasm/structure/binary/WasmBinaryFormatExceptions.java
@@ -7,7 +7,17 @@ import org.shedlang.compiler.backends.wasm.structure.ast.modules.WasmTagIndex;
import java.io.IOException;
public class WasmBinaryFormatExceptions {
- // Corresponds to https://github.com/WebAssembly/exception-handling/blob/main/proposals/exception-handling/Exceptions.md
+ // Corresponds to https://github.com/WebAssembly/exception-handling/blob/0f577bde2019ea6474d245ff096488bf8fe9a835/proposals/exception-handling/Exceptions.md
+ //
+ // Note that this version (v3) of the exception handling proposal has been
+ // superseded, see:
+ //
+ // * https://github.com/WebAssembly/exception-handling/blob/0f577bde2019ea6474d245ff096488bf8fe9a835/proposals/exception-handling/Exceptions.md
+ // * https://github.com/WebAssembly/exception-handling/issues/281
+ //
+ // However, this version of the proposal has been widely implemented, and
+ // is likely to continue to be supported for some time. We therefore use
+ // this version of the proposal for the time being.
private WasmBinaryFormatExceptions() {
}
diff --git a/src/main/java/org/shedlang/compiler/backends/wasm/structure/binary/WasmBinaryFormatInstructions.java b/src/main/java/org/shedlang/compiler/backends/wasm/structure/binary/WasmBinaryFormatInstructions.java
index 70d48997..ccdd4e7a 100644
--- a/src/main/java/org/shedlang/compiler/backends/wasm/structure/binary/WasmBinaryFormatInstructions.java
+++ b/src/main/java/org/shedlang/compiler/backends/wasm/structure/binary/WasmBinaryFormatInstructions.java
@@ -145,6 +145,17 @@ public class WasmBinaryFormatInstructions {
writer.writeByte(0x6b);
}
+ // == Exception Instructions (v3 proposal) ==
+
+ case WasmTry try_ -> {
+ writer.writeByte(0x06);
+ writeBlockType(try_.blockType(), writer);
+ for (var bodyInstruction : try_.body()) {
+ writeInstruction(bodyInstruction, writer);
+ }
+ writer.writeByte(0x0b);
+ }
+
// == Relocatable Instructions ==
case WasmMemoryAddressConst memoryAddressConst -> {