From 893ff4f5d4c4d370b30eea0b5a1502852e02e4b7 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Mon, 6 Apr 2026 10:51:24 +0100 Subject: Add Patio for calling local function with args --- .../shedlang/compiler/patio/PatioExampleTests.java | 32 +++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/src/test/java/org/shedlang/compiler/patio/PatioExampleTests.java b/src/test/java/org/shedlang/compiler/patio/PatioExampleTests.java index 9fc97792..21811753 100644 --- a/src/test/java/org/shedlang/compiler/patio/PatioExampleTests.java +++ b/src/test/java/org/shedlang/compiler/patio/PatioExampleTests.java @@ -683,7 +683,7 @@ public abstract class PatioExampleTests { } @Test - public void canCallFunctionDefinedInModule() throws IOException, InterruptedException { + public void canCallFunctionWithoutArgsDefinedInModule() throws IOException, InterruptedException { var calledFunction = PatioFunctionDefinition.builder() .withName("get") .withReturnType(PatioTypes.INT) @@ -711,6 +711,36 @@ public abstract class PatioExampleTests { )); } + @Test + public void canCallFunctionWithArgsDefinedInModule() throws IOException, InterruptedException { + var calledFunction = PatioFunctionDefinition.builder() + .withName("identity") + .addLocal(PatioLocal.param("x", PatioTypes.INT)) + .withReturnType(PatioTypes.INT) + .addBodyInstruction(Patio.return_(Patio.localRef("x"))) + .build(); + + var patioFunction = PatioFunctionDefinition.builder() + .withName(FUNCTION_NAME) + .withReturnType(PatioTypes.VOID) + .addLocal(Patio.val("x", PatioTypes.INT)) + .addBodyInstruction(Patio.call( + Optional.of(Patio.localRef("x")), + calledFunction.name(), + List.of(Patio.intConst(42)) + )) + .addBodyInstruction(emitInt(Patio.localRef("x"))) + .addBodyInstruction(Patio.returnVoid()) + .build(); + var patio = Patio.compilationUnit(List.of(calledFunction, patioFunction)); + + var result = run(patio); + + assertThat(result, isSequence( + isInt(42) + )); + } + @Test public void canCallPointerToFunctionDefinedInModule() throws IOException, InterruptedException { var calledFunction = PatioFunctionDefinition.builder() -- cgit v1.2.3