wa-lang.org/wazero@v1.0.2/imports/emscripten/testdata/invoke.wat (about)

     1  (module
     2    (type $0 (func (param i32)))
     3    (import "env" "invoke_i" (func $invoke_i (param i32) (result i32)))
     4    (import "env" "invoke_ii" (func $invoke_ii (param i32 i32) (result i32)))
     5    (import "env" "invoke_iii" (func $invoke_iii (param i32 i32 i32) (result i32)))
     6    (import "env" "invoke_iiii" (func $invoke_iiii (param i32 i32 i32 i32) (result i32)))
     7    (import "env" "invoke_iiiii" (func $invoke_iiiii (param i32 i32 i32 i32 i32) (result i32)))
     8    (import "env" "invoke_v" (func $invoke_v (param i32)))
     9    (import "env" "invoke_vi" (func $invoke_vi (param i32 i32)))
    10    (import "env" "invoke_vii" (func $invoke_vii (param i32 i32 i32)))
    11    (import "env" "invoke_viii" (func $invoke_viii (param i32 i32 i32 i32)))
    12    (import "env" "invoke_viiii" (func $invoke_viiii (param i32 i32 i32 i32 i32)))
    13  
    14    (table 20 20 funcref)
    15  
    16    (func $v_i32 (result i32) (i32.const 42))
    17    (func $v_i32_unreachable (result i32) unreachable)
    18  
    19    (elem (i32.const 0) $v_i32 $v_i32_unreachable)
    20  
    21    ;; call_v_i32 should be called with 0 or 1 and expect 42 or unreachable.
    22    (func $call_v_i32 (export "call_v_i32") (param i32) (result i32)
    23      (call $invoke_i (local.get 0)))
    24  
    25    (func $i32_i32 (param i32) (result i32) (local.get 0))
    26    (func $i32_i32_unreachable (param i32) (result i32) unreachable)
    27  
    28    (elem (i32.const 2) $i32_i32 $i32_i32_unreachable)
    29  
    30    ;; call_i32_i32 should be called with 2 or 3 followed by one number which is
    31    ;; the result on $0 == 2 or unreachable on 3.
    32    (func $call_i32_i32 (export "call_i32_i32") (param i32 i32) (result i32)
    33      (call $invoke_ii (local.get 0) (local.get 1)))
    34  
    35    (func $i32i32_i32 (param i32 i32) (result i32) (i32.add (local.get 0) (local.get 1)))
    36    (func $i32i32_i32_unreachable (param i32 i32) (result i32) unreachable)
    37  
    38    (elem (i32.const 4) $i32i32_i32 $i32i32_i32_unreachable)
    39  
    40    ;; call_i32i32_i32 should be called with 4 or 5 followed by two numbers
    41    ;; whose sum is the result on $0 == 4 or unreachable on 5.
    42    (func $call_i32i32_i32 (export "call_i32i32_i32") (param i32 i32 i32) (result i32)
    43      (call $invoke_iii (local.get 0) (local.get 1) (local.get 2)))
    44  
    45    (func $i32i32i32_i32 (param i32 i32 i32) (result i32)
    46      (i32.add (i32.add (local.get 0) (local.get 1)) (local.get 2)))
    47    (func $i32i32i32_i32_unreachable (param i32 i32 i32) (result i32) unreachable)
    48  
    49    (elem (i32.const 6) $i32i32i32_i32 $i32i32i32_i32_unreachable)
    50  
    51    ;; call_i32i32i32_i32 should be called with 6 or 7 followed by three numbers
    52    ;; whose sum is the result on $0 == 6 or unreachable on 7.
    53    (func $call_i32i32i32_i32 (export "call_i32i32i32_i32") (param i32 i32 i32 i32) (result i32)
    54      (call $invoke_iiii (local.get 0) (local.get 1) (local.get 2) (local.get 3)))
    55  
    56    (func $i32i32i32i32_i32 (param i32 i32 i32 i32) (result i32)
    57      (i32.add (i32.add (i32.add (local.get 0) (local.get 1)) (local.get 2)) (local.get 3)))
    58    (func $i32i32i32i32_i32_unreachable (param i32 i32 i32 i32) (result i32) unreachable)
    59  
    60    (elem (i32.const 8) $i32i32i32i32_i32 $i32i32i32i32_i32_unreachable)
    61  
    62    ;; calli32_i32i32i32i32_i32 should be called with 8 or 9 followed by four numbers
    63    ;; whose sum is the result on $0 == 8 or unreachable on 9.
    64    (func $calli32_i32i32i32i32_i32 (export "calli32_i32i32i32i32_i32") (param i32 i32 i32 i32 i32) (result i32)
    65      (call $invoke_iiiii (local.get 0) (local.get 1) (local.get 2) (local.get 3) (local.get 4)))
    66  
    67    (func $v_v)
    68    (func $v_v_unreachable unreachable)
    69  
    70    (elem (i32.const 10) $v_v $v_v_unreachable)
    71  
    72    ;; call_v_v should be called with 10 or 11 and expect unreachable on 11.
    73    (func $call_v_v (export "call_v_v") (param i32)
    74      (call $invoke_v (local.get 0)))
    75  
    76    (func $i32_v (param i32))
    77    (func $i32_v_unreachable (param i32) unreachable)
    78  
    79    (elem (i32.const 12) $i32_v $i32_v_unreachable)
    80  
    81    ;; call_i32_v should be called with 12 or 13 followed by one number and
    82    ;; expect unreachable on 2.
    83    (func $call_i32_v (export "call_i32_v") (param i32 i32)
    84      (call $invoke_vi (local.get 0) (local.get 1)))
    85  
    86    (func $i32i32_v (param i32 i32))
    87    (func $i32i32_v_unreachable (param i32 i32) unreachable)
    88  
    89    (elem (i32.const 14) $i32i32_v $i32i32_v_unreachable)
    90  
    91    ;; call_i32i32_v should be called with 14 or 15 followed by two numbers
    92    ;; and expect unreachable on 15.
    93    (func $call_i32i32_v (export "call_i32i32_v") (param i32 i32 i32)
    94      (call $invoke_vii (local.get 0) (local.get 1) (local.get 2)))
    95  
    96    (func $i32i32i32_v (param i32 i32 i32))
    97    (func $i32i32i32_v_unreachable (param i32 i32 i32) unreachable)
    98  
    99    (elem (i32.const 16) $i32i32i32_v $i32i32i32_v_unreachable)
   100  
   101    ;; call_i32i32i32_v should be called with 16 or 17 followed by three numbers
   102    ;; and expect unreachable on 17.
   103    (func $call_i32i32i32_v (export "call_i32i32i32_v") (param i32 i32 i32 i32)
   104      (call $invoke_viii (local.get 0) (local.get 1) (local.get 2) (local.get 3)))
   105  
   106    (func $i32i32i32i32_v (param i32 i32 i32 i32))
   107    (func $i32i32i32i32_v_unreachable (param i32 i32 i32 i32) unreachable)
   108  
   109    (elem (i32.const 18) $i32i32i32i32_v $i32i32i32i32_v_unreachable)
   110  
   111    ;; calli32_i32i32i32i32_v should be called with 18 or 19 followed by four
   112    ;; numbers and expect unreachable on 19.
   113    (func $calli32_i32i32i32i32_v (export "calli32_i32i32i32i32_v") (param i32 i32 i32 i32 i32)
   114      (call $invoke_viiii (local.get 0) (local.get 1) (local.get 2) (local.get 3) (local.get 4)))
   115  )