Skip to content

Commit 6d6fc9d

Browse files
authored
Wasm runtime: rename type $string to $bytes (#1835)
* Wasm runtime: rename type $string to $bytes * Wasm runtime: rename some functions
1 parent 2b42149 commit 6d6fc9d

34 files changed

+804
-805
lines changed

manual/wasm_runtime.wiki

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ float arrays, and Javascript values. The first field of a block is its
2424
tag, of type {{{(ref i31)}}}.
2525
{{{
2626
(type $block (array (mut (ref eq))))
27-
(type $string (array (mut i8)))
27+
(type $bytes (array (mut i8)))
2828
(type $float (struct (field f64)))
2929
(type $float_array (array (mut f64)))
3030
(type $js (struct (ref null any)))

runtime/wasm/array.wat

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
(func $caml_invalid_argument (param (ref eq))))
2121

2222
(type $block (array (mut (ref eq))))
23-
(type $string (array (mut i8)))
23+
(type $bytes (array (mut i8)))
2424
(type $float (struct (field f64)))
2525
(type $float_array (array (mut f64)))
2626

@@ -36,7 +36,7 @@
3636
(if (i32.ge_u (local.get $sz) (i32.const 0xfffffff))
3737
(then
3838
(call $caml_invalid_argument
39-
(array.new_data $string $Array_make
39+
(array.new_data $bytes $Array_make
4040
(i32.const 0) (i32.const 10)))))
4141
(if (i32.eqz (local.get $sz)) (then (return (global.get $empty_array))))
4242
(drop (block $not_float (result (ref eq))
@@ -58,7 +58,7 @@
5858
(if (i32.ge_u (local.get $sz) (i32.const 0x7ffffff))
5959
(then
6060
(call $caml_invalid_argument
61-
(array.new_data $string $Array_make
61+
(array.new_data $bytes $Array_make
6262
(i32.const 0) (i32.const 10)))))
6363
(if (i32.eqz (local.get $sz)) (then (return (global.get $empty_array))))
6464
(local.set $f
@@ -75,7 +75,7 @@
7575
(if (i32.ge_u (local.get $sz) (i32.const 0x7ffffff))
7676
(then
7777
(call $caml_invalid_argument
78-
(array.new_data $string $Array_make
78+
(array.new_data $bytes $Array_make
7979
(i32.const 0) (i32.const 10)))))
8080
(if (i32.eqz (local.get $sz)) (then (return (global.get $empty_array))))
8181
(array.new $float_array (f64.const 0) (local.get $sz)))

runtime/wasm/backtrace.wat

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
(func $caml_invalid_argument (param (ref eq))))
2121

2222
(type $block (array (mut (ref eq))))
23-
(type $string (array (mut i8)))
23+
(type $bytes (array (mut i8)))
2424

2525
(func (export "caml_get_exception_raw_backtrace")
2626
(param (ref eq)) (result (ref eq))
@@ -44,7 +44,7 @@
4444
(func (export "caml_raw_backtrace_slot")
4545
(param (ref eq) (ref eq)) (result (ref eq))
4646
(call $caml_invalid_argument
47-
(array.new_data $string $raw_backtrace_slot_err
47+
(array.new_data $bytes $raw_backtrace_slot_err
4848
(i32.const 0) (i32.const 52)))
4949
(ref.i31 (i32.const 0)))
5050

runtime/wasm/bigarray.wat

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,13 @@
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
74-
(param (ref $string)) (param i32) (param (ref extern)) (param i32)
72+
(import "bindings" "ta_blit_from_bytes"
73+
(func $ta_blit_from_bytes
74+
(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
78-
(param (ref extern)) (param i32) (param (ref $string)) (param i32)
76+
(import "bindings" "ta_blit_to_bytes"
77+
(func $ta_blit_to_bytes
78+
(param (ref extern)) (param i32) (param (ref $bytes)) (param i32)
7979
(param i32)))
8080
(import "fail" "caml_bound_error" (func $caml_bound_error))
8181
(import "fail" "caml_raise_out_of_memory" (func $caml_raise_out_of_memory))
@@ -128,7 +128,7 @@
128128
(func $caml_deserialize_int_8 (param (ref eq)) (result i64)))
129129

130130
(type $block (array (mut (ref eq))))
131-
(type $string (array (mut i8)))
131+
(type $bytes (array (mut i8)))
132132
(type $float (struct (field f64)))
133133
(type $float_array (array (mut f64)))
134134

@@ -143,7 +143,7 @@
143143
(type $dup (func (param (ref eq)) (result (ref eq))))
144144
(type $custom_operations
145145
(struct
146-
(field $id (ref $string))
146+
(field $id (ref $bytes))
147147
(field $compare (ref null $compare))
148148
(field $compare_ext (ref null $compare))
149149
(field $hash (ref null $hash))
@@ -155,7 +155,7 @@
155155

156156
(global $bigarray_ops (export "bigarray_ops") (ref $custom_operations)
157157
(struct.new $custom_operations
158-
(array.new_fixed $string 9 ;; "_bigarr02"
158+
(array.new_fixed $bytes 9 ;; "_bigarr02"
159159
(i32.const 95) (i32.const 98) (i32.const 105) (i32.const 103)
160160
(i32.const 97) (i32.const 114) (i32.const 114) (i32.const 48)
161161
(i32.const 50))
@@ -682,7 +682,7 @@
682682
(if (call $caml_deserialize_uint_1 (local.get $s))
683683
(then
684684
(call $caml_failwith
685-
(array.new_data $string $intern_overflow
685+
(array.new_data $bytes $intern_overflow
686686
(i32.const 0) (i32.const 56))))))
687687
;; int32
688688
(loop $loop
@@ -807,7 +807,7 @@
807807
(if (i32.gt_u (local.get $num_dims) (global.get $CAML_BA_MAX_NUM_DIMS))
808808
(then
809809
(call $caml_invalid_argument
810-
(array.new_data $string $ba_create_bad_dims
810+
(array.new_data $bytes $ba_create_bad_dims
811811
(i32.const 0) (i32.const 41)))))
812812
(local.set $dim
813813
(array.new $int_array (i32.const 0) (local.get $num_dims)))
@@ -823,7 +823,7 @@
823823
(if (i32.lt_s (local.get $n) (i32.const 0))
824824
(then
825825
(call $caml_invalid_argument
826-
(array.new_data $string $ba_create_negative_dim
826+
(array.new_data $bytes $ba_create_negative_dim
827827
(i32.const 0) (i32.const 35)))))
828828
(array.set $int_array
829829
(local.get $dim) (local.get $i) (local.get $n))
@@ -852,15 +852,15 @@
852852
(if (i32.lt_s (local.get $kind) (i32.const 0))
853853
(then
854854
(call $caml_invalid_argument
855-
(array.new_data $string $ta_unsupported_kind
855+
(array.new_data $bytes $ta_unsupported_kind
856856
(i32.const 0) (i32.const 41)))))
857857
(if (i32.eq (local.get $kind) (i32.const 14)) ;; Uint8ClampedArray
858858
(then (local.set $kind (i32.const 3))))
859859
(local.set $len (call $ta_length (local.get $data)))
860860
(if (i32.lt_s (local.get $len) (i32.const 0))
861861
(then
862862
(call $caml_invalid_argument
863-
(array.new_data $string $ta_too_large
863+
(array.new_data $bytes $ta_too_large
864864
(i32.const 0) (i32.const 34)))))
865865
(struct.new $bigarray
866866
(global.get $bigarray_ops)
@@ -1062,7 +1062,7 @@
10621062
(local.set $i (i31.get_s (ref.cast (ref i31) (local.get 1))))
10631063
(if (i32.ge_u (local.get $i) (array.len (local.get $dim)))
10641064
(then (call $caml_invalid_argument
1065-
(array.new_data $string $Bigarray_dim
1065+
(array.new_data $bytes $Bigarray_dim
10661066
(i32.const 0) (i32.const 12)))))
10671067
(ref.i31 (array.get $int_array (local.get $dim) (local.get $i))))
10681068

@@ -1427,7 +1427,7 @@
14271427
(struct.get $bigarray $ba_num_dims (local.get $b)))
14281428
(then
14291429
(call $caml_invalid_argument
1430-
(array.new_data $string $too_many_indices
1430+
(array.new_data $bytes $too_many_indices
14311431
(i32.const 0) (i32.const 32)))))
14321432
(local.set $sub_dim
14331433
(array.new $int_array (i32.const 0)
@@ -1544,7 +1544,7 @@
15441544
(local.get $changed_dim))))
15451545
(then
15461546
(call $caml_invalid_argument
1547-
(array.new_data $string $bad_subarray
1547+
(array.new_data $bytes $bad_subarray
15481548
(i32.const 0) (i32.const 27)))))
15491549
(local.set $new_dim
15501550
(array.new $int_array (i32.const 0) (local.get $num_dims)))
@@ -1674,7 +1674,7 @@
16741674
(struct.get $bigarray $ba_num_dims (local.get $src)))
16751675
(then
16761676
(call $caml_invalid_argument
1677-
(array.new_data $string $dim_mismatch
1677+
(array.new_data $bytes $dim_mismatch
16781678
(i32.const 0) (i32.const 33)))))
16791679
(local.set $sdim (struct.get $bigarray $ba_dim (local.get $src)))
16801680
(local.set $ddim (struct.get $bigarray $ba_dim (local.get $dst)))
@@ -1686,7 +1686,7 @@
16861686
(array.get $int_array (local.get $ddim) (local.get $i)))
16871687
(then
16881688
(call $caml_invalid_argument
1689-
(array.new_data $string $dim_mismatch
1689+
(array.new_data $bytes $dim_mismatch
16901690
(i32.const 0) (i32.const 33)))))
16911691
(local.set $i (i32.add (local.get $i) (i32.const 1)))
16921692
(br $loop))))
@@ -1711,7 +1711,7 @@
17111711
(if (i32.gt_u (local.get $num_dims) (global.get $CAML_BA_MAX_NUM_DIMS))
17121712
(then
17131713
(call $caml_invalid_argument
1714-
(array.new_data $string $bad_number_dim
1714+
(array.new_data $bytes $bad_number_dim
17151715
(i32.const 0) (i32.const 42)))))
17161716
(local.set $num_elts (i64.const 1))
17171717
(local.set $dim (array.new $int_array (i32.const 0) (local.get $num_dims)))
@@ -1726,7 +1726,7 @@
17261726
(if (i32.lt_s (local.get $d) (i32.const 0))
17271727
(then
17281728
(call $caml_invalid_argument
1729-
(array.new_data $string $negative_dim
1729+
(array.new_data $bytes $negative_dim
17301730
(i32.const 0) (i32.const 36)))))
17311731
(array.set $int_array (local.get $dim) (local.get $i)
17321732
(local.get $d))
@@ -1743,7 +1743,7 @@
17431743
(struct.get $bigarray $ba_dim (local.get $b))))
17441744
(then
17451745
(call $caml_invalid_argument
1746-
(array.new_data $string $size_mismatch
1746+
(array.new_data $bytes $size_mismatch
17471747
(i32.const 0) (i32.const 31)))))
17481748
(struct.new $bigarray
17491749
(global.get $bigarray_ops)
@@ -2163,29 +2163,29 @@
21632163
(param (ref eq)) (result (ref eq))
21642164
;; used to convert a typed array to a string
21652165
(local $a (ref extern)) (local $len i32)
2166-
(local $s (ref $string))
2166+
(local $s (ref $bytes))
21672167
(local.set $a
21682168
(ref.as_non_null (extern.convert_any (call $unwrap (local.get 0)))))
21692169
(local.set $len (call $ta_length (local.get $a)))
2170-
(local.set $s (array.new $string (i32.const 0) (local.get $len)))
2171-
(call $ta_blit_to_string
2170+
(local.set $s (array.new $bytes (i32.const 0) (local.get $len)))
2171+
(call $ta_blit_to_bytes
21722172
(local.get $a) (i32.const 0) (local.get $s) (i32.const 0)
21732173
(local.get $len))
21742174
(local.get $s))
21752175

21762176
(export "caml_uint8_array_of_bytes" (func $caml_uint8_array_of_string))
21772177
(func $caml_uint8_array_of_string (export "caml_uint8_array_of_string")
21782178
(param (ref eq)) (result (ref eq))
2179-
;; Convert a string to a typed array
2179+
;; Convert bytes to a typed array
21802180
(local $ta (ref extern)) (local $len i32)
2181-
(local $s (ref $string))
2182-
(local.set $s (ref.cast (ref $string) (local.get 0)))
2181+
(local $s (ref $bytes))
2182+
(local.set $s (ref.cast (ref $bytes) (local.get 0)))
21832183
(local.set $len (array.len (local.get $s)))
21842184
(local.set $ta
21852185
(call $ta_create
21862186
(i32.const 3) ;; Uint8Array
21872187
(local.get $len)))
2188-
(call $ta_blit_from_string
2188+
(call $ta_blit_from_bytes
21892189
(local.get $s) (i32.const 0) (local.get $ta) (i32.const 0)
21902190
(local.get $len))
21912191
(call $wrap (any.convert_extern (local.get $ta))))
@@ -2219,15 +2219,15 @@
22192219
(local.get $kind)
22202220
(local.get $layout)))
22212221

2222-
(func (export "string_set")
2222+
(func (export "bytes_set")
22232223
(param $s externref) (param $i i32) (param $v i32)
2224-
(array.set $string
2225-
(ref.cast (ref null $string) (any.convert_extern (local.get $s)))
2224+
(array.set $bytes
2225+
(ref.cast (ref null $bytes) (any.convert_extern (local.get $s)))
22262226
(local.get $i) (local.get $v)))
22272227

2228-
(func (export "string_get")
2228+
(func (export "bytes_get")
22292229
(param $s externref) (param $i i32) (result i32)
2230-
(array.get $string
2231-
(ref.cast (ref null $string) (any.convert_extern (local.get $s)))
2230+
(array.get $bytes
2231+
(ref.cast (ref null $bytes) (any.convert_extern (local.get $s)))
22322232
(local.get $i)))
22332233
)

runtime/wasm/bigstring.wat

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -48,18 +48,18 @@
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
53-
(param (ref $string)) (param i32) (param (ref extern)) (param i32)
51+
(import "bindings" "ta_blit_from_bytes"
52+
(func $ta_blit_from_bytes
53+
(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
57-
(param (ref extern)) (param i32) (param (ref $string)) (param i32)
55+
(import "bindings" "ta_blit_to_bytes"
56+
(func $ta_blit_to_bytes
57+
(param (ref extern)) (param i32) (param (ref $bytes)) (param i32)
5858
(param i32)))
5959
(import "hash" "caml_hash_mix_int"
6060
(func $caml_hash_mix_int (param i32) (param i32) (result i32)))
6161

62-
(type $string (array (mut i8)))
62+
(type $bytes (array (mut i8)))
6363

6464
(func (export "caml_hash_mix_bigstring")
6565
(param $h i32) (param $b (ref eq)) (result i32)
@@ -104,7 +104,7 @@
104104
(param $bs (ref eq)) (result (ref eq))
105105
(return_call $caml_js_get
106106
(call $caml_ba_to_typed_array (local.get $bs))
107-
(array.new_data $string $buffer (i32.const 0) (i32.const 6))))
107+
(array.new_data $bytes $buffer (i32.const 0) (i32.const 6))))
108108

109109
(export "bigstring_to_typed_array" (func $caml_ba_to_typed_array))
110110

@@ -160,10 +160,10 @@
160160
(local $i i32) (local $pos1 i32) (local $pos2 i32) (local $len i32)
161161
(local $c1 i32) (local $c2 i32)
162162
(local $d1 (ref extern))
163-
(local $s2 (ref $string))
163+
(local $s2 (ref $bytes))
164164
(local.set $d1 (call $caml_ba_get_data (local.get $s1)))
165165
(local.set $pos1 (i31.get_s (ref.cast (ref i31) (local.get $vpos1))))
166-
(local.set $s2 (ref.cast (ref $string) (local.get $vs2)))
166+
(local.set $s2 (ref.cast (ref $bytes) (local.get $vs2)))
167167
(local.set $pos2 (i31.get_s (ref.cast (ref i31) (local.get $vpos2))))
168168
(local.set $len (i31.get_s (ref.cast (ref i31) (local.get $vlen))))
169169
(loop $loop
@@ -173,7 +173,7 @@
173173
(call $ta_get_ui8 (local.get $d1)
174174
(i32.add (local.get $pos1) (local.get $i))))
175175
(local.set $c2
176-
(array.get_u $string (local.get $s2)
176+
(array.get_u $bytes (local.get $s2)
177177
(i32.add (local.get $pos2) (local.get $i))))
178178
(local.set $i (i32.add (local.get $i) (i32.const 1)))
179179
(br_if $loop (i32.eq (local.get $c1) (local.get $c2)))
@@ -233,14 +233,14 @@
233233
(param $ba2 (ref eq)) (param $vpos2 (ref eq))
234234
(param $vlen (ref eq)) (result (ref eq))
235235
(local $pos1 i32) (local $pos2 i32) (local $len i32)
236-
(local $s1 (ref $string))
236+
(local $s1 (ref $bytes))
237237
(local $d2 (ref extern))
238-
(local.set $s1 (ref.cast (ref $string) (local.get $str1)))
238+
(local.set $s1 (ref.cast (ref $bytes) (local.get $str1)))
239239
(local.set $pos1 (i31.get_s (ref.cast (ref i31) (local.get $vpos1))))
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))
@@ -252,13 +252,13 @@
252252
(param $vlen (ref eq)) (result (ref eq))
253253
(local $pos1 i32) (local $pos2 i32) (local $len i32)
254254
(local $d1 (ref extern))
255-
(local $s2 (ref $string))
255+
(local $s2 (ref $bytes))
256256
(local.set $d1 (call $caml_ba_get_data (local.get $ba1)))
257257
(local.set $pos1 (i31.get_s (ref.cast (ref i31) (local.get $vpos1))))
258-
(local.set $s2 (ref.cast (ref $string) (local.get $str2)))
258+
(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))

0 commit comments

Comments
 (0)