wa-lang.org/wazero@v1.0.2/internal/integration_test/spectest/v1/testdata/labels.wast (about)

     1  (module
     2    (func (export "block") (result i32)
     3      (block $exit (result i32)
     4        (br $exit (i32.const 1))
     5        (i32.const 0)
     6      )
     7    )
     8  
     9    (func (export "loop1") (result i32)
    10      (local $i i32)
    11      (local.set $i (i32.const 0))
    12      (block $exit (result i32)
    13        (loop $cont (result i32)
    14          (local.set $i (i32.add (local.get $i) (i32.const 1)))
    15          (if (i32.eq (local.get $i) (i32.const 5))
    16            (then (br $exit (local.get $i)))
    17          )
    18          (br $cont)
    19        )
    20      )
    21    )
    22  
    23    (func (export "loop2") (result i32)
    24      (local $i i32)
    25      (local.set $i (i32.const 0))
    26      (block $exit (result i32)
    27        (loop $cont (result i32)
    28          (local.set $i (i32.add (local.get $i) (i32.const 1)))
    29          (if (i32.eq (local.get $i) (i32.const 5))
    30            (then (br $cont))
    31          )
    32          (if (i32.eq (local.get $i) (i32.const 8))
    33            (then (br $exit (local.get $i)))
    34          )
    35          (local.set $i (i32.add (local.get $i) (i32.const 1)))
    36          (br $cont)
    37        )
    38      )
    39    )
    40  
    41    (func (export "loop3") (result i32)
    42      (local $i i32)
    43      (local.set $i (i32.const 0))
    44      (block $exit (result i32)
    45        (loop $cont (result i32)
    46          (local.set $i (i32.add (local.get $i) (i32.const 1)))
    47          (if (i32.eq (local.get $i) (i32.const 5))
    48            (then (br $exit (local.get $i)))
    49          )
    50          (local.get $i)
    51        )
    52      )
    53    )
    54  
    55    (func (export "loop4") (param $max i32) (result i32)
    56      (local $i i32)
    57      (local.set $i (i32.const 1))
    58      (block $exit (result i32)
    59        (loop $cont (result i32)
    60          (local.set $i (i32.add (local.get $i) (local.get $i)))
    61          (if (i32.gt_u (local.get $i) (local.get $max))
    62            (then (br $exit (local.get $i)))
    63          )
    64          (br $cont)
    65        )
    66      )
    67    )
    68  
    69    (func (export "loop5") (result i32)
    70      (i32.add
    71        (loop $l (result i32) (i32.const 1))
    72        (i32.const 1)
    73      )
    74    )
    75  
    76    (func (export "loop6") (result i32)
    77      (loop (result i32)
    78        (br_if 0 (i32.const 0))
    79        (i32.const 3)
    80      )
    81    )
    82  
    83    (func (export "if") (result i32)
    84      (local $i i32)
    85      (local.set $i (i32.const 0))
    86      (block
    87        (if $l
    88          (i32.const 1)
    89          (then (br $l) (local.set $i (i32.const 666)))
    90        )
    91        (local.set $i (i32.add (local.get $i) (i32.const 1)))
    92        (if $l
    93          (i32.const 1)
    94          (then (br $l) (local.set $i (i32.const 666)))
    95          (else (local.set $i (i32.const 888)))
    96        )
    97        (local.set $i (i32.add (local.get $i) (i32.const 1)))
    98        (if $l
    99          (i32.const 1)
   100          (then (br $l) (local.set $i (i32.const 666)))
   101          (else (local.set $i (i32.const 888)))
   102        )
   103        (local.set $i (i32.add (local.get $i) (i32.const 1)))
   104        (if $l
   105          (i32.const 0)
   106          (then (local.set $i (i32.const 888)))
   107          (else (br $l) (local.set $i (i32.const 666)))
   108        )
   109        (local.set $i (i32.add (local.get $i) (i32.const 1)))
   110        (if $l
   111          (i32.const 0)
   112          (then (local.set $i (i32.const 888)))
   113          (else (br $l) (local.set $i (i32.const 666)))
   114        )
   115        (local.set $i (i32.add (local.get $i) (i32.const 1)))
   116      )
   117      (local.get $i)
   118    )
   119  
   120    (func (export "if2") (result i32)
   121      (local $i i32)
   122      (local.set $i (i32.const 0))
   123      (block
   124        (if
   125          (i32.const 1)
   126          (then (br 0) (local.set $i (i32.const 666)))
   127        )
   128        (local.set $i (i32.add (local.get $i) (i32.const 1)))
   129        (if
   130          (i32.const 1)
   131          (then (br 0) (local.set $i (i32.const 666)))
   132          (else (local.set $i (i32.const 888)))
   133        )
   134        (local.set $i (i32.add (local.get $i) (i32.const 1)))
   135        (if
   136          (i32.const 1)
   137          (then (br 0) (local.set $i (i32.const 666)))
   138          (else (local.set $i (i32.const 888)))
   139        )
   140        (local.set $i (i32.add (local.get $i) (i32.const 1)))
   141        (if
   142          (i32.const 0)
   143          (then (local.set $i (i32.const 888)))
   144          (else (br 0) (local.set $i (i32.const 666)))
   145        )
   146        (local.set $i (i32.add (local.get $i) (i32.const 1)))
   147        (if
   148          (i32.const 0)
   149          (then (local.set $i (i32.const 888)))
   150          (else (br 0) (local.set $i (i32.const 666)))
   151        )
   152        (local.set $i (i32.add (local.get $i) (i32.const 1)))
   153      )
   154      (local.get $i)
   155    )
   156  
   157    (func (export "switch") (param i32) (result i32)
   158      (block $ret (result i32)
   159        (i32.mul (i32.const 10)
   160          (block $exit (result i32)
   161            (block $0
   162              (block $default
   163                (block $3
   164                  (block $2
   165                    (block $1
   166                      (br_table $0 $1 $2 $3 $default (local.get 0))
   167                    ) ;; 1
   168                  ) ;; 2
   169                  (br $exit (i32.const 2))
   170                ) ;; 3
   171                (br $ret (i32.const 3))
   172              ) ;; default
   173            ) ;; 0
   174            (i32.const 5)
   175          )
   176        )
   177      )
   178    )
   179  
   180    (func (export "return") (param i32) (result i32)
   181      (block $default
   182        (block $1
   183          (block $0
   184            (br_table $0 $1 (local.get 0))
   185            (br $default)
   186          ) ;; 0
   187          (return (i32.const 0))
   188        ) ;; 1
   189      ) ;; default
   190      (i32.const 2)
   191    )
   192  
   193    (func (export "br_if0") (result i32)
   194      (local $i i32)
   195      (local.set $i (i32.const 0))
   196      (block $outer (result i32)
   197        (block $inner
   198          (br_if $inner (i32.const 0))
   199          (local.set $i (i32.or (local.get $i) (i32.const 0x1)))
   200          (br_if $inner (i32.const 1))
   201          (local.set $i (i32.or (local.get $i) (i32.const 0x2)))
   202        )
   203        (drop (br_if $outer
   204          (block (result i32)
   205            (local.set $i (i32.or (local.get $i) (i32.const 0x4)))
   206            (local.get $i)
   207          )
   208          (i32.const 0)
   209        ))
   210        (local.set $i (i32.or (local.get $i) (i32.const 0x8)))
   211        (drop (br_if $outer
   212          (block (result i32)
   213            (local.set $i (i32.or (local.get $i) (i32.const 0x10)))
   214            (local.get $i)
   215          )
   216          (i32.const 1)
   217        ))
   218        (local.set $i (i32.or (local.get $i) (i32.const 0x20))) (local.get $i)
   219      )
   220    )
   221  
   222    (func (export "br_if1") (result i32)
   223      (block $l0 (result i32)
   224        (drop
   225          (br_if $l0
   226            (block $l1 (result i32) (br $l1 (i32.const 1)))
   227            (i32.const 1)
   228          )
   229        )
   230        (i32.const 0)
   231      )
   232    )
   233  
   234    (func (export "br_if2") (result i32)
   235      (block $l0 (result i32)
   236        (if (i32.const 1)
   237          (then
   238            (drop
   239              (br_if $l0
   240                (block $l1 (result i32) (br $l1 (i32.const 1)))
   241                (i32.const 1)
   242              )
   243            )
   244          )
   245        )
   246        (i32.const 0)
   247      )
   248    )
   249  
   250    (func (export "br_if3") (result i32)
   251      (local $i1 i32)
   252      (drop
   253        (i32.add
   254          (block $l0 (result i32)
   255            (drop (br_if $l0
   256              (block (result i32) (local.set $i1 (i32.const 1)) (local.get $i1))
   257              (block (result i32) (local.set $i1 (i32.const 2)) (local.get $i1))
   258            ))
   259            (i32.const 0)
   260          )
   261          (i32.const 0)
   262        )
   263      )
   264      (local.get $i1)
   265    )
   266  
   267    (func (export "br") (result i32)
   268      (block $l0 (result i32)
   269        (if (i32.const 1)
   270          (then (br $l0 (block $l1 (result i32) (br $l1 (i32.const 1)))))
   271          (else (block (drop (block $l1 (result i32) (br $l1 (i32.const 1))))))
   272        )
   273        (i32.const 1)
   274      )
   275    )
   276  
   277    (func (export "shadowing") (result i32)
   278      (block $l1 (result i32) (i32.xor (br $l1 (i32.const 1)) (i32.const 2)))
   279    )
   280  
   281    (func (export "redefinition") (result i32)
   282      (block $l1 (result i32)
   283        (i32.add
   284          (block $l1 (result i32) (i32.const 2))
   285          (block $l1 (result i32) (br $l1 (i32.const 3)))
   286        )
   287      )
   288    )
   289  )
   290  
   291  (assert_return (invoke "block") (i32.const 1))
   292  (assert_return (invoke "loop1") (i32.const 5))
   293  (assert_return (invoke "loop2") (i32.const 8))
   294  (assert_return (invoke "loop3") (i32.const 1))
   295  (assert_return (invoke "loop4" (i32.const 8)) (i32.const 16))
   296  (assert_return (invoke "loop5") (i32.const 2))
   297  (assert_return (invoke "loop6") (i32.const 3))
   298  (assert_return (invoke "if") (i32.const 5))
   299  (assert_return (invoke "if2") (i32.const 5))
   300  (assert_return (invoke "switch" (i32.const 0)) (i32.const 50))
   301  (assert_return (invoke "switch" (i32.const 1)) (i32.const 20))
   302  (assert_return (invoke "switch" (i32.const 2)) (i32.const 20))
   303  (assert_return (invoke "switch" (i32.const 3)) (i32.const 3))
   304  (assert_return (invoke "switch" (i32.const 4)) (i32.const 50))
   305  (assert_return (invoke "switch" (i32.const 5)) (i32.const 50))
   306  (assert_return (invoke "return" (i32.const 0)) (i32.const 0))
   307  (assert_return (invoke "return" (i32.const 1)) (i32.const 2))
   308  (assert_return (invoke "return" (i32.const 2)) (i32.const 2))
   309  (assert_return (invoke "br_if0") (i32.const 0x1d))
   310  (assert_return (invoke "br_if1") (i32.const 1))
   311  (assert_return (invoke "br_if2") (i32.const 1))
   312  (assert_return (invoke "br_if3") (i32.const 2))
   313  (assert_return (invoke "br") (i32.const 1))
   314  (assert_return (invoke "shadowing") (i32.const 1))
   315  (assert_return (invoke "redefinition") (i32.const 5))
   316  
   317  (assert_invalid
   318    (module (func (block $l (f32.neg (br_if $l (i32.const 1))) (nop))))
   319    "type mismatch"
   320  )
   321  (assert_invalid
   322    (module (func (block $l (br_if $l (f32.const 0) (i32.const 1)))))
   323    "type mismatch"
   324  )
   325  (assert_invalid
   326    (module (func (block $l (br_if $l (f32.const 0) (i32.const 1)))))
   327    "type mismatch"
   328  )