diff options
| author | Michael Williamson <mike@zwobble.org> | 2023-06-24 23:01:33 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2023-06-24 23:06:29 +0100 |
| commit | 5e15348d603b824f7d8725cb33852881294935ab (patch) | |
| tree | f4c2a17a7a3d18c687c27a16802a9951925bc8fb /src | |
| parent | 812f1c44f064c797687e739b8c722d9f528ecef6 (diff) | |
Add WasmExpression
Diffstat (limited to 'src')
4 files changed, 15 insertions, 8 deletions
diff --git a/src/main/java/org/shedlang/compiler/backends/wasm/structure/ast/instructions/WasmExpression.java b/src/main/java/org/shedlang/compiler/backends/wasm/structure/ast/instructions/WasmExpression.java new file mode 100644 index 00000000..ef0969e5 --- /dev/null +++ b/src/main/java/org/shedlang/compiler/backends/wasm/structure/ast/instructions/WasmExpression.java @@ -0,0 +1,6 @@ +package org.shedlang.compiler.backends.wasm.structure.ast.instructions; + +import java.util.List; + +public record WasmExpression(List<WasmInstruction> instructions) { +} diff --git a/src/main/java/org/shedlang/compiler/backends/wasm/structure/ast/modules/WasmFunction.java b/src/main/java/org/shedlang/compiler/backends/wasm/structure/ast/modules/WasmFunction.java index 2e5cf592..b63e6fc2 100644 --- a/src/main/java/org/shedlang/compiler/backends/wasm/structure/ast/modules/WasmFunction.java +++ b/src/main/java/org/shedlang/compiler/backends/wasm/structure/ast/modules/WasmFunction.java @@ -1,6 +1,6 @@ package org.shedlang.compiler.backends.wasm.structure.ast.modules; -import org.shedlang.compiler.backends.wasm.structure.ast.instructions.WasmInstruction; +import org.shedlang.compiler.backends.wasm.structure.ast.instructions.WasmExpression; import org.shedlang.compiler.backends.wasm.structure.ast.types.WasmFuncType; import org.shedlang.compiler.backends.wasm.structure.ast.types.WasmValueType; @@ -11,7 +11,7 @@ public record WasmFunction( List<WasmLocal> params, List<WasmLocal> locals, List<WasmValueType> resultTypes, - List<WasmInstruction> body + WasmExpression body ) { public WasmFuncType type() { return new WasmFuncType( 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 58d3d28c..3ed6b618 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 @@ -1,12 +1,12 @@ package org.shedlang.compiler.backends.wasm.structure.binary; import org.shedlang.compiler.backends.wasm.structure.BinaryWriter; +import org.shedlang.compiler.backends.wasm.structure.ast.instructions.WasmExpression; import org.shedlang.compiler.backends.wasm.structure.ast.instructions.WasmI32Const; import org.shedlang.compiler.backends.wasm.structure.ast.instructions.WasmI64Const; import org.shedlang.compiler.backends.wasm.structure.ast.instructions.WasmInstruction; import java.io.IOException; -import java.util.List; public class WasmBinaryFormatInstructions { // Corresponds to https://webassembly.github.io/spec/core/binary/instructions.html @@ -33,10 +33,10 @@ public class WasmBinaryFormatInstructions { // == Expressions == static void writeExpression( - List<WasmInstruction> instructions, + WasmExpression expression, BinaryWriter writer ) throws IOException { - for (var instruction : instructions) { + for (var instruction : expression.instructions()) { writeInstruction(instruction, writer); } writer.writeByte(0x0b); diff --git a/src/test/java/org/shedlang/compiler/backends/wasm/structure/WasmBinaryFormatModuleTests.java b/src/test/java/org/shedlang/compiler/backends/wasm/structure/WasmBinaryFormatModuleTests.java index 29c0feba..7cf142a4 100644 --- a/src/test/java/org/shedlang/compiler/backends/wasm/structure/WasmBinaryFormatModuleTests.java +++ b/src/test/java/org/shedlang/compiler/backends/wasm/structure/WasmBinaryFormatModuleTests.java @@ -2,6 +2,7 @@ package org.shedlang.compiler.backends.wasm.structure; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; +import org.shedlang.compiler.backends.wasm.structure.ast.instructions.WasmExpression; import org.shedlang.compiler.backends.wasm.structure.ast.instructions.WasmI32Const; import org.shedlang.compiler.backends.wasm.structure.ast.instructions.WasmI64Const; import org.shedlang.compiler.backends.wasm.structure.ast.modules.*; @@ -55,7 +56,7 @@ public class WasmBinaryFormatModuleTests { new WasmLocal("localB", WasmValueType.F64) ), List.of(WasmValueType.I32), - List.of(new WasmI32Const(0)) + new WasmExpression(List.of(new WasmI32Const(0))) )) .addFunction(new WasmFunction( "f2", @@ -66,7 +67,7 @@ public class WasmBinaryFormatModuleTests { new WasmLocal("localA", WasmValueType.I64) ), List.of(WasmValueType.I64), - List.of(new WasmI64Const(0)) + new WasmExpression(List.of(new WasmI64Const(0))) )); var result = serializeModule(module); @@ -103,7 +104,7 @@ public class WasmBinaryFormatModuleTests { ), List.of(), List.of(WasmValueType.I32), - List.of(new WasmI32Const(0)) + new WasmExpression(List.of(new WasmI32Const(0))) )) .addImport(new WasmImport( "ModuleName1", |
