Skip to content

Commit 8961485

Browse files
committed
Wasm runtime: rename some functions
1 parent e2ef90b commit 8961485

File tree

8 files changed

+59
-61
lines changed

8 files changed

+59
-61
lines changed

runtime/wasm/bigarray.wat

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,12 @@
6969
(import "bindings" "ta_subarray"
7070
(func $ta_subarray
7171
(param (ref extern)) (param i32) (param i32) (result (ref extern))))
72-
(import "bindings" "ta_blit_from_string"
73-
(func $ta_blit_from_string
72+
(import "bindings" "ta_blit_from_bytes"
73+
(func $ta_blit_from_bytes
7474
(param (ref $bytes)) (param i32) (param (ref extern)) (param i32)
7575
(param i32)))
76-
(import "bindings" "ta_blit_to_string"
77-
(func $ta_blit_to_string
76+
(import "bindings" "ta_blit_to_bytes"
77+
(func $ta_blit_to_bytes
7878
(param (ref extern)) (param i32) (param (ref $bytes)) (param i32)
7979
(param i32)))
8080
(import "fail" "caml_bound_error" (func $caml_bound_error))
@@ -2030,15 +2030,15 @@
20302030
(ref.as_non_null (extern.convert_any (call $unwrap (local.get 0)))))
20312031
(local.set $len (call $ta_length (local.get $a)))
20322032
(local.set $s (array.new $bytes (i32.const 0) (local.get $len)))
2033-
(call $ta_blit_to_string
2033+
(call $ta_blit_to_bytes
20342034
(local.get $a) (i32.const 0) (local.get $s) (i32.const 0)
20352035
(local.get $len))
20362036
(local.get $s))
20372037

20382038
(export "caml_uint8_array_of_bytes" (func $caml_uint8_array_of_string))
20392039
(func $caml_uint8_array_of_string (export "caml_uint8_array_of_string")
20402040
(param (ref eq)) (result (ref eq))
2041-
;; Convert a string to a typed array
2041+
;; Convert bytes to a typed array
20422042
(local $ta (ref extern)) (local $len i32)
20432043
(local $s (ref $bytes))
20442044
(local.set $s (ref.cast (ref $bytes) (local.get 0)))
@@ -2047,7 +2047,7 @@
20472047
(call $ta_create
20482048
(i32.const 3) ;; Uint8Array
20492049
(local.get $len)))
2050-
(call $ta_blit_from_string
2050+
(call $ta_blit_from_bytes
20512051
(local.get $s) (i32.const 0) (local.get $ta) (i32.const 0)
20522052
(local.get $len))
20532053
(call $wrap (any.convert_extern (local.get $ta))))

runtime/wasm/bigstring.wat

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,12 @@
4848
(func $ta_length (param (ref extern)) (result i32)))
4949
(import "bindings" "ta_bytes"
5050
(func $ta_bytes (param anyref) (result anyref)))
51-
(import "bindings" "ta_blit_from_string"
52-
(func $ta_blit_from_string
51+
(import "bindings" "ta_blit_from_bytes"
52+
(func $ta_blit_from_bytes
5353
(param (ref $bytes)) (param i32) (param (ref extern)) (param i32)
5454
(param i32)))
55-
(import "bindings" "ta_blit_to_string"
56-
(func $ta_blit_to_string
55+
(import "bindings" "ta_blit_to_bytes"
56+
(func $ta_blit_to_bytes
5757
(param (ref extern)) (param i32) (param (ref $bytes)) (param i32)
5858
(param i32)))
5959
(import "hash" "caml_hash_mix_int"
@@ -240,7 +240,7 @@
240240
(local.set $d2 (call $caml_ba_get_data (local.get $ba2)))
241241
(local.set $pos2 (i31.get_s (ref.cast (ref i31) (local.get $vpos2))))
242242
(local.set $len (i31.get_s (ref.cast (ref i31) (local.get $vlen))))
243-
(call $ta_blit_from_string
243+
(call $ta_blit_from_bytes
244244
(local.get $s1) (local.get $pos1)
245245
(local.get $d2) (local.get $pos2)
246246
(local.get $len))
@@ -258,7 +258,7 @@
258258
(local.set $s2 (ref.cast (ref $bytes) (local.get $str2)))
259259
(local.set $pos2 (i31.get_s (ref.cast (ref i31) (local.get $vpos2))))
260260
(local.set $len (i31.get_s (ref.cast (ref i31) (local.get $vlen))))
261-
(call $ta_blit_to_string
261+
(call $ta_blit_to_bytes
262262
(local.get $d1) (local.get $pos1)
263263
(local.get $s2) (local.get $pos2)
264264
(local.get $len))

runtime/wasm/custom.wat

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
(import "int64" "int64_ops" (global $int64_ops (ref $custom_operations)))
2323
(import "bigarray" "bigarray_ops"
2424
(global $bigarray_ops (ref $custom_operations)))
25-
(import "string" "caml_string_equal"
26-
(func $caml_string_equal
25+
(import "string" "caml_bytes_equal"
26+
(func $caml_bytes_equal
2727
(param (ref eq)) (param (ref eq)) (result (ref eq))))
2828

2929
(type $bytes (array (mut i8)))
@@ -116,7 +116,7 @@
116116
(loop $loop
117117
(if (i31.get_u
118118
(ref.cast (ref i31)
119-
(call $caml_string_equal (local.get $id)
119+
(call $caml_bytes_equal (local.get $id)
120120
(struct.get $custom_operations $id
121121
(struct.get $custom_operations_list $ops
122122
(local.get $l))))))

runtime/wasm/float.wat

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@
2727
(func $caml_invalid_argument (param (ref eq))))
2828
(import "ints" "lowercase_hex_table"
2929
(global $lowercase_hex_table (ref $chars)))
30-
(import "jsstring" "jsstring_of_string"
31-
(func $jsstring_of_string (param (ref $bytes)) (result anyref)))
32-
(import "jsstring" "string_of_jsstring"
33-
(func $string_of_jsstring (param anyref) (result (ref $bytes))))
30+
(import "jsstring" "jsstring_of_bytes"
31+
(func $jsstring_of_bytes (param (ref $bytes)) (result anyref)))
32+
(import "jsstring" "bytes_of_jsstring"
33+
(func $bytes_of_jsstring (param anyref) (result (ref $bytes))))
3434

3535
(type $float (struct (field f64)))
3636
(type $bytes (array (mut i8)))
@@ -308,7 +308,7 @@
308308
(local.get $precision) (local.get $conversion)
309309
(local.get $i)
310310
(f64.abs (local.get $f))))
311-
(local.set $s (call $string_of_jsstring (local.get $num)))
311+
(local.set $s (call $bytes_of_jsstring (local.get $num)))
312312
(br $sign (local.get $s))))
313313
(if (local.get $negative)
314314
(then
@@ -660,7 +660,7 @@
660660
(local.get $negative))))
661661
))))))))))))))))))
662662
(local.set $f
663-
(call $parse_float (call $jsstring_of_string (local.get $s))))
663+
(call $parse_float (call $jsstring_of_bytes (local.get $s))))
664664
(br_if $error (f64.ne (local.get $f) (local.get $f)))
665665
(return (struct.new $float (local.get $f))))
666666
(call $caml_failwith

runtime/wasm/io.wat

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,12 @@
5555
(func $ta_set_ui8 (param (ref extern)) (param i32) (param i32))) ;; ZZZ ??
5656
(import "bindings" "ta_get_ui8"
5757
(func $ta_get_ui8 (param (ref extern)) (param i32) (result i32)))
58-
(import "bindings" "ta_blit_from_string"
59-
(func $ta_blit_from_string
58+
(import "bindings" "ta_blit_from_bytes"
59+
(func $ta_blit_from_bytes
6060
(param (ref $bytes)) (param i32) (param (ref extern)) (param i32)
6161
(param i32)))
62-
(import "bindings" "ta_blit_to_string"
63-
(func $ta_blit_to_string
62+
(import "bindings" "ta_blit_to_bytes"
63+
(func $ta_blit_to_bytes
6464
(param (ref extern)) (param i32) (param (ref $bytes)) (param i32)
6565
(param i32)))
6666
(import "custom" "custom_compare_id"
@@ -367,7 +367,7 @@
367367
(then
368368
(if (i32.gt_u (local.get $len) (local.get $avail))
369369
(then (local.set $len (local.get $avail))))
370-
(call $ta_blit_to_string
370+
(call $ta_blit_to_bytes
371371
(struct.get $channel $buffer (local.get $ch))
372372
(struct.get $channel $curr (local.get $ch))
373373
(local.get $s) (local.get $pos)
@@ -382,7 +382,7 @@
382382
(struct.set $channel $max (local.get $ch) (local.get $nread))
383383
(if (i32.gt_u (local.get $len) (local.get $nread))
384384
(then (local.set $len (local.get $nread))))
385-
(call $ta_blit_to_string
385+
(call $ta_blit_to_bytes
386386
(struct.get $channel $buffer (local.get $ch))
387387
(i32.const 0)
388388
(local.get $s) (local.get $pos)
@@ -438,7 +438,7 @@
438438
(local.set $curr (i32.const 0))
439439
(if (i32.gt_u (local.get $len) (local.get $nread))
440440
(then (local.set $len (local.get $nread))))))))
441-
(call $ta_blit_to_string
441+
(call $ta_blit_to_bytes
442442
(local.get $buf) (local.get $curr)
443443
(local.get $s) (local.get $pos) (local.get $len))
444444
(struct.set $channel $curr (local.get $ch)
@@ -731,7 +731,7 @@
731731
(if (i32.ge_u (local.get $len) (local.get $free))
732732
(then (local.set $len (local.get $free))))
733733
(local.set $buf (struct.get $channel $buffer (local.get $ch)))
734-
(call $ta_blit_from_string
734+
(call $ta_blit_from_bytes
735735
(local.get $s) (local.get $pos)
736736
(local.get $buf) (local.get $curr) (local.get $len))
737737
(struct.set $channel $curr (local.get $ch)

runtime/wasm/jslib.wat

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,12 @@
8484
(func $caml_is_closure (param (ref eq)) (result i32)))
8585
(import "obj" "caml_is_last_arg"
8686
(func $caml_is_last_arg (param (ref eq)) (result i32)))
87-
(import "jsstring" "jsstring_of_string"
88-
(func $jsstring_of_string (param (ref $bytes)) (result anyref)))
89-
(import "jsstring" "string_of_jsstring"
90-
(func $string_of_jsstring (param anyref) (result (ref $bytes))))
91-
(import "jsstring" "jsstring_of_substring"
92-
(func $jsstring_of_substring
93-
(param (ref $bytes) i32 i32) (result anyref)))
87+
(import "jsstring" "jsstring_of_bytes"
88+
(func $jsstring_of_bytes (param (ref $bytes)) (result anyref)))
89+
(import "jsstring" "bytes_of_jsstring"
90+
(func $bytes_of_jsstring (param anyref) (result (ref $bytes))))
91+
(import "jsstring" "jsstring_of_subbytes"
92+
(func $jsstring_of_subbytes (param (ref $bytes) i32 i32) (result anyref)))
9493
(import "int32" "caml_copy_int32"
9594
(func $caml_copy_int32 (param i32) (result (ref eq))))
9695
(import "int32" "Int32_val"
@@ -188,7 +187,7 @@
188187
(result (ref eq))
189188
(if (ref.test (ref $bytes) (local.get $f))
190189
(then
191-
(local.set $f (call $caml_jsbytes_of_string (local.get $f)))))
190+
(local.set $f (call $caml_jsbytes_of_bytes (local.get $f)))))
192191
(return_call $wrap
193192
(call $meth_call (call $unwrap (local.get $o))
194193
(call $unwrap (local.get $f))
@@ -198,7 +197,7 @@
198197
(param (ref eq)) (param (ref eq)) (result (ref eq))
199198
(if (ref.test (ref $bytes) (local.get 1))
200199
(then
201-
(local.set 1 (call $caml_jsbytes_of_string (local.get 1)))))
200+
(local.set 1 (call $caml_jsbytes_of_bytes (local.get 1)))))
202201
(return_call $wrap
203202
(call $get
204203
(ref.as_non_null (extern.convert_any (call $unwrap (local.get 0))))
@@ -208,7 +207,7 @@
208207
(param (ref eq)) (param (ref eq)) (param (ref eq)) (result (ref eq))
209208
(if (ref.test (ref $bytes) (local.get 1))
210209
(then
211-
(local.set 1 (call $caml_jsbytes_of_string (local.get 1)))))
210+
(local.set 1 (call $caml_jsbytes_of_bytes (local.get 1)))))
212211
(call $set (call $unwrap (local.get 0)) (call $unwrap (local.get 1))
213212
(call $unwrap (local.get 2)))
214213
(ref.i31 (i32.const 0)))
@@ -217,7 +216,7 @@
217216
(param (ref eq)) (param (ref eq)) (result (ref eq))
218217
(if (ref.test (ref $bytes) (local.get 1))
219218
(then
220-
(local.set 1 (call $caml_jsbytes_of_string (local.get 1)))))
219+
(local.set 1 (call $caml_jsbytes_of_bytes (local.get 1)))))
221220
(call $delete (call $unwrap (local.get 0)) (call $unwrap (local.get 1)))
222221
(ref.i31 (i32.const 0)))
223222

@@ -265,7 +264,7 @@
265264
(array.get $block (local.get $a) (local.get $i))))
266265
(call $set (local.get $o)
267266
(call $unwrap
268-
(call $caml_jsstring_of_string
267+
(call $caml_jsstring_of_bytes
269268
(array.get $block (local.get $p) (i32.const 1))))
270269
(call $unwrap
271270
(array.get $block (local.get $p) (i32.const 2))))
@@ -454,24 +453,24 @@
454453
(local.get $acc)))))))))
455454
(return_call $unwrap (local.get $acc)))
456455

