1;; Functions
2
3(module (func) (export "a" (func 0)))
4(module (func) (export "a" (func 0)) (export "b" (func 0)))
5(module (func) (func) (export "a" (func 0)) (export "b" (func 1)))
6
7(module (func (export "a")))
8(module (func $a (export "a")))
9
10(module $Func
11  (export "e" (func $f))
12  (func $f (param $n i32) (result i32)
13    (return (i32.add (local.get $n) (i32.const 1)))
14  )
15)
16(assert_return (invoke "e" (i32.const 42)) (i32.const 43))
17(assert_return (invoke $Func "e" (i32.const 42)) (i32.const 43))
18(module)
19(module $Other1)
20(assert_return (invoke $Func "e" (i32.const 42)) (i32.const 43))
21
22(assert_invalid
23  (module (func) (export "a" (func 1)))
24  "unknown function"
25)
26(assert_invalid
27  (module (func) (export "a" (func 0)) (export "a" (func 0)))
28  "duplicate export name"
29)
30(assert_invalid
31  (module (func) (func) (export "a" (func 0)) (export "a" (func 1)))
32  "duplicate export name"
33)
34(assert_invalid
35  (module (func) (global i32 (i32.const 0)) (export "a" (func 0)) (export "a" (global 0)))
36  "duplicate export name"
37)
38(assert_invalid
39  (module (func) (table 0 funcref) (export "a" (func 0)) (export "a" (table 0)))
40  "duplicate export name"
41)
42(assert_invalid
43  (module (func) (memory 0) (export "a" (func 0)) (export "a" (memory 0)))
44  "duplicate export name"
45)
46
47
48;; Globals
49
50(module (global i32 (i32.const 0)) (export "a" (global 0)))
51(module (global i32 (i32.const 0)) (export "a" (global 0)) (export "b" (global 0)))
52(module (global i32 (i32.const 0)) (global i32 (i32.const 0)) (export "a" (global 0)) (export "b" (global 1)))
53
54(module (global (export "a") i32 (i32.const 0)))
55(module (global $a (export "a") i32 (i32.const 0)))
56
57(module $Global
58  (export "e" (global $g))
59  (global $g i32 (i32.const 42))
60)
61(assert_return (get "e") (i32.const 42))
62(assert_return (get $Global "e") (i32.const 42))
63(module)
64(module $Other2)
65(assert_return (get $Global "e") (i32.const 42))
66
67(assert_invalid
68  (module (global i32 (i32.const 0)) (export "a" (global 1)))
69  "unknown global"
70)
71(assert_invalid
72  (module (global i32 (i32.const 0)) (export "a" (global 0)) (export "a" (global 0)))
73  "duplicate export name"
74)
75(assert_invalid
76  (module (global i32 (i32.const 0)) (global i32 (i32.const 0)) (export "a" (global 0)) (export "a" (global 1)))
77  "duplicate export name"
78)
79(assert_invalid
80  (module (global i32 (i32.const 0)) (func) (export "a" (global 0)) (export "a" (func 0)))
81  "duplicate export name"
82)
83(assert_invalid
84  (module (global i32 (i32.const 0)) (table 0 funcref) (export "a" (global 0)) (export "a" (table 0)))
85  "duplicate export name"
86)
87(assert_invalid
88  (module (global i32 (i32.const 0)) (memory 0) (export "a" (global 0)) (export "a" (memory 0)))
89  "duplicate export name"
90)
91
92
93;; Tables
94
95(module (table 0 funcref) (export "a" (table 0)))
96(module (table 0 funcref) (export "a" (table 0)) (export "b" (table 0)))
97;; No multiple tables yet.
98;; (module (table 0 funcref) (table 0 funcref) (export "a" (table 0)) (export "b" (table 1)))
99
100(module (table (export "a") 0 funcref))
101(module (table (export "a") 0 1 funcref))
102(module (table $a (export "a") 0 funcref))
103(module (table $a (export "a") 0 1 funcref))
104
105(; TODO: access table ;)
106
107(assert_invalid
108  (module (table 0 funcref) (export "a" (table 1)))
109  "unknown table"
110)
111(assert_invalid
112  (module (table 0 funcref) (export "a" (table 0)) (export "a" (table 0)))
113  "duplicate export name"
114)
115;; No multiple tables yet.
116;; (assert_invalid
117;;   (module (table 0 funcref) (table 0 funcref) (export "a" (table 0)) (export "a" (table 1)))
118;;   "duplicate export name"
119;; )
120(assert_invalid
121  (module (table 0 funcref) (func) (export "a" (table 0)) (export "a" (func 0)))
122  "duplicate export name"
123)
124(assert_invalid
125  (module (table 0 funcref) (global i32 (i32.const 0)) (export "a" (table 0)) (export "a" (global 0)))
126  "duplicate export name"
127)
128(assert_invalid
129  (module (table 0 funcref) (memory 0) (export "a" (table 0)) (export "a" (memory 0)))
130  "duplicate export name"
131)
132
133
134;; Memories
135
136(module (memory 0) (export "a" (memory 0)))
137(module (memory 0) (export "a" (memory 0)) (export "b" (memory 0)))
138;; No multiple memories yet.
139;; (module (memory 0) (memory 0) (export "a" (memory 0)) (export "b" (memory 1)))
140
141(module (memory (export "a") 0))
142(module (memory (export "a") 0 1))
143(module (memory $a (export "a") 0))
144(module (memory $a (export "a") 0 1))
145
146(; TODO: access memory ;)
147
148(assert_invalid
149  (module (memory 0) (export "a" (memory 1)))
150  "unknown memory"
151)
152(assert_invalid
153  (module (memory 0) (export "a" (memory 0)) (export "a" (memory 0)))
154  "duplicate export name"
155)
156;; No multiple memories yet.
157;; (assert_invalid
158;;   (module (memory 0) (memory 0) (export "a" (memory 0)) (export "a" (memory 1)))
159;;   "duplicate export name"
160;; )
161(assert_invalid
162  (module (memory 0) (func) (export "a" (memory 0)) (export "a" (func 0)))
163  "duplicate export name"
164)
165(assert_invalid
166  (module (memory 0) (global i32 (i32.const 0)) (export "a" (memory 0)) (export "a" (global 0)))
167  "duplicate export name"
168)
169(assert_invalid
170  (module (memory 0) (table 0 funcref) (export "a" (memory 0)) (export "a" (table 0)))
171  "duplicate export name"
172)
173