Skip to content

Commit 7c1c8cf

Browse files
committed
Runtime: mark some bigstring stubs as weakdef
Theses stubs are being moved where they belong to (Base,Core_kernel, ..) Making stubs weak will provide a smoother transition.
1 parent cbb6fa7 commit 7c1c8cf

File tree

1 file changed

+20
-40
lines changed

1 file changed

+20
-40
lines changed

runtime/bigstring.js

Lines changed: 20 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
///////// BIGSTRING
22
//Provides: bigstring_alloc
33
//Requires: caml_ba_create
4+
//Weakdef
5+
//Will be defined in Base
46
function bigstring_alloc(_,size){
57
return caml_ba_create(12, 0, [0,size]);
68
}
79

810
//Provides: bigstring_destroy_stub
911
//Requires: caml_invalid_argument, caml_ba_create_from
12+
//Weakdef
13+
//Will be defined in Core_kernel
1014
function bigstring_destroy_stub(v_bstr) {
1115
if (v_bstr.data2 != null) {
1216
caml_invalid_argument("bigstring_destroy: unsupported kind");
@@ -30,6 +34,8 @@ function bigstring_destroy_stub(v_bstr) {
3034

3135
//Provides: bigstring_blit_bigstring_bytes_stub
3236
//Requires: caml_bytes_set, caml_ba_get_1
37+
//Weakdef
38+
//Will be defined in Base
3339
function bigstring_blit_bigstring_bytes_stub(v_bstr, v_src_pos, v_str, v_dst_pos, v_len){
3440
for(var i = 0; i < v_len; i++){
3541
var c = caml_ba_get_1(v_bstr,v_src_pos + i);
@@ -40,21 +46,27 @@ function bigstring_blit_bigstring_bytes_stub(v_bstr, v_src_pos, v_str, v_dst_pos
4046

4147
//Provides: bigstring_blit_bigstring_string_stub
4248
//Requires: bigstring_blit_bigstring_bytes_stub
49+
//From cstruct
4350
var bigstring_blit_bigstring_string_stub = bigstring_blit_bigstring_bytes_stub
4451

4552
//Provides: caml_blit_bigstring_to_string
4653
//Requires: bigstring_blit_bigstring_bytes_stub
54+
//From cstruct
4755
var caml_blit_bigstring_to_string = bigstring_blit_bigstring_bytes_stub
4856

4957
//Provides: bigstring_blit_string_bigstring_stub
5058
//Requires: caml_string_get, caml_ba_set_1
59+
//Weakdef
60+
//Will be defined in Base
5161
function bigstring_blit_string_bigstring_stub(v_str, v_src_pos, v_bstr, v_dst_pos, v_len){
5262
for (var i = 0; i < v_len; i++) caml_ba_set_1(v_bstr,v_dst_pos + i,caml_string_get(v_str,v_src_pos + i));
5363
return 0;
5464
}
5565

5666
//Provides: bigstring_blit_bytes_bigstring_stub
5767
//Requires: caml_bytes_get, caml_ba_set_1
68+
//Weakdef
69+
//Will be defined in Base
5870
function bigstring_blit_bytes_bigstring_stub(v_str, v_src_pos, v_bstr, v_dst_pos, v_len){
5971
for (var i = 0; i < v_len; i++) caml_ba_set_1(v_bstr,v_dst_pos + i,caml_bytes_get(v_str,v_src_pos + i));
6072
return 0;
@@ -65,13 +77,17 @@ var caml_blit_string_to_bigstring = bigstring_blit_string_bigstring_stub
6577

6678
//Provides: bigstring_blit_stub
6779
//Requires: caml_ba_get_1, caml_ba_set_1
80+
//Weakdef
81+
//Will be defined in Base
6882
function bigstring_blit_stub(s1, i1, s2, i2, len){
6983
for (var i = 0; i < len; i++) caml_ba_set_1(s2,i2 + i,caml_ba_get_1(s1,i1 + i));
7084
return 0;
7185
}
7286

7387
//Provides: bigstring_memcmp_stub
7488
//Requires: caml_ba_get_1
89+
//Weakdef
90+
//Will be defined in Base
7591
function bigstring_memcmp_stub(v_s1, v_s1_pos, v_s2, v_s2_pos, v_len){
7692
for (var i = 0; i < v_len; i++) {
7793
var a = caml_ba_get_1(v_s1,v_s1_pos + i);
@@ -84,6 +100,8 @@ function bigstring_memcmp_stub(v_s1, v_s1_pos, v_s2, v_s2_pos, v_len){
84100

85101
//Provides: bigstring_find
86102
//Requires: caml_ba_get_1
103+
//Weakdef
104+
//Will be defined in Base
87105
function bigstring_find(bs, chr, pos, len){
88106
while(len > 0){
89107
if(caml_ba_get_1(bs,pos) == chr) return pos;
@@ -94,57 +112,19 @@ function bigstring_find(bs, chr, pos, len){
94112
}
95113

96114
//Provides: bigstring_to_array_buffer mutable
115+
//js_of_ocaml lib
97116
function bigstring_to_array_buffer(bs) {
98117
return bs.data.buffer
99118
}
100119

101120
//Provides: bigstring_of_array_buffer mutable
102121
//Requires: caml_ba_create_from
122+
//js_of_ocaml lib
103123
function bigstring_of_array_buffer(ab) {
104124
var ta = new joo_global_object.Uint8Array(ab);
105125
return caml_ba_create_from(ta, null, 0, 12, 0, [ta.length])
106126
}
107127

108-
//Provides: bigstring_marshal_data_size_stub mutable
109-
//Requires: caml_failwith, caml_ba_uint8_get32
110-
function bigstring_marshal_data_size_stub (s, ofs) {
111-
if (caml_ba_uint8_get32(s, ofs) != (0x8495A6BE|0))
112-
caml_failwith("Marshal.data_size: bad object");
113-
return (caml_ba_uint8_get32(s, ofs + 4));
114-
}
115-
116-
//Provides: bigstring_unmarshal_stub mutable
117-
//Requires: BigStringReader, caml_input_value_from_reader
118-
function bigstring_unmarshal_stub(s,ofs) {
119-
var reader = new BigStringReader (s, typeof ofs=="number"?ofs:ofs[0]);
120-
return caml_input_value_from_reader(reader, ofs)
121-
}
122-
123-
124-
//Provides: bigstring_marshal_stub mutable
125-
//Requires: caml_output_val, bigstring_alloc, caml_ba_set_1
126-
function bigstring_marshal_stub (v, _fl) {
127-
/* ignores flags... */
128-
var arr = caml_output_val (v);
129-
var bs = bigstring_alloc(0,arr.length);
130-
for(var i = 0; i < arr.length; i++){
131-
caml_ba_set_1(bs, i, arr[i]);
132-
}
133-
return bs;
134-
}
135-
136-
//Provides: bigstring_marshal_blit_stub
137-
//Requires: caml_output_val, caml_failwith, caml_ba_set_1
138-
function bigstring_marshal_blit_stub (s, ofs, len, v, _fl) {
139-
/* ignores flags... */
140-
var t = caml_output_val (v);
141-
if (t.length > len) caml_failwith ("Marshal.to_buffer: buffer overflow");
142-
for(var i = 0; i < t.length; i++){
143-
caml_ba_set_1(s, (i + ofs), t[i]);
144-
}
145-
return t.length;
146-
}
147-
148128
//Provides: caml_hash_mix_bigstring
149129
//Requires: caml_hash_mix_string_arr
150130
function caml_hash_mix_bigstring(h, bs) {

0 commit comments

Comments
 (0)