diff options
| author | Michael Williamson <mike@zwobble.org> | 2023-12-28 00:30:37 +0000 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2023-12-28 00:30:37 +0000 |
| commit | d6e6efc43aa4f650725bbeba5450c6c44b56fd8f (patch) | |
| tree | bcf7d03878ffd216bdc5de14531aa430758e06e4 /src/test/java | |
| parent | 08d8d6c651baf72c86714b46df3794ee8227d98a (diff) | |
Add Patio example test for alloc-heap
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) |
