File: loop-across-modules.wast

package info (click to toggle)
rust-wasmtime 26.0.1%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 48,492 kB
  • sloc: ansic: 4,003; sh: 561; javascript: 542; cpp: 254; asm: 175; ml: 96; makefile: 55
file content (43 lines) | stat: -rw-r--r-- 1,013 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
;; Do the following loop: `A.f` indirect tail calls through the table, which is
;; populated by `B.start` to contain `B.g`, which in turn tail calls `A.f` and
;; the loop begins again.
;;
;; This is smoke testing that tail call chains across Wasm modules really do
;; have O(1) stack usage.

(module $A
  (type (func (param i32) (result i32)))

  (table (export "table") 1 1 funcref)

  (func (export "f") (param i32) (result i32)
    local.get 0
    i32.eqz
    if
      (return (i32.const 42))
    else
      (i32.sub (local.get 0) (i32.const 1))
      i32.const 0
      return_call_indirect (type 0)
    end
    unreachable
  )
)

(module $B
  (import "A" "table" (table $table 1 1 funcref))
  (import "A" "f" (func $f (param i32) (result i32)))

  (func $g (export "g") (param i32) (result i32)
    local.get 0
    return_call $f
  )

  (func $start
    (table.set $table (i32.const 0) (ref.func $g))
  )
  (start $start)
)

(assert_return (invoke $B "g" (i32.const 100000000))
               (i32.const 42))