diff options
| author | Michael Williamson <mike@zwobble.org> | 2023-11-26 22:34:51 +0000 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2023-11-26 22:34:51 +0000 |
| commit | 0020edc8158445d408a8ed198e1e3fdd78b6454b (patch) | |
| tree | 7484becb2461ae36b04c4506f13d7bc15831fdfe /src/test/java | |
| parent | 9f7c92ba7dd23debfc37cf6f7f88b0dd8c926b05 (diff) | |
Support using thrown value in catch block
Diffstat (limited to 'src/test/java')
4 files changed, 50 insertions, 1 deletions
diff --git a/src/test/java/org/shedlang/compiler/backends/llvm/LlvmPatioCodeGenTests.java b/src/test/java/org/shedlang/compiler/backends/llvm/LlvmPatioCodeGenTests.java index 65db8040..58f3aa00 100644 --- a/src/test/java/org/shedlang/compiler/backends/llvm/LlvmPatioCodeGenTests.java +++ b/src/test/java/org/shedlang/compiler/backends/llvm/LlvmPatioCodeGenTests.java @@ -96,4 +96,10 @@ public class LlvmPatioCodeGenTests extends PatioExampleTests { public void exceptionHandlerIsDiscardedAfterTry() { } + + @Disabled("WIP") + @Test + public void thrownValueIsPassedToCatchClause() { + + } } diff --git a/src/test/java/org/shedlang/compiler/backends/wasm/WasmPatioCodeGenTests.java b/src/test/java/org/shedlang/compiler/backends/wasm/WasmPatioCodeGenTests.java index fe87bfc8..1ede4222 100644 --- a/src/test/java/org/shedlang/compiler/backends/wasm/WasmPatioCodeGenTests.java +++ b/src/test/java/org/shedlang/compiler/backends/wasm/WasmPatioCodeGenTests.java @@ -9,6 +9,7 @@ import org.shedlang.compiler.backends.wasm.structure.ast.modules.WasmImport; import org.shedlang.compiler.backends.wasm.structure.ast.modules.WasmImportDescriptor; import org.shedlang.compiler.backends.wasm.structure.ast.types.WasmFuncType; import org.shedlang.compiler.backends.wasm.structure.ast.types.WasmValueType; +import org.shedlang.compiler.backends.wasm.structure.binary.WasmBinaryFormatTesting; import org.shedlang.compiler.filesystem.ShedCompilerFiles; import org.shedlang.compiler.patio.PatioExampleTests; import org.shedlang.compiler.patio.ast.PatioCompilationUnit; @@ -62,6 +63,8 @@ public class WasmPatioCodeGenTests extends PatioExampleTests { executablePath ); + WasmBinaryFormatTesting.validate(executablePath); + return TestProcessRunner.runCaptureOutput(List.of( "node", "--experimental-wasi-unstable-preview1", diff --git a/src/test/java/org/shedlang/compiler/backends/wasm/structure/binary/WasmBinaryFormatTesting.java b/src/test/java/org/shedlang/compiler/backends/wasm/structure/binary/WasmBinaryFormatTesting.java index 9d11dd18..cc9fd5fa 100644 --- a/src/test/java/org/shedlang/compiler/backends/wasm/structure/binary/WasmBinaryFormatTesting.java +++ b/src/test/java/org/shedlang/compiler/backends/wasm/structure/binary/WasmBinaryFormatTesting.java @@ -30,7 +30,7 @@ public class WasmBinaryFormatTesting { return objdump(modulePath); } - private static void validate(Path path) throws IOException, InterruptedException { + public static void validate(Path path) throws IOException, InterruptedException { TestProcessRunner.runCaptureOutput(List.of("wasm-validate", "--enable-exceptions", path.toString())) .throwOnError(); } diff --git a/src/test/java/org/shedlang/compiler/patio/PatioExampleTests.java b/src/test/java/org/shedlang/compiler/patio/PatioExampleTests.java index e95fc3fc..729b4b87 100644 --- a/src/test/java/org/shedlang/compiler/patio/PatioExampleTests.java +++ b/src/test/java/org/shedlang/compiler/patio/PatioExampleTests.java @@ -515,6 +515,46 @@ public abstract class PatioExampleTests { } @Test + public void thrownValueIsPassedToCatchClause() throws IOException, InterruptedException { + var patioFunction = PatioFunctionDefinition.builder() + .withName(FUNCTION_NAME) + .withReturnType(PatioTypes.INT) + .addLocal(Patio.val("r", PatioTypes.INT)) + .addLocal(Patio.val("e", PatioTypes.INT)) + .addBodyInstruction(Patio.try_( + List.of(Patio.localRef("r")), + List.of( + Patio.catchClause( + "Error", + Patio.localRef("e"), + Patio.block( + List.of(), + List.of(Patio.localRef("e")) + ) + ) + ), + Patio.block( + List.of( + Patio.throw_("Error", Patio.int_(1)) + ), + List.of(Patio.int_(0)) + ) + )) + .addBodyInstruction(Patio.return_( + Patio.localRef("r") + )) + .build(); + var patio = Patio.compilationUnit(List.of( + Patio.exceptionTypeDefinition("Error", PatioTypes.INT), + patioFunction + )); + + var result = run(patio); + + assertThat(result, isSilentExit(1)); + } + + @Test public void vars() throws IOException, InterruptedException { var patioFunction = PatioFunctionDefinition.builder() .withName(FUNCTION_NAME) |
