aboutsummaryrefslogtreecommitdiff
path: root/src/test/java
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2023-12-27 16:36:29 +0000
committerMichael Williamson <mike@zwobble.org>2023-12-27 16:36:29 +0000
commit099e5501ad29a5db8411973e7dbf5f61dfda33f0 (patch)
tree360c0a12c5955c359b6663085563e4a1ee8296eb /src/test/java
parentf7048d47b57ff21e03fd10f7917d87b2fd6c2dbb (diff)
Test loading of data elements
Diffstat (limited to 'src/test/java')
-rw-r--r--src/test/java/org/shedlang/compiler/patio/PatioExampleTests.java33
1 files changed, 33 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 db56958a..2972384d 100644
--- a/src/test/java/org/shedlang/compiler/patio/PatioExampleTests.java
+++ b/src/test/java/org/shedlang/compiler/patio/PatioExampleTests.java
@@ -2,8 +2,10 @@ package org.shedlang.compiler.patio;
import org.junit.jupiter.api.Test;
import org.shedlang.compiler.patio.types.PatioDataLayouts;
+import org.shedlang.compiler.patio.types.PatioDataValues;
import org.shedlang.compiler.patio.types.PatioTypes;
import org.shedlang.compiler.patio.instructions.Patio;
+import org.shedlang.compiler.sources.Sources;
import org.shedlang.compiler.testing.ExecutionResult;
import org.zwobble.precisely.Matcher;
@@ -17,6 +19,37 @@ public abstract class PatioExampleTests {
protected static final String FUNCTION_NAME = "run";
@Test
+ public void canLoadDataElementInt() throws IOException, InterruptedException {
+ var patioDataElement = new PatioDataElementImmutable(
+ "answer",
+ PatioDataValues.int_(42),
+ Sources.NULL
+ );
+ var patioFunction = PatioFunctionDefinition.builder()
+ .withName(FUNCTION_NAME)
+ .withReturnType(PatioTypes.INT)
+ .addLocal(Patio.val("x", PatioTypes.INT))
+ .addBodyInstruction(Patio.memoryLoad(
+ Patio.localRef("x"),
+ Patio.dataPtr("answer"),
+ PatioDataLayouts.INT,
+ List.of()
+ ))
+ .addBodyInstruction(Patio.return_(
+ Patio.localRef("x")
+ ))
+ .build();
+ var patio = Patio.compilationUnit(List.of(
+ patioDataElement,
+ patioFunction
+ ));
+
+ var result = run(patio);
+
+ assertThat(result, isSilentExit(42));
+ }
+
+ @Test
public void allocStack() throws IOException, InterruptedException {
var patioFunction = PatioFunctionDefinition.builder()
.withName(FUNCTION_NAME)