diff options
Diffstat (limited to 'src/test/java')
| -rw-r--r-- | src/test/java/org/shedlang/compiler/patio/PatioExampleTests.java | 50 |
1 files changed, 50 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 d25aa5a9..3855a497 100644 --- a/src/test/java/org/shedlang/compiler/patio/PatioExampleTests.java +++ b/src/test/java/org/shedlang/compiler/patio/PatioExampleTests.java @@ -89,6 +89,56 @@ public abstract class PatioExampleTests { } @Test + public void allocHeap() throws IOException, InterruptedException { + var patioFunction = PatioFunctionDefinition.builder() + .withName(FUNCTION_NAME) + .withReturnType(PatioTypes.INT) + .addLocal(Patio.val("x", PatioTypes.DATA_POINTER)) + .addLocal(Patio.val("y", PatioTypes.INT)) + .addLocal(Patio.val("z", PatioTypes.INT)) + .addLocal(Patio.val("r", PatioTypes.INT)) + .addBodyInstruction(Patio.allocHeap(Patio.localRef("x"), PatioDataLayouts.INT)) + .addBodyInstruction(Patio.memoryStore( + Patio.localRef("x"), + PatioDataLayouts.INT, + List.of(), + Patio.int_(42) + )) + .addBodyInstruction(Patio.memoryLoad( + Patio.localRef("y"), + Patio.localRef("x"), + PatioDataLayouts.INT, + List.of() + )) + .addBodyInstruction(Patio.intAdd( + Patio.localRef("z"), + Patio.localRef("y"), + Patio.int_(5) + )) + .addBodyInstruction(Patio.memoryStore( + Patio.localRef("x"), + PatioDataLayouts.INT, + List.of(), + Patio.localRef("z") + )) + .addBodyInstruction(Patio.memoryLoad( + Patio.localRef("r"), + Patio.localRef("x"), + PatioDataLayouts.INT, + List.of() + )) + .addBodyInstruction(Patio.return_( + Patio.localRef("r") + )) + .build(); + var patio = Patio.compilationUnit(List.of(patioFunction)); + + var result = run(patio); + + assertThat(result, isSilentExit(47)); + } + + @Test public void allocStack() throws IOException, InterruptedException { var patioFunction = PatioFunctionDefinition.builder() .withName(FUNCTION_NAME) |
