aboutsummaryrefslogtreecommitdiff
path: root/src/test/java
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2023-10-08 16:49:03 +0100
committerMichael Williamson <mike@zwobble.org>2023-10-08 16:49:03 +0100
commitebf5f513c8305ae37d03d990fb24e5b7a6623244 (patch)
treeca6870038c420a6552618747a917973e2e49c344 /src/test/java
parent2e491ca13d1035e10f4c5ed51af3d5246596820d (diff)
Support Patio switch with reachable default in LLVM code gen
Diffstat (limited to 'src/test/java')
-rw-r--r--src/test/java/org/shedlang/compiler/patio/PatioExampleTests.java41
1 files changed, 40 insertions, 1 deletions
diff --git a/src/test/java/org/shedlang/compiler/patio/PatioExampleTests.java b/src/test/java/org/shedlang/compiler/patio/PatioExampleTests.java
index 265dfbde..d5e296c6 100644
--- a/src/test/java/org/shedlang/compiler/patio/PatioExampleTests.java
+++ b/src/test/java/org/shedlang/compiler/patio/PatioExampleTests.java
@@ -50,7 +50,7 @@ public abstract class PatioExampleTests {
@Test
@Disabled("WIP")
- public void switch_() throws IOException, InterruptedException {
+ public void switchWithUnreachableDefault() throws IOException, InterruptedException {
var patioFunction = PatioFunctionDefinition.builder()
.withName(FUNCTION_NAME)
.withReturnType(PatioTypes.INT)
@@ -95,6 +95,45 @@ public abstract class PatioExampleTests {
}
@Test
+ @Disabled("WIP")
+ public void switchWithReachableDefault() throws IOException, InterruptedException {
+ var patioFunction = PatioFunctionDefinition.builder()
+ .withName(FUNCTION_NAME)
+ .withReturnType(PatioTypes.INT)
+ .addLocal(Patio.val("x", PatioTypes.INT))
+ .addLocal(Patio.val("x1", PatioTypes.INT))
+ .addLocal(Patio.val("x2", PatioTypes.INT))
+ .addBodyInstruction(Patio.switch_(
+ List.of(Patio.localRef("x")),
+ Patio.int_(2),
+ List.of(
+ Patio.switchCase(
+ 1,
+ Patio.block(
+ List.of(
+ Patio.localStore(Patio.localRef("x1"), Patio.int_(42))
+ ),
+ List.of(Patio.localRef("x1"))
+ )
+ )
+ ),
+ Patio.block(
+ List.of(
+ Patio.localStore(Patio.localRef("x2"), Patio.int_(47))
+ ),
+ List.of(Patio.localRef("x2"))
+ )
+ ))
+ .addBodyInstruction(Patio.return_(Patio.localRef("x")))
+ .build();
+ var patio = Patio.compilationUnit(List.of(patioFunction));
+
+ var result = run(patio);
+
+ assertThat(result, isSilentExit(47));
+ }
+
+ @Test
public void vars() throws IOException, InterruptedException {
var patioFunction = PatioFunctionDefinition.builder()
.withName(FUNCTION_NAME)