diff options
author | Thomas Lively <tlively@google.com> | 2024-01-04 14:25:18 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-04 14:25:18 -0800 |
commit | a58281ca114359cd6e65f5daaf086636aa18b0b0 (patch) | |
tree | ff98bd31d1c87b598027c2303b17855a44346515 /test/unit/input | |
parent | 0ed42cf976ce9a3dfbe9cbb0885122e8fb6a377b (diff) | |
download | binaryen-a58281ca114359cd6e65f5daaf086636aa18b0b0.tar.gz binaryen-a58281ca114359cd6e65f5daaf086636aa18b0b0.tar.bz2 binaryen-a58281ca114359cd6e65f5daaf086636aa18b0b0.zip |
Require `then` and `else` with `if` (#6201)
We previously supported (and primarily used) a non-standard text format for
conditionals in which the condition, if-true expression, and if-false expression
were all simply s-expression children of the `if` expression. The standard text
format, however, requires the use of `then` and `else` forms to introduce the
if-true and if-false arms of the conditional. Update the legacy text parser to
require the standard format and update all tests to match. Update the printer to
print the standard format as well.
The .wast and .wat test inputs were mechanically updated with this script:
https://gist.github.com/tlively/85ae7f01f92f772241ec994c840ccbb1
Diffstat (limited to 'test/unit/input')
-rw-r--r-- | test/unit/input/asyncify-pure.wat | 24 | ||||
-rw-r--r-- | test/unit/input/asyncify-sleep.wat | 54 |
2 files changed, 51 insertions, 27 deletions
diff --git a/test/unit/input/asyncify-pure.wat b/test/unit/input/asyncify-pure.wat index 961ab9442..671a6cf24 100644 --- a/test/unit/input/asyncify-pure.wat +++ b/test/unit/input/asyncify-pure.wat @@ -23,17 +23,21 @@ (call $print (i32.const 1000)) (if (i32.eqz (global.get $sleeping)) - (block - (call $print (i32.const 2000)) - (global.set $sleeping (i32.const 1)) - (i32.store (i32.const 16) (i32.const 24)) - (i32.store (i32.const 20) (i32.const 1024)) - (call $asyncify_start_unwind (i32.const 16)) + (then + (block + (call $print (i32.const 2000)) + (global.set $sleeping (i32.const 1)) + (i32.store (i32.const 16) (i32.const 24)) + (i32.store (i32.const 20) (i32.const 1024)) + (call $asyncify_start_unwind (i32.const 16)) + ) ) - (block - (call $print (i32.const 3000)) - (call $asyncify_stop_rewind) - (global.set $sleeping (i32.const 0)) + (else + (block + (call $print (i32.const 3000)) + (call $asyncify_stop_rewind) + (global.set $sleeping (i32.const 0)) + ) ) ) (call $print (i32.const 4000)) diff --git a/test/unit/input/asyncify-sleep.wat b/test/unit/input/asyncify-sleep.wat index 6d54f5c07..8c31408da 100644 --- a/test/unit/input/asyncify-sleep.wat +++ b/test/unit/input/asyncify-sleep.wat @@ -53,9 +53,9 @@ (global.set $temp (i32.const 1)) ) (func $inner (param $x i32) - (if (i32.eqz (local.get $x)) (call $post)) - (if (local.get $x) (call $sleep)) - (if (i32.eqz (local.get $x)) (call $post)) + (if (i32.eqz (local.get $x)) (then (call $post))) + (if (local.get $x) (then (call $sleep))) + (if (i32.eqz (local.get $x)) (then (call $post))) ) (func $post (global.set $temp @@ -77,7 +77,9 @@ (local.get $x) (i32.const 1) ) - (return (i32.const 1)) + (then + (return (i32.const 1)) + ) ) (call $sleep) (return @@ -103,7 +105,9 @@ (local.get $i) (local.get $x) ) - (return (local.get $ret)) + (then + (return (local.get $ret)) + ) ) (local.set $ret (i32.mul @@ -164,28 +168,44 @@ ) (func $if_else (export "if_else") (param $x i32) (param $y i32) (result i32) (if (i32.eq (local.get $x) (i32.const 1)) - (local.set $y - (i32.add (local.get $y) (i32.const 10)) + (then + (local.set $y + (i32.add (local.get $y) (i32.const 10)) + ) ) - (local.set $y - (i32.add (local.get $y) (i32.const 20)) + (else + (local.set $y + (i32.add (local.get $y) (i32.const 20)) + ) ) ) (if (i32.eq (local.get $x) (i32.const 1)) - (local.set $y - (i32.add (local.get $y) (i32.const 40)) + (then + (local.set $y + (i32.add (local.get $y) (i32.const 40)) + ) + ) + (else + (call $sleep) ) - (call $sleep) ) (if (i32.eq (local.get $x) (i32.const 1)) - (call $sleep) - (local.set $y - (i32.add (local.get $y) (i32.const 90)) + (then + (call $sleep) + ) + (else + (local.set $y + (i32.add (local.get $y) (i32.const 90)) + ) ) ) (if (i32.eq (local.get $x) (i32.const 1)) - (call $sleep) - (call $sleep) + (then + (call $sleep) + ) + (else + (call $sleep) + ) ) (local.set $y (i32.add (local.get $y) (i32.const 160)) |