1(component
2  (core module $m)
3  (core instance (instantiate $m))
4)
5
6(component
7  (core module $m
8    (func (export ""))
9  )
10  (core instance $i (instantiate $m))
11
12  (core module $m2
13    (func (import "" ""))
14  )
15  (core instance (instantiate $m2 (with "" (instance $i))))
16)
17
18(component
19  (core module $m
20    (func (export "a"))
21  )
22  (core instance $i (instantiate $m))
23
24  (core module $m2
25    (func (import "" "b"))
26  )
27  (core instance (instantiate $m2
28    (with "" (instance (export "b" (func $i "a"))))
29  ))
30)
31
32;; all kinds of imports for core wasm modules, and register a start function on
33;; one module to ensure that everything is correct
34(component
35  (core module $m
36    (func (export "a"))
37    (table (export "b") 1 funcref)
38    (memory (export "c") 1)
39    (global (export "d") i32 i32.const 1)
40  )
41  (core instance $i (instantiate $m))
42
43  (core module $m2
44    (import "" "a" (func $f))
45    (import "" "b" (table 1 funcref))
46    (import "" "c" (memory 1))
47    (import "" "d" (global $g i32))
48
49    (func $start
50      global.get $g
51      i32.const 1
52      i32.ne
53      if
54        unreachable
55      end
56
57      call $f
58    )
59
60    (start $start)
61
62    (data (i32.const 0) "hello")
63    (elem (i32.const 0) $start)
64  )
65  (core instance (instantiate $m2
66    (with "" (instance $i))
67  ))
68)
69
70;; double-check the start function runs by ensuring that a trap shows up and it
71;; sees the wrong value for the global import
72(assert_trap
73  (component
74    (core module $m
75      (global (export "g") i32 i32.const 1)
76    )
77    (core instance $i (instantiate $m))
78
79    (core module $m2
80      (import "" "g" (global $g i32))
81
82      (func $start
83        global.get $g
84        i32.const 0
85        i32.ne
86        if
87          unreachable
88        end
89      )
90
91      (start $start)
92    )
93    (core instance (instantiate $m2 (with "" (instance $i))))
94  )
95  "unreachable")
96
97;; shuffle around imports to get to what the target core wasm module needs
98(component
99  (core module $m
100    (func (export "1"))
101    (table (export "2") 1 funcref)
102    (memory (export "3") 1)
103    (global (export "4") i32 i32.const 1)
104  )
105  (core instance $i (instantiate $m))
106
107  (core module $m2
108    (import "" "a" (func $f))
109    (import "" "b" (table 1 funcref))
110    (import "" "c" (memory 1))
111    (import "" "d" (global $g i32))
112  )
113  (core instance (instantiate $m2
114    (with "" (instance
115      (export "a" (func $i "1"))
116      (export "b" (table $i "2"))
117      (export "c" (memory $i "3"))
118      (export "d" (global $i "4"))
119    ))
120  ))
121)
122