diff options
| author | Michael Williamson <mike@zwobble.org> | 2026-04-06 10:51:24 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2026-04-06 10:51:24 +0100 |
| commit | 893ff4f5d4c4d370b30eea0b5a1502852e02e4b7 (patch) | |
| tree | db6640bd375560da9bfcd5806ad9d9f247f834b4 | |
| parent | d5f3edad56395aff42839e055702f113dbcc8345 (diff) | |
Add Patio for calling local function with args
| -rw-r--r-- | src/test/java/org/shedlang/compiler/patio/PatioExampleTests.java | 32 |
1 files changed, 31 insertions, 1 deletions
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) @@ -712,6 +712,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() .withName("get") |
