Skip to content

Commit 637fc5c

Browse files
committed
print module path
1 parent 1f31bef commit 637fc5c

9 files changed

+105
-59
lines changed

jscomp/core/lam_compile.ml

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ let rec apply_with_arity_aux (fn : J.expression) (arity : int list)
5555
let params =
5656
Ext_list.init (x - len) (fun _ -> Ext_ident.create "param")
5757
in
58-
E.ocaml_fun params ~return_unit:false (* unknown info *) ~async:false
58+
E.ocaml_fun params ~return_unit:false (* unknown info *)
59+
~async:false
5960
[
6061
S.return_stmt
6162
(E.call
@@ -320,7 +321,9 @@ and compile_recursive_let ~all_bindings (cxt : Lam_compile_context.t)
320321
]
321322
else
322323
(* TODO: save computation of length several times *)
323-
E.ocaml_fun params (Js_output.output_as_block output) ~return_unit ~async
324+
E.ocaml_fun params
325+
(Js_output.output_as_block output)
326+
~return_unit ~async
324327
in
325328
( Js_output.output_of_expression
326329
(Declare (Alias, id))
@@ -398,7 +401,8 @@ and compile_recursive_let ~all_bindings (cxt : Lam_compile_context.t)
398401
[
399402
S.exp
400403
(E.runtime_call Js_runtime_modules.obj_runtime
401-
"update_dummy" [ E.var id; v ]);
404+
"update_dummy"
405+
[ E.var id; v ]);
402406
]),
403407
[ S.define_variable ~kind:Variable id (E.dummy_obj tag_info) ] )
404408
| _ -> assert false)
@@ -1366,7 +1370,7 @@ and compile_apply (appinfo : Lam.apply) (lambda_cxt : Lam_compile_context.t) =
13661370
~info:(call_info_of_ap_status appinfo.ap_info.ap_status)
13671371
fn_code args))
13681372

1369-
and compile_prim (prim_info : Lam.prim_info)
1373+
and compile_prim ?output_prefix (prim_info : Lam.prim_info)
13701374
(lambda_cxt : Lam_compile_context.t) =
13711375
match prim_info with
13721376
| { primitive = Pfield (_, fld_info); args = [ Lglobal_module id ]; _ } -> (
@@ -1534,13 +1538,14 @@ and compile_prim (prim_info : Lam.prim_info)
15341538
let args_code : J.block = List.concat args_block in
15351539
let exp =
15361540
(* TODO: all can be done in [compile_primitive] *)
1537-
Lam_compile_primitive.translate loc lambda_cxt primitive args_expr
1541+
Lam_compile_primitive.translate ?output_prefix loc lambda_cxt primitive
1542+
args_expr
15381543
in
15391544
Js_output.output_of_block_and_expression lambda_cxt.continuation args_code
15401545
exp
15411546

1542-
and compile_lambda (lambda_cxt : Lam_compile_context.t) (cur_lam : Lam.t) :
1543-
Js_output.t =
1547+
and compile_lambda ?output_prefix (lambda_cxt : Lam_compile_context.t)
1548+
(cur_lam : Lam.t) : Js_output.t =
15441549
match cur_lam with
15451550
| Lfunction { params; body; attr = { return_unit; async } } ->
15461551
Js_output.output_of_expression lambda_cxt.continuation
@@ -1598,7 +1603,7 @@ and compile_lambda (lambda_cxt : Lam_compile_context.t) (cur_lam : Lam.t) :
15981603
*)
15991604
Js_output.output_of_block_and_expression lambda_cxt.continuation []
16001605
(E.ml_module_as_var i)
1601-
| Lprim prim_info -> compile_prim prim_info lambda_cxt
1606+
| Lprim prim_info -> compile_prim ?output_prefix prim_info lambda_cxt
16021607
| Lsequence (l1, l2) ->
16031608
let output_l1 =
16041609
compile_lambda { lambda_cxt with continuation = EffectCall Not_tail } l1

jscomp/core/lam_compile.mli

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,5 @@
2727
val compile_recursive_lets :
2828
Lam_compile_context.t -> (Ident.t * Lam.t) list -> Js_output.t
2929

