From 3dfd0c6534584206d2f0bb6a88b56f7201d18197 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Fri, 14 Jul 2023 22:10:03 +0100 Subject: Handle params when defining functions in WASM backend --- .../wasm/WasmCodeGenDefineFunctionTests.java | 27 ++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'src/test/java') diff --git a/src/test/java/org/shedlang/compiler/backends/wasm/WasmCodeGenDefineFunctionTests.java b/src/test/java/org/shedlang/compiler/backends/wasm/WasmCodeGenDefineFunctionTests.java index 87a6dee6..d32f716a 100644 --- a/src/test/java/org/shedlang/compiler/backends/wasm/WasmCodeGenDefineFunctionTests.java +++ b/src/test/java/org/shedlang/compiler/backends/wasm/WasmCodeGenDefineFunctionTests.java @@ -58,4 +58,31 @@ public class WasmCodeGenDefineFunctionTests { snapshotter.assertSnapshot(objdumpContext(result)); } + + @Test + public void positionalAndNamedParamsAreDefined(Snapshotter snapshotter) throws IOException, InterruptedException { + var instruction = new DefineFunctionInstruction( + "f", + List.of(Instructions.param("param1"), Instructions.param("param2")), + List.of(Instructions.param("paramA"), Instructions.param("paramB")), + FreeVariables.of("a", "b"), + List.of( + Instructions.localLoad("a"), + Instructions.localLoad("param1"), + Instructions.intAdd(), + Instructions.localLoad("paramA"), + Instructions.intAdd(), + Instructions.return_() + ), + Sources.NULL + ); + var context = WasmCodeGenContext.EMPTY + .addShedLocal("b").context() + .addShedLocal("c").context() + .addShedLocal("a").context(); + + var result = WasmCodeGen.generateInstruction(instruction, context); + + snapshotter.assertSnapshot(objdumpContext(result)); + } } -- cgit v1.2.3