From 1b59e24699a80030c317672d163da099500b9893 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Hillerstr=C3=B6m?= <daniel.hillerstrom@ed.ac.uk> Date: Tue, 16 Feb 2021 16:27:41 +0000 Subject: [PATCH] Adds missing success reduction for `catch`. Extends test suite too. --- interpreter/exec/eval.ml | 3 +++ test/core/tinyexn.wast | 22 ++++++++++++++++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/interpreter/exec/eval.ml b/interpreter/exec/eval.ml index 68e4b2e7..c44dd72d 100644 --- a/interpreter/exec/eval.ml +++ b/interpreter/exec/eval.ml @@ -646,6 +646,9 @@ let rec step (c : config) : config = | Catch (n, es1, (_, {it = Throwing; _} :: _)), vs -> vs, [Label (n, [], ([], List.map plain es1)) @@ e.at] + | Catch (_, _, (vs', [])), vs -> + vs' @ vs, [] + | Catch (n, es', code'), vs -> let c' = step {c with code = code'} in vs, [Catch (n, es', c'.code) @@ e.at] diff --git a/test/core/tinyexn.wast b/test/core/tinyexn.wast index 3c9f2db0..278b834c 100644 --- a/test/core/tinyexn.wast +++ b/test/core/tinyexn.wast @@ -7,7 +7,7 @@ throw i32.const 0) (catch - (i32.const 1)))) + i32.const 1))) (func (export "catch-2") (result i32) (try (result i32) @@ -20,7 +20,23 @@ throw i32.const 1))) (catch - (i32.const 2)))) + i32.const 2))) + + (func (export "success-0") (result i32) + (try (result i32) + (do i32.const 0) + (catch i32.const 1))) + + (func (export "success-1") (result i32) + (try (result i32) + (do + (try (result i32) + (do + throw + i32.const 0) + (catch + i32.const 1))) + (catch i32.const 2))) (func (export "uncaught") (throw)) @@ -28,4 +44,6 @@ (assert_return (invoke "catch-1") (i32.const 1)) (assert_return (invoke "catch-2") (i32.const 2)) +(assert_return (invoke "success-0") (i32.const 0)) +(assert_return (invoke "success-1") (i32.const 1)) (assert_uncaught (invoke "uncaught") "uncaught exception")