@@ -228,13 +228,13 @@ type initialization = J.block
228
228
let compile output_prefix =
229
229
230
230
let rec compile_external_field (* Like [List.empty]*)
231
- (lamba_cxt : Lam_compile_context.t ) (id : Ident.t ) name : Js_output.t =
232
- match Lam_compile_env. query_external_id_info id name with
231
+ ?( dynamic_import = false ) (lamba_cxt : Lam_compile_context.t ) (id : Ident.t ) name : Js_output.t =
232
+ match Lam_compile_env. query_external_id_info ~dynamic_import id name with
233
233
| { persistent_closed_lambda = Some lam } when Lam_util. not_function lam ->
234
234
compile_lambda lamba_cxt lam
235
235
| _ ->
236
236
Js_output. output_of_expression lamba_cxt.continuation
237
- ~no_effects: no_effects_const (E. ml_var_dot id name)
237
+ ~no_effects: no_effects_const (E. ml_var_dot ~dynamic_import id name)
238
238
(* TODO: how nested module call would behave,
239
239
In the future, we should keep in track of if
240
240
it is fully applied from [Lapply]
@@ -263,10 +263,10 @@ let rec compile_external_field (* Like [List.empty]*)
263
263
for the function, generative module or functor can be a function,
264
264
however it can not be global -- global can only module
265
265
*)
266
- and compile_external_field_apply (appinfo : Lam.apply ) (module_id : Ident.t )
266
+ and compile_external_field_apply ?( dynamic_import = false ) (appinfo : Lam.apply ) (module_id : Ident.t )
267
267
(field_name : string ) (lambda_cxt : Lam_compile_context.t ) : Js_output.t =
268
268
let ident_info =
269
- Lam_compile_env. query_external_id_info module_id field_name
269
+ Lam_compile_env. query_external_id_info ~dynamic_import module_id field_name
270
270
in
271
271
let ap_args = appinfo.ap_args in
272
272
match ident_info.persistent_closed_lambda with
@@ -292,7 +292,7 @@ and compile_external_field_apply (appinfo : Lam.apply) (module_id : Ident.t)
292
292
| _ -> assert false )
293
293
in
294
294
295
- let fn = E. ml_var_dot module_id ident_info.name in
295
+ let fn = E. ml_var_dot ~dynamic_import module_id ident_info.name in
296
296
let expression =
297
297
match appinfo.ap_info.ap_status with
298
298
| (App_infer_full | App_uncurry ) as ap_status ->
@@ -1410,11 +1410,11 @@ and compile_apply (appinfo : Lam.apply) (lambda_cxt : Lam_compile_context.t) =
1410
1410
(* External function call: it can not be tailcall in this case*)
1411
1411
| {
1412
1412
ap_func =
1413
- Lprim { primitive = Pfield (_, fld_info); args = [ Lglobal_module id ]; _ };
1413
+ Lprim { primitive = Pfield (_, fld_info); args = [ Lglobal_module (id, dynamic_import) ]; _ };
1414
1414
} -> (
1415
1415
match fld_info with
1416
1416
| Fld_module { name } ->
1417
- compile_external_field_apply appinfo id name lambda_cxt
1417
+ compile_external_field_apply ~dynamic_import appinfo id name lambda_cxt
1418
1418
| _ -> assert false )
1419
1419
| _ -> (
1420
1420
(* TODO: ---
@@ -1491,11 +1491,11 @@ and compile_apply (appinfo : Lam.apply) (lambda_cxt : Lam_compile_context.t) =
1491
1491
and compile_prim (prim_info : Lam.prim_info )
1492
1492
(lambda_cxt : Lam_compile_context.t ) =
1493
1493
match prim_info with
1494
- | { primitive = Pfield (_ , fld_info ); args = [ Lglobal_module id ]; _ } -> (
1494
+ | { primitive = Pfield (_ , fld_info ); args = [ Lglobal_module (id, dynamic_import) ]; _ } -> (
1495
1495
(* should be before Lglobal_global *)
1496
1496
match fld_info with
1497
1497
| Fld_module { name = field } ->
1498
- compile_external_field lambda_cxt id field
1498
+ compile_external_field ~dynamic_import lambda_cxt id field
1499
1499
| _ -> assert false )
1500
1500
| { primitive = Praise ; args = [ e ]; _ } -> (
1501
1501
match
@@ -1715,13 +1715,13 @@ and compile_lambda (lambda_cxt : Lam_compile_context.t) (cur_lam : Lam.t) :
1715
1715
Js_output. output_of_expression lambda_cxt.continuation
1716
1716
~no_effects: no_effects_const
1717
1717
(Lam_compile_const. translate c)
1718
- | Lglobal_module i ->
1718
+ | Lglobal_module ( i , dynamic_import ) ->
1719
1719
(* introduced by
1720
1720
1. {[ include Array --> let include = Array ]}
1721
1721
2. inline functor application
1722
1722
*)
1723
1723
Js_output. output_of_block_and_expression lambda_cxt.continuation []
1724
- (E. ml_module_as_var i)
1724
+ (E. ml_module_as_var ~dynamic_import i)
1725
1725
| Lprim prim_info -> compile_prim prim_info lambda_cxt
1726
1726
| Lsequence (l1 , l2 ) ->
1727
1727
let output_l1 =
@@ -1759,4 +1759,4 @@ and compile_lambda (lambda_cxt : Lam_compile_context.t) (cur_lam : Lam.t) :
1759
1759
in compile_recursive_lets, compile_lambda
1760
1760
1761
1761
let compile_recursive_lets ~output_prefix = fst (compile output_prefix)
1762
- let compile_lambda ~output_prefix = snd (compile output_prefix)
1762
+ let compile_lambda ~output_prefix = snd (compile output_prefix)
0 commit comments