From 7fbdae255cbaf850d88488deb6e2f58defd65f41 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Fri, 15 Dec 2023 11:16:06 +0000 Subject: Add code gen for Patio blocks --- .../shedlang/compiler/patio/PatioExampleTests.java | 24 ++++++++++++++++++++++ 1 file changed, 24 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 729b4b87..95354c51 100644 --- a/src/test/java/org/shedlang/compiler/patio/PatioExampleTests.java +++ b/src/test/java/org/shedlang/compiler/patio/PatioExampleTests.java @@ -68,6 +68,30 @@ public abstract class PatioExampleTests { assertThat(result, isSilentExit(47)); } + @Test + public void block() throws IOException, InterruptedException { + var patioFunction = PatioFunctionDefinition.builder() + .withName(FUNCTION_NAME) + .withReturnType(PatioTypes.INT) + .addLocal(Patio.val("x", PatioTypes.INT)) + .addBodyInstruction(Patio.block( + List.of( + Patio.localStore( + Patio.localRef("x"), + Patio.int_(42) + ) + ), + List.of(Patio.localRef("x")) + )) + .addBodyInstruction(Patio.return_(Patio.localRef("x"))) + .build(); + var patio = Patio.compilationUnit(List.of(patioFunction)); + + var result = run(patio); + + assertThat(result, isSilentExit(42)); + } + @Test public void intAdd() throws IOException, InterruptedException { var patioFunction = PatioFunctionDefinition.builder() -- cgit v1.2.3