diff options
| author | Michael Williamson <mike@zwobble.org> | 2026-04-05 22:40:33 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2026-04-05 22:40:33 +0100 |
| commit | 423e5565da7261aa1c3337abc67fed5eac16cc60 (patch) | |
| tree | 46dbfe8c3cb91210477dac1b50e4fa2e8af7a5cb | |
| parent | 503ac552b80e3d7f488458e8efd8d1e95d2527b0 (diff) | |
Add test for calling pointers
| -rw-r--r-- | src/test/java/org/shedlang/compiler/patio/PatioExampleTests.java | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/test/java/org/shedlang/compiler/patio/PatioExampleTests.java b/src/test/java/org/shedlang/compiler/patio/PatioExampleTests.java index c55cd1f1..fa8dfb08 100644 --- a/src/test/java/org/shedlang/compiler/patio/PatioExampleTests.java +++ b/src/test/java/org/shedlang/compiler/patio/PatioExampleTests.java @@ -673,6 +673,35 @@ public abstract class PatioExampleTests { } @Test + public void canCallPointerToFunctionDefinedInModule() throws IOException, InterruptedException { + var calledFunction = PatioFunctionDefinition.builder() + .withName("get") + .withReturnType(PatioTypes.INT) + .addBodyInstruction(Patio.return_(Patio.intConst(42))) + .build(); + + var patioFunction = PatioFunctionDefinition.builder() + .withName(FUNCTION_NAME) + .withReturnType(PatioTypes.VOID) + .addLocal(Patio.val("x", PatioTypes.INT)) + .addBodyInstruction(Patio.callPointer( + Patio.localRef("x"), + Patio.functionPtrConst("get"), + List.of() + )) + .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 whenExceptionIsNotThrownThenTryReturnsFromBody() throws IOException, InterruptedException { var patioFunction = PatioFunctionDefinition.builder() .withName(FUNCTION_NAME) |
