summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorHeejin Ahn <aheejin@gmail.com>2020-05-06 16:38:37 -0700
committerGitHub <noreply@github.com>2020-05-06 16:38:37 -0700
commit5585d3a46f2b1daf74d4a7cf7b1d9a17b102b05c (patch)
tree19718aa2c531542e67165b5062aa97ddcf2e9037 /test
parent33ee4ccd4985ab134bf48dac4088131105290fee (diff)
downloadbinaryen-5585d3a46f2b1daf74d4a7cf7b1d9a17b102b05c.tar.gz
binaryen-5585d3a46f2b1daf74d4a7cf7b1d9a17b102b05c.tar.bz2
binaryen-5585d3a46f2b1daf74d4a7cf7b1d9a17b102b05c.zip
Add interpreter support for EH (#2780)
This adds interpreter support for EH instructions. This adds `ExceptionPackage` struct, which contains info of a thrown exception (an event tag and thrown values), and the union in `Literal` can take a `unique_ptr` to `ExceptionPackage`. We need a destructor, a copy constructor, and an assignment operator for `Literal`, because the union in `Literal` now has a member that cannot be trivially copied or deleted.
Diffstat (limited to 'test')
-rw-r--r--test/spec/exception-handling.wast191
1 files changed, 169 insertions, 22 deletions
diff --git a/test/spec/exception-handling.wast b/test/spec/exception-handling.wast
index 6e0ca9055..d8ae48631 100644
--- a/test/spec/exception-handling.wast
+++ b/test/spec/exception-handling.wast
@@ -1,39 +1,186 @@
(module
- (event $e0 (attr 0) (param i32))
- (event $e1 (attr 0) (param i32 f32))
+ (event $e-v (attr 0))
+ (event $e-i32 (attr 0) (param i32))
+ (event $e-i32-f32 (attr 0) (param i32 f32))
- (func (export "throw_test")
- (throw $e0 (i32.const 0))
+ (func $throw_single_value (export "throw_single_value")
+ (throw $e-i32 (i32.const 5))
)
- (func (export "rethrow_test")
+ (func (export "throw_multiple_values")
+ (throw $e-i32-f32 (i32.const 3) (f32.const 3.5))
+ )
+
+ (func (export "rethrow_nullref")
(rethrow (ref.null))
)
- (func (export "try_test") (result i32)
+ (func (export "try_nothrow") (result i32)
(try (result i32)
(i32.const 3)
(catch
(drop (exnref.pop))
+ (i32.const 0)
+ )
+ )
+ )
+
+ (func (export "try_throw_catch") (result i32)
+ (try (result i32)
+ (throw $e-i32 (i32.const 5))
+ (catch
+ (drop (exnref.pop))
(i32.const 3)
)
)
)
- (func (export "br_on_exn_test") (result i32)
+ (func (export "try_call_catch") (result i32)
+ (try (result i32)
+ (block
+ (call $throw_single_value)
+ (unreachable)
+ )
+ (catch
+ (drop (exnref.pop))
+ (i32.const 3)
+ )
+ )
+ )
+
+ (func (export "try_throw_rethrow")
+ (try
+ (throw $e-i32 (i32.const 5))
+ (catch
+ (rethrow (exnref.pop))
+ )
+ )
+ )
+
+ (func $try_call_rethrow (export "try_call_rethrow")
+ (try
+ (call $throw_single_value)
+ (catch
+ (rethrow (exnref.pop))
+ )
+ )
+ )
+
+ (func (export "br_on_exn_nullref") (result i32)
(block $l0 (result i32)
(drop
- (br_on_exn $l0 $e0 (ref.null))
+ (br_on_exn $l0 $e-i32 (ref.null))
)
(i32.const 0)
)
)
+
+ (func (export "br_on_exn_match_no_value") (local $exn exnref)
+ (try
+ (throw $e-v)
+ (catch
+ (local.set $exn (exnref.pop))
+ (block $l0
+ (rethrow
+ (br_on_exn $l0 $e-v (local.get $exn))
+ )
+ )
+ )
+ )
+ )
+
+ (func (export "br_on_exn_match_single_value") (result i32) (local $exn exnref)
+ (try (result i32)
+ (throw $e-i32 (i32.const 5))
+ (catch
+ (local.set $exn (exnref.pop))
+ (block $l0 (result i32)
+ (rethrow
+ (br_on_exn $l0 $e-i32 (local.get $exn))
+ )
+ )
+ )
+ )
+ )
+
+ (func (export "br_on_exn_match_multiple_values") (result i32 f32)
+ (local $exn exnref)
+ (try (result i32 f32)
+ (throw $e-i32-f32 (i32.const 3) (f32.const 3.5))
+ (catch
+ (local.set $exn (exnref.pop))
+ (block $l0 (result i32 f32)
+ (rethrow
+ (br_on_exn $l0 $e-i32-f32 (local.get $exn))
+ )
+ )
+ )
+ )
+ )
+
+ (func (export "br_on_exn_dont_match") (local $exn exnref)
+ (try
+ (throw $e-i32 (i32.const 5))
+ (catch
+ (local.set $exn (exnref.pop))
+ (block $l0
+ (rethrow
+ (br_on_exn $l0 $e-v (local.get $exn))
+ )
+ )
+ )
+ )
+ )
+
+ (func (export "call_br_on_exn") (result i32) (local $exn exnref)
+ (try (result i32)
+ (block
+ (call $throw_single_value)
+ (unreachable)
+ )
+ (catch
+ (local.set $exn (exnref.pop))
+ (block $l0 (result i32)
+ (rethrow
+ (br_on_exn $l0 $e-i32 (local.get $exn))
+ )
+ )
+ )
+ )
+ )
+
+ (func (export "call_rethrow_br_on_exn") (result i32) (local $exn exnref)
+ (try (result i32)
+ (block
+ (call $try_call_rethrow)
+ (unreachable)
+ )
+ (catch
+ (local.set $exn (exnref.pop))
+ (block $l0 (result i32)
+ (rethrow
+ (br_on_exn $l0 $e-i32 (local.get $exn))
+ )
+ )
+ )
+ )
+ )
)
-(assert_trap (invoke "throw_test"))
-(assert_trap (invoke "rethrow_test"))
-(assert_return (invoke "try_test") (i32.const 3))
-(assert_trap (invoke "br_on_exn_test"))
+(assert_trap (invoke "throw_single_value"))
+(assert_trap (invoke "throw_multiple_values"))
+(assert_trap (invoke "rethrow_nullref"))
+(assert_return (invoke "try_nothrow") (i32.const 3))
+(assert_return (invoke "try_throw_catch") (i32.const 3))
+(assert_return (invoke "try_call_catch") (i32.const 3))
+(assert_trap (invoke "try_throw_rethrow"))
+(assert_trap (invoke "try_call_rethrow"))
+(assert_trap (invoke "br_on_exn_nullref"))
+(assert_return (invoke "br_on_exn_match_no_value"))
+(assert_return (invoke "br_on_exn_match_single_value") (i32.const 5))
+(assert_return (invoke "br_on_exn_match_multiple_values") (tuple.make (i32.const 3) (f32.const 3.5)))
+(assert_trap (invoke "br_on_exn_dont_match"))
+(assert_return (invoke "call_rethrow_br_on_exn") (i32.const 5))
(assert_invalid
(module
@@ -61,9 +208,9 @@
(assert_invalid
(module
- (event $e0 (attr 0) (param i32))
+ (event $e-i32 (attr 0) (param i32))
(func $f0
- (throw $e0 (f32.const 0))
+ (throw $e-i32 (f32.const 0))
)
)
"event param types must match"
@@ -71,9 +218,9 @@
(assert_invalid
(module
- (event $e0 (attr 0) (param i32 f32))
+ (event $e-i32 (attr 0) (param i32 f32))
(func $f0
- (throw $e0 (f32.const 0))
+ (throw $e-i32 (f32.const 0))
)
)
"event's param numbers must match"
@@ -90,11 +237,11 @@
(assert_invalid
(module
- (event $e0 (attr 0) (param i32))
+ (event $e-i32 (attr 0) (param i32))
(func $f0 (result i32)
(block $l0 (result i32)
(drop
- (br_on_exn $l0 $e0 (i32.const 0))
+ (br_on_exn $l0 $e-i32 (i32.const 0))
)
(i32.const 0)
)
@@ -105,11 +252,11 @@
(assert_invalid
(module
- (event $e0 (attr 0) (param i32))
+ (event $e-i32 (attr 0) (param i32))
(func $f0 (result i32) (local $0 exnref)
(block $l0 (result i32)
(i32.eqz
- (br_on_exn $l0 $e0 (local.get $0))
+ (br_on_exn $l0 $e-i32 (local.get $0))
)
)
)
@@ -119,11 +266,11 @@
(assert_invalid
(module
- (event $e0 (attr 0) (param i32))
+ (event $e-i32 (attr 0) (param i32))
(func $f0 (result f32) (local $0 exnref)
(block $l0 (result f32)
(drop
- (br_on_exn $l0 $e0 (local.get $0))
+ (br_on_exn $l0 $e-i32 (local.get $0))
)
(f32.const 0)
)