diff options
| author | Michael Williamson <mike@zwobble.org> | 2023-12-27 16:07:04 +0000 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2023-12-27 16:07:04 +0000 |
| commit | 2dcdafd76ea85f03254b05d6d337d2cb99b58b98 (patch) | |
| tree | 095cd31659d6028e0d4a40f45bb58a5417803b32 /src/test/java | |
| parent | 12f23b59acc5ce9bfbf48accc71f32f282371e00 (diff) | |
Support bool-to-int and int-to-bool on wasm64
Diffstat (limited to 'src/test/java')
| -rw-r--r-- | src/test/java/org/shedlang/compiler/patio/PatioExampleTests.java | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/src/test/java/org/shedlang/compiler/patio/PatioExampleTests.java b/src/test/java/org/shedlang/compiler/patio/PatioExampleTests.java index 1a6813d4..db56958a 100644 --- a/src/test/java/org/shedlang/compiler/patio/PatioExampleTests.java +++ b/src/test/java/org/shedlang/compiler/patio/PatioExampleTests.java @@ -91,6 +91,78 @@ public abstract class PatioExampleTests { } @Test + public void boolToIntToBoolIsIdentityForFalse() throws IOException, InterruptedException { + var patioFunction = PatioFunctionDefinition.builder() + .withName(FUNCTION_NAME) + .withReturnType(PatioTypes.INT) + .addLocal(Patio.val("x", PatioTypes.BOOL)) + .addLocal(Patio.val("y", PatioTypes.INT)) + .addLocal(Patio.val("z", PatioTypes.BOOL)) + .addLocal(Patio.val("r", PatioTypes.INT)) + .addBodyInstruction(Patio.localStore( + Patio.localRef("x"), + Patio.bool(false) + )) + .addBodyInstruction(Patio.boolToInt( + Patio.localRef("y"), + Patio.localRef("x") + )) + .addBodyInstruction(Patio.intToBool( + Patio.localRef("z"), + Patio.localRef("y") + )) + .addBodyInstruction(Patio.if_( + List.of(Patio.localRef("r")), + Patio.localRef("z"), + Patio.block(List.of(), List.of(Patio.int_(42))), + Patio.block(List.of(), List.of(Patio.int_(47))) + )) + .addBodyInstruction(Patio.return_(Patio.localRef("r"))) + .build(); + var patio = Patio.compilationUnit(List.of(patioFunction)); + + var result = run(patio); + + assertThat(result, isSilentExit(47)); + } + + @Test + public void boolToIntToBoolIsIdentityForTrue() throws IOException, InterruptedException { + var patioFunction = PatioFunctionDefinition.builder() + .withName(FUNCTION_NAME) + .withReturnType(PatioTypes.INT) + .addLocal(Patio.val("x", PatioTypes.BOOL)) + .addLocal(Patio.val("y", PatioTypes.INT)) + .addLocal(Patio.val("z", PatioTypes.BOOL)) + .addLocal(Patio.val("r", PatioTypes.INT)) + .addBodyInstruction(Patio.localStore( + Patio.localRef("x"), + Patio.bool(true) + )) + .addBodyInstruction(Patio.boolToInt( + Patio.localRef("y"), + Patio.localRef("x") + )) + .addBodyInstruction(Patio.intToBool( + Patio.localRef("z"), + Patio.localRef("y") + )) + .addBodyInstruction(Patio.if_( + List.of(Patio.localRef("r")), + Patio.localRef("z"), + Patio.block(List.of(), List.of(Patio.int_(42))), + Patio.block(List.of(), List.of(Patio.int_(47))) + )) + .addBodyInstruction(Patio.return_(Patio.localRef("r"))) + .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() .withName(FUNCTION_NAME) |
