| 1 |
/* Copyright 2021 Mozilla Foundation |
| 2 |
* |
| 3 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 |
* you may not use this file except in compliance with the License. |
| 5 |
* You may obtain a copy of the License at |
| 6 |
* |
| 7 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 8 |
* |
| 9 |
* Unless required by applicable law or agreed to in writing, software |
| 10 |
* distributed under the License is distributed on an "AS IS" BASIS, |
| 11 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 |
* See the License for the specific language governing permissions and |
| 13 |
* limitations under the License. |
| 14 |
*/ |
| 15 |
|
| 16 |
// ./test/core/local_get.wast |
| 17 |
|
| 18 |
// ./test/core/local_get.wast:3 |
| 19 |
let $0 = instantiate(`(module |
| 20 |
;; Typing |
| 21 |
|
| 22 |
(func (export "type-local-i32") (result i32) (local i32) (local.get 0)) |
| 23 |
(func (export "type-local-i64") (result i64) (local i64) (local.get 0)) |
| 24 |
(func (export "type-local-f32") (result f32) (local f32) (local.get 0)) |
| 25 |
(func (export "type-local-f64") (result f64) (local f64) (local.get 0)) |
| 26 |
|
| 27 |
(func (export "type-param-i32") (param i32) (result i32) (local.get 0)) |
| 28 |
(func (export "type-param-i64") (param i64) (result i64) (local.get 0)) |
| 29 |
(func (export "type-param-f32") (param f32) (result f32) (local.get 0)) |
| 30 |
(func (export "type-param-f64") (param f64) (result f64) (local.get 0)) |
| 31 |
|
| 32 |
(func (export "type-mixed") (param i64 f32 f64 i32 i32) |
| 33 |
(local f32 i64 i64 f64) |
| 34 |
(drop (i64.eqz (local.get 0))) |
| 35 |
(drop (f32.neg (local.get 1))) |
| 36 |
(drop (f64.neg (local.get 2))) |
| 37 |
(drop (i32.eqz (local.get 3))) |
| 38 |
(drop (i32.eqz (local.get 4))) |
| 39 |
(drop (f32.neg (local.get 5))) |
| 40 |
(drop (i64.eqz (local.get 6))) |
| 41 |
(drop (i64.eqz (local.get 7))) |
| 42 |
(drop (f64.neg (local.get 8))) |
| 43 |
) |
| 44 |
|
| 45 |
;; Reading |
| 46 |
|
| 47 |
(func (export "read") (param i64 f32 f64 i32 i32) (result f64) |
| 48 |
(local f32 i64 i64 f64) |
| 49 |
(local.set 5 (f32.const 5.5)) |
| 50 |
(local.set 6 (i64.const 6)) |
| 51 |
(local.set 8 (f64.const 8)) |
| 52 |
(f64.add |
| 53 |
(f64.convert_i64_u (local.get 0)) |
| 54 |
(f64.add |
| 55 |
(f64.promote_f32 (local.get 1)) |
| 56 |
(f64.add |
| 57 |
(local.get 2) |
| 58 |
(f64.add |
| 59 |
(f64.convert_i32_u (local.get 3)) |
| 60 |
(f64.add |
| 61 |
(f64.convert_i32_s (local.get 4)) |
| 62 |
(f64.add |
| 63 |
(f64.promote_f32 (local.get 5)) |
| 64 |
(f64.add |
| 65 |
(f64.convert_i64_u (local.get 6)) |
| 66 |
(f64.add |
| 67 |
(f64.convert_i64_u (local.get 7)) |
| 68 |
(local.get 8) |
| 69 |
) |
| 70 |
) |
| 71 |
) |
| 72 |
) |
| 73 |
) |
| 74 |
) |
| 75 |
) |
| 76 |
) |
| 77 |
) |
| 78 |
|
| 79 |
;; As parameter of control constructs and instructions |
| 80 |
|
| 81 |
(func (export "as-block-value") (param i32) (result i32) |
| 82 |
(block (result i32) (local.get 0)) |
| 83 |
) |
| 84 |
(func (export "as-loop-value") (param i32) (result i32) |
| 85 |
(loop (result i32) (local.get 0)) |
| 86 |
) |
| 87 |
(func (export "as-br-value") (param i32) (result i32) |
| 88 |
(block (result i32) (br 0 (local.get 0))) |
| 89 |
) |
| 90 |
(func (export "as-br_if-value") (param i32) (result i32) |
| 91 |
(block $$l0 (result i32) (br_if $$l0 (local.get 0) (i32.const 1))) |
| 92 |
) |
| 93 |
|
| 94 |
(func (export "as-br_if-value-cond") (param i32) (result i32) |
| 95 |
(block (result i32) |
| 96 |
(br_if 0 (local.get 0) (local.get 0)) |
| 97 |
) |
| 98 |
) |
| 99 |
(func (export "as-br_table-value") (param i32) (result i32) |
| 100 |
(block |
| 101 |
(block |
| 102 |
(block |
| 103 |
(br_table 0 1 2 (local.get 0)) |
| 104 |
(return (i32.const 0)) |
| 105 |
) |
| 106 |
(return (i32.const 1)) |
| 107 |
) |
| 108 |
(return (i32.const 2)) |
| 109 |
) |
| 110 |
(i32.const 3) |
| 111 |
) |
| 112 |
|
| 113 |
(func (export "as-return-value") (param i32) (result i32) |
| 114 |
(return (local.get 0)) |
| 115 |
) |
| 116 |
|
| 117 |
(func (export "as-if-then") (param i32) (result i32) |
| 118 |
(if (result i32) (local.get 0) (then (local.get 0)) (else (i32.const 0))) |
| 119 |
) |
| 120 |
(func (export "as-if-else") (param i32) (result i32) |
| 121 |
(if (result i32) (local.get 0) (then (i32.const 1)) (else (local.get 0))) |
| 122 |
) |
| 123 |
)`); |
| 124 |
|
| 125 |
// ./test/core/local_get.wast:109 |
| 126 |
assert_return(() => invoke($0, `type-local-i32`, []), [value("i32", 0)]); |
| 127 |
|
| 128 |
// ./test/core/local_get.wast:110 |
| 129 |
assert_return(() => invoke($0, `type-local-i64`, []), [value("i64", 0n)]); |
| 130 |
|
| 131 |
// ./test/core/local_get.wast:111 |
| 132 |
assert_return(() => invoke($0, `type-local-f32`, []), [value("f32", 0)]); |
| 133 |
|
| 134 |
// ./test/core/local_get.wast:112 |
| 135 |
assert_return(() => invoke($0, `type-local-f64`, []), [value("f64", 0)]); |
| 136 |
|
| 137 |
// ./test/core/local_get.wast:114 |
| 138 |
assert_return(() => invoke($0, `type-param-i32`, [2]), [value("i32", 2)]); |
| 139 |
|
| 140 |
// ./test/core/local_get.wast:115 |
| 141 |
assert_return(() => invoke($0, `type-param-i64`, [3n]), [value("i64", 3n)]); |
| 142 |
|
| 143 |
// ./test/core/local_get.wast:116 |
| 144 |
assert_return(() => invoke($0, `type-param-f32`, [value("f32", 4.4)]), [value("f32", 4.4)]); |
| 145 |
|
| 146 |
// ./test/core/local_get.wast:117 |
| 147 |
assert_return(() => invoke($0, `type-param-f64`, [value("f64", 5.5)]), [value("f64", 5.5)]); |
| 148 |
|
| 149 |
// ./test/core/local_get.wast:119 |
| 150 |
assert_return(() => invoke($0, `as-block-value`, [6]), [value("i32", 6)]); |
| 151 |
|
| 152 |
// ./test/core/local_get.wast:120 |
| 153 |
assert_return(() => invoke($0, `as-loop-value`, [7]), [value("i32", 7)]); |
| 154 |
|
| 155 |
// ./test/core/local_get.wast:122 |
| 156 |
assert_return(() => invoke($0, `as-br-value`, [8]), [value("i32", 8)]); |
| 157 |
|
| 158 |
// ./test/core/local_get.wast:123 |
| 159 |
assert_return(() => invoke($0, `as-br_if-value`, [9]), [value("i32", 9)]); |
| 160 |
|
| 161 |
// ./test/core/local_get.wast:124 |
| 162 |
assert_return(() => invoke($0, `as-br_if-value-cond`, [10]), [value("i32", 10)]); |
| 163 |
|
| 164 |
// ./test/core/local_get.wast:125 |
| 165 |
assert_return(() => invoke($0, `as-br_table-value`, [1]), [value("i32", 2)]); |
| 166 |
|
| 167 |
// ./test/core/local_get.wast:127 |
| 168 |
assert_return(() => invoke($0, `as-return-value`, [0]), [value("i32", 0)]); |
| 169 |
|
| 170 |
// ./test/core/local_get.wast:129 |
| 171 |
assert_return(() => invoke($0, `as-if-then`, [1]), [value("i32", 1)]); |
| 172 |
|
| 173 |
// ./test/core/local_get.wast:130 |
| 174 |
assert_return(() => invoke($0, `as-if-else`, [0]), [value("i32", 0)]); |
| 175 |
|
| 176 |
// ./test/core/local_get.wast:132 |
| 177 |
assert_return(() => invoke($0, `type-mixed`, [1n, value("f32", 2.2), value("f64", 3.3), 4, 5]), []); |
| 178 |
|
| 179 |
// ./test/core/local_get.wast:138 |
| 180 |
assert_return( |
| 181 |
() => invoke($0, `read`, [1n, value("f32", 2), value("f64", 3.3), 4, 5]), |
| 182 |
[value("f64", 34.8)], |
| 183 |
); |
| 184 |
|
| 185 |
// ./test/core/local_get.wast:148 |
| 186 |
assert_invalid( |
| 187 |
() => instantiate(`(module (func $$type-local-num-vs-num (result i64) (local i32) (local.get 0)))`), |
| 188 |
`type mismatch`, |
| 189 |
); |
| 190 |
|
| 191 |
// ./test/core/local_get.wast:152 |
| 192 |
assert_invalid( |
| 193 |
() => instantiate(`(module (func $$type-local-num-vs-num (result i32) (local f32) (i32.eqz (local.get 0))))`), |
| 194 |
`type mismatch`, |
| 195 |
); |
| 196 |
|
| 197 |
// ./test/core/local_get.wast:156 |
| 198 |
assert_invalid( |
| 199 |
() => instantiate(`(module (func $$type-local-num-vs-num (result f64) (local f64 i64) (f64.neg (local.get 1))))`), |
| 200 |
`type mismatch`, |
| 201 |
); |
| 202 |
|
| 203 |
// ./test/core/local_get.wast:164 |
| 204 |
assert_invalid( |
| 205 |
() => instantiate(`(module (func $$type-param-num-vs-num (param i32) (result i64) (local.get 0)))`), |
| 206 |
`type mismatch`, |
| 207 |
); |
| 208 |
|
| 209 |
// ./test/core/local_get.wast:168 |
| 210 |
assert_invalid( |
| 211 |
() => instantiate(`(module (func $$type-param-num-vs-num (param f32) (result i32) (i32.eqz (local.get 0))))`), |
| 212 |
`type mismatch`, |
| 213 |
); |
| 214 |
|
| 215 |
// ./test/core/local_get.wast:172 |
| 216 |
assert_invalid( |
| 217 |
() => instantiate(`(module (func $$type-param-num-vs-num (param f64 i64) (result f64) (f64.neg (local.get 1))))`), |
| 218 |
`type mismatch`, |
| 219 |
); |
| 220 |
|
| 221 |
// ./test/core/local_get.wast:180 |
| 222 |
assert_invalid( |
| 223 |
() => instantiate(`(module (func $$type-empty-vs-i32 (local i32) (local.get 0)))`), |
| 224 |
`type mismatch`, |
| 225 |
); |
| 226 |
|
| 227 |
// ./test/core/local_get.wast:184 |
| 228 |
assert_invalid( |
| 229 |
() => instantiate(`(module (func $$type-empty-vs-i64 (local i64) (local.get 0)))`), |
| 230 |
`type mismatch`, |
| 231 |
); |
| 232 |
|
| 233 |
// ./test/core/local_get.wast:188 |
| 234 |
assert_invalid( |
| 235 |
() => instantiate(`(module (func $$type-empty-vs-f32 (local f32) (local.get 0)))`), |
| 236 |
`type mismatch`, |
| 237 |
); |
| 238 |
|
| 239 |
// ./test/core/local_get.wast:192 |
| 240 |
assert_invalid( |
| 241 |
() => instantiate(`(module (func $$type-empty-vs-f64 (local f64) (local.get 0)))`), |
| 242 |
`type mismatch`, |
| 243 |
); |
| 244 |
|
| 245 |
// ./test/core/local_get.wast:200 |
| 246 |
assert_invalid( |
| 247 |
() => instantiate(`(module (func $$unbound-local (local i32 i64) (local.get 3) drop))`), |
| 248 |
`unknown local`, |
| 249 |
); |
| 250 |
|
| 251 |
// ./test/core/local_get.wast:204 |
| 252 |
assert_invalid( |
| 253 |
() => instantiate(`(module (func $$large-local (local i32 i64) (local.get 14324343) drop))`), |
| 254 |
`unknown local`, |
| 255 |
); |
| 256 |
|
| 257 |
// ./test/core/local_get.wast:209 |
| 258 |
assert_invalid( |
| 259 |
() => instantiate(`(module (func $$unbound-param (param i32 i64) (local.get 2) drop))`), |
| 260 |
`unknown local`, |
| 261 |
); |
| 262 |
|
| 263 |
// ./test/core/local_get.wast:213 |
| 264 |
assert_invalid( |
| 265 |
() => instantiate(`(module (func $$large-param (param i32 i64) (local.get 714324343) drop))`), |
| 266 |
`unknown local`, |
| 267 |
); |
| 268 |
|
| 269 |
// ./test/core/local_get.wast:218 |
| 270 |
assert_invalid( |
| 271 |
() => instantiate(`(module (func $$unbound-mixed (param i32) (local i32 i64) (local.get 3) drop))`), |
| 272 |
`unknown local`, |
| 273 |
); |
| 274 |
|
| 275 |
// ./test/core/local_get.wast:222 |
| 276 |
assert_invalid( |
| 277 |
() => instantiate(`(module (func $$large-mixed (param i64) (local i32 i64) (local.get 214324343) drop))`), |
| 278 |
`unknown local`, |
| 279 |
); |