From 2bdc4841b680ee44e132bbb07f5167eaa7226f99 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Wed, 27 Jan 2021 17:46:31 +0000 Subject: [GC] ref.as_* (#3520) These are similar to is, but instead of returning an i32 answer, they trap on an invalid value, and return it otherwise. These could in theory be in a single RefDoThing, with opcodes for both As and Is, but as the return values are different, that would be a little odd, and the name would be less clear. --- test/heap-types.wast | 5 +++++ test/heap-types.wast.from-wast | 19 ++++++++++++++++++- test/heap-types.wast.fromBinary | 19 ++++++++++++++++++- test/heap-types.wast.fromBinary.noDebugInfo | 19 ++++++++++++++++++- 4 files changed, 59 insertions(+), 3 deletions(-) (limited to 'test') diff --git a/test/heap-types.wast b/test/heap-types.wast index 614bbb1c5..a36f12daf 100644 --- a/test/heap-types.wast +++ b/test/heap-types.wast @@ -187,4 +187,9 @@ (if (ref.is_data (local.get $x)) (unreachable)) (if (ref.is_i31 (local.get $x)) (unreachable)) ) + (func $ref.as_X (param $x anyref) + (drop (ref.as_func (local.get $x))) + (drop (ref.as_data (local.get $x))) + (drop (ref.as_i31 (local.get $x))) + ) ) diff --git a/test/heap-types.wast.from-wast b/test/heap-types.wast.from-wast index b717de63f..4ff3bceec 100644 --- a/test/heap-types.wast.from-wast +++ b/test/heap-types.wast.from-wast @@ -3,8 +3,8 @@ (type $[mut:f64] (array (mut f64))) (type ${} (struct )) (type ${mut:f32} (struct (field (mut f32)))) - (type $none_=>_none (func)) (type $anyref_=>_none (func (param anyref))) + (type $none_=>_none (func)) (type ${i32} (struct (field i32))) (type ${i32_i64} (struct (field i32) (field i64))) (type $[mut:i32] (array (mut i32))) @@ -217,4 +217,21 @@ (unreachable) ) ) + (func $ref.as_X (param $x anyref) + (drop + (ref.as_func + (local.get $x) + ) + ) + (drop + (ref.as_data + (local.get $x) + ) + ) + (drop + (ref.as_i31 + (local.get $x) + ) + ) + ) ) diff --git a/test/heap-types.wast.fromBinary b/test/heap-types.wast.fromBinary index 5b6dca2f6..9f0220c53 100644 --- a/test/heap-types.wast.fromBinary +++ b/test/heap-types.wast.fromBinary @@ -3,8 +3,8 @@ (type $[mut:f64] (array (mut f64))) (type ${} (struct )) (type ${mut:f32} (struct (field (mut f32)))) - (type $none_=>_none (func)) (type $anyref_=>_none (func (param anyref))) + (type $none_=>_none (func)) (type ${i32} (struct (field i32))) (type ${i32_i64} (struct (field i32) (field i64))) (type $[mut:i32] (array (mut i32))) @@ -216,5 +216,22 @@ (unreachable) ) ) + (func $ref.as_X (param $x anyref) + (drop + (ref.as_func + (local.get $x) + ) + ) + (drop + (ref.as_data + (local.get $x) + ) + ) + (drop + (ref.as_i31 + (local.get $x) + ) + ) + ) ) diff --git a/test/heap-types.wast.fromBinary.noDebugInfo b/test/heap-types.wast.fromBinary.noDebugInfo index fef210e11..864d66abb 100644 --- a/test/heap-types.wast.fromBinary.noDebugInfo +++ b/test/heap-types.wast.fromBinary.noDebugInfo @@ -3,8 +3,8 @@ (type $[mut:f64] (array (mut f64))) (type ${} (struct )) (type ${mut:f32} (struct (field (mut f32)))) - (type $none_=>_none (func)) (type $anyref_=>_none (func (param anyref))) + (type $none_=>_none (func)) (type ${i32} (struct (field i32))) (type ${i32_i64} (struct (field i32) (field i64))) (type $[mut:i32] (array (mut i32))) @@ -216,5 +216,22 @@ (unreachable) ) ) + (func $6 (param $0 anyref) + (drop + (ref.as_func + (local.get $0) + ) + ) + (drop + (ref.as_data + (local.get $0) + ) + ) + (drop + (ref.as_i31 + (local.get $0) + ) + ) + ) ) -- cgit v1.2.3