blob: 97d928f8468641477f430ffcaef46203dee98b5d (
plain)
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
;; Test globals
(module
(global $a i32 (i32.const -2))
(global (;1;) f32 (f32.const -3))
(global (;2;) f64 (f64.const -4))
(global $b i64 (i64.const -5))
(global $x (mut i32) (i32.const -12))
(global (;5;) (mut f32) (f32.const -13))
(global (;6;) (mut f64) (f64.const -14))
(global $y (mut i64) (i64.const -15))
(func (export "get-a") (result i32) (get_global $a))
(func (export "get-b") (result i64) (get_global $b))
(func (export "get-x") (result i32) (get_global $x))
(func (export "get-y") (result i64) (get_global $y))
(func (export "set-x") (param i32) (set_global $x (get_local 0)))
(func (export "set-y") (param i64) (set_global $y (get_local 0)))
(func (export "get-1") (result f32) (get_global 1))
(func (export "get-2") (result f64) (get_global 2))
(func (export "get-5") (result f32) (get_global 5))
(func (export "get-6") (result f64) (get_global 6))
(func (export "set-5") (param f32) (set_global 5 (get_local 0)))
(func (export "set-6") (param f64) (set_global 6 (get_local 0)))
)
(assert_return (invoke "get-a") (i32.const -2))
(assert_return (invoke "get-b") (i64.const -5))
(assert_return (invoke "get-x") (i32.const -12))
(assert_return (invoke "get-y") (i64.const -15))
(assert_return (invoke "get-1") (f32.const -3))
(assert_return (invoke "get-2") (f64.const -4))
(assert_return (invoke "get-5") (f32.const -13))
(assert_return (invoke "get-6") (f64.const -14))
(assert_return (invoke "set-x" (i32.const 6)))
(assert_return (invoke "set-y" (i64.const 7)))
(assert_return (invoke "set-5" (f32.const 8)))
(assert_return (invoke "set-6" (f64.const 9)))
(assert_return (invoke "get-x") (i32.const 6))
(assert_return (invoke "get-y") (i64.const 7))
(assert_return (invoke "get-5") (f32.const 8))
(assert_return (invoke "get-6") (f64.const 9))
(assert_invalid
(module (global f32 (f32.const 0)) (func (set_global 0 (i32.const 1))))
"global is immutable"
)
(assert_invalid
(module (import "m" "a" (global (mut i32))))
"mutable globals cannot be imported"
)
(assert_invalid
(module (global (import "m" "a") (mut i32)))
"mutable globals cannot be imported"
)
(assert_invalid
(module (global (mut f32) (f32.const 0)) (export "a" (global 0)))
"mutable globals cannot be exported"
)
(assert_invalid
(module (global (export "a") (mut f32) (f32.const 0)))
"mutable globals cannot be exported"
)
(assert_invalid
(module (global f32 (f32.neg (f32.const 0))))
"constant expression required"
)
(assert_invalid
(module (global f32 (get_local 0)))
"constant expression required"
)
(assert_invalid
(module (global i32 (f32.const 0)))
"type mismatch"
)
(assert_invalid
(module (global i32 (get_global 0)))
"unknown global"
)
(assert_invalid
(module (global i32 (get_global 1)) (global i32 (i32.const 0)))
"unknown global"
)
|