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

     1  ;; Test `loop` opcode
     2  
     3  (module
     4    (memory 1)
     5  
     6    (func $dummy)
     7  
     8    (func (export "empty")
     9      (loop)
    10      (loop $l)
    11    )
    12  
    13    (func (export "singular") (result i32)
    14      (loop (nop))
    15      (loop (result i32) (i32.const 7))
    16    )
    17  
    18    (func (export "multi") (result i32)
    19      (loop (call $dummy) (call $dummy) (call $dummy) (call $dummy))
    20      (loop (result i32) (call $dummy) (call $dummy) (i32.const 8) (call $dummy))
    21      (drop)
    22      (loop (result i32 i64 i32)
    23        (call $dummy) (call $dummy) (call $dummy) (i32.const 8) (call $dummy)
    24        (call $dummy) (call $dummy) (call $dummy) (i64.const 7) (call $dummy)
    25        (call $dummy) (call $dummy) (call $dummy) (i32.const 9) (call $dummy)
    26      )
    27      (drop) (drop)
    28    )
    29  
    30    (func (export "nested") (result i32)
    31      (loop (result i32)
    32        (loop (call $dummy) (block) (nop))
    33        (loop (result i32) (call $dummy) (i32.const 9))
    34      )
    35    )
    36  
    37    (func (export "deep") (result i32)
    38      (loop (result i32) (block (result i32)
    39        (loop (result i32) (block (result i32)
    40          (loop (result i32) (block (result i32)
    41            (loop (result i32) (block (result i32)
    42              (loop (result i32) (block (result i32)
    43                (loop (result i32) (block (result i32)
    44                  (loop (result i32) (block (result i32)
    45                    (loop (result i32) (block (result i32)
    46                      (loop (result i32) (block (result i32)
    47                        (loop (result i32) (block (result i32)
    48                          (loop (result i32) (block (result i32)
    49                            (loop (result i32) (block (result i32)
    50                              (loop (result i32) (block (result i32)
    51                                (loop (result i32) (block (result i32)
    52                                  (loop (result i32) (block (result i32)
    53                                    (loop (result i32) (block (result i32)
    54                                      (loop (result i32) (block (result i32)
    55                                        (loop (result i32) (block (result i32)
    56                                          (loop (result i32) (block (result i32)
    57                                            (loop (result i32) (block (result i32)
    58                                              (call $dummy) (i32.const 150)
    59                                            ))
    60                                          ))
    61                                        ))
    62                                      ))
    63                                    ))
    64                                  ))
    65                                ))
    66                              ))
    67                            ))
    68                          ))
    69                        ))
    70                      ))
    71                    ))
    72                  ))
    73                ))
    74              ))
    75            ))
    76          ))
    77        ))
    78      ))
    79    )
    80  
    81    (func (export "as-select-first") (result i32)
    82      (select (loop (result i32) (i32.const 1)) (i32.const 2) (i32.const 3))
    83    )
    84    (func (export "as-select-mid") (result i32)
    85      (select (i32.const 2) (loop (result i32) (i32.const 1)) (i32.const 3))
    86    )
    87    (func (export "as-select-last") (result i32)
    88      (select (i32.const 2) (i32.const 3) (loop (result i32) (i32.const 1)))
    89    )
    90  
    91    (func (export "as-if-condition")
    92      (loop (result i32) (i32.const 1)) (if (then (call $dummy)))
    93    )
    94    (func (export "as-if-then") (result i32)
    95      (if (result i32) (i32.const 1) (then (loop (result i32) (i32.const 1))) (else (i32.const 2)))
    96    )
    97    (func (export "as-if-else") (result i32)
    98      (if (result i32) (i32.const 1) (then (i32.const 2)) (else (loop (result i32) (i32.const 1))))
    99    )
   100  
   101    (func (export "as-br_if-first") (result i32)
   102      (block (result i32) (br_if 0 (loop (result i32) (i32.const 1)) (i32.const 2)))
   103    )
   104    (func (export "as-br_if-last") (result i32)
   105      (block (result i32) (br_if 0 (i32.const 2) (loop (result i32) (i32.const 1))))
   106    )
   107  
   108    (func (export "as-br_table-first") (result i32)
   109      (block (result i32) (loop (result i32) (i32.const 1)) (i32.const 2) (br_table 0 0))
   110    )
   111    (func (export "as-br_table-last") (result i32)
   112      (block (result i32) (i32.const 2) (loop (result i32) (i32.const 1)) (br_table 0 0))
   113    )
   114  
   115    (func $func (param i32 i32) (result i32) (local.get 0))
   116    (type $check (func (param i32 i32) (result i32)))
   117    (table funcref (elem $func))
   118    (func (export "as-call_indirect-first") (result i32)
   119      (block (result i32)
   120        (call_indirect (type $check)
   121          (loop (result i32) (i32.const 1)) (i32.const 2) (i32.const 0)
   122        )
   123      )
   124    )
   125    (func (export "as-call_indirect-mid") (result i32)
   126      (block (result i32)
   127        (call_indirect (type $check)
   128          (i32.const 2) (loop (result i32) (i32.const 1)) (i32.const 0)
   129        )
   130      )
   131    )
   132    (func (export "as-call_indirect-last") (result i32)
   133      (block (result i32)
   134        (call_indirect (type $check)
   135          (i32.const 1) (i32.const 2) (loop (result i32) (i32.const 0))
   136        )
   137      )
   138    )
   139  
   140    (func (export "as-store-first")
   141      (loop (result i32) (i32.const 1)) (i32.const 1) (i32.store)
   142    )
   143    (func (export "as-store-last")
   144      (i32.const 10) (loop (result i32) (i32.const 1)) (i32.store)
   145    )
   146  
   147    (func (export "as-memory.grow-value") (result i32)
   148      (memory.grow (loop (result i32) (i32.const 1)))
   149    )
   150  
   151    (func $f (param i32) (result i32) (local.get 0))
   152  
   153    (func (export "as-call-value") (result i32)
   154      (call $f (loop (result i32) (i32.const 1)))
   155    )
   156    (func (export "as-return-value") (result i32)
   157      (loop (result i32) (i32.const 1)) (return)
   158    )
   159    (func (export "as-drop-operand")
   160      (drop (loop (result i32) (i32.const 1)))
   161    )
   162    (func (export "as-br-value") (result i32)
   163      (block (result i32) (br 0 (loop (result i32) (i32.const 1))))
   164    )
   165    (func (export "as-local.set-value") (result i32)
   166      (local i32) (local.set 0 (loop (result i32) (i32.const 1))) (local.get 0)
   167    )
   168    (func (export "as-local.tee-value") (result i32)
   169      (local i32) (local.tee 0 (loop (result i32) (i32.const 1)))
   170    )
   171    (global $a (mut i32) (i32.const 0))
   172    (func (export "as-global.set-value") (result i32)
   173      (global.set $a (loop (result i32) (i32.const 1)))
   174      (global.get $a)
   175    )
   176    (func (export "as-load-operand") (result i32)
   177      (i32.load (loop (result i32) (i32.const 1)))
   178    )
   179  
   180    (func (export "as-unary-operand") (result i32)
   181      (i32.ctz (loop (result i32) (call $dummy) (i32.const 13)))
   182    )
   183    (func (export "as-binary-operand") (result i32)
   184      (i32.mul
   185        (loop (result i32) (call $dummy) (i32.const 3))
   186        (loop (result i32) (call $dummy) (i32.const 4))
   187      )
   188    )
   189    (func (export "as-test-operand") (result i32)
   190      (i32.eqz (loop (result i32) (call $dummy) (i32.const 13)))
   191    )
   192    (func (export "as-compare-operand") (result i32)
   193      (f32.gt
   194        (loop (result f32) (call $dummy) (f32.const 3))
   195        (loop (result f32) (call $dummy) (f32.const 3))
   196      )
   197    )
   198    (func (export "as-binary-operands") (result i32)
   199      (i32.mul
   200        (loop (result i32 i32)
   201          (call $dummy) (i32.const 3) (call $dummy) (i32.const 4)
   202        )
   203      )
   204    )
   205    (func (export "as-compare-operands") (result i32)
   206      (f32.gt
   207        (loop (result f32 f32)
   208          (call $dummy) (f32.const 3) (call $dummy) (f32.const 3)
   209        )
   210      )
   211    )
   212    (func (export "as-mixed-operands") (result i32)
   213      (loop (result i32 i32)
   214        (call $dummy) (i32.const 3) (call $dummy) (i32.const 4)
   215      )
   216      (i32.const 5)
   217      (i32.add)
   218      (i32.mul)
   219    )
   220  
   221    (func (export "break-bare") (result i32)
   222      (block (loop (br 1) (br 0) (unreachable)))
   223      (block (loop (br_if 1 (i32.const 1)) (unreachable)))
   224      (block (loop (br_table 1 (i32.const 0)) (unreachable)))
   225      (block (loop (br_table 1 1 1 (i32.const 1)) (unreachable)))
   226      (i32.const 19)
   227    )
   228    (func (export "break-value") (result i32)
   229      (block (result i32)
   230        (i32.const 0)
   231        (loop (param i32)
   232          (block (br 2 (i32.const 18)))
   233          (br 0 (i32.const 20))
   234        )
   235        (i32.const 19)
   236      )
   237    )
   238    (func (export "break-multi-value") (result i32 i32 i64)
   239      (block (result i32 i32 i64)
   240        (i32.const 0) (i32.const 0) (i64.const 0)
   241        (loop (param i32 i32 i64)
   242          (block (br 2 (i32.const 18) (i32.const -18) (i64.const 18)))
   243          (br 0 (i32.const 20) (i32.const -20) (i64.const 20))
   244        )
   245        (i32.const 19) (i32.const -19) (i64.const 19)
   246      )
   247    )
   248    (func (export "break-repeated") (result i32)
   249      (block (result i32)
   250        (loop (result i32)
   251          (br 1 (i32.const 18))
   252          (br 1 (i32.const 19))
   253          (drop (br_if 1 (i32.const 20) (i32.const 0)))
   254          (drop (br_if 1 (i32.const 20) (i32.const 1)))
   255          (br 1 (i32.const 21))
   256          (br_table 1 (i32.const 22) (i32.const 0))
   257          (br_table 1 1 1 (i32.const 23) (i32.const 1))
   258          (i32.const 21)
   259        )
   260      )
   261    )
   262    (func (export "break-inner") (result i32)
   263      (local i32)
   264      (local.set 0 (i32.const 0))
   265      (local.set 0 (i32.add (local.get 0) (block (result i32) (loop (result i32) (block (result i32) (br 2 (i32.const 0x1)))))))
   266      (local.set 0 (i32.add (local.get 0) (block (result i32) (loop (result i32) (loop (result i32) (br 2 (i32.const 0x2)))))))
   267      (local.set 0 (i32.add (local.get 0) (block (result i32) (loop (result i32) (block (result i32) (loop (result i32) (br 1 (i32.const 0x4))))))))
   268      (local.set 0 (i32.add (local.get 0) (block (result i32) (loop (result i32) (i32.ctz (br 1 (i32.const 0x8)))))))
   269      (local.set 0 (i32.add (local.get 0) (block (result i32) (loop (result i32) (i32.ctz (loop (result i32) (br 2 (i32.const 0x10))))))))
   270      (local.get 0)
   271    )
   272    (func (export "cont-inner") (result i32)
   273      (local i32)
   274      (local.set 0 (i32.const 0))
   275      (local.set 0 (i32.add (local.get 0) (loop (result i32) (loop (result i32) (br 1)))))
   276      (local.set 0 (i32.add (local.get 0) (loop (result i32) (i32.ctz (br 0)))))
   277      (local.set 0 (i32.add (local.get 0) (loop (result i32) (i32.ctz (loop (result i32) (br 1))))))
   278      (local.get 0)
   279    )
   280  
   281    (func (export "param") (result i32)
   282      (i32.const 1)
   283      (loop (param i32) (result i32)
   284        (i32.const 2)
   285        (i32.add)
   286      )
   287    )
   288    (func (export "params") (result i32)
   289      (i32.const 1)
   290      (i32.const 2)
   291      (loop (param i32 i32) (result i32)
   292        (i32.add)
   293      )
   294    )
   295    (func (export "params-id") (result i32)
   296      (i32.const 1)
   297      (i32.const 2)
   298      (loop (param i32 i32) (result i32 i32))
   299      (i32.add)
   300    )
   301    (func (export "param-break") (result i32)
   302      (local $x i32)
   303      (i32.const 1)
   304      (loop (param i32) (result i32)
   305        (i32.const 4)
   306        (i32.add)
   307        (local.tee $x)
   308        (local.get $x)
   309        (i32.const 10)
   310        (i32.lt_u)
   311        (br_if 0)
   312      )
   313    )
   314    (func (export "params-break") (result i32)
   315      (local $x i32)
   316      (i32.const 1)
   317      (i32.const 2)
   318      (loop (param i32 i32) (result i32)
   319        (i32.add)
   320        (local.tee $x)
   321        (i32.const 3)
   322        (local.get $x)
   323        (i32.const 10)
   324        (i32.lt_u)
   325        (br_if 0)
   326        (drop)
   327      )
   328    )
   329    (func (export "params-id-break") (result i32)
   330      (local $x i32)
   331      (local.set $x (i32.const 0))
   332      (i32.const 1)
   333      (i32.const 2)
   334      (loop (param i32 i32) (result i32 i32)
   335        (local.set $x (i32.add (local.get $x) (i32.const 1)))
   336        (br_if 0 (i32.lt_u (local.get $x) (i32.const 10)))
   337      )
   338      (i32.add)
   339    )
   340  
   341    (func $fx (export "effects") (result i32)
   342      (local i32)
   343      (block
   344        (loop
   345          (local.set 0 (i32.const 1))
   346          (local.set 0 (i32.mul (local.get 0) (i32.const 3)))
   347          (local.set 0 (i32.sub (local.get 0) (i32.const 5)))
   348          (local.set 0 (i32.mul (local.get 0) (i32.const 7)))
   349          (br 1)
   350          (local.set 0 (i32.mul (local.get 0) (i32.const 100)))
   351        )
   352      )
   353      (i32.eq (local.get 0) (i32.const -14))
   354    )
   355  
   356    (func (export "while") (param i64) (result i64)
   357      (local i64)
   358      (local.set 1 (i64.const 1))
   359      (block
   360        (loop
   361          (br_if 1 (i64.eqz (local.get 0)))
   362          (local.set 1 (i64.mul (local.get 0) (local.get 1)))
   363          (local.set 0 (i64.sub (local.get 0) (i64.const 1)))
   364          (br 0)
   365        )
   366      )
   367      (local.get 1)
   368    )
   369  
   370    (func (export "for") (param i64) (result i64)
   371      (local i64 i64)
   372      (local.set 1 (i64.const 1))
   373      (local.set 2 (i64.const 2))
   374      (block
   375        (loop
   376          (br_if 1 (i64.gt_u (local.get 2) (local.get 0)))
   377          (local.set 1 (i64.mul (local.get 1) (local.get 2)))
   378          (local.set 2 (i64.add (local.get 2) (i64.const 1)))
   379          (br 0)
   380        )
   381      )
   382      (local.get 1)
   383    )
   384  
   385    (func (export "nesting") (param f32 f32) (result f32)
   386      (local f32 f32)
   387      (block
   388        (loop
   389          (br_if 1 (f32.eq (local.get 0) (f32.const 0)))
   390          (local.set 2 (local.get 1))
   391          (block
   392            (loop
   393              (br_if 1 (f32.eq (local.get 2) (f32.const 0)))
   394              (br_if 3 (f32.lt (local.get 2) (f32.const 0)))
   395              (local.set 3 (f32.add (local.get 3) (local.get 2)))
   396              (local.set 2 (f32.sub (local.get 2) (f32.const 2)))
   397              (br 0)
   398            )
   399          )
   400          (local.set 3 (f32.div (local.get 3) (local.get 0)))
   401          (local.set 0 (f32.sub (local.get 0) (f32.const 1)))
   402          (br 0)
   403        )
   404      )
   405      (local.get 3)
   406    )
   407  
   408    (type $block-sig-1 (func))
   409    (type $block-sig-2 (func (result i32)))
   410    (type $block-sig-3 (func (param $x i32)))
   411    (type $block-sig-4 (func (param i32 f64 i32) (result i32 f64 i32)))
   412  
   413    (func (export "type-use")
   414      (loop (type $block-sig-1))
   415      (loop (type $block-sig-2) (i32.const 0))
   416      (loop (type $block-sig-3) (drop))
   417      (i32.const 0) (f64.const 0) (i32.const 0)
   418      (loop (type $block-sig-4))
   419      (drop) (drop) (drop)
   420      (loop (type $block-sig-2) (result i32) (i32.const 0))
   421      (loop (type $block-sig-3) (param i32) (drop))
   422      (i32.const 0) (f64.const 0) (i32.const 0)
   423      (loop (type $block-sig-4)
   424        (param i32) (param f64 i32) (result i32 f64) (result i32)
   425      )
   426      (drop) (drop) (drop)
   427    )
   428  )
   429  
   430  (assert_return (invoke "empty"))
   431  (assert_return (invoke "singular") (i32.const 7))
   432  (assert_return (invoke "multi") (i32.const 8))
   433  (assert_return (invoke "nested") (i32.const 9))
   434  (assert_return (invoke "deep") (i32.const 150))
   435  
   436  (assert_return (invoke "as-select-first") (i32.const 1))
   437  (assert_return (invoke "as-select-mid") (i32.const 2))
   438  (assert_return (invoke "as-select-last") (i32.const 2))
   439  
   440  (assert_return (invoke "as-if-condition"))
   441  (assert_return (invoke "as-if-then") (i32.const 1))
   442  (assert_return (invoke "as-if-else") (i32.const 2))
   443  
   444  (assert_return (invoke "as-br_if-first") (i32.const 1))
   445  (assert_return (invoke "as-br_if-last") (i32.const 2))
   446  
   447  (assert_return (invoke "as-br_table-first") (i32.const 1))
   448  (assert_return (invoke "as-br_table-last") (i32.const 2))
   449  
   450  (assert_return (invoke "as-call_indirect-first") (i32.const 1))
   451  (assert_return (invoke "as-call_indirect-mid") (i32.const 2))
   452  (assert_return (invoke "as-call_indirect-last") (i32.const 1))
   453  
   454  (assert_return (invoke "as-store-first"))
   455  (assert_return (invoke "as-store-last"))
   456  
   457  (assert_return (invoke "as-memory.grow-value") (i32.const 1))
   458  (assert_return (invoke "as-call-value") (i32.const 1))
   459  (assert_return (invoke "as-return-value") (i32.const 1))
   460  (assert_return (invoke "as-drop-operand"))
   461  (assert_return (invoke "as-br-value") (i32.const 1))
   462  (assert_return (invoke "as-local.set-value") (i32.const 1))
   463  (assert_return (invoke "as-local.tee-value") (i32.const 1))
   464  (assert_return (invoke "as-global.set-value") (i32.const 1))
   465  (assert_return (invoke "as-load-operand") (i32.const 1))
   466  
   467  (assert_return (invoke "as-unary-operand") (i32.const 0))
   468  (assert_return (invoke "as-binary-operand") (i32.const 12))
   469  (assert_return (invoke "as-test-operand") (i32.const 0))
   470  (assert_return (invoke "as-compare-operand") (i32.const 0))
   471  (assert_return (invoke "as-binary-operands") (i32.const 12))
   472  (assert_return (invoke "as-compare-operands") (i32.const 0))
   473  (assert_return (invoke "as-mixed-operands") (i32.const 27))
   474  
   475  (assert_return (invoke "break-bare") (i32.const 19))
   476  (assert_return (invoke "break-value") (i32.const 18))
   477  (assert_return (invoke "break-multi-value")
   478    (i32.const 18) (i32.const -18) (i64.const 18)
   479  )
   480  (assert_return (invoke "break-repeated") (i32.const 18))
   481  (assert_return (invoke "break-inner") (i32.const 0x1f))
   482  
   483  (assert_return (invoke "param") (i32.const 3))
   484  (assert_return (invoke "params") (i32.const 3))
   485  (assert_return (invoke "params-id") (i32.const 3))
   486  (assert_return (invoke "param-break") (i32.const 13))
   487  (assert_return (invoke "params-break") (i32.const 12))
   488  (assert_return (invoke "params-id-break") (i32.const 3))
   489  
   490  (assert_return (invoke "effects") (i32.const 1))
   491  
   492  (assert_return (invoke "while" (i64.const 0)) (i64.const 1))
   493  (assert_return (invoke "while" (i64.const 1)) (i64.const 1))
   494  (assert_return (invoke "while" (i64.const 2)) (i64.const 2))
   495  (assert_return (invoke "while" (i64.const 3)) (i64.const 6))
   496  (assert_return (invoke "while" (i64.const 5)) (i64.const 120))
   497  (assert_return (invoke "while" (i64.const 20)) (i64.const 2432902008176640000))
   498  
   499  (assert_return (invoke "for" (i64.const 0)) (i64.const 1))
   500  (assert_return (invoke "for" (i64.const 1)) (i64.const 1))
   501  (assert_return (invoke "for" (i64.const 2)) (i64.const 2))
   502  (assert_return (invoke "for" (i64.const 3)) (i64.const 6))
   503  (assert_return (invoke "for" (i64.const 5)) (i64.const 120))
   504  (assert_return (invoke "for" (i64.const 20)) (i64.const 2432902008176640000))
   505  
   506  (assert_return (invoke "nesting" (f32.const 0) (f32.const 7)) (f32.const 0))
   507  (assert_return (invoke "nesting" (f32.const 7) (f32.const 0)) (f32.const 0))
   508  (assert_return (invoke "nesting" (f32.const 1) (f32.const 1)) (f32.const 1))
   509  (assert_return (invoke "nesting" (f32.const 1) (f32.const 2)) (f32.const 2))
   510  (assert_return (invoke "nesting" (f32.const 1) (f32.const 3)) (f32.const 4))
   511  (assert_return (invoke "nesting" (f32.const 1) (f32.const 4)) (f32.const 6))
   512  (assert_return (invoke "nesting" (f32.const 1) (f32.const 100)) (f32.const 2550))
   513  (assert_return (invoke "nesting" (f32.const 1) (f32.const 101)) (f32.const 2601))
   514  (assert_return (invoke "nesting" (f32.const 2) (f32.const 1)) (f32.const 1))
   515  (assert_return (invoke "nesting" (f32.const 3) (f32.const 1)) (f32.const 1))
   516  (assert_return (invoke "nesting" (f32.const 10) (f32.const 1)) (f32.const 1))
   517  (assert_return (invoke "nesting" (f32.const 2) (f32.const 2)) (f32.const 3))
   518  (assert_return (invoke "nesting" (f32.const 2) (f32.const 3)) (f32.const 4))
   519  (assert_return (invoke "nesting" (f32.const 7) (f32.const 4)) (f32.const 10.3095235825))
   520  (assert_return (invoke "nesting" (f32.const 7) (f32.const 100)) (f32.const 4381.54785156))
   521  (assert_return (invoke "nesting" (f32.const 7) (f32.const 101)) (f32.const 2601))
   522  
   523  (assert_return (invoke "type-use"))
   524  
   525  (assert_malformed
   526    (module quote
   527      "(type $sig (func (param i32) (result i32)))"
   528      "(func (i32.const 0) (loop (type $sig) (result i32) (param i32)))"
   529    )
   530    "unexpected token"
   531  )
   532  (assert_malformed
   533    (module quote
   534      "(type $sig (func (param i32) (result i32)))"
   535      "(func (i32.const 0) (loop (param i32) (type $sig) (result i32)))"
   536    )
   537    "unexpected token"
   538  )
   539  (assert_malformed
   540    (module quote
   541      "(type $sig (func (param i32) (result i32)))"
   542      "(func (i32.const 0) (loop (param i32) (result i32) (type $sig)))"
   543    )
   544    "unexpected token"
   545  )
   546  (assert_malformed
   547    (module quote
   548      "(type $sig (func (param i32) (result i32)))"
   549      "(func (i32.const 0) (loop (result i32) (type $sig) (param i32)))"
   550    )
   551    "unexpected token"
   552  )
   553  (assert_malformed
   554    (module quote
   555      "(type $sig (func (param i32) (result i32)))"
   556      "(func (i32.const 0) (loop (result i32) (param i32) (type $sig)))"
   557    )
   558    "unexpected token"
   559  )
   560  (assert_malformed
   561    (module quote
   562      "(func (i32.const 0) (loop (result i32) (param i32)))"
   563    )
   564    "unexpected token"
   565  )
   566  
   567  (assert_malformed
   568    (module quote "(func (i32.const 0) (loop (param $x i32) (drop)))")
   569    "unexpected token"
   570  )
   571  (assert_malformed
   572    (module quote
   573      "(type $sig (func))"
   574      "(func (loop (type $sig) (result i32) (i32.const 0)) (unreachable))"
   575    )
   576    "inline function type"
   577  )
   578  (assert_malformed
   579    (module quote
   580      "(type $sig (func (param i32) (result i32)))"
   581      "(func (loop (type $sig) (result i32) (i32.const 0)) (unreachable))"
   582    )
   583    "inline function type"
   584  )
   585  (assert_malformed
   586    (module quote
   587      "(type $sig (func (param i32) (result i32)))"
   588      "(func (i32.const 0) (loop (type $sig) (param i32) (drop)) (unreachable))"
   589    )
   590    "inline function type"
   591  )
   592  (assert_malformed
   593    (module quote
   594      "(type $sig (func (param i32 i32) (result i32)))"
   595      "(func (i32.const 0) (loop (type $sig) (param i32) (result i32)) (unreachable))"
   596    )
   597    "inline function type"
   598  )
   599  
   600  (assert_invalid
   601    (module
   602      (type $sig (func))
   603      (func (loop (type $sig) (i32.const 0)))
   604    )
   605    "type mismatch"
   606  )
   607  
   608  (assert_invalid
   609    (module (func $type-empty-i32 (result i32) (loop)))
   610    "type mismatch"
   611  )
   612  (assert_invalid
   613    (module (func $type-empty-i64 (result i64) (loop)))
   614    "type mismatch"
   615  )
   616  (assert_invalid
   617    (module (func $type-empty-f32 (result f32) (loop)))
   618    "type mismatch"
   619  )
   620  (assert_invalid
   621    (module (func $type-empty-f64 (result f64) (loop)))
   622    "type mismatch"
   623  )
   624  
   625  (assert_invalid
   626    (module (func $type-value-num-vs-void
   627      (loop (i32.const 1))
   628    ))
   629    "type mismatch"
   630  )
   631  (assert_invalid
   632    (module (func $type-value-nums-vs-void
   633      (loop (i32.const 1) (i32.const 2))
   634    ))
   635    "type mismatch"
   636  )
   637  (assert_invalid
   638    (module (func $type-value-empty-vs-num (result i32)
   639      (loop (result i32))
   640    ))
   641    "type mismatch"
   642  )
   643  (assert_invalid
   644    (module (func $type-value-empty-vs-nums (result i32 i32)
   645      (loop (result i32 i32))
   646    ))
   647    "type mismatch"
   648  )
   649  (assert_invalid
   650    (module (func $type-value-void-vs-num (result i32)
   651      (loop (result i32) (nop))
   652    ))
   653    "type mismatch"
   654  )
   655  (assert_invalid
   656    (module (func $type-value-void-vs-nums (result i32 i32)
   657      (loop (result i32 i32) (nop))
   658    ))
   659    "type mismatch"
   660  )
   661  (assert_invalid
   662    (module (func $type-value-num-vs-num (result i32)
   663      (loop (result i32) (f32.const 0))
   664    ))
   665    "type mismatch"
   666  )
   667  (assert_invalid
   668    (module (func $type-value-num-vs-nums (result i32 i32)
   669      (loop (result i32 i32) (i32.const 0))
   670    ))
   671    "type mismatch"
   672  )
   673  (assert_invalid
   674    (module (func $type-value-partial-vs-nums (result i32 i32)
   675      (i32.const 1) (loop (result i32 i32) (i32.const 2))
   676    ))
   677    "type mismatch"
   678  )
   679  (assert_invalid
   680    (module (func $type-value-nums-vs-num (result i32)
   681      (loop (result i32) (i32.const 1) (i32.const 2))
   682    ))
   683    "type mismatch"
   684  )
   685  (assert_invalid
   686    (module (func $type-value-unreached-select (result i32)
   687      (loop (result i64) (select (unreachable) (unreachable) (unreachable)))
   688    ))
   689    "type mismatch"
   690  )
   691  
   692  (assert_invalid
   693    (module
   694      (func $type-value-empty-in-block
   695        (i32.const 0)
   696        (block (loop (result i32)) (drop))
   697      )
   698    )
   699    "type mismatch"
   700  )
   701  (assert_invalid
   702    (module
   703      (func $type-value-empty-in-loop
   704        (i32.const 0)
   705        (loop (loop (result i32)) (drop))
   706      )
   707    )
   708    "type mismatch"
   709  )
   710  (assert_invalid
   711    (module
   712      (func $type-value-empty-in-then
   713        (i32.const 0) (i32.const 0)
   714        (if (then (loop (result i32)) (drop)))
   715      )
   716    )
   717    "type mismatch"
   718  )
   719  
   720  (assert_invalid
   721    (module (func $type-param-void-vs-num
   722      (loop (param i32) (drop))
   723    ))
   724    "type mismatch"
   725  )
   726  (assert_invalid
   727    (module (func $type-param-void-vs-nums
   728      (loop (param i32 f64) (drop) (drop))
   729    ))
   730    "type mismatch"
   731  )
   732  (assert_invalid
   733    (module (func $type-param-num-vs-num
   734      (f32.const 0) (loop (param i32) (drop))
   735    ))
   736    "type mismatch"
   737  )
   738  (assert_invalid
   739    (module (func $type-param-num-vs-nums
   740      (f32.const 0) (loop (param f32 i32) (drop) (drop))
   741    ))
   742    "type mismatch"
   743  )
   744  (assert_invalid
   745    (module (func $type-param-nested-void-vs-num
   746      (block (loop (param i32) (drop)))
   747    ))
   748    "type mismatch"
   749  )
   750  (assert_invalid
   751    (module (func $type-param-void-vs-nums
   752      (block (loop (param i32 f64) (drop) (drop)))
   753    ))
   754    "type mismatch"
   755  )
   756  (assert_invalid
   757    (module (func $type-param-num-vs-num
   758      (block (f32.const 0) (loop (param i32) (drop)))
   759    ))
   760    "type mismatch"
   761  )
   762  (assert_invalid
   763    (module (func $type-param-num-vs-nums
   764      (block (f32.const 0) (loop (param f32 i32) (drop) (drop)))
   765    ))
   766    "type mismatch"
   767  )
   768  
   769  (assert_malformed
   770    (module quote "(func (param i32) (result i32) loop (param $x i32) end)")
   771    "unexpected token"
   772  )
   773  (assert_malformed
   774    (module quote "(func (param i32) (result i32) (loop (param $x i32)))")
   775    "unexpected token"
   776  )
   777  
   778  (assert_malformed
   779    (module quote "(func loop end $l)")
   780    "mismatching label"
   781  )
   782  (assert_malformed
   783    (module quote "(func loop $a end $l)")
   784    "mismatching label"
   785  )