From e6e4fc67d93a354eb3ab7f04bb2f833a90650025 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Mon, 6 Apr 2026 14:47:58 +0100 Subject: Add Patio test for loading from mutable data element decl --- .../compiler/backends/wasm/PatioToWasmTests.java | 7 ++++- .../shedlang/compiler/patio/PatioExampleTests.java | 34 ++++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/test/java/org/shedlang/compiler/backends/wasm/PatioToWasmTests.java b/src/test/java/org/shedlang/compiler/backends/wasm/PatioToWasmTests.java index 8ba247c8..946c49fb 100644 --- a/src/test/java/org/shedlang/compiler/backends/wasm/PatioToWasmTests.java +++ b/src/test/java/org/shedlang/compiler/backends/wasm/PatioToWasmTests.java @@ -47,8 +47,13 @@ public abstract class PatioToWasmTests extends PatioExampleTests { } var executablePath = workingDirectory.resolve("main.wasm"); + + var runtime = ShedRuntime.defaultRuntime(wasmTarget().targetName()); WasmBackend.forTarget(wasmTarget()).link( - List.of(objectPath), + List.of( + objectPath, + runtime.dir().resolve("libpatio_test.a") + ), executablePath, ShedRuntime.defaultRuntime(wasmTarget().targetName()) ); diff --git a/src/test/java/org/shedlang/compiler/patio/PatioExampleTests.java b/src/test/java/org/shedlang/compiler/patio/PatioExampleTests.java index 21811753..4d24fd5e 100644 --- a/src/test/java/org/shedlang/compiler/patio/PatioExampleTests.java +++ b/src/test/java/org/shedlang/compiler/patio/PatioExampleTests.java @@ -183,6 +183,40 @@ public abstract class PatioExampleTests { )); } + @Test + public void canLoadFromMutableDataElementDeclaration() throws IOException, InterruptedException { + var patioDataElement = new PatioDataElementMutableDeclaration( + "patio__test__101", + PatioDataLayouts.INT32, + Sources.NULL + ); + var patioFunction = PatioFunctionDefinition.builder() + .withName(FUNCTION_NAME) + .withReturnType(PatioTypes.VOID) + .addLocal(Patio.val("x", PatioTypes.INT)) + .addBodyInstruction(Patio.memoryLoad( + Patio.localRef("x"), + Patio.dataPtrConst("patio__test__101"), + PatioDataLayouts.INT, + List.of() + )) + .addBodyInstruction(emitInt( + Patio.localRef("x") + )) + .addBodyInstruction(Patio.returnVoid()) + .build(); + var patio = Patio.compilationUnit(List.of( + patioDataElement, + patioFunction + )); + + var result = run(patio); + + assertThat(result, isSequence( + isInt(101) + )); + } + @Test public void dataPtrCanBeNull() throws IOException, InterruptedException { var patioFunction = PatioFunctionDefinition.builder() -- cgit v1.2.3