diff options
| author | Michael Williamson <mike@zwobble.org> | 2026-04-06 14:47:58 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2026-04-06 14:47:58 +0100 |
| commit | e6e4fc67d93a354eb3ab7f04bb2f833a90650025 (patch) | |
| tree | be1ef7d897cedb83416cf9cc8a0a13dce5a78313 /src | |
| parent | 73e6bbee9908c9128907c3a68b4e3c5a29a7dfae (diff) | |
Add Patio test for loading from mutable data element decl
Diffstat (limited to 'src')
| -rw-r--r-- | src/test/java/org/shedlang/compiler/backends/wasm/PatioToWasmTests.java | 7 | ||||
| -rw-r--r-- | src/test/java/org/shedlang/compiler/patio/PatioExampleTests.java | 34 |
2 files changed, 40 insertions, 1 deletions
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 @@ -184,6 +184,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() .withName(FUNCTION_NAME) |
