github.com/tetratelabs/wazero@v1.7.3-0.20240513003603-48f702e154b5/internal/integration_test/spectest/v1/testdata/local_get.wast (about) 1 ;; Test `local.get` operator 2 3 (module 4 ;; Typing 5 6 (func (export "type-local-i32") (result i32) (local i32) (local.get 0)) 7 (func (export "type-local-i64") (result i64) (local i64) (local.get 0)) 8 (func (export "type-local-f32") (result f32) (local f32) (local.get 0)) 9 (func (export "type-local-f64") (result f64) (local f64) (local.get 0)) 10 11 (func (export "type-param-i32") (param i32) (result i32) (local.get 0)) 12 (func (export "type-param-i64") (param i64) (result i64) (local.get 0)) 13 (func (export "type-param-f32") (param f32) (result f32) (local.get 0)) 14 (func (export "type-param-f64") (param f64) (result f64) (local.get 0)) 15 16 (func (export "type-mixed") (param i64 f32 f64 i32 i32) 17 (local f32 i64 i64 f64) 18 (drop (i64.eqz (local.get 0))) 19 (drop (f32.neg (local.get 1))) 20 (drop (f64.neg (local.get 2))) 21 (drop (i32.eqz (local.get 3))) 22 (drop (i32.eqz (local.get 4))) 23 (drop (f32.neg (local.get 5))) 24 (drop (i64.eqz (local.get 6))) 25 (drop (i64.eqz (local.get 7))) 26 (drop (f64.neg (local.get 8))) 27 ) 28 29 ;; Reading 30 31 (func (export "read") (param i64 f32 f64 i32 i32) (result f64) 32 (local f32 i64 i64 f64) 33 (local.set 5 (f32.const 5.5)) 34 (local.set 6 (i64.const 6)) 35 (local.set 8 (f64.const 8)) 36 (f64.add 37 (f64.convert_i64_u (local.get 0)) 38 (f64.add 39 (f64.promote_f32 (local.get 1)) 40 (f64.add 41 (local.get 2) 42 (f64.add 43 (f64.convert_i32_u (local.get 3)) 44 (f64.add 45 (f64.convert_i32_s (local.get 4)) 46 (f64.add 47 (f64.promote_f32 (local.get 5)) 48 (f64.add 49 (f64.convert_i64_u (local.get 6)) 50 (f64.add 51 (f64.convert_i64_u (local.get 7)) 52 (local.get 8) 53 ) 54 ) 55 ) 56 ) 57 ) 58 ) 59 ) 60 ) 61 ) 62 63 ;; As parameter of control constructs and instructions 64 65 (func (export "as-block-value") (param i32) (result i32) 66 (block (result i32) (local.get 0)) 67 ) 68 (func (export "as-loop-value") (param i32) (result i32) 69 (loop (result i32) (local.get 0)) 70 ) 71 (func (export "as-br-value") (param i32) (result i32) 72 (block (result i32) (br 0 (local.get 0))) 73 ) 74 (func (export "as-br_if-value") (param i32) (result i32) 75 (block $l0 (result i32) (br_if $l0 (local.get 0) (i32.const 1))) 76 ) 77 78 (func (export "as-br_if-value-cond") (param i32) (result i32) 79 (block (result i32) 80 (br_if 0 (local.get 0) (local.get 0)) 81 ) 82 ) 83 (func (export "as-br_table-value") (param i32) (result i32) 84 (block 85 (block 86 (block 87 (br_table 0 1 2 (local.get 0)) 88 (return (i32.const 0)) 89 ) 90 (return (i32.const 1)) 91 ) 92 (return (i32.const 2)) 93 ) 94 (i32.const 3) 95 ) 96 97 (func (export "as-return-value") (param i32) (result i32) 98 (return (local.get 0)) 99 ) 100 101 (func (export "as-if-then") (param i32) (result i32) 102 (if (result i32) (local.get 0) (then (local.get 0)) (else (i32.const 0))) 103 ) 104 (func (export "as-if-else") (param i32) (result i32) 105 (if (result i32) (local.get 0) (then (i32.const 1)) (else (local.get 0))) 106 ) 107 ) 108 109 (assert_return (invoke "type-local-i32") (i32.const 0)) 110 (assert_return (invoke "type-local-i64") (i64.const 0)) 111 (assert_return (invoke "type-local-f32") (f32.const 0)) 112 (assert_return (invoke "type-local-f64") (f64.const 0)) 113 114 (assert_return (invoke "type-param-i32" (i32.const 2)) (i32.const 2)) 115 (assert_return (invoke "type-param-i64" (i64.const 3)) (i64.const 3)) 116 (assert_return (invoke "type-param-f32" (f32.const 4.4)) (f32.const 4.4)) 117 (assert_return (invoke "type-param-f64" (f64.const 5.5)) (f64.const 5.5)) 118 119 (assert_return (invoke "as-block-value" (i32.const 6)) (i32.const 6)) 120 (assert_return (invoke "as-loop-value" (i32.const 7)) (i32.const 7)) 121 122 (assert_return (invoke "as-br-value" (i32.const 8)) (i32.const 8)) 123 (assert_return (invoke "as-br_if-value" (i32.const 9)) (i32.const 9)) 124 (assert_return (invoke "as-br_if-value-cond" (i32.const 10)) (i32.const 10)) 125 (assert_return (invoke "as-br_table-value" (i32.const 1)) (i32.const 2)) 126 127 (assert_return (invoke "as-return-value" (i32.const 0)) (i32.const 0)) 128 129 (assert_return (invoke "as-if-then" (i32.const 1)) (i32.const 1)) 130 (assert_return (invoke "as-if-else" (i32.const 0)) (i32.const 0)) 131 132 (assert_return 133 (invoke "type-mixed" 134 (i64.const 1) (f32.const 2.2) (f64.const 3.3) (i32.const 4) (i32.const 5) 135 ) 136 ) 137 138 (assert_return 139 (invoke "read" 140 (i64.const 1) (f32.const 2) (f64.const 3.3) (i32.const 4) (i32.const 5) 141 ) 142 (f64.const 34.8) 143 ) 144 145 146 ;; Invalid typing of access to locals 147 148 (assert_invalid 149 (module (func $type-local-num-vs-num (result i64) (local i32) (local.get 0))) 150 "type mismatch" 151 ) 152 (assert_invalid 153 (module (func $type-local-num-vs-num (result i32) (local f32) (i32.eqz (local.get 0)))) 154 "type mismatch" 155 ) 156 (assert_invalid 157 (module (func $type-local-num-vs-num (result f64) (local f64 i64) (f64.neg (local.get 1)))) 158 "type mismatch" 159 ) 160 161 162 ;; Invalid typing of access to parameters 163 164 (assert_invalid 165 (module (func $type-param-num-vs-num (param i32) (result i64) (local.get 0))) 166 "type mismatch" 167 ) 168 (assert_invalid 169 (module (func $type-param-num-vs-num (param f32) (result i32) (i32.eqz (local.get 0)))) 170 "type mismatch" 171 ) 172 (assert_invalid 173 (module (func $type-param-num-vs-num (param f64 i64) (result f64) (f64.neg (local.get 1)))) 174 "type mismatch" 175 ) 176 177 178 ;; local.set should have retval 179 180 (assert_invalid 181 (module (func $type-empty-vs-i32 (local i32) (local.get 0))) 182 "type mismatch" 183 ) 184 (assert_invalid 185 (module (func $type-empty-vs-i64 (local i64) (local.get 0))) 186 "type mismatch" 187 ) 188 (assert_invalid 189 (module (func $type-empty-vs-f32 (local f32) (local.get 0))) 190 "type mismatch" 191 ) 192 (assert_invalid 193 (module (func $type-empty-vs-f64 (local f64) (local.get 0))) 194 "type mismatch" 195 ) 196 197 198 ;; Invalid local index 199 200 (assert_invalid 201 (module (func $unbound-local (local i32 i64) (local.get 3))) 202 "unknown local" 203 ) 204 (assert_invalid 205 (module (func $large-local (local i32 i64) (local.get 14324343))) 206 "unknown local" 207 ) 208 209 (assert_invalid 210 (module (func $unbound-param (param i32 i64) (local.get 2))) 211 "unknown local" 212 ) 213 (assert_invalid 214 (module (func $large-param (param i32 i64) (local.get 714324343))) 215 "unknown local" 216 ) 217 218 (assert_invalid 219 (module (func $unbound-mixed (param i32) (local i32 i64) (local.get 3))) 220 "unknown local" 221 ) 222 (assert_invalid 223 (module (func $large-mixed (param i64) (local i32 i64) (local.get 214324343))) 224 "unknown local" 225 ) 226