Skip to content

Commit 600d4dd

Browse files
committed
finish bytes primitive
1 parent 6d3e6dc commit 600d4dd

30 files changed

+106
-98
lines changed

Diff for: jscomp/core/lam_dispatch_primitive.ml

+11-5
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,9 @@ let translate loc (prim_name : string)
467467
end
468468

469469

470+
#if OCAML_VERSION =~ ">4.03.0" then
471+
| "caml_create_bytes"
472+
#end
470473
| "caml_create_string" ->
471474
(* Bytes.create *)
472475
(* Note that for invalid range, JS raise an Exception RangeError,
@@ -478,7 +481,8 @@ let translate loc (prim_name : string)
478481
->
479482
E.array NA []
480483
| _ ->
481-
call Js_runtime_modules.string
484+
E.runtime_call Js_runtime_modules.string
485+
"caml_create_bytes" args
482486
end
483487
| "caml_bool_compare" ->
484488
begin match args with
@@ -529,14 +533,16 @@ let translate loc (prim_name : string)
529533
call Js_runtime_modules.caml_primitive
530534
| _ -> assert false
531535
end
532-
536+
| "caml_fill_string"
537+
| "caml_fill_bytes"
538+
->
539+
E.runtime_call
540+
Js_runtime_modules.string "caml_fill_bytes" args
533541
| "caml_string_get"
534542
| "string_of_bytes"
535543
| "bytes_of_string"
536-
537544
| "caml_is_printable"
538-
| "caml_string_of_char_array"
539-
| "caml_fill_string"
545+
| "caml_string_of_char_array"
540546
| "caml_blit_string"
541547
| "caml_blit_bytes"
542548
->

Diff for: jscomp/runtime/caml_string.ml

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ let caml_string_get s i=
5151
else Bs_string.unsafe_get s i
5252

5353

54-
let caml_create_string len : bytes =
54+
let caml_create_bytes len : bytes =
5555
(* Node raise [RangeError] exception *)
5656
if len < 0 then raise (Invalid_argument "String.create")
5757
else
@@ -65,7 +65,7 @@ let caml_create_string len : bytes =
6565

6666

6767

68-
let caml_fill_string (s : bytes) i l (c : char) =
68+
let caml_fill_bytes (s : bytes) i l (c : char) =
6969
if l > 0 then
7070
for k = i to l + i - 1 do
7171
unsafe_set s k c

Diff for: jscomp/runtime/caml_string.mli

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ val caml_is_printable : char -> bool
3737
val caml_string_of_char_array : char array -> string
3838
val caml_string_get : string -> int -> char
3939

40-
val caml_create_string : int -> bytes
41-
val caml_fill_string : bytes -> int -> int -> char -> unit
40+
val caml_create_bytes : int -> bytes
41+
val caml_fill_bytes : bytes -> int -> int -> char -> unit
4242
val caml_blit_string : string -> int -> bytes -> int -> int -> unit
4343
val caml_blit_bytes : bytes -> int -> bytes -> int -> int -> unit
4444
val caml_string_get16 : string -> int -> int

Diff for: jscomp/test/bytes_split_gpr_743_test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ function eq(loc, param) {
2828
return /* () */0;
2929
}
3030

31-
var b = Caml_string.caml_create_string(3);
31+
var b = Caml_string.caml_create_bytes(3);
3232

3333
b[0] = /* "a" */97;
3434

@@ -47,7 +47,7 @@ eq("File \"bytes_split_gpr_743_test.ml\", line 17, characters 5-12", /* tuple */
4747
res
4848
]);
4949

50-
var b$1 = Caml_string.caml_create_string(3);
50+
var b$1 = Caml_string.caml_create_bytes(3);
5151

5252
b$1[0] = /* "a" */97;
5353

