aboutsummaryrefslogtreecommitdiff
path: root/src/test/java/org
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2026-04-06 10:51:24 +0100
committerMichael Williamson <mike@zwobble.org>2026-04-06 10:51:24 +0100
commit893ff4f5d4c4d370b30eea0b5a1502852e02e4b7 (patch)
treedb6640bd375560da9bfcd5806ad9d9f247f834b4 /src/test/java/org
parentd5f3edad56395aff42839e055702f113dbcc8345 (diff)
Add Patio for calling local function with args
Diffstat (limited to 'src/test/java/org')
-rw-r--r--src/test/java/org/shedlang/compiler/patio/PatioExampleTests.java32
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")