Skip to content

Commit d0545e5

Browse files
Hongbo Zhangbobzhang
Hongbo Zhang
authored andcommitted
done: place holder for array and string (+2 squashed commits)
Squashed commits: [bd951a8] WIP [68f337e] WIP: move tests locally and start bindings to array
1 parent 208f3ec commit d0545e5

File tree

331 files changed

+1271
-1275
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

331 files changed

+1271
-1275
lines changed

docs/OCaml-call-JS.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -712,13 +712,13 @@ We introduced `bs.re` for Javascript regex expresion:
712712
let f = [%bs.re "/b/g"]
713713
```
714714

715-
The compiler will infer `f` has type `Js.re` and generate code as below
715+
The compiler will infer `f` has type `Js_re.t` and generate code as below
716716

717717
```
718718
var f = /b/g
719719
```
720720

721-
> Note that `Js.re` is an abstract type, we are working on providing bindings for it
721+
> Note that `Js_re.t` is an abstract type, we are working on providing bindings for it
722722
723723
## Examples:
724724

jscomp/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ install:
9595
cp ./bin/bsc ../bin/
9696
cp ./runtime/*.cmt* ../lib/ocaml/
9797
cp ./runtime/*.cmj* ../lib/ocaml/
98-
cp ./runtime/js.cmi ../lib/ocaml/
98+
cp ./runtime/js.cmi ./runtime/js_array.cmi ./runtime/js_string.cmi ./runtime/js_re.cmi ../lib/ocaml/
9999
cp ./stdlib/*.cm* ../lib/ocaml/
100100

101101
TMP_OCAMLLIB=$(shell ocamlopt.opt -where)

jscomp/build.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ cd ./test/
4646
# ./build.sh 2>> ../build.compile
4747
make $TARGET.cmj 2>> ../build.compile
4848

49-
cat ../../lib/js/test/$TARGET.js >> ../build.compile
49+
cat $TARGET.js >> ../build.compile
5050
make -j30 all 2>>../build.compile
5151
make depend 2>>../build.compile
5252
echo "<<Test finished" >> ../build.compile

jscomp/common/js_config.ml

-1
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,6 @@ let stdlib_set = String_set.of_list [
197197
"stdLabels";
198198
"camlinternalLazy";
199199
"map";
200-
201200
(* "std_exit"; *)
202201
(* https://developer.mozilla.org/de/docs/Web/Events/beforeunload *)
203202
"camlinternalMod";

jscomp/common/js_config.mli

+1-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ val get_no_any_assert : unit -> bool
120120
(** Internal use *)
121121
val runtime_set : String_set.t
122122
val stdlib_set : String_set.t
123-
123+
(** only used in {!Js_generate_require} *)
124124

125125
val block : string
126126
val int32 : string

jscomp/runtime/.runtimedepend

+51-36
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,14 @@ caml_string.cmi :
2121
caml_sys.cmi :
2222
caml_utils.cmi :
2323
caml_weak.cmi :
24+
js_array.cmi :
2425
js_primitive.cmi : js.cmj
26+
js_re.cmi :
27+
js_string.cmi :
2528
block.cmj : block.cmi
2629
block.cmx : block.cmi
30+
bs_string.cmj :
31+
bs_string.cmx :
2732
caml_array.cmj : caml_array.cmi
2833
caml_array.cmx : caml_array.cmi
2934
caml_backtrace.cmj : caml_backtrace.cmi
@@ -36,26 +41,26 @@ caml_exceptions.cmj : caml_builtin_exceptions.cmi caml_exceptions.cmi
3641
caml_exceptions.cmx : caml_builtin_exceptions.cmx caml_exceptions.cmi
3742
caml_float.cmj : typed_array.cmj js_float.cmj caml_float.cmi
3843
caml_float.cmx : typed_array.cmx js_float.cmx caml_float.cmi
39-
caml_format.cmj : js_string.cmj js_nativeint.cmj js_int64.cmj js_int.cmj \
40-
js_float.cmj caml_utils.cmi caml_format.cmi
41-
caml_format.cmx : js_string.cmx js_nativeint.cmx js_int64.cmx js_int.cmx \
42-
js_float.cmx caml_utils.cmx caml_format.cmi
44+
caml_format.cmj : js_nativeint.cmj js_int64.cmj js_int.cmj js_float.cmj \
45+
caml_utils.cmi bs_string.cmj caml_format.cmi
46+
caml_format.cmx : js_nativeint.cmx js_int64.cmx js_int.cmx js_float.cmx \
47+
caml_utils.cmx bs_string.cmx caml_format.cmi
4348
caml_gc.cmj : caml_gc.cmi
4449
caml_gc.cmx : caml_gc.cmi
45-
caml_hash.cmj : js_string.cmj js_obj.cmj js.cmj caml_queue.cmi caml_hash.cmi
46-
caml_hash.cmx : js_string.cmx js_obj.cmx js.cmx caml_queue.cmx caml_hash.cmi
50+
caml_hash.cmj : js_obj.cmj js.cmj caml_queue.cmi bs_string.cmj caml_hash.cmi
51+
caml_hash.cmx : js_obj.cmx js.cmx caml_queue.cmx bs_string.cmx caml_hash.cmi
4752
caml_int32.cmj : caml_int32.cmi
4853
caml_int32.cmx : caml_int32.cmi
49-
caml_int64.cmj : typed_array.cmj js_string.cmj js_float.cmj caml_utils.cmi \
50-
caml_int32.cmi caml_int64.cmi
51-
caml_int64.cmx : typed_array.cmx js_string.cmx js_float.cmx caml_utils.cmx \
52-
caml_int32.cmx caml_int64.cmi
53-
caml_io.cmj : js_string.cmj js.cmj
54-
caml_io.cmx : js_string.cmx js.cmx
54+
caml_int64.cmj : typed_array.cmj js_float.cmj caml_utils.cmi caml_int32.cmi \
55+
bs_string.cmj caml_int64.cmi
56+
caml_int64.cmx : typed_array.cmx js_float.cmx caml_utils.cmx caml_int32.cmx \
57+
bs_string.cmx caml_int64.cmi
58+
caml_io.cmj : js.cmj bs_string.cmj
59+
caml_io.cmx : js.cmx bs_string.cmx
5560
caml_lexer.cmj : caml_lexer.cmi
5661
caml_lexer.cmx : caml_lexer.cmi
57-
caml_md5.cmj : js_string.cmj caml_md5.cmi
58-
caml_md5.cmx : js_string.cmx caml_md5.cmi
62+
caml_md5.cmj : bs_string.cmj caml_md5.cmi
63+
caml_md5.cmx : bs_string.cmx caml_md5.cmi
5964
caml_module.cmj :
6065
caml_module.cmx :
6166
caml_obj.cmj : js_obj.cmj js.cmj caml_obj.cmi
@@ -68,8 +73,8 @@ caml_primitive.cmj : caml_primitive.cmi
6873
caml_primitive.cmx : caml_primitive.cmi
6974
caml_queue.cmj : caml_queue.cmi
7075
caml_queue.cmx : caml_queue.cmi
71-
caml_string.cmj : js_string.cmj caml_string.cmi
72-
caml_string.cmx : js_string.cmx caml_string.cmi
76+
caml_string.cmj : bs_string.cmj caml_string.cmi
77+
caml_string.cmx : bs_string.cmx caml_string.cmi
7378
caml_sys.cmj : js_float.cmj caml_sys.cmi
7479
caml_sys.cmx : js_float.cmx caml_sys.cmi
7580
caml_utils.cmj : caml_utils.cmi
@@ -80,6 +85,8 @@ curry.cmj : caml_oo.cmi caml_array.cmi
8085
curry.cmx : caml_oo.cmx caml_array.cmx
8186
js.cmj :
8287
js.cmx :
88+
js_array.cmj : js_array.cmi
89+
js_array.cmx : js_array.cmi
8390
js_float.cmj :
8491
js_float.cmx :
8592
js_int.cmj :
@@ -92,14 +99,18 @@ js_obj.cmj : js.cmj
9299
js_obj.cmx : js.cmx
93100
js_primitive.cmj : js.cmj js_primitive.cmi
94101
js_primitive.cmx : js.cmx js_primitive.cmi
95-
js_string.cmj :
96-
js_string.cmx :
102+
js_re.cmj : js_re.cmi
103+
js_re.cmx : js_re.cmi
104+
js_string.cmj : js_string.cmi
105+
js_string.cmx : js_string.cmi
97106
js_unsafe.cmj : js.cmj
98107
js_unsafe.cmx : js.cmx
99108
typed_array.cmj :
100109
typed_array.cmx :
101110
block.cmo : block.cmi
102111
block.cmj : block.cmi
112+
bs_string.cmo :
113+
bs_string.cmj :
103114
caml_array.cmo : caml_array.cmi
104115
caml_array.cmj : caml_array.cmi
105116
caml_backtrace.cmo : caml_backtrace.cmi
@@ -112,26 +123,26 @@ caml_exceptions.cmo : caml_builtin_exceptions.cmi caml_exceptions.cmi
112123
caml_exceptions.cmj : caml_builtin_exceptions.cmj caml_exceptions.cmi
113124
caml_float.cmo : typed_array.cmo js_float.cmo caml_float.cmi
114125
caml_float.cmj : typed_array.cmj js_float.cmj caml_float.cmi
115-
caml_format.cmo : js_string.cmo js_nativeint.cmo js_int64.cmo js_int.cmo \
116-
js_float.cmo caml_utils.cmi caml_format.cmi
117-
caml_format.cmj : js_string.cmj js_nativeint.cmj js_int64.cmj js_int.cmj \
118-
js_float.cmj caml_utils.cmj caml_format.cmi
126+
caml_format.cmo : js_nativeint.cmo js_int64.cmo js_int.cmo js_float.cmo \
127+
caml_utils.cmi bs_string.cmo caml_format.cmi
128+
caml_format.cmj : js_nativeint.cmj js_int64.cmj js_int.cmj js_float.cmj \
129+
caml_utils.cmj bs_string.cmj caml_format.cmi
119130
caml_gc.cmo : caml_gc.cmi
120131
caml_gc.cmj : caml_gc.cmi
121-
caml_hash.cmo : js_string.cmo js_obj.cmo js.cmo caml_queue.cmi caml_hash.cmi
122-
caml_hash.cmj : js_string.cmj js_obj.cmj js.cmj caml_queue.cmj caml_hash.cmi
132+
caml_hash.cmo : js_obj.cmo js.cmo caml_queue.cmi bs_string.cmo caml_hash.cmi
133+
caml_hash.cmj : js_obj.cmj js.cmj caml_queue.cmj bs_string.cmj caml_hash.cmi
123134
caml_int32.cmo : caml_int32.cmi
124135
caml_int32.cmj : caml_int32.cmi
125-
caml_int64.cmo : typed_array.cmo js_string.cmo js_float.cmo caml_utils.cmi \
126-
caml_int32.cmi caml_int64.cmi
127-
caml_int64.cmj : typed_array.cmj js_string.cmj js_float.cmj caml_utils.cmj \
128-
caml_int32.cmj caml_int64.cmi
129-
caml_io.cmo : js_string.cmo js.cmo
130-
caml_io.cmj : js_string.cmj js.cmj
136+
caml_int64.cmo : typed_array.cmo js_float.cmo caml_utils.cmi caml_int32.cmi \
137+
bs_string.cmo caml_int64.cmi
138+
caml_int64.cmj : typed_array.cmj js_float.cmj caml_utils.cmj caml_int32.cmj \
139+
bs_string.cmj caml_int64.cmi
140+
caml_io.cmo : js.cmo bs_string.cmo
141+
caml_io.cmj : js.cmj bs_string.cmj
131142
caml_lexer.cmo : caml_lexer.cmi
132143
caml_lexer.cmj : caml_lexer.cmi
133-
caml_md5.cmo : js_string.cmo caml_md5.cmi
134-
caml_md5.cmj : js_string.cmj caml_md5.cmi
144+
caml_md5.cmo : bs_string.cmo caml_md5.cmi
145+
caml_md5.cmj : bs_string.cmj caml_md5.cmi
135146
caml_module.cmo :
136147
caml_module.cmj :
137148
caml_obj.cmo : js_obj.cmo js.cmo caml_obj.cmi
@@ -144,8 +155,8 @@ caml_primitive.cmo : caml_primitive.cmi
144155
caml_primitive.cmj : caml_primitive.cmi
145156
caml_queue.cmo : caml_queue.cmi
146157
caml_queue.cmj : caml_queue.cmi
147-
caml_string.cmo : js_string.cmo caml_string.cmi
148-
caml_string.cmj : js_string.cmj caml_string.cmi
158+
caml_string.cmo : bs_string.cmo caml_string.cmi
159+
caml_string.cmj : bs_string.cmj caml_string.cmi
149160
caml_sys.cmo : js_float.cmo caml_sys.cmi
150161
caml_sys.cmj : js_float.cmj caml_sys.cmi
151162
caml_utils.cmo : caml_utils.cmi
@@ -156,6 +167,8 @@ curry.cmo : caml_oo.cmi caml_array.cmi
156167
curry.cmj : caml_oo.cmj caml_array.cmj
157168
js.cmo :
158169
js.cmj :
170+
js_array.cmo : js_array.cmi
171+
js_array.cmj : js_array.cmi
159172
js_float.cmo :
160173
js_float.cmj :
161174
js_int.cmo :
@@ -168,8 +181,10 @@ js_obj.cmo : js.cmo
168181
js_obj.cmj : js.cmj
169182
js_primitive.cmo : js.cmo js_primitive.cmi
170183
js_primitive.cmj : js.cmj js_primitive.cmi
171-
js_string.cmo :
172-
js_string.cmj :
184+
js_re.cmo : js_re.cmi
185+
js_re.cmj : js_re.cmi
186+
js_string.cmo : js_string.cmi
187+
js_string.cmj : js_string.cmi
173188
js_unsafe.cmo : js.cmo
174189
js_unsafe.cmj : js.cmj
175190
typed_array.cmo :

jscomp/runtime/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ OTHERS= caml_array caml_string \
99
caml_format caml_md5 caml_queue caml_hash caml_weak\
1010
caml_backtrace caml_int32 caml_gc typed_array \
1111
js_primitive caml_basic caml_oo curry caml_module js_unsafe \
12-
js_string js_float js_obj js_nativeint js_int
12+
bs_string js_float js_obj js_nativeint js_int js_array js_string js_re
1313

1414
SOURCE_LIST= $(OTHERS) caml_builtin_exceptions block js
1515

jscomp/runtime/bs_string.ml

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
(* Copyright (C) 2015-2016 Bloomberg Finance L.P.
2+
*
3+
* This program is free software: you can redistribute it and/or modify
4+
* it under the terms of the GNU Lesser General Public License as published by
5+
* the Free Software Foundation, either version 3 of the License, or
6+
* (at your option) any later version.
7+
*
8+
* In addition to the permissions granted to you by the LGPL, you may combine
9+
* or link a "work that uses the Library" with a publicly distributed version
10+
* of this file to produce a combined library or application, then distribute
11+
* that combined work under the terms of your choosing, with no requirement
12+
* to comply with the obligations normally placed on you by section 4 of the
13+
* LGPL version 3 (or the corresponding section of a later version of the LGPL
14+
* should you choose to use a later version).
15+
*
16+
* This program is distributed in the hope that it will be useful,
17+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19+
* GNU Lesser General Public License for more details.
20+
*
21+
* You should have received a copy of the GNU Lesser General Public License
22+
* along with this program; if not, write to the Free Software
23+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
24+
25+
external string_of_char : char -> string = "js_string_of_char"
26+
(** TODO: check with {!String.of_char}
27+
it's quite common that we have
28+
{[ Bs_string.of_char x.[0] ]}
29+
It would be nice to generate code as below
30+
{[ x[0]
31+
]}
32+
*)
33+
34+
external of_char : char -> string = "String.fromCharCode"
35+
[@@bs.call]
36+
external toUpperCase : string -> string = "toUpperCase" [@@bs.send]
37+
external of_int : int -> base:int -> string = "toString" [@@bs.send]
38+
external of_nativeint : nativeint -> base:int -> string = "toString" [@@bs.send]
39+
external slice : string -> int -> int -> string = "slice"
40+
[@@bs.send]
41+
external slice_rest : string -> int -> string = "slice"
42+
[@@bs.send]
43+
external index_of : string -> string -> int = "indexOf"
44+
[@@bs.send]
45+
external append : string -> string -> string = "js_string_append"
46+
external of_small_int_array : int array -> string = "js_string_of_small_int_array"
47+
external of_small_int32_array : int32 array -> string = "js_string_of_small_int_array"
48+
external lastIndexOf : string -> string -> int = "lastIndexOf"
49+
[@@bs.send]
50+
external of_any : 'a -> string = "js_anything_to_string"
51+
52+
53+
(***********************)
54+
(* replaced primitives *)
55+
external length : string -> int = "%string_length"
56+
external get : string -> int -> char = "%string_safe_get"
57+
external create : int -> bytes = "caml_create_string"
58+
external unsafe_get : string -> int -> char = "%string_unsafe_get"
59+
external unsafe_set : bytes -> int -> char -> unit = "%bytes_unsafe_set"
60+
external unsafe_blit : string -> int -> bytes -> int -> int -> unit
61+
= "caml_blit_string" "noalloc"
62+
external unsafe_fill : bytes -> int -> int -> char -> unit
63+
= "caml_fill_string" "noalloc"

0 commit comments

Comments
 (0)