|
40 | 40 | (if (i32.ne (local.get $len) (i32.const 0))
|
41 | 41 | (then
|
42 | 42 | (local.set $c (array.get_u $bytes (local.get $s) (i32.const 0)))
|
43 |
| - (if (i32.eq (local.get $c) (i32.const 45)) |
| 43 | + (if (i32.eq (local.get $c) (@char "-")) |
44 | 44 | (then
|
45 | 45 | (local.set $sign (i32.const -1))
|
46 | 46 | (local.set $i (i32.const 1)))
|
47 |
| - (else (if (i32.eq (local.get $c) (i32.const 43)) |
| 47 | + (else (if (i32.eq (local.get $c) (@char "+")) |
48 | 48 | (then (local.set $i (i32.const 1))))))))
|
49 | 49 | (if (i32.lt_s (i32.add (local.get $i) (i32.const 1)) (local.get $len))
|
50 | 50 | (then (if (i32.eq (array.get_u $bytes (local.get $s) (local.get $i))
|
|
53 | 53 | (local.set $c
|
54 | 54 | (array.get_u $bytes (local.get $s)
|
55 | 55 | (i32.add (local.get $i) (i32.const 1))))
|
56 |
| - (if (i32.or (i32.eq (local.get $c) (i32.const 88)) |
57 |
| - (i32.eq (local.get $c) (i32.const 120))) |
| 56 | + (if (i32.or (i32.eq (local.get $c) (@char "X")) |
| 57 | + (i32.eq (local.get $c) (@char "x"))) |
58 | 58 | (then
|
59 | 59 | (local.set $base (i32.const 16))
|
60 | 60 | (local.set $signedness (i32.const 0))
|
61 | 61 | (local.set $i (i32.add (local.get $i) (i32.const 2))))
|
62 |
| - (else (if (i32.or (i32.eq (local.get $c) (i32.const 79)) |
63 |
| - (i32.eq (local.get $c) (i32.const 111))) |
| 62 | + (else (if (i32.or (i32.eq (local.get $c) (@char "O")) |
| 63 | + (i32.eq (local.get $c) (@char "o"))) |
64 | 64 | (then
|
65 | 65 | (local.set $base (i32.const 8))
|
66 | 66 | (local.set $signedness (i32.const 0))
|
67 | 67 | (local.set $i (i32.add (local.get $i) (i32.const 2))))
|
68 |
| - (else (if (i32.or (i32.eq (local.get $c) (i32.const 66)) |
69 |
| - (i32.eq (local.get $c) (i32.const 98))) |
| 68 | + (else (if (i32.or (i32.eq (local.get $c) (@char "B")) |
| 69 | + (i32.eq (local.get $c) (@char "b"))) |
70 | 70 | (then
|
71 | 71 | (local.set $base (i32.const 2))
|
72 | 72 | (local.set $signedness (i32.const 0))
|
73 | 73 | (local.set $i (i32.add (local.get $i) (i32.const 2))))
|
74 |
| - (else (if (i32.or (i32.eq (local.get $c) (i32.const 85)) |
75 |
| - (i32.eq (local.get $c) (i32.const 117))) |
| 74 | + (else (if (i32.or (i32.eq (local.get $c) (@char "U")) |
| 75 | + (i32.eq (local.get $c) (@char "u"))) |
76 | 76 | (then
|
77 | 77 | (local.set $signedness (i32.const 0))
|
78 | 78 | (local.set $i (i32.add (local.get $i)
|
|
82 | 82 | (local.get $base)))
|
83 | 83 |
|
84 | 84 | (func $parse_digit (export "parse_digit") (param $c i32) (result i32)
|
85 |
| - (if (i32.and (i32.ge_u (local.get $c) (i32.const 48)) |
86 |
| - (i32.le_u (local.get $c) (i32.const 57))) |
87 |
| - (then (return (i32.sub (local.get $c) (i32.const 48))))) |
88 |
| - (if (i32.and (i32.ge_u (local.get $c) (i32.const 65)) |
89 |
| - (i32.le_u (local.get $c) (i32.const 90))) |
| 85 | + (if (i32.and (i32.ge_u (local.get $c) (@char "0")) |
| 86 | + (i32.le_u (local.get $c) (@char "9"))) |
| 87 | + (then (return (i32.sub (local.get $c) (@char "0"))))) |
| 88 | + (if (i32.and (i32.ge_u (local.get $c) (@char "A")) |
| 89 | + (i32.le_u (local.get $c) (@char "Z"))) |
90 | 90 | (then (return (i32.sub (local.get $c) (i32.const 55)))))
|
91 |
| - (if (i32.and (i32.ge_u (local.get $c) (i32.const 97)) |
92 |
| - (i32.le_u (local.get $c) (i32.const 122))) |
| 91 | + (if (i32.and (i32.ge_u (local.get $c) (@char "a")) |
| 92 | + (i32.le_u (local.get $c) (@char "z"))) |
93 | 93 | (then (return (i32.sub (local.get $c) (i32.const 87)))))
|
94 | 94 | (return (i32.const -1)))
|
95 | 95 |
|
|
123 | 123 | (if (i32.lt_s (local.get $i) (local.get $len))
|
124 | 124 | (then
|
125 | 125 | (local.set $c (array.get_u $bytes (local.get $s) (local.get $i)))
|
126 |
| - (br_if $loop (i32.eq (local.get $c) (i32.const 95))) ;; '_' |
| 126 | + (br_if $loop (i32.eq (local.get $c) (@char "_"))) |
127 | 127 | (local.set $d (call $parse_digit (local.get $c)))
|
128 | 128 | (if (i32.ge_u (local.get $d) (local.get $base))
|
129 | 129 | (then (call $caml_failwith (local.get $errmsg))))
|
|
178 | 178 |
|
179 | 179 | (global $lowercase_hex_table (export "lowercase_hex_table") (ref $chars)
|
180 | 180 | (array.new_fixed $chars 16
|
181 |
| - (i32.const 48) (i32.const 49) (i32.const 50) (i32.const 51) |
182 |
| - (i32.const 52) (i32.const 53) (i32.const 54) (i32.const 55) |
183 |
| - (i32.const 56) (i32.const 57) (i32.const 97) (i32.const 98) |
184 |
| - (i32.const 99) (i32.const 100) (i32.const 101) (i32.const 102))) |
| 181 | + (@char "0") (@char "1") (@char "2") (@char "3") |
| 182 | + (@char "4") (@char "5") (@char "6") (@char "7") |
| 183 | + (@char "8") (@char "9") (@char "a") (@char "b") |
| 184 | + (@char "c") (@char "d") (@char "e") (@char "f"))) |
185 | 185 |
|
186 | 186 | (global $uppercase_hex_table (export "uppercase_hex_table") (ref $chars)
|
187 | 187 | (array.new_fixed $chars 16
|
188 |
| - (i32.const 48) (i32.const 49) (i32.const 50) (i32.const 51) |
189 |
| - (i32.const 52) (i32.const 53) (i32.const 54) (i32.const 55) |
190 |
| - (i32.const 56) (i32.const 57) (i32.const 65) (i32.const 66) |
191 |
| - (i32.const 67) (i32.const 68) (i32.const 69) (i32.const 70))) |
| 188 | + (@char "0") (@char "1") (@char "2") (@char "3") |
| 189 | + (@char "4") (@char "5") (@char "6") (@char "7") |
| 190 | + (@char "8") (@char "9") (@char "A") (@char "B") |
| 191 | + (@char "C") (@char "D") (@char "E") (@char "F"))) |
192 | 192 |
|
193 | 193 | (func $format_int_default (param $d i32) (result (ref eq))
|
194 | 194 | (local $s (ref $bytes))
|
|
207 | 207 | (loop $write
|
208 | 208 | (local.set $i (i32.sub (local.get $i) (i32.const 1)))
|
209 | 209 | (array.set $bytes (local.get $s) (local.get $i)
|
210 |
| - (i32.add (i32.const 48) |
| 210 | + (i32.add (@char "0") |
211 | 211 | (i32.rem_u (local.get $d) (i32.const 10))))
|
212 | 212 | (local.set $d (i32.div_u (local.get $d) (i32.const 10)))
|
213 | 213 | (br_if $write (local.get $d)))
|
214 | 214 | (if (local.get $negative)
|
215 |
| - (then |
216 |
| - (array.set $bytes (local.get $s) (i32.const 0) |
217 |
| - (i32.const 45)))) ;; '-' |
| 215 | + (then (array.set $bytes (local.get $s) (i32.const 0) (@char "-")))) |
218 | 216 | (local.get $s))
|
219 | 217 |
|
220 | 218 | (@string $format_error "format_int: bad format")
|
|
231 | 229 | (br_if $bad_format (i32.lt_u (local.get $len) (i32.const 2)))
|
232 | 230 | (br_if $bad_format
|
233 | 231 | (i32.ne (array.get_u $bytes (local.get $s) (i32.const 0))
|
234 |
| - (i32.const 37))) ;; '%' |
| 232 | + (@char "%"))) |
235 | 233 | (local.set $c (array.get_u $bytes (local.get $s) (i32.const 1)))
|
236 |
| - (if (i32.eq (local.get $c) (i32.const 43)) ;; '+' |
| 234 | + (if (i32.eq (local.get $c) (@char "+")) |
237 | 235 | (then
|
238 | 236 | (local.set $sign_style (i32.const 1))
|
239 | 237 | (local.set $i (i32.add (local.get $i) (i32.const 1)))))
|
240 |
| - (if (i32.eq (local.get $c) (i32.const 32)) ;; ' ' |
| 238 | + (if (i32.eq (local.get $c) (@char " ")) |
241 | 239 | (then
|
242 | 240 | (local.set $sign_style (i32.const 2))
|
243 | 241 | (local.set $i (i32.add (local.get $i) (i32.const 1)))))
|
244 |
| - (if (i32.eq (local.get $c) (i32.const 35)) ;; '#' |
| 242 | + (if (i32.eq (local.get $c) (@char "#")) |
245 | 243 | (then
|
246 | 244 | (local.set $alternate (i32.const 1))
|
247 | 245 | (local.set $i (i32.add (local.get $i) (i32.const 1)))))
|
248 | 246 | (br_if $bad_format (i32.eq (local.get $i) (local.get $len)))
|
249 | 247 | (local.set $c (array.get_u $bytes (local.get $s) (local.get $i)))
|
250 |
| - (if (i32.or (i32.or (i32.eq (local.get $c) (i32.const 76)) ;; 'L' |
251 |
| - (i32.eq (local.get $c) (i32.const 108))) ;; 'l' |
252 |
| - (i32.eq (local.get $c) (i32.const 110))) ;; 'n' |
| 248 | + (if (i32.or (i32.or (i32.eq (local.get $c) (@char "L")) |
| 249 | + (i32.eq (local.get $c) (@char "l"))) |
| 250 | + (i32.eq (local.get $c) (@char "n"))) |
253 | 251 | (then
|
254 | 252 | (local.set $i (i32.add (local.get $i) (i32.const 1)))
|
255 | 253 | (br_if $bad_format (i32.eq (local.get $i) (local.get $len)))
|
256 | 254 | (local.set $c
|
257 | 255 | (array.get_u $bytes (local.get $s) (local.get $i)))))
|
258 | 256 | (br_if $bad_format
|
259 | 257 | (i32.ne (i32.add (local.get $i) (i32.const 1)) (local.get $len)))
|
260 |
| - (if (i32.or (i32.eq (local.get $c) (i32.const 100)) ;; 'd' |
261 |
| - (i32.eq (local.get $c) (i32.const 105))) ;; 'i' |
| 258 | + (if (i32.or (i32.eq (local.get $c) (@char "d")) |
| 259 | + (i32.eq (local.get $c) (@char "i"))) |
262 | 260 | (then
|
263 | 261 | (local.set $base (i32.const 10))
|
264 | 262 | (local.set $signed (i32.const 1)))
|
265 |
| - (else (if (i32.eq (local.get $c) (i32.const 117)) ;; 'u' |
| 263 | + (else (if (i32.eq (local.get $c) (@char "u")) |
266 | 264 | (then
|
267 | 265 | (local.set $base (i32.const 10)))
|
268 |
| - (else (if (i32.eq (local.get $c) (i32.const 120)) ;; 'x' |
| 266 | + (else (if (i32.eq (local.get $c) (@char "x")) |
269 | 267 | (then
|
270 | 268 | (local.set $base (i32.const 16)))
|
271 |
| - (else (if (i32.eq (local.get $c) (i32.const 88)) ;; 'X' |
| 269 | + (else (if (i32.eq (local.get $c) (@char "X")) |
272 | 270 | (then
|
273 | 271 | (local.set $base (i32.const 16))
|
274 | 272 | (local.set $uppercase (i32.const 1)))
|
275 |
| - (else (if (i32.eq (local.get $c) (i32.const 111)) ;; 'o' |
| 273 | + (else (if (i32.eq (local.get $c) (@char "o")) |
276 | 274 | (then
|
277 | 275 | (local.set $base (i32.const 8)))
|
278 | 276 | (else
|
|
300 | 298 | (if (i32.eq (array.len (local.get $s)) (i32.const 2))
|
301 | 299 | (then
|
302 | 300 | (if (i32.eq (array.get_u $bytes (local.get $s) (i32.const 1))
|
303 |
| - (i32.const 100)) ;; 'd' |
| 301 | + (@char "d")) |
304 | 302 | (then (return_call $format_int_default (local.get $d))))))
|
305 | 303 | (local.set $format (call $parse_int_format (local.get $s)))
|
306 | 304 | (local.set $sign_style (tuple.extract 5 0 (local.get $format)))
|
|
353 | 351 | (br_if $write (local.get $d)))
|
354 | 352 | (if (local.get $negative)
|
355 | 353 | (then
|
356 |
| - (array.set $bytes (local.get $s) (i32.const 0) |
357 |
| - (i32.const 45))) ;; '-' |
| 354 | + (array.set $bytes (local.get $s) (i32.const 0) (@char "-"))) |
358 | 355 | (else
|
359 | 356 | (if (local.get $sign_style)
|
360 | 357 | (then
|
361 | 358 | (if (i32.eq (local.get $sign_style) (i32.const 1))
|
362 | 359 | (then
|
363 | 360 | (array.set $bytes (local.get $s) (i32.const 0)
|
364 |
| - (i32.const 43))) ;; '+' |
| 361 | + (@char "+"))) |
365 | 362 | (else
|
366 | 363 | (array.set $bytes (local.get $s) (i32.const 0)
|
367 |
| - (i32.const 32)))))))) ;; ' ' |
| 364 | + (@char " ")))))))) |
368 | 365 | (if (local.get $alternate)
|
369 | 366 | (then
|
370 | 367 | (if (local.get $i)
|
371 | 368 | (then
|
372 |
| - (array.set $bytes (local.get $s) (i32.const 0) |
373 |
| - (i32.const 48)) ;; '0' |
| 369 | + (array.set $bytes (local.get $s) (i32.const 0) (@char "0")) |
374 | 370 | (if (i32.eq (local.get $base) (i32.const 16))
|
375 | 371 | (then
|
376 | 372 | (array.set $bytes (local.get $s) (i32.const 1)
|
377 |
| - (select (i32.const 88) (i32.const 120) ;; 'X' 'x' |
| 373 | + (select (@char "X") (@char "x") |
378 | 374 | (local.get $uppercase)))))))))
|
379 | 375 | (local.get $s))
|
380 | 376 | )
|
0 commit comments