From 88a8e93bd196371180b82f01d43c2de180376e97 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Mon, 6 Apr 2026 09:28:52 +0100 Subject: Implement int / data-ptr conversion in patio-to-cranelift --- .../shedlang/compiler/patio/PatioExampleTests.java | 39 ++++++++++++++++++++++ 1 file changed, 39 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 fa8dfb08..9fc97792 100644 --- a/src/test/java/org/shedlang/compiler/patio/PatioExampleTests.java +++ b/src/test/java/org/shedlang/compiler/patio/PatioExampleTests.java @@ -204,6 +204,45 @@ public abstract class PatioExampleTests { assertThat(result, isSequence()); } + @Test + public void canConvertBetweenDataPtrAndInt() throws IOException, InterruptedException { + var patioDataElement = new PatioDataElementImmutableDefinition( + "answer", + PatioVisibility.PRIVATE, + PatioDataValues.int_(42), + Sources.NULL + ); + var patioFunction = PatioFunctionDefinition.builder() + .withName(FUNCTION_NAME) + .withReturnType(PatioTypes.VOID) + .addLocal(Patio.val("x", PatioTypes.INT)) + .addLocal(Patio.val("ptr_int", PatioTypes.INT)) + .addLocal(Patio.val("ptr", PatioTypes.DATA_PTR)) + .addBodyInstruction(Patio.dataPtrToInt(Patio.localRef("ptr_int"), Patio.dataPtrConst("answer"))) + .addBodyInstruction(Patio.intToDataPtr(Patio.localRef("ptr"), Patio.localRef("ptr_int"))) + .addBodyInstruction(Patio.memoryLoad( + Patio.localRef("x"), + Patio.localRef("ptr"), + 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(42) + )); + } + @Test public void blockSingleResult() throws IOException, InterruptedException { var patioFunction = PatioFunctionDefinition.builder() -- cgit v1.2.3