diff options
| author | Michael Williamson <mike@zwobble.org> | 2026-03-30 23:04:06 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2026-03-30 23:04:06 +0100 |
| commit | 33a08d74b30e08a634b83d14a77ecc080aec0050 (patch) | |
| tree | 80a244526bfd62c3196bf0e747e6deb22d99a76c /src | |
| parent | fa0c31ab7c5c91715094214aad90d744fc2ddfc1 (diff) | |
Add Patio test for locals
Diffstat (limited to 'src')
| -rw-r--r-- | src/main/java/org/shedlang/compiler/patio/PatioLocal.java | 4 | ||||
| -rw-r--r-- | src/test/java/org/shedlang/compiler/patio/PatioExampleTests.java | 25 |
2 files changed, 29 insertions, 0 deletions
diff --git a/src/main/java/org/shedlang/compiler/patio/PatioLocal.java b/src/main/java/org/shedlang/compiler/patio/PatioLocal.java index fb600c54..0cd853cb 100644 --- a/src/main/java/org/shedlang/compiler/patio/PatioLocal.java +++ b/src/main/java/org/shedlang/compiler/patio/PatioLocal.java @@ -8,6 +8,10 @@ public record PatioLocal(String name, PatioType type, PatioLocalType localType) return new PatioLocal(name, type, PatioLocalType.PARAM); } + public static PatioLocal val(String name, PatioType type) { + return new PatioLocal(name, type, PatioLocalType.VAL); + } + public PatioLocalRef ref() { return new PatioLocalRef(name()); } diff --git a/src/test/java/org/shedlang/compiler/patio/PatioExampleTests.java b/src/test/java/org/shedlang/compiler/patio/PatioExampleTests.java index 41185d38..08f4a50f 100644 --- a/src/test/java/org/shedlang/compiler/patio/PatioExampleTests.java +++ b/src/test/java/org/shedlang/compiler/patio/PatioExampleTests.java @@ -42,6 +42,31 @@ public abstract class PatioExampleTests { } @Test + public void localsAreStoredByName() throws IOException, InterruptedException { + var patioFunction = PatioFunctionDefinition.builder() + .withName(FUNCTION_NAME) + .withReturnType(PatioTypes.VOID) + .addLocal(PatioLocal.val("a", PatioTypes.INT)) + .addLocal(PatioLocal.val("b", PatioTypes.INT)) + .addBodyInstruction(Patio.localStore(Patio.localRef("a"), Patio.intConst(42))) + .addBodyInstruction(Patio.localStore(Patio.localRef("b"), Patio.intConst(47))) + .addBodyInstruction(emitInt(Patio.localRef("a"))) + .addBodyInstruction(emitInt(Patio.localRef("b"))) + .addBodyInstruction(Patio.returnVoid()) + .build(); + var patio = Patio.compilationUnit(List.of( + patioFunction + )); + + var result = run(patio); + + assertThat(result, isSequence( + isInt(42), + isInt(47) + )); + } + + @Test public void canLoadDataElementInt() throws IOException, InterruptedException { var patioDataElement = new PatioDataElementImmutableDefinition( "answer", |
