1;; Test `call_indirect` calls between modules. 2 3(module 4 ;; Auxiliary definitions 5 (type $proc (func)) 6 (type $out-i32 (func (result i32))) 7 (type $out-i64 (func (result i64))) 8 (type $out-f32 (func (result f32))) 9 (type $out-f64 (func (result f64))) 10 (type $over-i32 (func (param i32) (result i32))) 11 (type $over-i64 (func (param i64) (result i64))) 12 (type $over-f32 (func (param f32) (result f32))) 13 (type $over-f64 (func (param f64) (result f64))) 14 (type $f32-i32 (func (param f32 i32) (result i32))) 15 (type $i32-i64 (func (param i32 i64) (result i64))) 16 (type $f64-f32 (func (param f64 f32) (result f32))) 17 (type $i64-f64 (func (param i64 f64) (result f64))) 18 (type $over-i32-duplicate (func (param i32) (result i32))) 19 (type $over-i64-duplicate (func (param i64) (result i64))) 20 (type $over-f32-duplicate (func (param f32) (result f32))) 21 (type $over-f64-duplicate (func (param f64) (result f64))) 22 23 (func $const-i32 (type $out-i32) (i32.const 0x132)) 24 (func $const-i64 (type $out-i64) (i64.const 0x164)) 25 (func $const-f32 (type $out-f32) (f32.const 0xf32)) 26 (func $const-f64 (type $out-f64) (f64.const 0xf64)) 27 28 (func $id-i32 (type $over-i32) (local.get 0)) 29 (func $id-i64 (type $over-i64) (local.get 0)) 30 (func $id-f32 (type $over-f32) (local.get 0)) 31 (func $id-f64 (type $over-f64) (local.get 0)) 32 33 (func $i32-i64 (type $i32-i64) (local.get 1)) 34 (func $i64-f64 (type $i64-f64) (local.get 1)) 35 (func $f32-i32 (type $f32-i32) (local.get 1)) 36 (func $f64-f32 (type $f64-f32) (local.get 1)) 37 38 (func $over-i32-duplicate (type $over-i32-duplicate) (local.get 0)) 39 (func $over-i64-duplicate (type $over-i64-duplicate) (local.get 0)) 40 (func $over-f32-duplicate (type $over-f32-duplicate) (local.get 0)) 41 (func $over-f64-duplicate (type $over-f64-duplicate) (local.get 0)) 42 43 (table (export "table") funcref 44 (elem 45 $const-i32 $const-i64 $const-f32 $const-f64 46 $id-i32 $id-i64 $id-f32 $id-f64 47 $f32-i32 $i32-i64 $f64-f32 $i64-f64 48 $over-i32-duplicate $over-i64-duplicate 49 $over-f32-duplicate $over-f64-duplicate 50 ) 51 ) 52 53 ;; Typing 54 55 (func (export "type-i32") (result i32) 56 (call_indirect (type $out-i32) (i32.const 0)) 57 ) 58 (func (export "type-i64") (result i64) 59 (call_indirect (type $out-i64) (i32.const 1)) 60 ) 61 (func (export "type-f32") (result f32) 62 (call_indirect (type $out-f32) (i32.const 2)) 63 ) 64 (func (export "type-f64") (result f64) 65 (call_indirect (type $out-f64) (i32.const 3)) 66 ) 67 68 (func (export "type-index") (result i64) 69 (call_indirect (type $over-i64) (i64.const 100) (i32.const 5)) 70 ) 71 72 (func (export "type-first-i32") (result i32) 73 (call_indirect (type $over-i32) (i32.const 32) (i32.const 4)) 74 ) 75 (func (export "type-first-i64") (result i64) 76 (call_indirect (type $over-i64) (i64.const 64) (i32.const 5)) 77 ) 78 (func (export "type-first-f32") (result f32) 79 (call_indirect (type $over-f32) (f32.const 1.32) (i32.const 6)) 80 ) 81 (func (export "type-first-f64") (result f64) 82 (call_indirect (type $over-f64) (f64.const 1.64) (i32.const 7)) 83 ) 84 85 (func (export "type-second-i32") (result i32) 86 (call_indirect (type $f32-i32) (f32.const 32.1) (i32.const 32) (i32.const 8)) 87 ) 88 (func (export "type-second-i64") (result i64) 89 (call_indirect (type $i32-i64) (i32.const 32) (i64.const 64) (i32.const 9)) 90 ) 91 (func (export "type-second-f32") (result f32) 92 (call_indirect (type $f64-f32) (f64.const 64) (f32.const 32) (i32.const 10)) 93 ) 94 (func (export "type-second-f64") (result f64) 95 (call_indirect (type $i64-f64) (i64.const 64) (f64.const 64.1) (i32.const 11)) 96 ) 97) 98 99(register "test") 100 101(module 102 ;; Auxiliary definitions. These are the same types as "test"'s, but in a 103 ;; different order, since call_indirect types are compared structurally. 104 (type $out-i32 (func (result i32))) 105 (type $out-i64 (func (result i64))) 106 (type $out-f32 (func (result f32))) 107 (type $out-f64 (func (result f64))) 108 (type $over-i32 (func (param i32) (result i32))) 109 (type $over-i64 (func (param i64) (result i64))) 110 (type $over-f32 (func (param f32) (result f32))) 111 (type $over-f64 (func (param f64) (result f64))) 112 (type $f32-i32 (func (param f32 i32) (result i32))) 113 (type $i32-i64 (func (param i32 i64) (result i64))) 114 (type $f64-f32 (func (param f64 f32) (result f32))) 115 (type $i64-f64 (func (param i64 f64) (result f64))) 116 (type $over-i32-duplicate (func (param i32) (result i32))) 117 (type $over-i64-duplicate (func (param i64) (result i64))) 118 (type $over-f32-duplicate (func (param f32) (result f32))) 119 (type $over-f64-duplicate (func (param f64) (result f64))) 120 (type $proc (func)) 121 122 ;; Import the table from "test". 123 124 (import "test" "table" (table 16 funcref)) 125 126 ;; Typing 127 128 (func (export "type-i32") (result i32) 129 (call_indirect (type $out-i32) (i32.const 0)) 130 ) 131 (func (export "type-i64") (result i64) 132 (call_indirect (type $out-i64) (i32.const 1)) 133 ) 134 (func (export "type-f32") (result f32) 135 (call_indirect (type $out-f32) (i32.const 2)) 136 ) 137 (func (export "type-f64") (result f64) 138 (call_indirect (type $out-f64) (i32.const 3)) 139 ) 140 141 (func (export "type-index") (result i64) 142 (call_indirect (type $over-i64) (i64.const 100) (i32.const 5)) 143 ) 144 145 (func (export "type-first-i32") (result i32) 146 (call_indirect (type $over-i32) (i32.const 32) (i32.const 4)) 147 ) 148 (func (export "type-first-i64") (result i64) 149 (call_indirect (type $over-i64) (i64.const 64) (i32.const 5)) 150 ) 151 (func (export "type-first-f32") (result f32) 152 (call_indirect (type $over-f32) (f32.const 1.32) (i32.const 6)) 153 ) 154 (func (export "type-first-f64") (result f64) 155 (call_indirect (type $over-f64) (f64.const 1.64) (i32.const 7)) 156 ) 157 158 (func (export "type-second-i32") (result i32) 159 (call_indirect (type $f32-i32) (f32.const 32.1) (i32.const 32) (i32.const 8)) 160 ) 161 (func (export "type-second-i64") (result i64) 162 (call_indirect (type $i32-i64) (i32.const 32) (i64.const 64) (i32.const 9)) 163 ) 164 (func (export "type-second-f32") (result f32) 165 (call_indirect (type $f64-f32) (f64.const 64) (f32.const 32) (i32.const 10)) 166 ) 167 (func (export "type-second-f64") (result f64) 168 (call_indirect (type $i64-f64) (i64.const 64) (f64.const 64.1) (i32.const 11)) 169 ) 170) 171 172(assert_return (invoke "type-i32") (i32.const 0x132)) 173(assert_return (invoke "type-i64") (i64.const 0x164)) 174(assert_return (invoke "type-f32") (f32.const 0xf32)) 175(assert_return (invoke "type-f64") (f64.const 0xf64)) 176 177(assert_return (invoke "type-index") (i64.const 100)) 178 179(assert_return (invoke "type-first-i32") (i32.const 32)) 180(assert_return (invoke "type-first-i64") (i64.const 64)) 181(assert_return (invoke "type-first-f32") (f32.const 1.32)) 182(assert_return (invoke "type-first-f64") (f64.const 1.64)) 183 184(assert_return (invoke "type-second-i32") (i32.const 32)) 185(assert_return (invoke "type-second-i64") (i64.const 64)) 186(assert_return (invoke "type-second-f32") (f32.const 32)) 187(assert_return (invoke "type-second-f64") (f64.const 64.1)) 188