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 funcref (ref.null func))
17 (func (export "get-a") (result i32) (global.get $a))
18 (func (export "get-b") (result i64) (global.get $b))
19 (func (export "get-r") (result externref) (global.get $r))
20 (func (export "get-x") (result i32) (global.get $x))
21 (func (export "get-y") (result i64) (global.get $y))
22 (func (export "set-x") (param i32) (global.set $x (local.get 0)))
23 (func (export "set-y") (param i64) (global.set $y (local.get 0)))
25 (func (export "get-1") (result f32) (global.get 1))
26 (func (export "get-2") (result f64) (global.get 2))
27 (func (export "get-5") (result f32) (global.get 5))
28 (func (export "get-6") (result f64) (global.get 6))
29 (func (export "set-5") (param f32) (global.set 5 (local.get 0)))
30 (func (export "set-6") (param f64) (global.set 6 (local.get 0)))
32 ;; As the argument of control constructs and instructions
38 (func (export "as-select-first") (result i32)
39 (select (global.get $x) (i32.const 2) (i32.const 3))
41 (func (export "as-select-mid") (result i32)
42 (select (i32.const 2) (global.get $x) (i32.const 3))
44 (func (export "as-select-last") (result i32)
45 (select (i32.const 2) (i32.const 3) (global.get $x))
48 (func (export "as-loop-first") (result i32)
50 (global.get $x) (call $dummy) (call $dummy)
53 (func (export "as-loop-mid") (result i32)
55 (call $dummy) (global.get $x) (call $dummy)
58 (func (export "as-loop-last") (result i32)
60 (call $dummy) (call $dummy) (global.get $x)
64 (func (export "as-if-condition") (result i32)
65 (if (result i32) (global.get $x)
66 (then (call $dummy) (i32.const 2))
67 (else (call $dummy) (i32.const 3))
70 (func (export "as-if-then") (result i32)
71 (if (result i32) (i32.const 1)
72 (then (global.get $x)) (else (i32.const 2))
75 (func (export "as-if-else") (result i32)
76 (if (result i32) (i32.const 0)
77 (then (i32.const 2)) (else (global.get $x))
81 (func (export "as-br_if-first") (result i32)
83 (br_if 0 (global.get $x) (i32.const 2))
84 (return (i32.const 3))
87 (func (export "as-br_if-last") (result i32)
89 (br_if 0 (i32.const 2) (global.get $x))
90 (return (i32.const 3))
94 (func (export "as-br_table-first") (result i32)
96 (global.get $x) (i32.const 2) (br_table 0 0)
99 (func (export "as-br_table-last") (result i32)
101 (i32.const 2) (global.get $x) (br_table 0 0)
105 (func $func (param i32 i32) (result i32) (local.get 0))
106 (type $check (func (param i32 i32) (result i32)))
107 (table funcref (elem $func))
108 (func (export "as-call_indirect-first") (result i32)
110 (call_indirect (type $check)
111 (global.get $x) (i32.const 2) (i32.const 0)
115 (func (export "as-call_indirect-mid") (result i32)
117 (call_indirect (type $check)
118 (i32.const 2) (global.get $x) (i32.const 0)
122 (func (export "as-call_indirect-last") (result i32)
124 (call_indirect (type $check)
125 (i32.const 2) (i32.const 0) (global.get $x)
130 (func (export "as-store-first")
131 (global.get $x) (i32.const 1) (i32.store)
133 (func (export "as-store-last")
134 (i32.const 0) (global.get $x) (i32.store)
136 (func (export "as-load-operand") (result i32)
137 (i32.load (global.get $x))
139 (func (export "as-memory.grow-value") (result i32)
140 (memory.grow (global.get $x))
143 (func $f (param i32) (result i32) (local.get 0))
144 (func (export "as-call-value") (result i32)
145 (call $f (global.get $x))
148 (func (export "as-return-value") (result i32)
149 (global.get $x) (return)
151 (func (export "as-drop-operand")
152 (drop (global.get $x))
154 (func (export "as-br-value") (result i32)
155 (block (result i32) (br 0 (global.get $x)))
158 (func (export "as-local.set-value") (param i32) (result i32)
159 (local.set 0 (global.get $x))
162 (func (export "as-local.tee-value") (param i32) (result i32)
163 (local.tee 0 (global.get $x))
165 (func (export "as-global.set-value") (result i32)
166 (global.set $x (global.get $x))
170 (func (export "as-unary-operand") (result i32)
171 (i32.eqz (global.get $x))
173 (func (export "as-binary-operand") (result i32)
175 (global.get $x) (global.get $x)
178 (func (export "as-compare-operand") (result i32)
180 (global.get 0) (i32.const 1)
185 (assert_return (invoke "get-a") (i32.const -2))
186 (assert_return (invoke "get-b") (i64.const -5))
187 (assert_return (invoke "get-r") (ref.null extern))
188 (assert_return (invoke "get-x") (i32.const -12))
189 (assert_return (invoke "get-y") (i64.const -15))
191 (assert_return (invoke "get-1") (f32.const -3))
192 (assert_return (invoke "get-2") (f64.const -4))
193 (assert_return (invoke "get-5") (f32.const -13))
194 (assert_return (invoke "get-6") (f64.const -14))
196 (assert_return (invoke "set-x" (i32.const 6)))
197 (assert_return (invoke "set-y" (i64.const 7)))
198 (assert_return (invoke "set-5" (f32.const 8)))
199 (assert_return (invoke "set-6" (f64.const 9)))
201 (assert_return (invoke "get-x") (i32.const 6))
202 (assert_return (invoke "get-y") (i64.const 7))
203 (assert_return (invoke "get-5") (f32.const 8))
204 (assert_return (invoke "get-6") (f64.const 9))
206 (assert_return (invoke "as-select-first") (i32.const 6))
207 (assert_return (invoke "as-select-mid") (i32.const 2))
208 (assert_return (invoke "as-select-last") (i32.const 2))
210 (assert_return (invoke "as-loop-first") (i32.const 6))
211 (assert_return (invoke "as-loop-mid") (i32.const 6))
212 (assert_return (invoke "as-loop-last") (i32.const 6))
214 (assert_return (invoke "as-if-condition") (i32.const 2))
215 (assert_return (invoke "as-if-then") (i32.const 6))
216 (assert_return (invoke "as-if-else") (i32.const 6))
218 (assert_return (invoke "as-br_if-first") (i32.const 6))
219 (assert_return (invoke "as-br_if-last") (i32.const 2))
221 (assert_return (invoke "as-br_table-first") (i32.const 6))
222 (assert_return (invoke "as-br_table-last") (i32.const 2))
224 (assert_return (invoke "as-call_indirect-first") (i32.const 6))
225 (assert_return (invoke "as-call_indirect-mid") (i32.const 2))
226 (assert_trap (invoke "as-call_indirect-last") "undefined element")
228 (assert_return (invoke "as-store-first"))
229 (assert_return (invoke "as-store-last"))
230 (assert_return (invoke "as-load-operand") (i32.const 1))
231 (assert_return (invoke "as-memory.grow-value") (i32.const 1))
233 (assert_return (invoke "as-call-value") (i32.const 6))
235 (assert_return (invoke "as-return-value") (i32.const 6))
236 (assert_return (invoke "as-drop-operand"))
237 (assert_return (invoke "as-br-value") (i32.const 6))
239 (assert_return (invoke "as-local.set-value" (i32.const 1)) (i32.const 6))
240 (assert_return (invoke "as-local.tee-value" (i32.const 1)) (i32.const 6))
241 (assert_return (invoke "as-global.set-value") (i32.const 6))
243 (assert_return (invoke "as-unary-operand") (i32.const 0))
244 (assert_return (invoke "as-binary-operand") (i32.const 36))
245 (assert_return (invoke "as-compare-operand") (i32.const 1))
248 (module (global f32 (f32.const 0)) (func (global.set 0 (f32.const 1))))
249 "global is immutable"
252 ;; mutable globals can be exported
253 (module (global (mut f32) (f32.const 0)) (export "a" (global 0)))
254 (module (global (export "a") (mut f32) (f32.const 0)))
257 (module (global f32 (f32.neg (f32.const 0))))
258 "constant expression required"
262 (module (global f32 (local.get 0)))
263 "constant expression required"
267 (module (global f32 (f32.neg (f32.const 1))))
268 "constant expression required"
272 (module (global i32 (i32.const 0) (nop)))
273 "constant expression required"
277 (module (global i32 (nop)))
278 "constant expression required"
282 (module (global i32 (f32.const 0)))
287 (module (global i32 (i32.const 0) (i32.const 0)))
292 (module (global i32 (;empty instruction sequence;)))
297 (module (global (import "" "") externref) (global funcref (global.get 0)))
302 (module (global i32 (global.get 0)))
307 (module (global i32 (global.get 1)) (global i32 (i32.const 0)))
312 (import "spectest" "global_i32" (global i32))
316 "\00asm" "\01\00\00\00"
317 "\02\98\80\80\80\00" ;; import section
319 "\08\73\70\65\63\74\65\73\74" ;; "spectest"
320 "\0a\67\6c\6f\62\61\6c\5f\69\33\32" ;; "global_i32"
321 "\03" ;; GlobalImport
323 "\02" ;; malformed mutability
325 "malformed mutability"
329 "\00asm" "\01\00\00\00"
330 "\02\98\80\80\80\00" ;; import section
332 "\08\73\70\65\63\74\65\73\74" ;; "spectest"
333 "\0a\67\6c\6f\62\61\6c\5f\69\33\32" ;; "global_i32"
334 "\03" ;; GlobalImport
336 "\ff" ;; malformed mutability
338 "malformed mutability"
342 (global i32 (i32.const 0))
346 "\00asm" "\01\00\00\00"
347 "\06\86\80\80\80\00" ;; global section
350 "\02" ;; malformed mutability
351 "\41\00" ;; i32.const 0
354 "malformed mutability"
358 "\00asm" "\01\00\00\00"
359 "\06\86\80\80\80\00" ;; global section
362 "\ff" ;; malformed mutability
363 "\41\00" ;; i32.const 0
366 "malformed mutability"
372 (global $x (mut i32) (i32.const 0))
373 (func $type-global.set-value-empty
381 (global $x (mut i32) (i32.const 0))
382 (func $type-global.set-value-empty-in-block
384 (block (global.set $x))
391 (global $x (mut i32) (i32.const 0))
392 (func $type-global.set-value-empty-in-loop
394 (loop (global.set $x))
401 (global $x (mut i32) (i32.const 0))
402 (func $type-global.set-value-empty-in-then
403 (i32.const 0) (i32.const 0)
404 (if (then (global.set $x)))
411 (global $x (mut i32) (i32.const 0))
412 (func $type-global.set-value-empty-in-else
413 (i32.const 0) (i32.const 0)
414 (if (result i32) (then (i32.const 0)) (else (global.set $x)))
421 (global $x (mut i32) (i32.const 0))
422 (func $type-global.set-value-empty-in-br
424 (block (br 0 (global.set $x)))
431 (global $x (mut i32) (i32.const 0))
432 (func $type-global.set-value-empty-in-br_if
434 (block (br_if 0 (global.set $x)))
441 (global $x (mut i32) (i32.const 0))
442 (func $type-global.set-value-empty-in-br_table
444 (block (br_table 0 (global.set $x)))
451 (global $x (mut i32) (i32.const 0))
452 (func $type-global.set-value-empty-in-return
453 (return (global.set $x))
460 (global $x (mut i32) (i32.const 0))
461 (func $type-global.set-value-empty-in-select
462 (select (global.set $x) (i32.const 1) (i32.const 2))
469 (global $x (mut i32) (i32.const 0))
470 (func $type-global.set-value-empty-in-call
471 (call 1 (global.set $x))
473 (func (param i32) (result i32) (local.get 0))
479 (global $x (mut i32) (i32.const 0))
480 (func $f (param i32) (result i32) (local.get 0))
481 (type $sig (func (param i32) (result i32)))
482 (table funcref (elem $f))
483 (func $type-global.set-value-empty-in-call_indirect
485 (call_indirect (type $sig)
486 (global.set $x) (i32.const 0)
494 ;; Duplicate identifier errors
496 (assert_malformed (module quote
497 "(global $foo i32 (i32.const 0))"
498 "(global $foo i32 (i32.const 0))")
500 (assert_malformed (module quote
501 "(import \"\" \"\" (global $foo i32))"
502 "(global $foo i32 (i32.const 0))")
504 (assert_malformed (module quote
505 "(import \"\" \"\" (global $foo i32))"
506 "(import \"\" \"\" (global $foo i32))")