Skip to content

Commit a2ceb9c

Browse files
authored
Merge pull request #635 from bloomberg/upgrade
rename Js_array to Js_arr to avoid conflict with runtime module name
2 parents 2bdefbd + 70de682 commit a2ceb9c

File tree

10 files changed

+87
-96
lines changed

10 files changed

+87
-96
lines changed

jscomp/core.mllib

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ lam_group
5050
j
5151
js_ast_util
5252

53-
js_array
53+
js_arr
5454
js_program_loader
5555
js_output
5656
js_dump

jscomp/foo.itarget

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ syntax/syntax.cmxa
44
core.cmxa
55
depends/depends.cmxa
66
bs_ppx_main.cmx
7-
ocamlpack_main.cmx
7+
ocamlpack_main.cmx
8+
jsoo_main.cmo

jscomp/js.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ set -e
33
## building js
44
# ocamlbuild -use-ocamlfind -no-hygiene -syntax camlp4o -pkgs js_of_ocaml,js_of_ocaml.syntax,js_of_ocaml.toplevel exports.byte
55

6-
ocamlbuild -lflags -no-check-prims -use-ocamlfind -no-hygiene -pkgs compiler-libs.bytecomp -no-links jsoo_exports.byte
7-
js_of_ocaml -I +compiler-libs --toplevel +dynlink.js +toplevel.js +weak.js _build/jsoo_exports.byte -I ./runtime/ --file js.cmi:/cmis --file js_unsafe.cmi:/cmis --file js_re.cmi:/cmis -o _build/exports.js
6+
ocamlbuild -lflags -no-check-prims -use-ocamlfind -no-hygiene -pkgs compiler-libs.bytecomp -no-links jsoo_main.byte
7+
8+
# jsoo_mkcmis stdlib
9+
js_of_ocaml -I +compiler-libs --toplevel +weak.js +toplevel.js ./polyfill.js _build/jsoo_main.byte -I ./runtime/ --file js.cmi:/cmis/js.cmi --file js_unsafe.cmi:/cmis/js_unsafe.cmi --file js_re.cmi:/cmis/js_re.cmi -o _build/exports.js
810

911
rm -rf $BUCKLESCRIPT_DOC/js-demo/exports.js && cp _build/exports.js $BUCKLESCRIPT_DOC/js-demo/
1012

File renamed without changes.
File renamed without changes.

jscomp/jsoo_exports.ml

Lines changed: 0 additions & 89 deletions
This file was deleted.

jscomp/jsoo_driver.ml renamed to jscomp/jsoo_main.ml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,60 @@ let compile : string -> string = string_of_fmt (implementation false)
105105
let shake_compile : string -> string = string_of_fmt (implementation true)
106106

107107

108+
(** *)
109+
module Js = struct
110+
module Unsafe = struct
111+
type any
112+
external inject : 'a -> any = "%identity"
113+
external get : 'a -> 'b -> 'c = "caml_js_get"
114+
external set : 'a -> 'b -> 'c -> unit = "caml_js_set"
115+
external pure_js_expr : string -> 'a = "caml_pure_js_expr"
116+
let global = pure_js_expr "joo_global_object"
117+
external obj : (string * any) array -> 'a = "caml_js_object"
118+
end
119+
type (-'a, +'b) meth_callback
120+
type 'a callback = (unit, 'a) meth_callback
121+
external wrap_callback : ('a -> 'b) -> ('c, 'a -> 'b) meth_callback = "caml_js_wrap_callback"
122+
external wrap_meth_callback : ('a -> 'b) -> ('a, 'b) meth_callback = "caml_js_wrap_meth_callback"
123+
type + 'a t
124+
type js_string
125+
external string : string -> js_string t = "caml_js_from_string"
126+
external to_string : js_string t -> string = "caml_js_to_string"
127+
end
128+
129+
130+
let export (field : string) v =
131+
Js.Unsafe.set (Js.Unsafe.global) field v
132+
;;
133+
134+
(* To add a directory to the load path *)
135+
136+
let dir_directory d =
137+
Config.load_path := d :: !Config.load_path
138+
139+
140+
let () =
141+
dir_directory "/cmis"
142+
143+
144+
145+
let _ =
146+
export "ocaml"
147+
(Js.Unsafe.(obj
148+
[|"compile",
149+
inject @@
150+
Js.wrap_meth_callback
151+
(fun _ code ->
152+
Js.string (compile (Js.to_string code)));
153+
"shake_compile",
154+
inject @@
155+
Js.wrap_meth_callback
156+
(fun _ code ->
157+
Js.string (shake_compile (Js.to_string code)));
158+
"version", Js.Unsafe.inject (Js.string (Js_config.version))
159+
|]))
160+
161+
108162
(* local variables: *)
109163
(* compile-command: "ocamlbuild -use-ocamlfind -pkg compiler-libs -no-hygiene driver.cmo" *)
110164
(* end: *)

jscomp/jsoo_main.mli

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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. *)

jscomp/lam_compile.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ and compile_recursive_let
307307
match x with
308308
| Lam.Lvar lid
309309
-> S.exp
310-
(Js_array.set_array (E.var id) (E.int (Int32.of_int i)) (E.var lid))
310+
(Js_arr.set_array (E.var id) (E.int (Int32.of_int i)) (E.var lid))
311311
| _ -> assert false
312312
) ls)
313313
), []

jscomp/lam_compile_external_call.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,14 +236,14 @@ let translate_ffi (ffi : Ast_external_attributes.ffi ) prim_name
236236
->
237237
begin match args with
238238
| [obj; v ] ->
239-
Js_array.ref_array obj v
239+
Js_arr.ref_array obj v
240240
| _ -> assert false
241241
end
242242
| Js_set_index
243243
->
244244
begin match args with
245245
| [obj; v ; value] ->
246-
Js_array.set_array obj v value
246+
Js_arr.set_array obj v value
247247
| _ -> assert false
248248
end
249249

0 commit comments

Comments
 (0)