From f26cd009c75f0ef19468ef44a1fae065e43b0eae Mon Sep 17 00:00:00 2001 From: Andreas Rossberg Date: Fri, 2 Sep 2016 13:07:11 +0200 Subject: [PATCH] Make br_if return its operands --- ml-proto/spec/check.ml | 2 +- ml-proto/spec/eval.ml | 2 +- ml-proto/test/br_if.wast | 46 ++++++++++++-------------- ml-proto/test/func.wast | 2 +- ml-proto/test/labels.wast | 57 ++++++++++++-------------------- ml-proto/test/left-to-right.wast | 2 +- ml-proto/test/nop.wast | 5 ++- 7 files changed, 48 insertions(+), 68 deletions(-) diff --git a/ml-proto/spec/check.ml b/ml-proto/spec/check.ml index a15d3131fb..0c4be1655a 100644 --- a/ml-proto/spec/check.ml +++ b/ml-proto/spec/check.ml @@ -192,7 +192,7 @@ let rec check_instr (c : context) (e : instr) (stack : stack_type) : op_type = check_arity n e.at; let ts = List.tl (peek_n (n + 1) stack) in unify (label c x) ts e.at; - (ts @ [I32Type]) --> Stack [] + (ts @ [I32Type]) --> Stack ts | BrTable (n, xs, x) -> check_arity n e.at; diff --git a/ml-proto/spec/eval.ml b/ml-proto/spec/eval.ml index 715d676abe..130a229a6c 100644 --- a/ml-proto/spec/eval.ml +++ b/ml-proto/spec/eval.ml @@ -140,7 +140,7 @@ let rec step_instr (c : config) (vs : value stack) (e : instr) assert false (* abrupt *) | BrIf (n, x), I32 0l :: vs' -> - drop n vs' e.at, [] + vs', [] | BrIf (n, x), I32 i :: vs' -> vs', [Br (n, x) @@ e.at] diff --git a/ml-proto/test/br_if.wast b/ml-proto/test/br_if.wast index 957cec4a4b..2ad79088b4 100644 --- a/ml-proto/test/br_if.wast +++ b/ml-proto/test/br_if.wast @@ -7,23 +7,22 @@ (block (br_if 0 (get_local 0)) (return (i32.const 2))) (i32.const 3) ) (func "as-block-mid" (param i32) (result i32) - (block (call $dummy) (br_if 0 (get_local 0)) (return (i32.const 2))) (i32.const 3) + (block (call $dummy) (br_if 0 (get_local 0)) (return (i32.const 2))) + (i32.const 3) ) (func "as-block-last" (param i32) (block (call $dummy) (call $dummy) (br_if 0 (get_local 0))) ) - (func "as-block-first-value" (param i32) (result i32) - (block (br_if 0 (i32.const 10) (get_local 0)) (i32.const 11)) - ) - (func "as-block-mid-value" (param i32) (result i32) - (block (call $dummy) (br_if 0 (i32.const 20) (get_local 0)) (i32.const 21)) + (func "as-block-last-value" (param i32) (result i32) + (block (call $dummy) (call $dummy) (br_if 0 (i32.const 11) (get_local 0))) ) (func "as-loop-first" (param i32) (result i32) - (loop (br_if 1 (i32.const 3) (get_local 0)) (i32.const 2)) + (block (loop (br_if 1 (get_local 0)) (return (i32.const 2)))) (i32.const 3) ) (func "as-loop-mid" (param i32) (result i32) - (loop (call $dummy) (br_if 1 (i32.const 4) (get_local 0)) (i32.const 2)) + (block (loop (call $dummy) (br_if 1 (get_local 0)) (return (i32.const 2)))) + (i32.const 4) ) (func "as-loop-last" (param i32) (loop (call $dummy) (br_if 1 (get_local 0))) @@ -43,7 +42,7 @@ (drop (i32.const 2)) (i32.add (i32.const 4) - (block (br_if 1 (i32.const 8) (get_local 0)) (i32.const 16)) + (block (drop (br_if 1 (i32.const 8) (get_local 0))) (i32.const 16)) ) ) ) @@ -55,7 +54,7 @@ (block (drop (i32.const 2)) (br 0 - (block (br_if 1 (i32.const 8) (get_local 0)) (i32.const 4)) + (block (drop (br_if 1 (i32.const 8) (get_local 0))) (i32.const 4)) ) (i32.const 16) ) @@ -67,10 +66,10 @@ (i32.const 1) (block (drop (i32.const 2)) - (br_if 0 - (block (br_if 1 (i32.const 8) (get_local 0)) (i32.const 4)) + (drop (br_if 0 + (block (drop (br_if 1 (i32.const 8) (get_local 0))) (i32.const 4)) (i32.const 1) - ) + )) (i32.const 16) ) ) @@ -81,10 +80,10 @@ (i32.const 1) (block (drop (i32.const 2)) - (br_if 0 + (drop (br_if 0 (i32.const 4) - (block (br_if 1 (i32.const 8) (get_local 0)) (i32.const 1)) - ) + (block (drop (br_if 1 (i32.const 8) (get_local 0))) (i32.const 1)) + )) (i32.const 16) ) ) @@ -96,7 +95,7 @@ (block (drop (i32.const 2)) (br_table 0 - (block (br_if 1 (i32.const 8) (get_local 0)) (i32.const 4)) + (block (drop (br_if 1 (i32.const 8) (get_local 0))) (i32.const 4)) (i32.const 1) ) (i32.const 16) @@ -111,7 +110,7 @@ (drop (i32.const 2)) (br_table 0 (i32.const 4) - (block (br_if 1 (i32.const 8) (get_local 0)) (i32.const 1)) + (block (drop (br_if 1 (i32.const 8) (get_local 0))) (i32.const 1)) ) (i32.const 16) ) @@ -125,11 +124,8 @@ (assert_return (invoke "as-block-mid" (i32.const 1)) (i32.const 3)) (assert_return (invoke "as-block-last" (i32.const 0))) (assert_return (invoke "as-block-last" (i32.const 1))) - -(assert_return (invoke "as-block-first-value" (i32.const 0)) (i32.const 11)) -(assert_return (invoke "as-block-first-value" (i32.const 1)) (i32.const 10)) -(assert_return (invoke "as-block-mid-value" (i32.const 0)) (i32.const 21)) -(assert_return (invoke "as-block-mid-value" (i32.const 1)) (i32.const 20)) +(assert_return (invoke "as-block-last-value" (i32.const 0)) (i32.const 11)) +(assert_return (invoke "as-block-last-value" (i32.const 1)) (i32.const 11)) (assert_return (invoke "as-loop-first" (i32.const 0)) (i32.const 2)) (assert_return (invoke "as-loop-first" (i32.const 1)) (i32.const 3)) @@ -259,13 +255,13 @@ ) (assert_invalid (module (func $type-false-arg-num-vs-num (result i32) - (block (br_if 0 (i64.const 1) (i32.const 0)) (i32.const 1)) + (block (drop (br_if 0 (i64.const 1) (i32.const 0))) (i32.const 1)) )) "type mismatch" ) (assert_invalid (module (func $type-true-arg-num-vs-num (result i32) - (block (br_if 0 (i64.const 1) (i32.const 0)) (i32.const 1)) + (block (drop (br_if 0 (i64.const 1) (i32.const 0))) (i32.const 1)) )) "type mismatch" ) diff --git a/ml-proto/test/func.wast b/ml-proto/test/func.wast index 5bbb40077e..442f2e70bb 100644 --- a/ml-proto/test/func.wast +++ b/ml-proto/test/func.wast @@ -120,7 +120,7 @@ (br_if 0 (get_local 0)) ) (func "break-br_if-num" (param i32) (result i32) - (br_if 0 (i32.const 50) (get_local 0)) (i32.const 51) + (drop (br_if 0 (i32.const 50) (get_local 0))) (i32.const 51) ) (func "break-br_table-empty" (param i32) diff --git a/ml-proto/test/labels.wast b/ml-proto/test/labels.wast index 3e511ac405..b13be54d03 100644 --- a/ml-proto/test/labels.wast +++ b/ml-proto/test/labels.wast @@ -193,39 +193,44 @@ (br_if $inner (i32.const 1)) (set_local $i (i32.or (get_local $i) (i32.const 0x2))) ) - (br_if $outer - (block (set_local $i (i32.or (get_local $i) (i32.const 0x4))) (get_local $i)) (i32.const 0) - ) + (drop (br_if $outer + (block (set_local $i (i32.or (get_local $i) (i32.const 0x4))) (get_local $i)) + (i32.const 0) + )) (set_local $i (i32.or (get_local $i) (i32.const 0x8))) - (br_if $outer - (block (set_local $i (i32.or (get_local $i) (i32.const 0x10))) (get_local $i)) (i32.const 1) - ) + (drop (br_if $outer + (block (set_local $i (i32.or (get_local $i) (i32.const 0x10))) (get_local $i)) + (i32.const 1) + )) (set_local $i (i32.or (get_local $i) (i32.const 0x20))) (get_local $i) ) ) (func $br_if1 (result i32) (block $l0 - (br_if $l0 (block $l1 (br $l1 (i32.const 1))) (i32.const 1)) - (i32.const 1))) + (drop (br_if $l0 (block $l1 (br $l1 (i32.const 1))) (i32.const 1))) + (i32.const 1) + ) + ) (func $br_if2 (result i32) (block $l0 (if (i32.const 1) - (br $l0 - (block $l1 - (br $l1 (i32.const 1))))) - (i32.const 1))) + (br $l0 (block $l1 (br $l1 (i32.const 1)))) + ) + (i32.const 1) + ) + ) (func $br_if3 (result i32) (local $i1 i32) (drop (i32.add (block $l0 - (br_if $l0 + (drop (br_if $l0 (block (set_local $i1 (i32.const 1)) (get_local $i1)) (block (set_local $i1 (i32.const 2)) (get_local $i1)) - ) + )) (i32.const 0) ) (i32.const 0) @@ -312,30 +317,10 @@ "type mismatch" ) (assert_invalid - (module (func (result f32) (block $l (br_if $l (f32.const 0) (i32.const 1))))) + (module (func (block $l (br_if $l (f32.const 0) (i32.const 1))))) "type mismatch" ) (assert_invalid - (module (func (result i32) (block $l (br_if $l (f32.const 0) (i32.const 1))))) - "type mismatch" -) -(assert_invalid - (module (func (block $l (f32.neg (br_if $l (f32.const 0) (i32.const 1)))))) - "type mismatch" -) -(assert_invalid - (module - (func (param i32) (result i32) - (block $l (f32.neg (br_if $l (f32.const 0) (get_local 0)))) - ) - ) - "type mismatch" -) -(assert_invalid - (module - (func (param i32) (result f32) - (block $l (f32.neg (block $i (br_if $l (f32.const 3) (get_local 0))))) - ) - ) + (module (func (block $l (br_if $l (f32.const 0) (i32.const 1))))) "type mismatch" ) diff --git a/ml-proto/test/left-to-right.wast b/ml-proto/test/left-to-right.wast index dc3ed2f623..b990e98b34 100644 --- a/ml-proto/test/left-to-right.wast +++ b/ml-proto/test/left-to-right.wast @@ -161,7 +161,7 @@ (func $br_if (result i32) (block (call $reset) - (br_if 0 (call $i32_left) (i32.and (call $i32_right) (i32.const 0))) + (drop (br_if 0 (call $i32_left) (i32.and (call $i32_right) (i32.const 0)))) (call $get) ) ) diff --git a/ml-proto/test/nop.wast b/ml-proto/test/nop.wast index bde3b7d63b..a6c2f729c6 100644 --- a/ml-proto/test/nop.wast +++ b/ml-proto/test/nop.wast @@ -86,15 +86,14 @@ ) (func "as-br_if-mid" (param i32) (result i32) - block (get_local 0) (nop) (get_local 0) br_if 1 0 (i32.const 0) end + block (get_local 0) (nop) (get_local 0) br_if 1 0 end ) (func "as-br_if-last" (param i32) (result i32) - block (get_local 0) (get_local 0) (nop) br_if 1 0 (i32.const 0) end + block (get_local 0) (get_local 0) (nop) br_if 1 0 end ) (func "as-br_if-everywhere" (param i32) (result i32) block (nop) (nop) (get_local 0) (nop) (nop) (get_local 0) (nop) (nop) br_if 1 0 - (i32.const 0) end )