diff options
| author | Michael Williamson <mike@zwobble.org> | 2026-04-05 21:50:12 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2026-04-05 21:50:12 +0100 |
| commit | e937b17b276ca98950c5c2e09e646ccd9338278c (patch) | |
| tree | 9cdcc1abb1b9ed30755b6a2d934f1ba6becfc3cc /src/test/java | |
| parent | 46babf5169a62a1ebc28d8605fdb2e3720c1f4f9 (diff) | |
Support mutable data elements in patio-to-cranelift
Diffstat (limited to 'src/test/java')
| -rw-r--r-- | src/test/java/org/shedlang/compiler/patio/PatioExampleTests.java | 41 |
1 files changed, 41 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 0cc1574d..8a2cea87 100644 --- a/src/test/java/org/shedlang/compiler/patio/PatioExampleTests.java +++ b/src/test/java/org/shedlang/compiler/patio/PatioExampleTests.java @@ -143,6 +143,47 @@ public abstract class PatioExampleTests { } @Test + public void canStoreToThenLoadFromMutableDataElement() throws IOException, InterruptedException { + var patioDataElement = new PatioDataElementMutableDefinition( + "answer", + PatioVisibility.PRIVATE, + PatioDataValues.int_(42), + Sources.NULL + ); + var patioFunction = PatioFunctionDefinition.builder() + .withName(FUNCTION_NAME) + .withReturnType(PatioTypes.VOID) + .addLocal(Patio.val("x", PatioTypes.INT)) + .addBodyInstruction(Patio.memoryStore( + Patio.dataPtrConst("answer"), + PatioDataLayouts.INT, + List.of(), + Patio.intConst(47) + )) + .addBodyInstruction(Patio.memoryLoad( + Patio.localRef("x"), + Patio.dataPtrConst("answer"), + PatioDataLayouts.INT, + List.of() + )) + .addBodyInstruction(emitInt( + Patio.localRef("x") + )) + .addBodyInstruction(Patio.returnVoid()) + .build(); + var patio = Patio.compilationUnit(List.of( + patioDataElement, + patioFunction + )); + + var result = run(patio); + + assertThat(result, isSequence( + isInt(47) + )); + } + + @Test public void dataPtrCanBeNull() throws IOException, InterruptedException { var patioFunction = PatioFunctionDefinition.builder() .withName(FUNCTION_NAME) |
