github.com/wasilibs/wazerox@v0.0.0-20240124024944-4923be63ab5f/internal/integration_test/spectest/v1/testdata/func_ptrs.wast (about)

     1  (module
     2    (type    (func))                           ;; 0: void -> void
     3    (type $S (func))                           ;; 1: void -> void
     4    (type    (func (param)))                   ;; 2: void -> void
     5    (type    (func (result i32)))              ;; 3: void -> i32
     6    (type    (func (param) (result i32)))      ;; 4: void -> i32
     7    (type $T (func (param i32) (result i32)))  ;; 5: i32 -> i32
     8    (type $U (func (param i32)))               ;; 6: i32 -> void
     9  
    10    (func $print (import "spectest" "print_i32") (type 6))
    11  
    12    (func (type 0))
    13    (func (type $S))
    14  
    15    (func (export "one") (type 4) (i32.const 13))
    16    (func (export "two") (type $T) (i32.add (local.get 0) (i32.const 1)))
    17  
    18    ;; Both signature and parameters are allowed (and required to match)
    19    ;; since this allows the naming of parameters.
    20    (func (export "three") (type $T) (param $a i32) (result i32)
    21      (i32.sub (local.get 0) (i32.const 2))
    22    )
    23  
    24    (func (export "four") (type $U) (call $print (local.get 0)))
    25  )
    26  
    27  (assert_return (invoke "one") (i32.const 13))
    28  (assert_return (invoke "two" (i32.const 13)) (i32.const 14))
    29  (assert_return (invoke "three" (i32.const 13)) (i32.const 11))
    30  (invoke "four" (i32.const 83))
    31  
    32  (assert_invalid (module (elem (i32.const 0))) "unknown table")
    33  (assert_invalid (module (elem (i32.const 0) 0) (func)) "unknown table")
    34  
    35  (assert_invalid
    36    (module (table 1 funcref) (elem (i64.const 0)))
    37    "type mismatch"
    38  )
    39  (assert_invalid
    40    (module (table 1 funcref) (elem (i32.ctz (i32.const 0))))
    41    "constant expression required"
    42  )
    43  (assert_invalid
    44    (module (table 1 funcref) (elem (nop)))
    45    "constant expression required"
    46  )
    47  
    48  (assert_invalid (module (func (type 42))) "unknown type")
    49  (assert_invalid (module (import "spectest" "print_i32" (func (type 43)))) "unknown type")
    50  
    51  (module
    52    (type $T (func (param) (result i32)))
    53    (type $U (func (param) (result i32)))
    54    (table funcref (elem $t1 $t2 $t3 $u1 $u2 $t1 $t3))
    55  
    56    (func $t1 (type $T) (i32.const 1))
    57    (func $t2 (type $T) (i32.const 2))
    58    (func $t3 (type $T) (i32.const 3))
    59    (func $u1 (type $U) (i32.const 4))
    60    (func $u2 (type $U) (i32.const 5))
    61  
    62    (func (export "callt") (param $i i32) (result i32)
    63      (call_indirect (type $T) (local.get $i))
    64    )
    65  
    66    (func (export "callu") (param $i i32) (result i32)
    67      (call_indirect (type $U) (local.get $i))
    68    )
    69  )
    70  
    71  (assert_return (invoke "callt" (i32.const 0)) (i32.const 1))
    72  (assert_return (invoke "callt" (i32.const 1)) (i32.const 2))
    73  (assert_return (invoke "callt" (i32.const 2)) (i32.const 3))
    74  (assert_return (invoke "callt" (i32.const 3)) (i32.const 4))
    75  (assert_return (invoke "callt" (i32.const 4)) (i32.const 5))
    76  (assert_return (invoke "callt" (i32.const 5)) (i32.const 1))
    77  (assert_return (invoke "callt" (i32.const 6)) (i32.const 3))
    78  (assert_trap (invoke "callt" (i32.const 7)) "undefined element")
    79  (assert_trap (invoke "callt" (i32.const 100)) "undefined element")
    80  (assert_trap (invoke "callt" (i32.const -1)) "undefined element")
    81  
    82  (assert_return (invoke "callu" (i32.const 0)) (i32.const 1))
    83  (assert_return (invoke "callu" (i32.const 1)) (i32.const 2))
    84  (assert_return (invoke "callu" (i32.const 2)) (i32.const 3))
    85  (assert_return (invoke "callu" (i32.const 3)) (i32.const 4))
    86  (assert_return (invoke "callu" (i32.const 4)) (i32.const 5))
    87  (assert_return (invoke "callu" (i32.const 5)) (i32.const 1))
    88  (assert_return (invoke "callu" (i32.const 6)) (i32.const 3))
    89  (assert_trap (invoke "callu" (i32.const 7)) "undefined element")
    90  (assert_trap (invoke "callu" (i32.const 100)) "undefined element")
    91  (assert_trap (invoke "callu" (i32.const -1)) "undefined element")
    92  
    93  (module
    94    (type $T (func (result i32)))
    95    (table funcref (elem 0 1))
    96  
    97    (func $t1 (type $T) (i32.const 1))
    98    (func $t2 (type $T) (i32.const 2))
    99  
   100    (func (export "callt") (param $i i32) (result i32)
   101      (call_indirect (type $T) (local.get $i))
   102    )
   103  )
   104  
   105  (assert_return (invoke "callt" (i32.const 0)) (i32.const 1))
   106  (assert_return (invoke "callt" (i32.const 1)) (i32.const 2))