From 099e5501ad29a5db8411973e7dbf5f61dfda33f0 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Wed, 27 Dec 2023 16:36:29 +0000 Subject: Test loading of data elements --- .../shedlang/compiler/patio/PatioExampleTests.java | 33 ++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'src/test/java') 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; @@ -16,6 +18,37 @@ import static org.zwobble.precisely.Matchers.*; 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() -- cgit v1.2.3