From d0052b8a59f75af5bbe1bb2adf0357b69d24f659 Mon Sep 17 00:00:00 2001 From: butterunderflow Date: Sun, 1 Dec 2024 12:01:19 +0800 Subject: [PATCH] cleanup --- src/main/scala/wasm/MiniWasmFX.scala | 3 +- src/test/scala/genwasym/TestFx.scala | 59 ++++++++++++++-------------- 2 files changed, 30 insertions(+), 32 deletions(-) diff --git a/src/main/scala/wasm/MiniWasmFX.scala b/src/main/scala/wasm/MiniWasmFX.scala index c4c0290e..9ab63249 100644 --- a/src/main/scala/wasm/MiniWasmFX.scala +++ b/src/main/scala/wasm/MiniWasmFX.scala @@ -228,9 +228,8 @@ case class EvaluatorFX(module: ModuleInstance) { // resumable try-catch exception handling: case TryCatch(es1, es2) => - // push trail1 to join point + // put trail1 into join point val join: MCont[Ans] = (newStack) => eval(rest, stack, frame, kont, trail1, mkont, trail2, h) - // todo: update comment here // here we clear the trail2, to forbid breaking out of the try-catch block val newHandler: Handler[Ans] = (newStack) => eval(es2, newStack, frame, init: Cont[Ans], List(), join, List(), h) eval(es1, List(), frame, init: Cont[Ans], List(), join, List(), newHandler) diff --git a/src/test/scala/genwasym/TestFx.scala b/src/test/scala/genwasym/TestFx.scala index c7a78b98..f5070047 100644 --- a/src/test/scala/genwasym/TestFx.scala +++ b/src/test/scala/genwasym/TestFx.scala @@ -127,11 +127,39 @@ class TestFx extends FunSuite { test("try-catch-block") { testFileOutput("./benchmarks/wasm/trycatch/try_catch_block.wat", List(1, 2, 3, 4, 5)) } + + test("try-catch-br2") { + testFileOutput("./benchmarks/wasm/trycatch/try_catch_br2.wat", List(1, 2, 6, 4, 5)) + } + + test("try-catch-br") { + // break out of try block is not allowed + assertThrows[IndexOutOfBoundsException] { + testFileOutput("./benchmarks/wasm/trycatch/try_catch_br.wat", List(1, 2, 6)) + } + } + + test("try-catch-throw-twice") { + testFileOutput("./benchmarks/wasm/trycatch/throw_twice.wat", List(1, 2, 6, 2, 3, 4, 4, 5)) + } - // Note: the interaction between try-catch and block is not well-defined yet + test("try-catch-throw-twice2") { + testFileOutput("./benchmarks/wasm/trycatch/throw_twice2.wat", List(1, 2, 6, 2, 3, 4, 4, 5)) + } + test("try-catch-br3") { + testFileOutput("./benchmarks/wasm/trycatch/try_catch_br3.wat", List(1, 2, 3, 4, 5)) + } + + test("try-catch-catch-br") { + testFileOutput("./benchmarks/wasm/trycatch/try_catch_catch_br.wat", List(1, 2, 6, 4, 6, 5)) + } /* REAL WASMFX STUFF */ + // TODO: test after implemented cont_bind3 + // test("simple script") { + // TestWastFile("./benchmarks/wasm/wasmfx/cont_bind3.bin.wast") + // } test("cont") { // testFile("./benchmarks/wasm/wasmfx/callcont.wast", None, ExpInt(11)) @@ -172,34 +200,5 @@ class TestFx extends FunSuite { test("cont_bind_5") { testWastFile("./benchmarks/wasm/wasmfx/cont_bind5.bin.wast") } - // test("test_cont") { - // testFile("./benchmarks/wasm/wasmfx/test_cont-strip.wast") - // } - - test("try-catch-br2") { - testFileOutput("./benchmarks/wasm/trycatch/try_catch_br2.wat", List(1, 2, 6, 4, 5)) - } - - test("try-catch-br") { - // break out of try block is not allowed - assertThrows[IndexOutOfBoundsException] { - testFileOutput("./benchmarks/wasm/trycatch/try_catch_br.wat", List(1, 2, 6)) - } - } - - test("try-catch-throw-twice") { - testFileOutput("./benchmarks/wasm/trycatch/throw_twice.wat", List(1, 2, 6, 2, 3, 4, 4, 5)) - } - test("try-catch-throw-twice2") { - testFileOutput("./benchmarks/wasm/trycatch/throw_twice2.wat", List(1, 2, 6, 2, 3, 4, 4, 5)) - } - - test("try-catch-br3") { - testFileOutput("./benchmarks/wasm/trycatch/try_catch_br3.wat", List(1, 2, 3, 4, 5)) - } - - test("try-catch-catch-br") { - testFileOutput("./benchmarks/wasm/trycatch/try_catch_catch_br.wat", List(1, 2, 6, 4, 6, 5)) - } }