aboutsummaryrefslogtreecommitdiff
path: root/src/test/java
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2026-04-06 09:28:52 +0100
committerMichael Williamson <mike@zwobble.org>2026-04-06 09:34:08 +0100
commit88a8e93bd196371180b82f01d43c2de180376e97 (patch)
tree0695546bd5aa6e7c23e00037f3aee2c3b798efe0 /src/test/java
parent0d2157f1236c760cab7c5092b21e779e35caa9f2 (diff)
Implement int / data-ptr conversion in patio-to-cranelift
Diffstat (limited to 'src/test/java')
-rw-r--r--src/test/java/org/shedlang/compiler/patio/PatioExampleTests.java39
1 files changed, 39 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 fa8dfb08..9fc97792 100644
--- a/src/test/java/org/shedlang/compiler/patio/PatioExampleTests.java
+++ b/src/test/java/org/shedlang/compiler/patio/PatioExampleTests.java
@@ -205,6 +205,45 @@ public abstract class PatioExampleTests {
}
@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()
.withName(FUNCTION_NAME)