diff options
| author | Michael Williamson <mike@zwobble.org> | 2026-04-05 21:37:17 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2026-04-05 21:42:10 +0100 |
| commit | 10d5eca372ed85d9beab8f91e0cadcd6f8e24fac (patch) | |
| tree | 9204c7a1f716bb7182c46e9ae00614cdaf8e48b0 | |
| parent | 197ddfce216d81f57691261a931f23bbe855bdfa (diff) | |
Support null data pointer
| -rw-r--r-- | patio-to-cranelift/src/lib.rs | 6 | ||||
| -rw-r--r-- | src/test/java/org/shedlang/compiler/patio/PatioExampleTests.java | 21 | ||||
| -rw-r--r-- | src/test/java/org/shedlang/compiler/patio/instructions/Patio.java | 4 |
3 files changed, 29 insertions, 2 deletions
diff --git a/patio-to-cranelift/src/lib.rs b/patio-to-cranelift/src/lib.rs index 74dd4993..85e11f7b 100644 --- a/patio-to-cranelift/src/lib.rs +++ b/patio-to-cranelift/src/lib.rs @@ -568,16 +568,18 @@ fn compile_data_ptr_value( data_ptr_value: &PatioDataPtrValue, context: &mut CompilerFunctionContext<'_>, ) -> cranelift_codegen::ir::Value { + let data_ptr_type = context.pointer_type(); + match data_ptr_value { PatioDataPtrValue::DataElement { name } => { let global_value = context.data_ptr(name); - let data_ptr_type = context.pointer_type(); context .function_builder .ins() .global_value(data_ptr_type, global_value) } - PatioDataPtrValue::Null => todo!(), + + PatioDataPtrValue::Null => context.function_builder.ins().iconst(data_ptr_type, 0), } } diff --git a/src/test/java/org/shedlang/compiler/patio/PatioExampleTests.java b/src/test/java/org/shedlang/compiler/patio/PatioExampleTests.java index 9ea6aef2..0cc1574d 100644 --- a/src/test/java/org/shedlang/compiler/patio/PatioExampleTests.java +++ b/src/test/java/org/shedlang/compiler/patio/PatioExampleTests.java @@ -143,6 +143,27 @@ public abstract class PatioExampleTests { } @Test + public void dataPtrCanBeNull() throws IOException, InterruptedException { + var patioFunction = PatioFunctionDefinition.builder() + .withName(FUNCTION_NAME) + .addLocal(PatioLocal.val("x", PatioTypes.DATA_PTR)) + .addBodyInstruction(Patio.localStore( + Patio.localRef("x"), + Patio.dataPtrConst(Patio.dataPtrValueNull()) + )) + .withReturnType(PatioTypes.VOID) + .addBodyInstruction(Patio.returnVoid()) + .build(); + var patio = Patio.compilationUnit(List.of( + patioFunction + )); + + var result = run(patio); + + assertThat(result, isSequence()); + } + + @Test public void blockSingleResult() throws IOException, InterruptedException { var patioFunction = PatioFunctionDefinition.builder() .withName(FUNCTION_NAME) diff --git a/src/test/java/org/shedlang/compiler/patio/instructions/Patio.java b/src/test/java/org/shedlang/compiler/patio/instructions/Patio.java index f8f8dbf6..d6d236c6 100644 --- a/src/test/java/org/shedlang/compiler/patio/instructions/Patio.java +++ b/src/test/java/org/shedlang/compiler/patio/instructions/Patio.java @@ -119,6 +119,10 @@ public class Patio { return PatioDataPtrConst.dataElement(name); } + public static PatioOperand dataPtrConst(PatioDataPtrValue value) { + return new PatioDataPtrConst(value); + } + public static PatioInstruction dataPtrToInt(PatioLocalRef destination, PatioOperand value) { return new PatioDataPtrToInt( destination, |
