Skip to content

Commit d3b6428

Browse files
committed
Merge pull request #66 from bloomberg/shake
add support for non export mode, so it play nice with playground
2 parents 1e9ff3b + f5555f7 commit d3b6428

File tree

9 files changed

+57
-1988
lines changed

9 files changed

+57
-1988
lines changed

jscomp/jsoo_driver.ml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
* }
3131
*)
3232

33-
let implementation ppf str =
33+
let implementation non_export ppf str =
3434
let modulename = "Test" in
3535
(* let env = !Toploop.toplevel_env in *)
3636
(* Compmisc.init_path false; *)
@@ -51,7 +51,7 @@ let implementation ppf str =
5151
|> (* Printlambda.lambda ppf *) (fun lam ->
5252
let buffer = Buffer.create 1000 in
5353
let () = Js_dump.(pp_program
54-
(Lam_compile_group.compile ~filename:""
54+
(Lam_compile_group.compile ~filename:"" non_export
5555
!finalenv !types_signature lam)
5656
(Ext_pp.from_buffer buffer)) in
5757
let v = Buffer.contents buffer in
@@ -88,8 +88,8 @@ let string_of_fmt (f : Format.formatter -> 'a -> unit) v =
8888
Format.pp_print_flush fmt () in
8989
Buffer.contents buf
9090

91-
let compile : string -> string = string_of_fmt implementation
92-
91+
let compile : string -> string = string_of_fmt (implementation false)
92+
let shake_compile : string -> string = string_of_fmt (implementation true)
9393

9494

9595
(* local variables: *)

jscomp/jsoo_exports.ml

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,19 @@ let () = JsooTop.initialize()
3333
let _ =
3434
export "ocaml"
3535
(Js.Unsafe.(obj
36-
[|"compile",
37-
inject @@
38-
Js.wrap_meth_callback
39-
(fun _ code ->
40-
Js.string (Jsoo_driver.compile (Js.to_string code)))
41-
|]))
36+
[|"compile",
37+
inject @@
38+
Js.wrap_meth_callback
39+
(fun _ code ->
40+
Js.string (Jsoo_driver.compile (Js.to_string code)));
41+
"shake_compile",
42+
inject @@
43+
Js.wrap_meth_callback
44+
(fun _ code ->
45+
Js.string (Jsoo_driver.shake_compile (Js.to_string code)))
46+
|]))
47+
48+
4249
(* local variables: *)
4350
(* compile-command: "ocamlbuild -cflags -dsource -use-ocamlfind -no-hygiene -pkgs js_of_ocaml,js_of_ocaml.toplevel exports.cmo" *)
4451
(* end: *)

jscomp/lam_compile_group.ml

Lines changed: 35 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,13 @@ let compile_group ({filename = file_name; env;} as meta : Lam_stats.meta)
151151
(** Actually simplify_lets is kind of global optimization since it requires you to know whether
152152
it's used or not
153153
*)
154-
let compile ~filename env sigs lam : J.program =
154+
let compile ~filename non_export env _sigs lam : J.program =
155155

156-
let export_idents = Translmod.get_export_identifiers() in
156+
let export_idents =
157+
if non_export then
158+
[]
159+
else Translmod.get_export_identifiers()
160+
in
157161
let () = Translmod.reset () in (* To make toplevel happy - reentrant for js-demo *)
158162
let () = Lam_compile_env.reset () in
159163

@@ -206,28 +210,32 @@ let compile ~filename env sigs lam : J.program =
206210
match Lam_group.flatten [] biglambda with
207211
| Lprim( (Pmakeblock (_,_,_), lambda_exports)), rest ->
208212
let coercion_groups, new_exports =
209-
List.fold_right2
210-
(fun eid lam (coercions, new_exports) ->
211-
match (lam : Lambda.lambda) with
212-
| Lvar id when Ident.name id = Ident.name eid ->
213-
(coercions, id :: new_exports)
214-
| _ -> (** TODO : bug
215-
check [map.ml] here coercion, we introduced
216-
rebound which is not corrrect
217-
{[
218-
let Make/identifier = function (funarg){
219-
var $$let = Make/identifier(funarg);
220-
return [0, ..... ]
221-
}
222-
]}
223-
Possible fix ?
224-
change export identifier, we should do this in the very
225-
beginning since lots of optimizations depend on this
226-
however
227-
*)
228-
(Lam_group.Single(Strict ,eid, lam) :: coercions,
229-
eid :: new_exports))
230-
meta.exports lambda_exports ([],[])in
213+
if non_export then
214+
[], []
215+
else
216+
List.fold_right2
217+
(fun eid lam (coercions, new_exports) ->
218+
match (lam : Lambda.lambda) with
219+
| Lvar id when Ident.name id = Ident.name eid ->
220+
(coercions, id :: new_exports)
221+
| _ -> (** TODO : bug
222+
check [map.ml] here coercion, we introduced
223+
rebound which is not corrrect
224+
{[
225+
let Make/identifier = function (funarg){
226+
var $$let = Make/identifier(funarg);
227+
return [0, ..... ]
228+
}
229+
]}
230+
Possible fix ?
231+
change export identifier, we should do this in the very
232+
beginning since lots of optimizations depend on this
233+
however
234+
*)
235+
(Lam_group.Single(Strict ,eid, lam) :: coercions,
236+
eid :: new_exports))
237+
meta.exports lambda_exports ([],[])
238+
in
231239

232240
let meta = { meta with
233241
export_idents = Lam_util.ident_set_of_list new_exports;
@@ -297,7 +305,8 @@ let compile ~filename env sigs lam : J.program =
297305
(* Exporting ... *)
298306
let v =
299307
Lam_stats_util.export_to_cmj meta maybe_pure external_module_ids
300-
lambda_exports in
308+
(if non_export then [] else lambda_exports)
309+
in
301310
(if not @@ Ext_string.is_empty filename then
302311
Js_cmj_format.to_file
303312
(Ext_filename.chop_extension ~loc:__LOC__ filename ^ ".cmj") v);
@@ -333,7 +342,7 @@ let lambda_as_module
333342
Lam_current_unit.set_debug_file "ari_regress_test.ml";
334343
Ext_pervasives.with_file_as_chan
335344
(Ext_filename.chop_extension ~loc:__LOC__ filename ^ ".js")
336-
(fun chan -> Js_dump.dump_program (compile ~filename env sigs lam) chan)
345+
(fun chan -> Js_dump.dump_program (compile ~filename false env sigs lam) chan)
337346
end
338347
(* We can use {!Env.current_unit = "Pervasives"} to tell if it is some specific module,
339348
We need handle some definitions in standard libraries in a special way, most are io specific,

jscomp/lam_compile_group.mli

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,12 @@
3030
*)
3131
val compile :
3232
filename : string ->
33+
bool ->
3334
Env.t ->
3435
Types.signature ->
3536
Lambda.lambda ->
3637
J.program
3738

38-
val lambda_as_module : Env.t -> Types.signature -> string -> Lambda.lambda -> unit
39+
val lambda_as_module :
40+
Env.t ->
41+
Types.signature -> string -> Lambda.lambda -> unit

jscomp/test/.depend

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -202,12 +202,6 @@ test_export2.cmo :
202202
test_export2.cmx :
203203
test_external.cmo :
204204
test_external.cmx :
205-
test_fastdt.cmo : ../stdlib/sys.cmi ../stdlib/string.cmi \
206-
../stdlib/random.cmi ../stdlib/printf.cmi ../stdlib/list.cmi \
207-
../stdlib/hashtbl.cmi ../stdlib/array.cmi
208-
test_fastdt.cmx : ../stdlib/sys.cmx ../stdlib/string.cmx \
209-
../stdlib/random.cmx ../stdlib/printf.cmx ../stdlib/list.cmx \
210-
../stdlib/hashtbl.cmx ../stdlib/array.cmx
211205
test_ffi.cmo :
212206
test_ffi.cmx :
213207
test_fib.cmo :
@@ -560,12 +554,6 @@ test_export2.cmo :
560554
test_export2.cmj :
561555
test_external.cmo :
562556
test_external.cmj :
563-
test_fastdt.cmo : ../stdlib/sys.cmi ../stdlib/string.cmi \
564-
../stdlib/random.cmi ../stdlib/printf.cmi ../stdlib/list.cmi \
565-
../stdlib/hashtbl.cmi ../stdlib/array.cmi
566-
test_fastdt.cmj : ../stdlib/sys.cmj ../stdlib/string.cmj \
567-
../stdlib/random.cmj ../stdlib/printf.cmj ../stdlib/list.cmj \
568-
../stdlib/hashtbl.cmj ../stdlib/array.cmj
569557
test_ffi.cmo :
570558
test_ffi.cmj :
571559
test_fib.cmo :

jscomp/test/test.mllib

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ test_order
1313
test_trywith
1414
arith_parser
1515
test_array_primitive
16-
test_fastdt
16+
# test_fastdt
1717
test_js_ffi
1818
test_pack
1919
test_seq

jscomp/test/test_fastdt.d.ts

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

0 commit comments

Comments
 (0)