Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make br_if return its operands #330

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ml-proto/spec/check.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion ml-proto/spec/eval.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
46 changes: 21 additions & 25 deletions ml-proto/test/br_if.wast
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand All @@ -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))
)
)
)
Expand All @@ -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)
)
Expand All @@ -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)
)
)
Expand All @@ -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)
)
)
Expand All @@ -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)
Expand All @@ -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)
)
Expand All @@ -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))
Expand Down Expand Up @@ -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"
)
Expand Down
2 changes: 1 addition & 1 deletion ml-proto/test/func.wast
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
57 changes: 21 additions & 36 deletions ml-proto/test/labels.wast
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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"
)
2 changes: 1 addition & 1 deletion ml-proto/test/left-to-right.wast
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)
)
Expand Down
5 changes: 2 additions & 3 deletions ml-proto/test/nop.wast
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand Down