github.com/tetratelabs/wazero@v1.7.1/internal/integration_test/spectest/v2/testdata/imports.wast (about)

     1  ;; Auxiliary module to import from
     2  
     3  (module
     4    (func (export "func"))
     5    (func (export "func-i32") (param i32))
     6    (func (export "func-f32") (param f32))
     7    (func (export "func->i32") (result i32) (i32.const 22))
     8    (func (export "func->f32") (result f32) (f32.const 11))
     9    (func (export "func-i32->i32") (param i32) (result i32) (local.get 0))
    10    (func (export "func-i64->i64") (param i64) (result i64) (local.get 0))
    11    (global (export "global-i32") i32 (i32.const 55))
    12    (global (export "global-f32") f32 (f32.const 44))
    13    (global (export "global-mut-i64") (mut i64) (i64.const 66))
    14    (table (export "table-10-inf") 10 funcref)
    15    (table (export "table-10-20") 10 20 funcref)
    16    (memory (export "memory-2-inf") 2)
    17    ;; Multiple memories are not yet supported
    18    ;; (memory (export "memory-2-4") 2 4)
    19  )
    20  
    21  (register "test")
    22  
    23  
    24  ;; Functions
    25  
    26  (module
    27    (type $func_i32 (func (param i32)))
    28    (type $func_i64 (func (param i64)))
    29    (type $func_f32 (func (param f32)))
    30    (type $func_f64 (func (param f64)))
    31  
    32    (import "spectest" "print_i32" (func (param i32)))
    33    (func (import "spectest" "print_i64") (param i64))
    34    (import "spectest" "print_i32" (func $print_i32 (param i32)))
    35    (import "spectest" "print_i64" (func $print_i64 (param i64)))
    36    (import "spectest" "print_f32" (func $print_f32 (param f32)))
    37    (import "spectest" "print_f64" (func $print_f64 (param f64)))
    38    (import "spectest" "print_i32_f32" (func $print_i32_f32 (param i32 f32)))
    39    (import "spectest" "print_f64_f64" (func $print_f64_f64 (param f64 f64)))
    40    (func $print_i32-2 (import "spectest" "print_i32") (param i32))
    41    (func $print_f64-2 (import "spectest" "print_f64") (param f64))
    42    (import "test" "func-i64->i64" (func $i64->i64 (param i64) (result i64)))
    43  
    44    (func (export "p1") (import "spectest" "print_i32") (param i32))
    45    (func $p (export "p2") (import "spectest" "print_i32") (param i32))
    46    (func (export "p3") (export "p4") (import "spectest" "print_i32") (param i32))
    47    (func (export "p5") (import "spectest" "print_i32") (type 0))
    48    (func (export "p6") (import "spectest" "print_i32") (type 0) (param i32) (result))
    49  
    50    (import "spectest" "print_i32" (func (type $forward)))
    51    (func (import "spectest" "print_i32") (type $forward))
    52    (type $forward (func (param i32)))
    53  
    54    (table funcref (elem $print_i32 $print_f64))
    55  
    56    (func (export "print32") (param $i i32)
    57      (local $x f32)
    58      (local.set $x (f32.convert_i32_s (local.get $i)))
    59      (call 0 (local.get $i))
    60      (call $print_i32_f32
    61        (i32.add (local.get $i) (i32.const 1))
    62        (f32.const 42)
    63      )
    64      (call $print_i32 (local.get $i))
    65      (call $print_i32-2 (local.get $i))
    66      (call $print_f32 (local.get $x))
    67      (call_indirect (type $func_i32) (local.get $i) (i32.const 0))
    68    )
    69  
    70    (func (export "print64") (param $i i64)
    71      (local $x f64)
    72      (local.set $x (f64.convert_i64_s (call $i64->i64 (local.get $i))))
    73      (call 1 (local.get $i))
    74      (call $print_f64_f64
    75        (f64.add (local.get $x) (f64.const 1))
    76        (f64.const 53)
    77      )
    78      (call $print_i64 (local.get $i))
    79      (call $print_f64 (local.get $x))
    80      (call $print_f64-2 (local.get $x))
    81      (call_indirect (type $func_f64) (local.get $x) (i32.const 1))
    82    )
    83  )
    84  
    85  (assert_return (invoke "print32" (i32.const 13)))
    86  (assert_return (invoke "print64" (i64.const 24)))
    87  
    88  (assert_invalid
    89    (module 
    90      (type (func (result i32)))
    91      (import "test" "func" (func (type 1)))
    92    )
    93    "unknown type"
    94  )
    95  
    96  ;; Export sharing name with import
    97  (module
    98    (import "spectest" "print_i32" (func $imported_print (param i32)))
    99    (func (export "print_i32") (param $i i32)
   100      (call $imported_print (local.get $i))
   101    )
   102  )
   103  
   104  (assert_return (invoke "print_i32" (i32.const 13)))
   105  
   106  ;; Export sharing name with import
   107  (module
   108    (import "spectest" "print_i32" (func $imported_print (param i32)))
   109    (func (export "print_i32") (param $i i32) (param $j i32) (result i32)
   110      (i32.add (local.get $i) (local.get $j))
   111    )
   112  )
   113  
   114  (assert_return (invoke "print_i32" (i32.const 5) (i32.const 11)) (i32.const 16))
   115  
   116  (module (import "test" "func" (func)))
   117  (module (import "test" "func-i32" (func (param i32))))
   118  (module (import "test" "func-f32" (func (param f32))))
   119  (module (import "test" "func->i32" (func (result i32))))
   120  (module (import "test" "func->f32" (func (result f32))))
   121  (module (import "test" "func-i32->i32" (func (param i32) (result i32))))
   122  (module (import "test" "func-i64->i64" (func (param i64) (result i64))))
   123  
   124  (assert_unlinkable
   125    (module (import "test" "unknown" (func)))
   126    "unknown import"
   127  )
   128  (assert_unlinkable
   129    (module (import "spectest" "unknown" (func)))
   130    "unknown import"
   131  )
   132  
   133  (assert_unlinkable
   134    (module (import "test" "func" (func (param i32))))
   135    "incompatible import type"
   136  )
   137  (assert_unlinkable
   138    (module (import "test" "func" (func (result i32))))
   139    "incompatible import type"
   140  )
   141  (assert_unlinkable
   142    (module (import "test" "func" (func (param i32) (result i32))))
   143    "incompatible import type"
   144  )
   145  (assert_unlinkable
   146    (module (import "test" "func-i32" (func)))
   147    "incompatible import type"
   148  )
   149  (assert_unlinkable
   150    (module (import "test" "func-i32" (func (result i32))))
   151    "incompatible import type"
   152  )
   153  (assert_unlinkable
   154    (module (import "test" "func-i32" (func (param f32))))
   155    "incompatible import type"
   156  )
   157  (assert_unlinkable
   158    (module (import "test" "func-i32" (func (param i64))))
   159    "incompatible import type"
   160  )
   161  (assert_unlinkable
   162    (module (import "test" "func-i32" (func (param i32) (result i32))))
   163    "incompatible import type"
   164  )
   165  (assert_unlinkable
   166    (module (import "test" "func->i32" (func)))
   167    "incompatible import type"
   168  )
   169  (assert_unlinkable
   170    (module (import "test" "func->i32" (func (param i32))))
   171    "incompatible import type"
   172  )
   173  (assert_unlinkable
   174    (module (import "test" "func->i32" (func (result f32))))
   175    "incompatible import type"
   176  )
   177  (assert_unlinkable
   178    (module (import "test" "func->i32" (func (result i64))))
   179    "incompatible import type"
   180  )
   181  (assert_unlinkable
   182    (module (import "test" "func->i32" (func (param i32) (result i32))))
   183    "incompatible import type"
   184  )
   185  (assert_unlinkable
   186    (module (import "test" "func-i32->i32" (func)))
   187    "incompatible import type"
   188  )
   189  (assert_unlinkable
   190    (module (import "test" "func-i32->i32" (func (param i32))))
   191    "incompatible import type"
   192  )
   193  (assert_unlinkable
   194    (module (import "test" "func-i32->i32" (func (result i32))))
   195    "incompatible import type"
   196  )
   197  
   198  (assert_unlinkable
   199    (module (import "test" "global-i32" (func (result i32))))
   200    "incompatible import type"
   201  )
   202  (assert_unlinkable
   203    (module (import "test" "table-10-inf" (func)))
   204    "incompatible import type"
   205  )
   206  (assert_unlinkable
   207    (module (import "test" "memory-2-inf" (func)))
   208    "incompatible import type"
   209  )
   210  (assert_unlinkable
   211    (module (import "spectest" "global_i32" (func)))
   212    "incompatible import type"
   213  )
   214  (assert_unlinkable
   215    (module (import "spectest" "table" (func)))
   216    "incompatible import type"
   217  )
   218  (assert_unlinkable
   219    (module (import "spectest" "memory" (func)))
   220    "incompatible import type"
   221  )
   222  
   223  
   224  ;; Globals
   225  
   226  (module
   227    (import "spectest" "global_i32" (global i32))
   228    (global (import "spectest" "global_i32") i32)
   229  
   230    (import "spectest" "global_i32" (global $x i32))
   231    (global $y (import "spectest" "global_i32") i32)
   232  
   233    (import "spectest" "global_i64" (global i64))
   234    (import "spectest" "global_f32" (global f32))
   235    (import "spectest" "global_f64" (global f64))
   236  
   237    (func (export "get-0") (result i32) (global.get 0))
   238    (func (export "get-1") (result i32) (global.get 1))
   239    (func (export "get-x") (result i32) (global.get $x))
   240    (func (export "get-y") (result i32) (global.get $y))
   241    (func (export "get-4") (result i64) (global.get 4))
   242    (func (export "get-5") (result f32) (global.get 5))
   243    (func (export "get-6") (result f64) (global.get 6))
   244  )
   245  
   246  (assert_return (invoke "get-0") (i32.const 666))
   247  (assert_return (invoke "get-1") (i32.const 666))
   248  (assert_return (invoke "get-x") (i32.const 666))
   249  (assert_return (invoke "get-y") (i32.const 666))
   250  (assert_return (invoke "get-4") (i64.const 666))
   251  (assert_return (invoke "get-5") (f32.const 666.6))
   252  (assert_return (invoke "get-6") (f64.const 666.6))
   253  
   254  (module (import "test" "global-i32" (global i32)))
   255  (module (import "test" "global-f32" (global f32)))
   256  (module (import "test" "global-mut-i64" (global (mut i64))))
   257  
   258  (assert_unlinkable
   259    (module (import "test" "unknown" (global i32)))
   260    "unknown import"
   261  )
   262  (assert_unlinkable
   263    (module (import "spectest" "unknown" (global i32)))
   264    "unknown import"
   265  )
   266  
   267  (assert_unlinkable
   268    (module (import "test" "global-i32" (global i64)))
   269    "incompatible import type"
   270  )
   271  (assert_unlinkable
   272    (module (import "test" "global-i32" (global f32)))
   273    "incompatible import type"
   274  )
   275  (assert_unlinkable
   276    (module (import "test" "global-i32" (global f64)))
   277    "incompatible import type"
   278  )
   279  (assert_unlinkable
   280    (module (import "test" "global-i32" (global (mut i32))))
   281    "incompatible import type"
   282  )
   283  (assert_unlinkable
   284    (module (import "test" "global-f32" (global i32)))
   285    "incompatible import type"
   286  )
   287  (assert_unlinkable
   288    (module (import "test" "global-f32" (global i64)))
   289    "incompatible import type"
   290  )
   291  (assert_unlinkable
   292    (module (import "test" "global-f32" (global f64)))
   293    "incompatible import type"
   294  )
   295  (assert_unlinkable
   296    (module (import "test" "global-f32" (global (mut f32))))
   297    "incompatible import type"
   298  )
   299  (assert_unlinkable
   300    (module (import "test" "global-mut-i64" (global (mut i32))))
   301    "incompatible import type"
   302  )
   303  (assert_unlinkable
   304    (module (import "test" "global-mut-i64" (global (mut f32))))
   305    "incompatible import type"
   306  )
   307  (assert_unlinkable
   308    (module (import "test" "global-mut-i64" (global (mut f64))))
   309    "incompatible import type"
   310  )
   311  (assert_unlinkable
   312    (module (import "test" "global-mut-i64" (global i64)))
   313    "incompatible import type"
   314  )
   315  
   316  (assert_unlinkable
   317    (module (import "test" "func" (global i32)))
   318    "incompatible import type"
   319  )
   320  (assert_unlinkable
   321    (module (import "test" "table-10-inf" (global i32)))
   322    "incompatible import type"
   323  )
   324  (assert_unlinkable
   325    (module (import "test" "memory-2-inf" (global i32)))
   326    "incompatible import type"
   327  )
   328  (assert_unlinkable
   329    (module (import "spectest" "print_i32" (global i32)))
   330    "incompatible import type"
   331  )
   332  (assert_unlinkable
   333    (module (import "spectest" "table" (global i32)))
   334    "incompatible import type"
   335  )
   336  (assert_unlinkable
   337    (module (import "spectest" "memory" (global i32)))
   338    "incompatible import type"
   339  )
   340  
   341  
   342  ;; Tables
   343  
   344  (module
   345    (type (func (result i32)))
   346    (import "spectest" "table" (table $tab 10 20 funcref))
   347    (elem (table $tab) (i32.const 1) func $f $g)
   348  
   349    (func (export "call") (param i32) (result i32)
   350      (call_indirect $tab (type 0) (local.get 0))
   351    )
   352    (func $f (result i32) (i32.const 11))
   353    (func $g (result i32) (i32.const 22))
   354  )
   355  
   356  (assert_trap (invoke "call" (i32.const 0)) "uninitialized element")
   357  (assert_return (invoke "call" (i32.const 1)) (i32.const 11))
   358  (assert_return (invoke "call" (i32.const 2)) (i32.const 22))
   359  (assert_trap (invoke "call" (i32.const 3)) "uninitialized element")
   360  (assert_trap (invoke "call" (i32.const 100)) "undefined element")
   361  
   362  
   363  (module
   364    (type (func (result i32)))
   365    (table $tab (import "spectest" "table") 10 20 funcref)
   366    (elem (table $tab) (i32.const 1) func $f $g)
   367  
   368    (func (export "call") (param i32) (result i32)
   369      (call_indirect $tab (type 0) (local.get 0))
   370    )
   371    (func $f (result i32) (i32.const 11))
   372    (func $g (result i32) (i32.const 22))
   373  )
   374  
   375  (assert_trap (invoke "call" (i32.const 0)) "uninitialized element")
   376  (assert_return (invoke "call" (i32.const 1)) (i32.const 11))
   377  (assert_return (invoke "call" (i32.const 2)) (i32.const 22))
   378  (assert_trap (invoke "call" (i32.const 3)) "uninitialized element")
   379  (assert_trap (invoke "call" (i32.const 100)) "undefined element")
   380  
   381  
   382  (module
   383    (import "spectest" "table" (table 0 funcref))
   384    (import "spectest" "table" (table 0 funcref))
   385    (table 10 funcref)
   386    (table 10 funcref)
   387  )
   388  
   389  (module (import "test" "table-10-inf" (table 10 funcref)))
   390  (module (import "test" "table-10-inf" (table 5 funcref)))
   391  (module (import "test" "table-10-inf" (table 0 funcref)))
   392  (module (import "test" "table-10-20" (table 10 funcref)))
   393  (module (import "test" "table-10-20" (table 5 funcref)))
   394  (module (import "test" "table-10-20" (table 0 funcref)))
   395  (module (import "test" "table-10-20" (table 10 20 funcref)))
   396  (module (import "test" "table-10-20" (table 5 20 funcref)))
   397  (module (import "test" "table-10-20" (table 0 20 funcref)))
   398  (module (import "test" "table-10-20" (table 10 25 funcref)))
   399  (module (import "test" "table-10-20" (table 5 25 funcref)))
   400  (module (import "test" "table-10-20" (table 0 25 funcref)))
   401  (module (import "spectest" "table" (table 10 funcref)))
   402  (module (import "spectest" "table" (table 5 funcref)))
   403  (module (import "spectest" "table" (table 0 funcref)))
   404  (module (import "spectest" "table" (table 10 20 funcref)))
   405  (module (import "spectest" "table" (table 5 20 funcref)))
   406  (module (import "spectest" "table" (table 0 20 funcref)))
   407  (module (import "spectest" "table" (table 10 25 funcref)))
   408  (module (import "spectest" "table" (table 5 25 funcref)))
   409  
   410  (assert_unlinkable
   411    (module (import "test" "unknown" (table 10 funcref)))
   412    "unknown import"
   413  )
   414  (assert_unlinkable
   415    (module (import "spectest" "unknown" (table 10 funcref)))
   416    "unknown import"
   417  )
   418  
   419  (assert_unlinkable
   420    (module (import "test" "table-10-inf" (table 12 funcref)))
   421    "incompatible import type"
   422  )
   423  (assert_unlinkable
   424    (module (import "test" "table-10-inf" (table 10 20 funcref)))
   425    "incompatible import type"
   426  )
   427  (assert_unlinkable
   428    (module (import "test" "table-10-20" (table 12 20 funcref)))
   429    "incompatible import type"
   430  )
   431  (assert_unlinkable
   432    (module (import "test" "table-10-20" (table 10 18 funcref)))
   433    "incompatible import type"
   434  )
   435  (assert_unlinkable
   436    (module (import "spectest" "table" (table 12 funcref)))
   437    "incompatible import type"
   438  )
   439  (assert_unlinkable
   440    (module (import "spectest" "table" (table 10 15 funcref)))
   441    "incompatible import type"
   442  )
   443  
   444  (assert_unlinkable
   445    (module (import "test" "func" (table 10 funcref)))
   446    "incompatible import type"
   447  )
   448  (assert_unlinkable
   449    (module (import "test" "global-i32" (table 10 funcref)))
   450    "incompatible import type"
   451  )
   452  (assert_unlinkable
   453    (module (import "test" "memory-2-inf" (table 10 funcref)))
   454    "incompatible import type"
   455  )
   456  (assert_unlinkable
   457    (module (import "spectest" "print_i32" (table 10 funcref)))
   458    "incompatible import type"
   459  )
   460  
   461  
   462  
   463  ;; Memories
   464  
   465  (module
   466    (import "spectest" "memory" (memory 1 2))
   467    (data (memory 0) (i32.const 10) "\10")
   468  
   469    (func (export "load") (param i32) (result i32) (i32.load (local.get 0)))
   470  )
   471  
   472  (assert_return (invoke "load" (i32.const 0)) (i32.const 0))
   473  (assert_return (invoke "load" (i32.const 10)) (i32.const 16))
   474  (assert_return (invoke "load" (i32.const 8)) (i32.const 0x100000))
   475  (assert_trap (invoke "load" (i32.const 1000000)) "out of bounds memory access")
   476  
   477  (module
   478    (memory (import "spectest" "memory") 1 2)
   479    (data (memory 0) (i32.const 10) "\10")
   480  
   481    (func (export "load") (param i32) (result i32) (i32.load (local.get 0)))
   482  )
   483  (assert_return (invoke "load" (i32.const 0)) (i32.const 0))
   484  (assert_return (invoke "load" (i32.const 10)) (i32.const 16))
   485  (assert_return (invoke "load" (i32.const 8)) (i32.const 0x100000))
   486  (assert_trap (invoke "load" (i32.const 1000000)) "out of bounds memory access")
   487  
   488  (assert_invalid
   489    (module (import "" "" (memory 1)) (import "" "" (memory 1)))
   490    "multiple memories"
   491  )
   492  (assert_invalid
   493    (module (import "" "" (memory 1)) (memory 0))
   494    "multiple memories"
   495  )
   496  (assert_invalid
   497    (module (memory 0) (memory 0))
   498    "multiple memories"
   499  )
   500  
   501  (module (import "test" "memory-2-inf" (memory 2)))
   502  (module (import "test" "memory-2-inf" (memory 1)))
   503  (module (import "test" "memory-2-inf" (memory 0)))
   504  (module (import "spectest" "memory" (memory 1)))
   505  (module (import "spectest" "memory" (memory 0)))
   506  (module (import "spectest" "memory" (memory 1 2)))
   507  (module (import "spectest" "memory" (memory 0 2)))
   508  (module (import "spectest" "memory" (memory 1 3)))
   509  (module (import "spectest" "memory" (memory 0 3)))
   510  
   511  (assert_unlinkable
   512    (module (import "test" "unknown" (memory 1)))
   513    "unknown import"
   514  )
   515  (assert_unlinkable
   516    (module (import "spectest" "unknown" (memory 1)))
   517    "unknown import"
   518  )
   519  
   520  (assert_unlinkable
   521    (module (import "test" "memory-2-inf" (memory 3)))
   522    "incompatible import type"
   523  )
   524  (assert_unlinkable
   525    (module (import "test" "memory-2-inf" (memory 2 3)))
   526    "incompatible import type"
   527  )
   528  (assert_unlinkable
   529    (module (import "spectest" "memory" (memory 2)))
   530    "incompatible import type"
   531  )
   532  (assert_unlinkable
   533    (module (import "spectest" "memory" (memory 1 1)))
   534    "incompatible import type"
   535  )
   536  
   537  (assert_unlinkable
   538    (module (import "test" "func-i32" (memory 1)))
   539    "incompatible import type"
   540  )
   541  (assert_unlinkable
   542    (module (import "test" "global-i32" (memory 1)))
   543    "incompatible import type"
   544  )
   545  (assert_unlinkable
   546    (module (import "test" "table-10-inf" (memory 1)))
   547    "incompatible import type"
   548  )
   549  (assert_unlinkable
   550    (module (import "spectest" "print_i32" (memory 1)))
   551    "incompatible import type"
   552  )
   553  (assert_unlinkable
   554    (module (import "spectest" "global_i32" (memory 1)))
   555    "incompatible import type"
   556  )
   557  (assert_unlinkable
   558    (module (import "spectest" "table" (memory 1)))
   559    "incompatible import type"
   560  )
   561  
   562  (assert_unlinkable
   563    (module (import "spectest" "memory" (memory 2)))
   564    "incompatible import type"
   565  )
   566  (assert_unlinkable
   567    (module (import "spectest" "memory" (memory 1 1)))
   568    "incompatible import type"
   569  )
   570  
   571  (module
   572    (import "spectest" "memory" (memory 0 3))  ;; actual has max size 2
   573    (func (export "grow") (param i32) (result i32) (memory.grow (local.get 0)))
   574  )
   575  (assert_return (invoke "grow" (i32.const 0)) (i32.const 1))
   576  (assert_return (invoke "grow" (i32.const 1)) (i32.const 1))
   577  (assert_return (invoke "grow" (i32.const 0)) (i32.const 2))
   578  (assert_return (invoke "grow" (i32.const 1)) (i32.const -1))
   579  (assert_return (invoke "grow" (i32.const 0)) (i32.const 2))
   580  
   581  (module $Mgm
   582    (memory (export "memory") 1) ;; initial size is 1
   583    (func (export "grow") (result i32) (memory.grow (i32.const 1)))
   584  )
   585  (register "grown-memory" $Mgm)
   586  (assert_return (invoke $Mgm "grow") (i32.const 1)) ;; now size is 2
   587  (module $Mgim1
   588    ;; imported memory limits should match, because external memory size is 2 now
   589    (memory (export "memory") (import "grown-memory" "memory") 2) 
   590    (func (export "grow") (result i32) (memory.grow (i32.const 1)))
   591  )
   592  (register "grown-imported-memory" $Mgim1)
   593  (assert_return (invoke $Mgim1 "grow") (i32.const 2)) ;; now size is 3
   594  (module $Mgim2
   595    ;; imported memory limits should match, because external memory size is 3 now
   596    (import "grown-imported-memory" "memory" (memory 3))
   597    (func (export "size") (result i32) (memory.size))
   598  )
   599  (assert_return (invoke $Mgim2 "size") (i32.const 3))
   600  
   601  
   602  ;; Syntax errors
   603  
   604  (assert_malformed
   605    (module quote "(func) (import \"\" \"\" (func))")
   606    "import after function"
   607  )
   608  (assert_malformed
   609    (module quote "(func) (import \"\" \"\" (global i64))")
   610    "import after function"
   611  )
   612  (assert_malformed
   613    (module quote "(func) (import \"\" \"\" (table 0 funcref))")
   614    "import after function"
   615  )
   616  (assert_malformed
   617    (module quote "(func) (import \"\" \"\" (memory 0))")
   618    "import after function"
   619  )
   620  
   621  (assert_malformed
   622    (module quote "(global i64 (i64.const 0)) (import \"\" \"\" (func))")
   623    "import after global"
   624  )
   625  (assert_malformed
   626    (module quote "(global i64 (i64.const 0)) (import \"\" \"\" (global f32))")
   627    "import after global"
   628  )
   629  (assert_malformed
   630    (module quote "(global i64 (i64.const 0)) (import \"\" \"\" (table 0 funcref))")
   631    "import after global"
   632  )
   633  (assert_malformed
   634    (module quote "(global i64 (i64.const 0)) (import \"\" \"\" (memory 0))")
   635    "import after global"
   636  )
   637  
   638  (assert_malformed
   639    (module quote "(table 0 funcref) (import \"\" \"\" (func))")
   640    "import after table"
   641  )
   642  (assert_malformed
   643    (module quote "(table 0 funcref) (import \"\" \"\" (global i32))")
   644    "import after table"
   645  )
   646  (assert_malformed
   647    (module quote "(table 0 funcref) (import \"\" \"\" (table 0 funcref))")
   648    "import after table"
   649  )
   650  (assert_malformed
   651    (module quote "(table 0 funcref) (import \"\" \"\" (memory 0))")
   652    "import after table"
   653  )
   654  
   655  (assert_malformed
   656    (module quote "(memory 0) (import \"\" \"\" (func))")
   657    "import after memory"
   658  )
   659  (assert_malformed
   660    (module quote "(memory 0) (import \"\" \"\" (global i32))")
   661    "import after memory"
   662  )
   663  (assert_malformed
   664    (module quote "(memory 0) (import \"\" \"\" (table 1 3 funcref))")
   665    "import after memory"
   666  )
   667  (assert_malformed
   668    (module quote "(memory 0) (import \"\" \"\" (memory 1 2))")
   669    "import after memory"
   670  )
   671  
   672  ;; This module is required to validate, regardless of whether it can be
   673  ;; linked. Overloading is not possible in wasm itself, but it is possible
   674  ;; in modules from which wasm can import.
   675  (module)
   676  (register "not wasm")
   677  (assert_unlinkable
   678    (module
   679      (import "not wasm" "overloaded" (func))
   680      (import "not wasm" "overloaded" (func (param i32)))
   681      (import "not wasm" "overloaded" (func (param i32 i32)))
   682      (import "not wasm" "overloaded" (func (param i64)))
   683      (import "not wasm" "overloaded" (func (param f32)))
   684      (import "not wasm" "overloaded" (func (param f64)))
   685      (import "not wasm" "overloaded" (func (result i32)))
   686      (import "not wasm" "overloaded" (func (result i64)))
   687      (import "not wasm" "overloaded" (func (result f32)))
   688      (import "not wasm" "overloaded" (func (result f64)))
   689      (import "not wasm" "overloaded" (global i32))
   690      (import "not wasm" "overloaded" (global i64))
   691      (import "not wasm" "overloaded" (global f32))
   692      (import "not wasm" "overloaded" (global f64))
   693      (import "not wasm" "overloaded" (table 0 funcref))
   694      (import "not wasm" "overloaded" (memory 0))
   695    )
   696    "unknown import"
   697  )