Skip to content

Commit

Permalink
Add a simple test for multiple tables
Browse files Browse the repository at this point in the history
  • Loading branch information
rossberg committed Mar 11, 2021
1 parent 9082bcd commit 122e4be
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions test/core/return_call_indirect.wast
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,27 @@
)
)

;; Multiple tables

(table $tab2 funcref (elem $tab-f1))
(table $tab3 funcref (elem $tab-f2))

(func $tab-f1 (result i32) (i32.const 0x133))
(func $tab-f2 (result i32) (i32.const 0x134))

(func (export "call-tab") (param $i i32) (result i32)
(if (i32.eq (local.get $i) (i32.const 0))
(then (return_call_indirect (type $out-i32) (i32.const 0)))
)
(if (i32.eq (local.get $i) (i32.const 1))
(then (return_call_indirect 1 (type $out-i32) (i32.const 0)))
)
(if (i32.eq (local.get $i) (i32.const 2))
(then (return_call_indirect $tab3 (type $out-i32) (i32.const 0)))
)
(i32.const 0)
)

;; Recursion

(func $fac (export "fac") (type $over-i64)
Expand Down Expand Up @@ -223,6 +244,10 @@
(assert_trap (invoke "dispatch-structural" (i32.const 11)) "indirect call type mismatch")
(assert_trap (invoke "dispatch-structural" (i32.const 16)) "indirect call type mismatch")

(assert_return (invoke "call-tab" (i32.const 0)) (i32.const 0x132))
(assert_return (invoke "call-tab" (i32.const 1)) (i32.const 0x133))
(assert_return (invoke "call-tab" (i32.const 2)) (i32.const 0x134))

(assert_return (invoke "fac" (i64.const 0)) (i64.const 1))
(assert_return (invoke "fac" (i64.const 1)) (i64.const 1))
(assert_return (invoke "fac" (i64.const 5)) (i64.const 120))
Expand Down

0 comments on commit 122e4be

Please sign in to comment.