Diff for: jscomp/test/complex_if_test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ function escaped(s) {
3737
if (n === s.length) {
3838
return Bytes.copy(s);
3939
} else {
40-
var s$prime = Caml_string.caml_create_string(n);
40+
var s$prime = Caml_string.caml_create_bytes(n);
4141
n = 0;
4242
for(var i$1 = 0 ,i_finish$1 = s.length - 1 | 0; i$1 <= i_finish$1; ++i$1){
4343
var c = s[i$1];

Diff for: jscomp/test/ext_bytes_test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ function escaped(s) {
2727
if (n === s.length) {
2828
return Bytes.copy(s);
2929
} else {
30-
var s$prime = Caml_string.caml_create_string(n);
30+
var s$prime = Caml_string.caml_create_bytes(n);
3131
n = 0;
3232
for(var i$1 = 0 ,i_finish$1 = s.length - 1 | 0; i$1 <= i_finish$1; ++i$1){
3333
var c = s[i$1];

Diff for: jscomp/test/ext_string_test.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ function is_empty(s) {
245245

246246
function repeat(n, s) {
247247
var len = s.length;
248-
var res = Caml_string.caml_create_string(Caml_int32.imul(n, len));
248+
var res = Caml_string.caml_create_bytes(Caml_int32.imul(n, len));
249249
for(var i = 0 ,i_finish = n - 1 | 0; i <= i_finish; ++i){
250250
$$String.blit(s, 0, res, Caml_int32.imul(i, len), len);
251251
}
@@ -403,7 +403,7 @@ function equal(x, y) {
403403
function unsafe_concat_with_length(len, sep, l) {
404404
if (l) {
405405
var hd = l[0];
406-
var r = Caml_string.caml_create_string(len);
406+
var r = Caml_string.caml_create_bytes(len);
407407
var hd_len = hd.length;
408408
var sep_len = sep.length;
409409
Caml_string.caml_blit_string(hd, 0, r, 0, hd_len);
@@ -647,7 +647,7 @@ function concat_array(sep, s) {
647647
for(var i = 0 ,i_finish = s_len - 1 | 0; i <= i_finish; ++i){
648648
len = len + s[i].length | 0;
649649
}
650-
var target = Caml_string.caml_create_string(len + Caml_int32.imul(s_len - 1 | 0, sep_len) | 0);
650+
var target = Caml_string.caml_create_bytes(len + Caml_int32.imul(s_len - 1 | 0, sep_len) | 0);
651651
var hd = s[0];
652652
var hd_len = hd.length;
653653
Caml_string.caml_blit_string(hd, 0, target, 0, hd_len);
@@ -674,7 +674,7 @@ function concat3(a, b, c) {
674674
var b_len = b.length;
675675
var c_len = c.length;
676676
var len = (a_len + b_len | 0) + c_len | 0;
677-
var target = Caml_string.caml_create_string(len);
677+
var target = Caml_string.caml_create_bytes(len);
678678
Caml_string.caml_blit_string(a, 0, target, 0, a_len);
679679
Caml_string.caml_blit_string(b, 0, target, a_len, b_len);
680680
Caml_string.caml_blit_string(c, 0, target, a_len + b_len | 0, c_len);
@@ -687,7 +687,7 @@ function concat4(a, b, c, d) {
687687
var c_len = c.length;
688688
var d_len = d.length;
689689
var len = ((a_len + b_len | 0) + c_len | 0) + d_len | 0;
690-
var target = Caml_string.caml_create_string(len);
690+
var target = Caml_string.caml_create_bytes(len);
691691
Caml_string.caml_blit_string(a, 0, target, 0, a_len);
692692
Caml_string.caml_blit_string(b, 0, target, a_len, b_len);
693693
Caml_string.caml_blit_string(c, 0, target, a_len + b_len | 0, c_len);
@@ -702,7 +702,7 @@ function concat5(a, b, c, d, e) {
702702
var d_len = d.length;
703703
var e_len = e.length;
704704
var len = (((a_len + b_len | 0) + c_len | 0) + d_len | 0) + e_len | 0;
705-
var target = Caml_string.caml_create_string(len);
705+
var target = Caml_string.caml_create_bytes(len);
706706
Caml_string.caml_blit_string(a, 0, target, 0, a_len);
707707
Caml_string.caml_blit_string(b, 0, target, a_len, b_len);
708708
Caml_string.caml_blit_string(c, 0, target, a_len + b_len | 0, c_len);

Diff for: jscomp/test/ocaml_parsetree_test.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -10379,7 +10379,7 @@ var keyword_table = create_hashtable(149, /* :: */[
1037910379
]
1038010380
]);
1038110381

10382-
var initial_string_buffer = Caml_string.caml_create_string(256);
10382+
var initial_string_buffer = Caml_string.caml_create_bytes(256);
1038310383

1038410384
var string_buff = /* record */[/* contents */initial_string_buffer];
1038510385

@@ -10393,7 +10393,7 @@ function reset_string_buffer(param) {
1039310393

1039410394
function store_string_char(c) {
1039510395
if (string_index[0] >= string_buff[0].length) {
10396-
var new_buff = Caml_string.caml_create_string((string_buff[0].length << 1));
10396+
var new_buff = Caml_string.caml_create_bytes((string_buff[0].length << 1));
1039710397
Bytes.blit(string_buff[0], 0, new_buff, 0, string_buff[0].length);
1039810398
string_buff[0] = new_buff;
1039910399
}
@@ -10525,7 +10525,7 @@ function cvt_nativeint_literal(s) {
1052510525

1052610526
function remove_underscores(s) {
1052710527
var l = s.length;
10528-
var b = Caml_string.caml_create_string(l);
10528+
var b = Caml_string.caml_create_bytes(l);
1052910529
var _src = 0;
1053010530
var _dst = 0;
1053110531
while(true) {

Diff for: jscomp/test/ocaml_re_test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1873,8 +1873,8 @@ function colorize(c, regexp) {
18731873
}
18741874

18751875
function flatten_cmap(cm) {
1876-
var c = Caml_string.caml_create_string(256);
1877-
var col_repr = Caml_string.caml_create_string(256);
1876+
var c = Caml_string.caml_create_bytes(256);
1877+
var col_repr = Caml_string.caml_create_bytes(256);
18781878
var v = 0;
18791879
c[0] = /* "\000" */0;
18801880
col_repr[0] = /* "\000" */0;

Diff for: jscomp/test/ocaml_typedtree_test.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -20725,7 +20725,7 @@ var keyword_table = create_hashtable(149, /* :: */[
2072520725
]
2072620726
]);
2072720727

20728-
var initial_string_buffer = Caml_string.caml_create_string(256);
20728+
var initial_string_buffer = Caml_string.caml_create_bytes(256);
2072920729

2073020730
var string_buff = /* record */[/* contents */initial_string_buffer];
2073120731

@@ -20739,7 +20739,7 @@ function reset_string_buffer(param) {
2073920739

2074020740
function store_string_char(c) {
2074120741
if (string_index[0] >= string_buff[0].length) {
20742-
var new_buff = Caml_string.caml_create_string((string_buff[0].length << 1));
20742+
var new_buff = Caml_string.caml_create_bytes((string_buff[0].length << 1));
2074320743
Bytes.blit(string_buff[0], 0, new_buff, 0, string_buff[0].length);
2074420744
string_buff[0] = new_buff;
2074520745
}
@@ -20871,7 +20871,7 @@ function cvt_nativeint_literal(s) {
2087120871

2087220872
function remove_underscores(s) {
2087320873
var l = s.length;
20874-
var b = Caml_string.caml_create_string(l);
20874+
var b = Caml_string.caml_create_bytes(l);
2087520875
var _src = 0;
2087620876
var _dst = 0;
2087720877
while(true) {
@@ -47653,7 +47653,7 @@ function is_big(obj) {
4765347653
var size = error_size[0];
4765447654
if (size > 0) {
4765547655
if (buffer[0].length < size) {
47656-
buffer[0] = Caml_string.caml_create_string(size);
47656+
buffer[0] = Caml_string.caml_create_bytes(size);
4765747657
}
4765847658
try {
4765947659
Marshal.to_buffer(buffer[0], 0, size, obj, /* [] */0);

Diff for: jscomp/test/parser_api.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -830,7 +830,7 @@ function create_hashtable(size, init) {
830830
}
831831

832832
function copy_file(ic, oc) {
833-
var buff = Caml_string.caml_create_string(4096);
833+
var buff = Caml_string.caml_create_bytes(4096);
834834
var _param = /* () */0;
835835
while(true) {
836836
var n = Pervasives.input(ic, buff, 0, 4096);
@@ -845,7 +845,7 @@ function copy_file(ic, oc) {
845845
}
846846

847847
function copy_file_chunk(ic, oc, len) {
848-
var buff = Caml_string.caml_create_string(4096);
848+
var buff = Caml_string.caml_create_bytes(4096);
849849
var _n = len;
850850
while(true) {
851851
var n = _n;
@@ -866,7 +866,7 @@ function copy_file_chunk(ic, oc, len) {
866866

867867
function string_of_file(ic) {
868868
var b = $$Buffer.create(65536);
869-
var buff = Caml_string.caml_create_string(4096);
869+
var buff = Caml_string.caml_create_bytes(4096);
870870
var _param = /* () */0;
871871
while(true) {
872872
var n = Pervasives.input(ic, buff, 0, 4096);
@@ -1106,9 +1106,9 @@ function create(str_size) {
11061106
var tbl_size = Caml_int32.div(str_size, Sys.max_string_length) + 1 | 0;
11071107
var tbl = Caml_array.caml_make_vect(tbl_size, Bytes.empty);
11081108
for(var i = 0 ,i_finish = tbl_size - 2 | 0; i <= i_finish; ++i){
1109-
Caml_array.caml_array_set(tbl, i, Caml_string.caml_create_string(Sys.max_string_length));
1109+
Caml_array.caml_array_set(tbl, i, Caml_string.caml_create_bytes(Sys.max_string_length));
11101110
}
1111-
Caml_array.caml_array_set(tbl, tbl_size - 1 | 0, Caml_string.caml_create_string(Caml_int32.mod_(str_size, Sys.max_string_length)));
1111+
Caml_array.caml_array_set(tbl, tbl_size - 1 | 0, Caml_string.caml_create_bytes(Caml_int32.mod_(str_size, Sys.max_string_length)));
11121112
return tbl;
11131113
}
11141114

@@ -13133,7 +13133,7 @@ var keyword_table = create_hashtable(149, /* :: */[
1313313133
]
1313413134
]);
1313513135

13136-
var initial_string_buffer = Caml_string.caml_create_string(256);
13136+
var initial_string_buffer = Caml_string.caml_create_bytes(256);
1313713137

1313813138
var string_buff = /* record */[/* contents */initial_string_buffer];
1313913139

@@ -13147,7 +13147,7 @@ function reset_string_buffer(param) {
1314713147

1314813148
function store_string_char(c) {
1314913149
if (string_index[0] >= string_buff[0].length) {
13150-
var new_buff = Caml_string.caml_create_string((string_buff[0].length << 1));
13150+
var new_buff = Caml_string.caml_create_bytes((string_buff[0].length << 1));
1315113151
Bytes.blit(string_buff[0], 0, new_buff, 0, string_buff[0].length);
1315213152
string_buff[0] = new_buff;
1315313153
}
@@ -13287,7 +13287,7 @@ function cvt_nativeint_literal(s) {
1328713287

1328813288
function remove_underscores(s) {
1328913289
var l = s.length;
13290-
var b = Caml_string.caml_create_string(l);
13290+
var b = Caml_string.caml_create_bytes(l);
1329113291
var _src = 0;
1329213292
var _dst = 0;
1329313293
while(true) {

Diff for: jscomp/test/qcc.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ var glo = Bytes.make(4096, /* "\000" */0);
116116

117117
var gpos = /* record */[/* contents */0];
118118

119-
var s = Caml_string.caml_create_string(100);
119+
var s = Caml_string.caml_create_bytes(100);
120120

121121
function getq(param) {
122122
var c = Curry._1(getch, /* () */0);

Diff for: jscomp/test/sexpm.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ function make($staropt$star, refill) {
351351
var bufsize = $staropt$star !== undefined ? $staropt$star : 1024;
352352
var bufsize$1 = Caml_primitive.caml_int_min(bufsize > 16 ? bufsize : 16, Sys.max_string_length);
353353
return /* record */[
354-
/* buf */Caml_string.caml_create_string(bufsize$1),
354+
/* buf */Caml_string.caml_create_bytes(bufsize$1),
355355
/* refill */refill,
356356
/* atom */$$Buffer.create(32),
357357
/* i */0,
@@ -983,7 +983,7 @@ function MakeDecode(funarg) {
983983
var bufsize = $staropt$star !== undefined ? $staropt$star : 1024;
984984
var bufsize$1 = Caml_primitive.caml_int_min(bufsize > 16 ? bufsize : 16, Sys.max_string_length);
985985
return /* record */[
986-
/* buf */Caml_string.caml_create_string(bufsize$1),
986+
/* buf */Caml_string.caml_create_bytes(bufsize$1),
987987
/* refill */refill,
988988
/* atom */$$Buffer.create(32),
989989
/* i */0,

Diff for: jscomp/test/string_bound_get_test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ function u_d(param) {
1515
return Caml_string.get("ghos", -1);
1616
}
1717

18-
var u_e = Caml_string.caml_create_string(32);
18+
var u_e = Caml_string.caml_create_bytes(32);
1919

2020
var u_f = Caml_bytes.get(u_e, 0);
2121

Diff for: jscomp/test/string_runtime_test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ var suites_001 = /* :: */[
3636
(function (param) {
3737
var match = List.split(List.map((function (x) {
3838
var len = x;
39-
var b = Caml_string.caml_create_string(1000);
40-
Caml_string.caml_fill_string(b, 0, len, /* "c" */99);
39+
var b = Caml_string.caml_create_bytes(1000);
40+
Caml_string.caml_fill_bytes(b, 0, len, /* "c" */99);
4141
return /* tuple */[
4242
Caml_string.bytes_to_string(b),
4343
Caml_string.bytes_to_string(Bytes.init(len, (function (param) {

Diff for: jscomp/test/test_bug.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ function escaped(s) {
3434
if (n === s.length) {
3535
return Bytes.copy(s);
3636
} else {
37-
var s$prime = Caml_string.caml_create_string(n);
37+
var s$prime = Caml_string.caml_create_bytes(n);
3838
n = 0;
3939
for(var i$1 = 0 ,i_finish$1 = s.length - 1 | 0; i$1 <= i_finish$1; ++i$1){
4040
var c$1 = s[i$1];

0 commit comments

Comments
 (0)