|
1 | 1 | ;; Test `return_call_indirect` operator
|
2 | 2 |
|
3 | 3 | (module
|
| 4 | + (import "spectest" "print_i32_f32" (func $print_i32_f32 (param i32 f32))) |
| 5 | + |
4 | 6 | ;; Auxiliary definitions
|
5 | 7 | (type $proc (func))
|
6 | 8 | (type $out-i32 (func (result i32)))
|
|
40 | 42 | (func $over-f32-duplicate (type $over-f32-duplicate) (local.get 0))
|
41 | 43 | (func $over-f64-duplicate (type $over-f64-duplicate) (local.get 0))
|
42 | 44 |
|
| 45 | + (func $tailprint_i32_f32 (export "tailprint_i32_f32") (param i32 f32) |
| 46 | + (return_call $print_i32_f32 (local.get 0) (local.get 1)) |
| 47 | + ) |
| 48 | + |
| 49 | + (func $swizzle (param f64 i64) (result i32 f32) |
| 50 | + (i32.wrap_i64 (local.get 1)) |
| 51 | + (f32.demote_f64 (local.get 0)) |
| 52 | + ) |
| 53 | + |
| 54 | + (func $type-f64-i64-to-i32-f32 (export "type-f64-i64-to-i32-f32") (param f64 i64) (result i32 f32) |
| 55 | + (return_call $swizzle (local.get 0) (local.get 1)) |
| 56 | + ) |
| 57 | + |
43 | 58 | (table funcref
|
44 | 59 | (elem
|
45 | 60 | $const-i32 $const-i64 $const-f32 $const-f64
|
|
208 | 223 | )
|
209 | 224 | )
|
210 | 225 | )
|
| 226 | + |
| 227 | + ;; Multiple parameters / multiple results |
| 228 | + (table $tab4 funcref (elem $tailprint_i32_f32 $type-f64-i64-to-i32-f32)) |
| 229 | + |
| 230 | + (func (export "call_tailprint") (param i32 f32) |
| 231 | + (return_call_indirect $tab4 (param i32 f32) (local.get 0) (local.get 1) (i32.const 0)) |
| 232 | + ) |
| 233 | + |
| 234 | + (func (export "call_mpmr") (param f64 i64) (result i32 f32) |
| 235 | + (return_call_indirect $tab4 (param f64 i64) (result i32 f32) (local.get 0) (local.get 1) (i32.const 1)) |
| 236 | + ) |
211 | 237 | )
|
212 | 238 |
|
213 | 239 | (assert_return (invoke "type-i32") (i32.const 0x132))
|
|
233 | 259 | (assert_return (invoke "dispatch" (i32.const 17) (i64.const 2)) (i64.const 2))
|
234 | 260 | (assert_trap (invoke "dispatch" (i32.const 0) (i64.const 2)) "indirect call type mismatch")
|
235 | 261 | (assert_trap (invoke "dispatch" (i32.const 15) (i64.const 2)) "indirect call type mismatch")
|
236 |
| -(assert_trap (invoke "dispatch" (i32.const 20) (i64.const 2)) "undefined element") |
| 262 | +(assert_trap (invoke "dispatch" (i32.const 22) (i64.const 2)) "undefined element") |
237 | 263 | (assert_trap (invoke "dispatch" (i32.const -1) (i64.const 2)) "undefined element")
|
238 | 264 | (assert_trap (invoke "dispatch" (i32.const 1213432423) (i64.const 2)) "undefined element")
|
239 | 265 |
|
|
266 | 292 | (assert_return (invoke "odd" (i32.const 200_002)) (i32.const 99))
|
267 | 293 | (assert_return (invoke "odd" (i32.const 300_003)) (i32.const 44))
|
268 | 294 |
|
| 295 | +(assert_return (invoke "call_tailprint" (i32.const 5) (f32.const 91.0))) |
| 296 | +(assert_return (invoke "call_mpmr" (f64.const 4.2) (i64.const 99)) (i32.const 99) (f32.const 4.2)) |
269 | 297 |
|
270 | 298 | ;; Invalid syntax
|
271 | 299 |
|
|
0 commit comments