30-
val compile_lambda : Lam_compile_context.t -> Lam.t -> Js_output.t
30+
val compile_lambda :
31+
?output_prefix:string -> Lam_compile_context.t -> Lam.t -> Js_output.t

jscomp/core/lam_compile_main.ml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
(* module S = Js_stmt_make *)
3535

3636

37-
let compile_group (meta : Lam_stats.t)
37+
let compile_group ~output_prefix (meta : Lam_stats.t)
3838
(x : Lam_group.t) : Js_output.t =
3939
match x with
4040
(*
@@ -61,7 +61,7 @@ let compile_group (meta : Lam_stats.t)
6161
(* let lam = Optimizer.simplify_lets [] lam in *)
6262
(* can not apply again, it's wrong USE it with care*)
6363
(* ([Js_stmt_make.comment (Gen_of_env.query_type id env )], None) ++ *)
64-
Lam_compile.compile_lambda { continuation = Declare (kind, id);
64+
Lam_compile.compile_lambda ~output_prefix { continuation = Declare (kind, id);
6565
jmp_table = Lam_compile_context.empty_handler_map;
6666
meta
6767
} lam
@@ -74,7 +74,7 @@ let compile_group (meta : Lam_stats.t)
7474
}
7575
id_lams
7676
| Nop lam -> (* TODO: Side effect callls, log and see statistics *)
77-
Lam_compile.compile_lambda {continuation = EffectCall Not_tail;
77+
Lam_compile.compile_lambda ~output_prefix {continuation = EffectCall Not_tail;
7878
jmp_table = Lam_compile_context.empty_handler_map;
7979
meta
8080
} lam
@@ -231,7 +231,7 @@ let maybe_pure = no_side_effects groups in
231231
let () = Ext_log.dwarn ~__POS__ "\n@[[TIME:]Pre-compile: %f@]@." (Sys.time () *. 1000.) in
232232
# 224 "core/lam_compile_main.pp.ml"
233233
let body =
234-
Ext_list.map groups (fun group -> compile_group meta group)
234+
Ext_list.map groups (fun group -> compile_group ~output_prefix meta group)
235235
|> Js_output.concat
236236
|> Js_output.output_as_block
237237
in

jscomp/core/lam_compile_primitive.ml

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ let ensure_value_unit (st : Lam_compile_context.continuation) e : E.t =
3636
| EffectCall Not_tail -> e
3737
(* NeedValue should return a meaningful expression*)
3838

39-
let translate loc (cxt : Lam_compile_context.t) (prim : Lam_primitive.t)
40-
(args : J.expression list) : J.expression =
39+
let translate ?output_prefix loc (cxt : Lam_compile_context.t)
40+
(prim : Lam_primitive.t) (args : J.expression list) : J.expression =
4141
match prim with
4242
| Pis_not_none -> Js_of_lam_option.is_not_none (Ext_list.singleton_exn args)
4343
| Pcreate_extension s -> E.make_exception s
@@ -82,9 +82,20 @@ let translate loc (cxt : Lam_compile_context.t) (prim : Lam_primitive.t)
8282
match args with
8383
| [ e ] -> (
8484
match e.expression_desc with
85-
| _ ->
86-
let d = Js_dump.string_of_expression e in
87-
E.str ("TODO:import " ^ d) )
85+
| _ -> (
86+
match output_prefix with
87+
| Some output_prefix ->
88+
let output_dir = Filename.dirname output_prefix in
89+
let d = Js_dump.string_of_expression e in
90+
let id = Ident.create d in
91+
let path =
92+
Js_name_of_module_id.string_of_module_id
93+
(Lam_module_ident.of_ml id)
94+
~output_dir Js_packages_info.Es6
95+
in
96+
print_endline path;
97+
E.str ("TODO:import " ^ d)
98+
| None -> assert false))
8899
| _ -> assert false)
89100
| Pjs_function_length -> E.function_length (Ext_list.singleton_exn args)
90101
| Pcaml_obj_length -> E.obj_length (Ext_list.singleton_exn args)

jscomp/core/lam_compile_primitive.mli

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
*)
3030

3131
val translate :
32+
?output_prefix:string ->
3233
Location.t ->
3334
Lam_compile_context.t ->
3435
Lam_primitive.t ->

jscomp/test/Import.js

Lines changed: 6 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)