4 (global $a i32 (i32.const -2))
5 (global (;1;) f32 (f32.const -3))
6 (global (;2;) f64 (f64.const -4))
7 (global $b i64 (i64.const -5))
9 (global $x (mut i32) (i32.const -12))
10 (global (;5;) (mut f32) (f32.const -13))
11 (global (;6;) (mut f64) (f64.const -14))
12 (global $y (mut i64) (i64.const -15))
14 (global $r externref (ref.null extern))
15 (global $mr (mut externref) (ref.null extern))
16 (global funcref (ref.null func))
18 (func (export "get-a") (result i32) (global.get $a))
19 (func (export "get-b") (result i64) (global.get $b))
20 (func (export "get-r") (result externref) (global.get $r))
21 (func (export "get-mr") (result externref) (global.get $mr))
22 (func (export "get-x") (result i32) (global.get $x))
23 (func (export "get-y") (result i64) (global.get $y))
24 (func (export "set-x") (param i32) (global.set $x (local.get 0)))
25 (func (export "set-y") (param i64) (global.set $y (local.get 0)))
26 (func (export "set-mr") (param externref) (global.set $mr (local.get 0)))
28 (func (export "get-1") (result f32) (global.get 1))
29 (func (export "get-2") (result f64) (global.get 2))
30 (func (export "get-5") (result f32) (global.get 5))
31 (func (export "get-6") (result f64) (global.get 6))
32 (func (export "set-5") (param f32) (global.set 5 (local.get 0)))
33 (func (export "set-6") (param f64) (global.set 6 (local.get 0)))
35 ;; As the argument of control constructs and instructions
41 (func (export "as-select-first") (result i32)
42 (select (global.get $x) (i32.const 2) (i32.const 3))
44 (func (export "as-select-mid") (result i32)
45 (select (i32.const 2) (global.get $x) (i32.const 3))
47 (func (export "as-select-last") (result i32)
48 (select (i32.const 2) (i32.const 3) (global.get $x))
51 (func (export "as-loop-first") (result i32)
53 (global.get $x) (call $dummy) (call $dummy)
56 (func (export "as-loop-mid") (result i32)
58 (call $dummy) (global.get $x) (call $dummy)
61 (func (export "as-loop-last") (result i32)
63 (call $dummy) (call $dummy) (global.get $x)
67 (func (export "as-if-condition") (result i32)
68 (if (result i32) (global.get $x)
69 (then (call $dummy) (i32.const 2))
70 (else (call $dummy) (i32.const 3))
73 (func (export "as-if-then") (result i32)
74 (if (result i32) (i32.const 1)
75 (then (global.get $x)) (else (i32.const 2))
78 (func (export "as-if-else") (result i32)
79 (if (result i32) (i32.const 0)
80 (then (i32.const 2)) (else (global.get $x))
84 (func (export "as-br_if-first") (result i32)
86 (br_if 0 (global.get $x) (i32.const 2))
87 (return (i32.const 3))
90 (func (export "as-br_if-last") (result i32)
92 (br_if 0 (i32.const 2) (global.get $x))
93 (return (i32.const 3))
97 (func (export "as-br_table-first") (result i32)
99 (global.get $x) (i32.const 2) (br_table 0 0)
102 (func (export "as-br_table-last") (result i32)
104 (i32.const 2) (global.get $x) (br_table 0 0)
108 (func $func (param i32 i32) (result i32) (local.get 0))
109 (type $check (func (param i32 i32) (result i32)))
110 (table funcref (elem $func))
111 (func (export "as-call_indirect-first") (result i32)
113 (call_indirect (type $check)
114 (global.get $x) (i32.const 2) (i32.const 0)
118 (func (export "as-call_indirect-mid") (result i32)
120 (call_indirect (type $check)
121 (i32.const 2) (global.get $x) (i32.const 0)
125 (func (export "as-call_indirect-last") (result i32)
127 (call_indirect (type $check)
128 (i32.const 2) (i32.const 0) (global.get $x)
133 (func (export "as-store-first")
134 (global.get $x) (i32.const 1) (i32.store)
136 (func (export "as-store-last")
137 (i32.const 0) (global.get $x) (i32.store)
139 (func (export "as-load-operand") (result i32)
140 (i32.load (global.get $x))
142 (func (export "as-memory.grow-value") (result i32)
143 (memory.grow (global.get $x))
146 (func $f (param i32) (result i32) (local.get 0))
147 (func (export "as-call-value") (result i32)
148 (call $f (global.get $x))
151 (func (export "as-return-value") (result i32)
152 (global.get $x) (return)
154 (func (export "as-drop-operand")
155 (drop (global.get $x))
157 (func (export "as-br-value") (result i32)
158 (block (result i32) (br 0 (global.get $x)))
161 (func (export "as-local.set-value") (param i32) (result i32)
162 (local.set 0 (global.get $x))
165 (func (export "as-local.tee-value") (param i32) (result i32)
166 (local.tee 0 (global.get $x))
168 (func (export "as-global.set-value") (result i32)
169 (global.set $x (global.get $x))
173 (func (export "as-unary-operand") (result i32)
174 (i32.eqz (global.get $x))
176 (func (export "as-binary-operand") (result i32)
178 (global.get $x) (global.get $x)
181 (func (export "as-compare-operand") (result i32)
183 (global.get 0) (i32.const 1)
188 (assert_return (invoke "get-a") (i32.const -2))
189 (assert_return (invoke "get-b") (i64.const -5))
190 (assert_return (invoke "get-r") (ref.null extern))
191 (assert_return (invoke "get-mr") (ref.null extern))
192 (assert_return (invoke "get-x") (i32.const -12))
193 (assert_return (invoke "get-y") (i64.const -15))
195 (assert_return (invoke "get-1") (f32.const -3))
196 (assert_return (invoke "get-2") (f64.const -4))
197 (assert_return (invoke "get-5") (f32.const -13))
198 (assert_return (invoke "get-6") (f64.const -14))
200 (assert_return (invoke "set-x" (i32.const 6)))
201 (assert_return (invoke "set-y" (i64.const 7)))
202 (assert_return (invoke "set-5" (f32.const 8)))
203 (assert_return (invoke "set-6" (f64.const 9)))
204 (assert_return (invoke "set-mr" (ref.extern 10)))
206 (assert_return (invoke "get-x") (i32.const 6))
207 (assert_return (invoke "get-y") (i64.const 7))
208 (assert_return (invoke "get-5") (f32.const 8))
209 (assert_return (invoke "get-6") (f64.const 9))
210 (assert_return (invoke "get-mr") (ref.extern 10))
212 (assert_return (invoke "as-select-first") (i32.const 6))
213 (assert_return (invoke "as-select-mid") (i32.const 2))
214 (assert_return (invoke "as-select-last") (i32.const 2))
216 (assert_return (invoke "as-loop-first") (i32.const 6))
217 (assert_return (invoke "as-loop-mid") (i32.const 6))
218 (assert_return (invoke "as-loop-last") (i32.const 6))
220 (assert_return (invoke "as-if-condition") (i32.const 2))
221 (assert_return (invoke "as-if-then") (i32.const 6))
222 (assert_return (invoke "as-if-else") (i32.const 6))
224 (assert_return (invoke "as-br_if-first") (i32.const 6))
225 (assert_return (invoke "as-br_if-last") (i32.const 2))
227 (assert_return (invoke "as-br_table-first") (i32.const 6))
228 (assert_return (invoke "as-br_table-last") (i32.const 2))
230 (assert_return (invoke "as-call_indirect-first") (i32.const 6))
231 (assert_return (invoke "as-call_indirect-mid") (i32.const 2))
232 (assert_trap (invoke "as-call_indirect-last") "undefined element")
234 (assert_return (invoke "as-store-first"))
235 (assert_return (invoke "as-store-last"))
236 (assert_return (invoke "as-load-operand") (i32.const 1))
237 (assert_return (invoke "as-memory.grow-value") (i32.const 1))
239 (assert_return (invoke "as-call-value") (i32.const 6))
241 (assert_return (invoke "as-return-value") (i32.const 6))
242 (assert_return (invoke "as-drop-operand"))
243 (assert_return (invoke "as-br-value") (i32.const 6))
245 (assert_return (invoke "as-local.set-value" (i32.const 1)) (i32.const 6))
246 (assert_return (invoke "as-local.tee-value" (i32.const 1)) (i32.const 6))
247 (assert_return (invoke "as-global.set-value") (i32.const 6))
249 (assert_return (invoke "as-unary-operand") (i32.const 0))
250 (assert_return (invoke "as-binary-operand") (i32.const 36))
251 (assert_return (invoke "as-compare-operand") (i32.const 1))
254 (module (global f32 (f32.const 0)) (func (global.set 0 (f32.const 1))))
255 "global is immutable"
258 ;; mutable globals can be exported
259 (module (global (mut f32) (f32.const 0)) (export "a" (global 0)))
260 (module (global (export "a") (mut f32) (f32.const 0)))
263 (module (global f32 (f32.neg (f32.const 0))))
264 "constant expression required"
268 (module (global f32 (local.get 0)))
269 "constant expression required"
273 (module (global f32 (f32.neg (f32.const 1))))
274 "constant expression required"
278 (module (global i32 (i32.const 0) (nop)))
279 "constant expression required"
283 (module (global i32 (nop)))
284 "constant expression required"
288 (module (global i32 (f32.const 0)))
293 (module (global i32 (i32.const 0) (i32.const 0)))
298 (module (global i32 (;empty instruction sequence;)))
303 (module (global (import "" "") externref) (global funcref (global.get 0)))
308 (module (global i32 (global.get 0)))
313 (module (global i32 (global.get 1)) (global i32 (i32.const 0)))
318 (import "spectest" "global_i32" (global i32))
322 "\00asm" "\01\00\00\00"
323 "\02\98\80\80\80\00" ;; import section
325 "\08\73\70\65\63\74\65\73\74" ;; "spectest"
326 "\0a\67\6c\6f\62\61\6c\5f\69\33\32" ;; "global_i32"
327 "\03" ;; GlobalImport
329 "\02" ;; malformed mutability
331 "malformed mutability"
335 "\00asm" "\01\00\00\00"
336 "\02\98\80\80\80\00" ;; import section
338 "\08\73\70\65\63\74\65\73\74" ;; "spectest"
339 "\0a\67\6c\6f\62\61\6c\5f\69\33\32" ;; "global_i32"
340 "\03" ;; GlobalImport
342 "\ff" ;; malformed mutability
344 "malformed mutability"
348 (global i32 (i32.const 0))
352 "\00asm" "\01\00\00\00"
353 "\06\86\80\80\80\00" ;; global section
356 "\02" ;; malformed mutability
357 "\41\00" ;; i32.const 0
360 "malformed mutability"
364 "\00asm" "\01\00\00\00"
365 "\06\86\80\80\80\00" ;; global section
368 "\ff" ;; malformed mutability
369 "\41\00" ;; i32.const 0
372 "malformed mutability"
378 (global $x (mut i32) (i32.const 0))
379 (func $type-global.set-value-empty
387 (global $x (mut i32) (i32.const 0))
388 (func $type-global.set-value-empty-in-block
390 (block (global.set $x))
397 (global $x (mut i32) (i32.const 0))
398 (func $type-global.set-value-empty-in-loop
400 (loop (global.set $x))
407 (global $x (mut i32) (i32.const 0))
408 (func $type-global.set-value-empty-in-then
409 (i32.const 0) (i32.const 0)
410 (if (then (global.set $x)))
417 (global $x (mut i32) (i32.const 0))
418 (func $type-global.set-value-empty-in-else
419 (i32.const 0) (i32.const 0)
420 (if (result i32) (then (i32.const 0)) (else (global.set $x)))
427 (global $x (mut i32) (i32.const 0))
428 (func $type-global.set-value-empty-in-br
430 (block (br 0 (global.set $x)))
437 (global $x (mut i32) (i32.const 0))
438 (func $type-global.set-value-empty-in-br_if
440 (block (br_if 0 (global.set $x)))
447 (global $x (mut i32) (i32.const 0))
448 (func $type-global.set-value-empty-in-br_table
450 (block (br_table 0 (global.set $x)))
457 (global $x (mut i32) (i32.const 0))
458 (func $type-global.set-value-empty-in-return
459 (return (global.set $x))
466 (global $x (mut i32) (i32.const 0))
467 (func $type-global.set-value-empty-in-select
468 (select (global.set $x) (i32.const 1) (i32.const 2))
475 (global $x (mut i32) (i32.const 0))
476 (func $type-global.set-value-empty-in-call
477 (call 1 (global.set $x))
479 (func (param i32) (result i32) (local.get 0))
485 (global $x (mut i32) (i32.const 0))
486 (func $f (param i32) (result i32) (local.get 0))
487 (type $sig (func (param i32) (result i32)))
488 (table funcref (elem $f))
489 (func $type-global.set-value-empty-in-call_indirect
491 (call_indirect (type $sig)
492 (global.set $x) (i32.const 0)
500 ;; Duplicate identifier errors
502 (assert_malformed (module quote
503 "(global $foo i32 (i32.const 0))"
504 "(global $foo i32 (i32.const 0))")
506 (assert_malformed (module quote
507 "(import \"\" \"\" (global $foo i32))"
508 "(global $foo i32 (i32.const 0))")
510 (assert_malformed (module quote
511 "(import \"\" \"\" (global $foo i32))"
512 "(import \"\" \"\" (global $foo i32))")