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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
|
/* Copyright 2021 Mozilla Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// ./test/core/local_get.wast
// ./test/core/local_get.wast:3
let $0 = instantiate(`(module
;; Typing
(func (export "type-local-i32") (result i32) (local i32) (local.get 0))
(func (export "type-local-i64") (result i64) (local i64) (local.get 0))
(func (export "type-local-f32") (result f32) (local f32) (local.get 0))
(func (export "type-local-f64") (result f64) (local f64) (local.get 0))
(func (export "type-param-i32") (param i32) (result i32) (local.get 0))
(func (export "type-param-i64") (param i64) (result i64) (local.get 0))
(func (export "type-param-f32") (param f32) (result f32) (local.get 0))
(func (export "type-param-f64") (param f64) (result f64) (local.get 0))
(func (export "type-mixed") (param i64 f32 f64 i32 i32)
(local f32 i64 i64 f64)
(drop (i64.eqz (local.get 0)))
(drop (f32.neg (local.get 1)))
(drop (f64.neg (local.get 2)))
(drop (i32.eqz (local.get 3)))
(drop (i32.eqz (local.get 4)))
(drop (f32.neg (local.get 5)))
(drop (i64.eqz (local.get 6)))
(drop (i64.eqz (local.get 7)))
(drop (f64.neg (local.get 8)))
)
;; Reading
(func (export "read") (param i64 f32 f64 i32 i32) (result f64)
(local f32 i64 i64 f64)
(local.set 5 (f32.const 5.5))
(local.set 6 (i64.const 6))
(local.set 8 (f64.const 8))
(f64.add
(f64.convert_i64_u (local.get 0))
(f64.add
(f64.promote_f32 (local.get 1))
(f64.add
(local.get 2)
(f64.add
(f64.convert_i32_u (local.get 3))
(f64.add
(f64.convert_i32_s (local.get 4))
(f64.add
(f64.promote_f32 (local.get 5))
(f64.add
(f64.convert_i64_u (local.get 6))
(f64.add
(f64.convert_i64_u (local.get 7))
(local.get 8)
)
)
)
)
)
)
)
)
)
;; As parameter of control constructs and instructions
(func (export "as-block-value") (param i32) (result i32)
(block (result i32) (local.get 0))
)
(func (export "as-loop-value") (param i32) (result i32)
(loop (result i32) (local.get 0))
)
(func (export "as-br-value") (param i32) (result i32)
(block (result i32) (br 0 (local.get 0)))
)
(func (export "as-br_if-value") (param i32) (result i32)
(block $$l0 (result i32) (br_if $$l0 (local.get 0) (i32.const 1)))
)
(func (export "as-br_if-value-cond") (param i32) (result i32)
(block (result i32)
(br_if 0 (local.get 0) (local.get 0))
)
)
(func (export "as-br_table-value") (param i32) (result i32)
(block
(block
(block
(br_table 0 1 2 (local.get 0))
(return (i32.const 0))
)
(return (i32.const 1))
)
(return (i32.const 2))
)
(i32.const 3)
)
(func (export "as-return-value") (param i32) (result i32)
(return (local.get 0))
)
(func (export "as-if-then") (param i32) (result i32)
(if (result i32) (local.get 0) (then (local.get 0)) (else (i32.const 0)))
)
(func (export "as-if-else") (param i32) (result i32)
(if (result i32) (local.get 0) (then (i32.const 1)) (else (local.get 0)))
)
)`);
// ./test/core/local_get.wast:109
assert_return(() => invoke($0, `type-local-i32`, []), [value("i32", 0)]);
// ./test/core/local_get.wast:110
assert_return(() => invoke($0, `type-local-i64`, []), [value("i64", 0n)]);
// ./test/core/local_get.wast:111
assert_return(() => invoke($0, `type-local-f32`, []), [value("f32", 0)]);
// ./test/core/local_get.wast:112
assert_return(() => invoke($0, `type-local-f64`, []), [value("f64", 0)]);
// ./test/core/local_get.wast:114
assert_return(() => invoke($0, `type-param-i32`, [2]), [value("i32", 2)]);
// ./test/core/local_get.wast:115
assert_return(() => invoke($0, `type-param-i64`, [3n]), [value("i64", 3n)]);
// ./test/core/local_get.wast:116
assert_return(() => invoke($0, `type-param-f32`, [value("f32", 4.4)]), [value("f32", 4.4)]);
// ./test/core/local_get.wast:117
assert_return(() => invoke($0, `type-param-f64`, [value("f64", 5.5)]), [value("f64", 5.5)]);
// ./test/core/local_get.wast:119
assert_return(() => invoke($0, `as-block-value`, [6]), [value("i32", 6)]);
// ./test/core/local_get.wast:120
assert_return(() => invoke($0, `as-loop-value`, [7]), [value("i32", 7)]);
// ./test/core/local_get.wast:122
assert_return(() => invoke($0, `as-br-value`, [8]), [value("i32", 8)]);
// ./test/core/local_get.wast:123
assert_return(() => invoke($0, `as-br_if-value`, [9]), [value("i32", 9)]);
// ./test/core/local_get.wast:124
assert_return(() => invoke($0, `as-br_if-value-cond`, [10]), [value("i32", 10)]);
// ./test/core/local_get.wast:125
assert_return(() => invoke($0, `as-br_table-value`, [1]), [value("i32", 2)]);
// ./test/core/local_get.wast:127
assert_return(() => invoke($0, `as-return-value`, [0]), [value("i32", 0)]);
// ./test/core/local_get.wast:129
assert_return(() => invoke($0, `as-if-then`, [1]), [value("i32", 1)]);
// ./test/core/local_get.wast:130
assert_return(() => invoke($0, `as-if-else`, [0]), [value("i32", 0)]);
// ./test/core/local_get.wast:132
assert_return(() => invoke($0, `type-mixed`, [1n, value("f32", 2.2), value("f64", 3.3), 4, 5]), []);
// ./test/core/local_get.wast:138
assert_return(
() => invoke($0, `read`, [1n, value("f32", 2), value("f64", 3.3), 4, 5]),
[value("f64", 34.8)],
);
// ./test/core/local_get.wast:148
assert_invalid(
() => instantiate(`(module (func $$type-local-num-vs-num (result i64) (local i32) (local.get 0)))`),
`type mismatch`,
);
// ./test/core/local_get.wast:152
assert_invalid(
() => instantiate(`(module (func $$type-local-num-vs-num (result i32) (local f32) (i32.eqz (local.get 0))))`),
`type mismatch`,
);
// ./test/core/local_get.wast:156
assert_invalid(
() => instantiate(`(module (func $$type-local-num-vs-num (result f64) (local f64 i64) (f64.neg (local.get 1))))`),
`type mismatch`,
);
// ./test/core/local_get.wast:164
assert_invalid(
() => instantiate(`(module (func $$type-param-num-vs-num (param i32) (result i64) (local.get 0)))`),
`type mismatch`,
);
// ./test/core/local_get.wast:168
assert_invalid(
() => instantiate(`(module (func $$type-param-num-vs-num (param f32) (result i32) (i32.eqz (local.get 0))))`),
`type mismatch`,
);
// ./test/core/local_get.wast:172
assert_invalid(
() => instantiate(`(module (func $$type-param-num-vs-num (param f64 i64) (result f64) (f64.neg (local.get 1))))`),
`type mismatch`,
);
// ./test/core/local_get.wast:180
assert_invalid(
() => instantiate(`(module (func $$type-empty-vs-i32 (local i32) (local.get 0)))`),
`type mismatch`,
);
// ./test/core/local_get.wast:184
assert_invalid(
() => instantiate(`(module (func $$type-empty-vs-i64 (local i64) (local.get 0)))`),
`type mismatch`,
);
// ./test/core/local_get.wast:188
assert_invalid(
() => instantiate(`(module (func $$type-empty-vs-f32 (local f32) (local.get 0)))`),
`type mismatch`,
);
// ./test/core/local_get.wast:192
assert_invalid(
() => instantiate(`(module (func $$type-empty-vs-f64 (local f64) (local.get 0)))`),
`type mismatch`,
);
// ./test/core/local_get.wast:200
assert_invalid(
() => instantiate(`(module (func $$unbound-local (local i32 i64) (local.get 3) drop))`),
`unknown local`,
);
// ./test/core/local_get.wast:204
assert_invalid(
() => instantiate(`(module (func $$large-local (local i32 i64) (local.get 14324343) drop))`),
`unknown local`,
);
// ./test/core/local_get.wast:209
assert_invalid(
() => instantiate(`(module (func $$unbound-param (param i32 i64) (local.get 2) drop))`),
`unknown local`,
);
// ./test/core/local_get.wast:213
assert_invalid(
() => instantiate(`(module (func $$large-param (param i32 i64) (local.get 714324343) drop))`),
`unknown local`,
);
// ./test/core/local_get.wast:218
assert_invalid(
() => instantiate(`(module (func $$unbound-mixed (param i32) (local i32 i64) (local.get 3) drop))`),
`unknown local`,
);
// ./test/core/local_get.wast:222
assert_invalid(
() => instantiate(`(module (func $$large-mixed (param i64) (local i32 i64) (local.get 214324343) drop))`),
`unknown local`,
);
// ./test/core/local_get.wast:230
let $1 = instantiate(`(module
(func (export "get-after-set") (param $$p (ref extern)) (result (ref extern))
(local $$x (ref extern))
(local.set $$x (local.get $$p))
(local.get $$x)
)
(func (export "get-after-tee") (param $$p (ref extern)) (result (ref extern))
(local $$x (ref extern))
(drop (local.tee $$x (local.get $$p)))
(local.get $$x)
)
(func (export "get-in-block-after-set") (param $$p (ref extern)) (result (ref extern))
(local $$x (ref extern))
(local.set $$x (local.get $$p))
(block (result (ref extern)) (local.get $$x))
)
)`);
// ./test/core/local_get.wast:252
assert_invalid(
() => instantiate(`(module (func $$uninit (local $$x (ref extern)) (drop (local.get $$x))))`),
`uninitialized local`,
);
// ./test/core/local_get.wast:256
assert_invalid(
() => instantiate(`(module
(func $$uninit-after-end (param $$p (ref extern))
(local $$x (ref extern))
(block (local.set $$x (local.get $$p)) (drop (local.tee $$x (local.get $$p))))
(drop (local.get $$x))
)
)`),
`uninitialized local`,
);
|