From 02d268ef9d0e42db38715f796621962f7d47c4a6 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Wed, 27 Dec 2023 16:38:46 +0000 Subject: Fix writing of int data elements for wasm64 --- .../shedlang/compiler/patio/PatioExampleTests.java | 39 ++++++++++++++++++++++ 1 file changed, 39 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 2972384d..d25aa5a9 100644 --- a/src/test/java/org/shedlang/compiler/patio/PatioExampleTests.java +++ b/src/test/java/org/shedlang/compiler/patio/PatioExampleTests.java @@ -49,6 +49,45 @@ public abstract class PatioExampleTests { assertThat(result, isSilentExit(42)); } + @Test + public void canLoadIntFromMiddleOfDataElement() throws IOException, InterruptedException { + var patioDataElement = new PatioDataElementImmutable( + "answer", + PatioDataValues.struct(List.of( + PatioDataValues.int_(37), + PatioDataValues.int_(42), + PatioDataValues.int_(47) + )), + 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.struct(List.of( + PatioDataLayouts.INT, + PatioDataLayouts.INT, + PatioDataLayouts.INT + )), + List.of(1) + )) + .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