457-
(export "caml_js_from_string" (func $caml_jsstring_of_string))
458-
(func $caml_jsstring_of_string (export "caml_jsstring_of_string")
456+
(export "caml_js_from_string" (func $caml_jsstring_of_bytes))
457+
(func $caml_jsstring_of_bytes (export "caml_jsstring_of_string")
459458
(param (ref eq)) (result (ref eq))
460459
(local $s (ref $bytes))
461460
(local.set $s (ref.cast (ref $bytes) (local.get 0)))
462-
(return (struct.new $js (call $jsstring_of_string (local.get $s)))))
461+
(return (struct.new $js (call $jsstring_of_bytes (local.get $s)))))
463462

464463
(func (export "caml_jsstring_of_substring")
465464
(param $s (ref eq)) (param $i (ref eq)) (param $l (ref eq))
466465
(result (ref eq))
467466
(return
468467
(struct.new $js
469-
(call $jsstring_of_substring
468+
(call $jsstring_of_subbytes
470469
(ref.cast (ref $bytes) (local.get $s))
471470
(i31.get_u (ref.cast (ref i31) (local.get $i)))
472471
(i31.get_u (ref.cast (ref i31) (local.get $l)))))))
473472

474-
(func $caml_jsbytes_of_string (export "caml_jsbytes_of_string")
473+
(func $caml_jsbytes_of_bytes (export "caml_jsbytes_of_string")
475474
(param (ref eq)) (result (ref eq))
476475
(local $s (ref $bytes))
477476
(local $s' (ref $bytes))
@@ -492,7 +491,7 @@
492491
(then
493492
(return
494493
(struct.new $js
495-
(call $jsstring_of_string (local.get $s))))))
494+
(call $jsstring_of_bytes (local.get $s))))))
496495
(local.set $s'
497496
(array.new $bytes (i32.const 0)
498497
(i32.add (local.get $i) (local.get $n))))
@@ -519,20 +518,20 @@
519518
(local.set $n (i32.add (local.get $n) (i32.const 2)))))
520519
(local.set $i (i32.add (local.get $i) (i32.const 1)))
521520
(br $fill))))
522-
(return (struct.new $js (call $jsstring_of_string (local.get $s')))))
521+
(return (struct.new $js (call $jsstring_of_bytes (local.get $s')))))
523522

524523
(export "caml_js_to_string" (func $caml_string_of_jsstring))
525524
(func $caml_string_of_jsstring (export "caml_string_of_jsstring")
526525
(param $s (ref eq)) (result (ref eq))
527-
(return_call $string_of_jsstring
526+
(return_call $bytes_of_jsstring
528527
(struct.get $js 0 (ref.cast (ref $js) (local.get $s)))))
529528

530529
(func (export "caml_string_of_jsbytes")
531530
(param $s (ref eq)) (result (ref eq))
532531
(local $l i32) (local $i i32) (local $n i32) (local $c i32)
533532
(local $s' (ref $bytes)) (local $s'' (ref $bytes))
534533
(local.set $s'
535-
(call $string_of_jsstring
534+
(call $bytes_of_jsstring
536535
(struct.get $js 0 (ref.cast (ref $js) (local.get $s)))))
537536
(local.set $l (array.len (local.get $s')))
538537
(local.set $i (i32.const 0))
@@ -652,7 +651,7 @@
652651
(call $meth_call
653652
(local.get $exn)
654653
(call $unwrap
655-
(call $caml_jsstring_of_string
654+
(call $caml_jsstring_of_bytes
656655
(array.new_data $bytes $toString
657656
(i32.const 0) (i32.const 8))))
658657
(any.convert_extern (call $new_array (i32.const 0))))))))

runtime/wasm/jsstring.wat

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,7 @@
9898

9999
(export "jsstring_hash" (func $hash_string))
100100

101-
;; Used by package zarith_stubs_js
102-
(func $jsstring_of_substring (export "jsstring_of_substring")
101+
(func $jsstring_of_subbytes (export "jsstring_of_subbytes")
103102
(param $s (ref $bytes)) (param $pos i32) (param $len i32)
104103
(result anyref)
105104
(local $i i32) (local $c i32)
@@ -130,14 +129,14 @@
130129
(any.convert_extern
131130
(call $fromCharCodeArray (global.get $buffer)
132131
(i32.const 0) (local.get $len))))))
133-
(return_call $jsstring_of_substring_fallback
132+
(return_call $jsstring_of_subbytes_fallback
134133
(local.get $s) (local.get $pos) (local.get $len)))
135134

136-
(func (export "jsstring_of_string") (param $s (ref $bytes)) (result anyref)
137-
(return_call $jsstring_of_substring
135+
(func (export "jsstring_of_bytes") (param $s (ref $bytes)) (result anyref)
136+
(return_call $jsstring_of_subbytes
138137
(local.get $s) (i32.const 0) (array.len (local.get $s))))
139138

140-
(func (export "string_of_jsstring") (param $s anyref) (result (ref $bytes))
139+
(func (export "bytes_of_jsstring") (param $s anyref) (result (ref $bytes))
141140
(if (global.get $text_converters_available)
142141
(then
143142
(return_call $encodeStringToUTF8Array
@@ -162,7 +161,7 @@
162161
(local.set $i (i32.add (local.get $i) (i32.const 1)))
163162
(br $loop)))))
164163

165-
(func $jsstring_of_substring_fallback
164+
(func $jsstring_of_subbytes_fallback
166165
(param $s (ref $bytes)) (param $pos i32) (param $len i32)
167166
(result anyref)
168167
(local $s' anyref)

runtime/wasm/runtime.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,10 +221,10 @@
221221
ta_copy: (ta, t, s, n) => ta.copyWithin(t, s, n),
222222
ta_bytes: (a) =>
223223
new Uint8Array(a.buffer, a.byteOffset, a.length * a.BYTES_PER_ELEMENT),
224-
ta_blit_from_string: (s, p1, a, p2, l) => {
224+
ta_blit_from_bytes: (s, p1, a, p2, l) => {
225225
for (let i = 0; i < l; i++) a[p2 + i] = string_get(s, p1 + i);
226226
},
227-
ta_blit_to_string: (a, p1, s, p2, l) => {
227+
ta_blit_to_bytes: (a, p1, s, p2, l) => {
228228
for (let i = 0; i < l; i++) string_set(s, p2 + i, a[p1 + i]);
229229
},
230230
wrap_callback: (f) =>

0 commit comments

Comments
 (0)