From e937b17b276ca98950c5c2e09e646ccd9338278c Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sun, 5 Apr 2026 21:50:12 +0100 Subject: Support mutable data elements in patio-to-cranelift --- .../shedlang/compiler/patio/PatioExampleTests.java | 41 ++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'src/test/java') 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 @@ -142,6 +142,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() -- cgit v1.2.3