controlflow.wast 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. ;;-------------------------------------------------------------------------------------------------------
  2. ;; Copyright (C) Microsoft. All rights reserved.
  3. ;; Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. ;;-------------------------------------------------------------------------------------------------------
  5. (module
  6. (func $c (result f32)
  7. (return (f32.const 1001.2)))
  8. (func $b (param i32) (result f32)
  9. (return
  10. (if f32 (get_local 0)
  11. (then (f32.const 1))
  12. (else (f32.const 2))
  13. )
  14. )
  15. )
  16. (func $a (export "a") (param i32) (result f32)
  17. (block f32 (call $b (get_local 0)) (call $c) (drop)))
  18. (func $e (param i32) (result i32)
  19. (i32.const 0))
  20. (func (export "yield_top") (param i32) (result i32)
  21. (block
  22. (return (i32.add
  23. (br_if 0 (i32.const 4) (get_local 0))
  24. (i32.const 3)
  25. ))
  26. )
  27. (i32.const 3)
  28. )
  29. (func (export "br_if") (param i32) (result i32)
  30. (block i32
  31. (block
  32. (br_if 1 (i32.const 4) (get_local 0))
  33. (drop)
  34. )
  35. (i32.const 3)
  36. )
  37. )
  38. (func (export "br") (result i32)
  39. (block
  40. (i32.const 4)
  41. (br 0)
  42. (drop)
  43. )
  44. (i32.const 3)
  45. )
  46. (func (export "block") (result i32)
  47. (i32.const 4)
  48. (block
  49. (i32.const 5)
  50. (br 0)
  51. (drop)
  52. )
  53. )
  54. )
  55. (assert_return (invoke "a" (i32.const 0)) (f32.const 2))
  56. (assert_return (invoke "a" (i32.const 1)) (f32.const 1))
  57. (assert_return (invoke "yield_top" (i32.const 0)) (i32.const 7))
  58. (assert_return (invoke "yield_top" (i32.const 1)) (i32.const 3))
  59. (assert_return (invoke "br_if" (i32.const 0)) (i32.const 3))
  60. (assert_return (invoke "br_if" (i32.const 1)) (i32.const 4))
  61. (assert_return (invoke "br") (i32.const 3))
  62. (assert_return (invoke "block") (i32.const 4))