Skip to content
This repository was archived by the owner on Apr 25, 2025. It is now read-only.

Commit e19c032

Browse files
authored
Merge pull request #534 from fitzgen/more-i31ref-spec-tests
Add additional `i31ref` spec tests
2 parents b172ec0 + 18ab40c commit e19c032

File tree

1 file changed

+177
-0
lines changed

1 file changed

+177
-0
lines changed

test/core/gc/i31.wast

Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,15 @@
1919

2020
(global $i (ref i31) (ref.i31 (i32.const 2)))
2121
(global $m (mut (ref i31)) (ref.i31 (i32.const 3)))
22+
2223
(func (export "get_globals") (result i32 i32)
2324
(i31.get_u (global.get $i))
2425
(i31.get_u (global.get $m))
2526
)
27+
28+
(func (export "set_global") (param i32)
29+
(global.set $m (ref.i31 (local.get 0)))
30+
)
2631
)
2732

2833
(assert_return (invoke "new" (i32.const 1)) (ref.i31))
@@ -49,3 +54,175 @@
4954
(assert_trap (invoke "get_s-null") "null i31 reference")
5055

5156
(assert_return (invoke "get_globals") (i32.const 2) (i32.const 3))
57+
58+
(invoke "set_global" (i32.const 1234))
59+
(assert_return (invoke "get_globals") (i32.const 2) (i32.const 1234))
60+
61+
(module $tables_of_i31ref
62+
(table $table 3 10 i31ref)
63+
(elem (table $table) (i32.const 0) i31ref (item (ref.i31 (i32.const 999)))
64+
(item (ref.i31 (i32.const 888)))
65+
(item (ref.i31 (i32.const 777))))
66+
67+
(func (export "size") (result i32)
68+
table.size $table
69+
)
70+
71+
(func (export "get") (param i32) (result i32)
72+
(i31.get_u (table.get $table (local.get 0)))
73+
)
74+
75+
(func (export "grow") (param i32 i32) (result i32)
76+
(table.grow $table (ref.i31 (local.get 1)) (local.get 0))
77+
)
78+
79+
(func (export "fill") (param i32 i32 i32)
80+
(table.fill $table (local.get 0) (ref.i31 (local.get 1)) (local.get 2))
81+
)
82+
83+
(func (export "copy") (param i32 i32 i32)
84+
(table.copy $table $table (local.get 0) (local.get 1) (local.get 2))
85+
)
86+
87+
(elem $elem i31ref (item (ref.i31 (i32.const 123)))
88+
(item (ref.i31 (i32.const 456)))
89+
(item (ref.i31 (i32.const 789))))
90+
(func (export "init") (param i32 i32 i32)
91+
(table.init $table $elem (local.get 0) (local.get 1) (local.get 2))
92+
)
93+
)
94+
95+
;; Initial state.
96+
(assert_return (invoke "size") (i32.const 3))
97+
(assert_return (invoke "get" (i32.const 0)) (i32.const 999))
98+
(assert_return (invoke "get" (i32.const 1)) (i32.const 888))
99+
(assert_return (invoke "get" (i32.const 2)) (i32.const 777))
100+
101+
;; Grow from size 3 to size 5.
102+
(assert_return (invoke "grow" (i32.const 2) (i32.const 333)) (i32.const 3))
103+
(assert_return (invoke "size") (i32.const 5))
104+
(assert_return (invoke "get" (i32.const 3)) (i32.const 333))
105+
(assert_return (invoke "get" (i32.const 4)) (i32.const 333))
106+
107+
;; Fill table[2..4] = 111.
108+
(invoke "fill" (i32.const 2) (i32.const 111) (i32.const 2))
109+
(assert_return (invoke "get" (i32.const 2)) (i32.const 111))
110+
(assert_return (invoke "get" (i32.const 3)) (i32.const 111))
111+
112+
;; Copy from table[0..2] to table[3..5].
113+
(invoke "copy" (i32.const 3) (i32.const 0) (i32.const 2))
114+
(assert_return (invoke "get" (i32.const 3)) (i32.const 999))
115+
(assert_return (invoke "get" (i32.const 4)) (i32.const 888))
116+
117+
;; Initialize the passive element at table[1..4].
118+
(invoke "init" (i32.const 1) (i32.const 0) (i32.const 3))
119+
(assert_return (invoke "get" (i32.const 1)) (i32.const 123))
120+
(assert_return (invoke "get" (i32.const 2)) (i32.const 456))
121+
(assert_return (invoke "get" (i32.const 3)) (i32.const 789))
122+
123+
(module $env
124+
(global (export "g") i32 (i32.const 42))
125+
)
126+
(register "env")
127+
128+
(module $i31ref_of_global_table_initializer
129+
(global $g (import "env" "g") i32)
130+
(table $t 3 3 (ref i31) (ref.i31 (global.get $g)))
131+
(func (export "get") (param i32) (result i32)
132+
(i31.get_u (local.get 0) (table.get $t))
133+
)
134+
)
135+
136+
(assert_return (invoke "get" (i32.const 0)) (i32.const 42))
137+
(assert_return (invoke "get" (i32.const 0)) (i32.const 42))
138+
(assert_return (invoke "get" (i32.const 0)) (i32.const 42))
139+
140+
(module $i31ref_of_global_global_initializer
141+
(global $g0 (import "env" "g") i32)
142+
(global $g1 i31ref (ref.i31 (global.get $g0)))
143+
(func (export "get") (result i32)
144+
(i31.get_u (global.get $g1))
145+
)
146+
)
147+
148+
(assert_return (invoke "get") (i32.const 42))
149+
150+
(module $anyref_global_of_i31ref
151+
(global $c anyref (ref.i31 (i32.const 1234)))
152+
(global $m (mut anyref) (ref.i31 (i32.const 5678)))
153+
154+
(func (export "get_globals") (result i32 i32)
155+
(i31.get_u (ref.cast i31ref (global.get $c)))
156+
(i31.get_u (ref.cast i31ref (global.get $m)))
157+
)
158+
159+
(func (export "set_global") (param i32)
160+
(global.set $m (ref.i31 (local.get 0)))
161+
)
162+
)
163+
164+
(assert_return (invoke "get_globals") (i32.const 1234) (i32.const 5678))
165+
(invoke "set_global" (i32.const 0))
166+
(assert_return (invoke "get_globals") (i32.const 1234) (i32.const 0))
167+
168+
(module $anyref_table_of_i31ref
169+
(table $table 3 10 anyref)
170+
(elem (table $table) (i32.const 0) i31ref (item (ref.i31 (i32.const 999)))
171+
(item (ref.i31 (i32.const 888)))
172+
(item (ref.i31 (i32.const 777))))
173+
174+
(func (export "size") (result i32)
175+
table.size $table
176+
)
177+
178+
(func (export "get") (param i32) (result i32)
179+
(i31.get_u (ref.cast i31ref (table.get $table (local.get 0))))
180+
)
181+
182+
(func (export "grow") (param i32 i32) (result i32)
183+
(table.grow $table (ref.i31 (local.get 1)) (local.get 0))
184+
)
185+
186+
(func (export "fill") (param i32 i32 i32)
187+
(table.fill $table (local.get 0) (ref.i31 (local.get 1)) (local.get 2))
188+
)
189+
190+
(func (export "copy") (param i32 i32 i32)
191+
(table.copy $table $table (local.get 0) (local.get 1) (local.get 2))
192+
)
193+
194+
(elem $elem i31ref (item (ref.i31 (i32.const 123)))
195+
(item (ref.i31 (i32.const 456)))
196+
(item (ref.i31 (i32.const 789))))
197+
(func (export "init") (param i32 i32 i32)
198+
(table.init $table $elem (local.get 0) (local.get 1) (local.get 2))
199+
)
200+
)
201+
202+
;; Initial state.
203+
(assert_return (invoke "size") (i32.const 3))
204+
(assert_return (invoke "get" (i32.const 0)) (i32.const 999))
205+
(assert_return (invoke "get" (i32.const 1)) (i32.const 888))
206+
(assert_return (invoke "get" (i32.const 2)) (i32.const 777))
207+
208+
;; Grow from size 3 to size 5.
209+
(assert_return (invoke "grow" (i32.const 2) (i32.const 333)) (i32.const 3))
210+
(assert_return (invoke "size") (i32.const 5))
211+
(assert_return (invoke "get" (i32.const 3)) (i32.const 333))
212+
(assert_return (invoke "get" (i32.const 4)) (i32.const 333))
213+
214+
;; Fill table[2..4] = 111.
215+
(invoke "fill" (i32.const 2) (i32.const 111) (i32.const 2))
216+
(assert_return (invoke "get" (i32.const 2)) (i32.const 111))
217+
(assert_return (invoke "get" (i32.const 3)) (i32.const 111))
218+
219+
;; Copy from table[0..2] to table[3..5].
220+
(invoke "copy" (i32.const 3) (i32.const 0) (i32.const 2))
221+
(assert_return (invoke "get" (i32.const 3)) (i32.const 999))
222+
(assert_return (invoke "get" (i32.const 4)) (i32.const 888))
223+
224+
;; Initialize the passive element at table[1..4].
225+
(invoke "init" (i32.const 1) (i32.const 0) (i32.const 3))
226+
(assert_return (invoke "get" (i32.const 1)) (i32.const 123))
227+
(assert_return (invoke "get" (i32.const 2)) (i32.const 456))
228+
(assert_return (invoke "get" (i32.const 3)) (i32.const 789))

0 commit comments

Comments
 (0)