Skip to content

Commit fba07a1

Browse files
cristianocmununki
authored andcommitted
Add skeleton for import.
Goes from the front-end all the way to where the primitive should be handled in the back-end, and prints a dump of the back-end expression.
1 parent 3aedb24 commit fba07a1

19 files changed

+2219
-2143
lines changed

jscomp/core/lam_analysis.ml

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ let rec no_side_effects (lam : Lam.t) : bool =
4646
( "?int64_float_of_bits"
4747
(* more safe to check if arguments are constant *)
4848
(* non-observable side effect *)
49-
| "?sys_get_argv" (* should be fine *)
50-
| "?string_repeat" | "?make_vect" | "?create_bytes" | "?obj_dup"
51-
| "caml_array_dup" | "?nativeint_add" | "?nativeint_div"
52-
| "?nativeint_mod" | "?nativeint_lsr" | "?nativeint_mul" ),
49+
| "?sys_get_argv" (* should be fine *) | "?string_repeat"
50+
| "?make_vect" | "?create_bytes" | "?obj_dup" | "caml_array_dup"
51+
| "?nativeint_add" | "?nativeint_div" | "?nativeint_mod"
52+
| "?nativeint_lsr" | "?nativeint_mul" ),
5353
_ ) ->
5454
true
5555
| _, _ -> false)
@@ -58,9 +58,9 @@ let rec no_side_effects (lam : Lam.t) : bool =
5858
| [ _; Lconst cst ] -> not_zero_constant cst
5959
| _ -> false)
6060
| Pcreate_extension _ | Pjs_typeof | Pis_null | Pis_not_none | Psome
61-
| Psome_not_nest | Pis_undefined | Pis_null_undefined | Pnull_to_opt
62-
| Pundefined_to_opt | Pnull_undefined_to_opt | Pjs_fn_make _
63-
| Pjs_object_create _
61+
| Psome_not_nest | Pis_undefined | Pis_null_undefined | Pimport
62+
| Pnull_to_opt | Pundefined_to_opt | Pnull_undefined_to_opt
63+
| Pjs_fn_make _ | Pjs_object_create _
6464
(* TODO: check *)
6565
| Pbytes_to_string | Pmakeblock _
6666
(* whether it's mutable or not *)
@@ -87,9 +87,8 @@ let rec no_side_effects (lam : Lam.t) : bool =
8787
| Pasrint64 | Pint64comp _
8888
(* Operations on big arrays: (unsafe, #dimensions, kind, layout) *)
8989
(* Compile time constants *)
90-
| Pctconst _ (* Integer to external pointer *)
91-
| Poffsetint _ | Pstringadd | Pjs_function_length | Pcaml_obj_length
92-
| Pwrap_exn
90+
| Pctconst _ (* Integer to external pointer *) | Poffsetint _ | Pstringadd
91+
| Pjs_function_length | Pcaml_obj_length | Pwrap_exn
9392
| Praw_js_code
9493
{
9594
code_info =
@@ -197,8 +196,7 @@ and size_constant x =
197196
| Const_js_null | Const_js_undefined | Const_module_alias | Const_js_true
198197
| Const_js_false ->
199198
1
200-
| Const_string _ ->
201-
1
199+
| Const_string _ -> 1
202200
| Const_some s -> size_constant s
203201
| Const_block (_, _, str) ->
204202
Ext_list.fold_left str 0 (fun acc x -> acc + size_constant x)
@@ -211,7 +209,6 @@ let args_all_const (args : Lam.t list) =
211209
Ext_list.for_all args (fun x -> match x with Lconst _ -> true | _ -> false)
212210

213211
let exit_inline_size = 7
214-
215212
let small_inline_size = 5
216213

217214
(** destruct pattern will work better

jscomp/core/lam_compile_primitive.ml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,14 @@ let translate loc (cxt : Lam_compile_context.t) (prim : Lam_primitive.t)
7878
| _ -> E.runtime_call Js_runtime_modules.option "nullable_to_opt" args
7979
)
8080
| _ -> assert false)
81+
| Pimport -> (
82+
match args with
83+
| [ e ] -> (
84+
match e.expression_desc with
85+
| _ ->
86+
let d = Js_dump.string_of_expression e in
87+
E.str ("TODO:import " ^ d) )
88+
| _ -> assert false)
8189
| Pjs_function_length -> E.function_length (Ext_list.singleton_exn args)
8290
| Pcaml_obj_length -> E.obj_length (Ext_list.singleton_exn args)
8391
| Pis_null -> E.is_null (Ext_list.singleton_exn args)
@@ -301,7 +309,8 @@ let translate loc (cxt : Lam_compile_context.t) (prim : Lam_primitive.t)
301309
| Backend_type ->
302310
E.make_block E.zero_int_literal
303311
(Blk_constructor { name = "Other"; num_nonconst = 1; tag = 0 })
304-
[ E.str "BS" ] Immutable)
312+
[ E.str "BS" ]
313+
Immutable)
305314
| Pduprecord -> Lam_dispatch_primitive.translate loc "?obj_dup" args
306315
| Plazyforce
307316
(* FIXME: we don't inline lazy force or at least

jscomp/core/lam_convert.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,7 @@ let convert (exports : Set_ident.t) (lam : Lambda.lambda) :
480480
| "#nullable_to_opt" -> Pnull_undefined_to_opt
481481
| "#null_to_opt" -> Pnull_to_opt
482482
| "#is_nullable" -> Pis_null_undefined
483+
| "#import" -> Pimport
483484
| "#string_append" -> Pstringadd
484485
| "#wrap_exn" -> Pwrap_exn
485486
| "#obj_length" -> Pcaml_obj_length

jscomp/core/lam_primitive.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ type t =
142142
| Pis_null
143143
| Pis_undefined
144144
| Pis_null_undefined
145+
| Pimport
145146
| Pjs_typeof
146147
| Pjs_function_length
147148
| Pcaml_obj_length
@@ -218,6 +219,7 @@ let eq_primitive_approx (lhs : t) (rhs : t) =
218219
| Psome_not_nest -> rhs = Psome_not_nest
219220
| Pis_undefined -> rhs = Pis_undefined
220221
| Pis_null_undefined -> rhs = Pis_null_undefined
222+
| Pimport -> rhs = Pimport
221223
| Pjs_typeof -> rhs = Pjs_typeof
222224
| Pisint -> rhs = Pisint
223225
| Pis_poly_var_block -> rhs = Pis_poly_var_block

jscomp/core/lam_primitive.mli

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ type t =
130130
| Pis_null
131131
| Pis_undefined
132132
| Pis_null_undefined
133+
| Pimport
133134
| Pjs_typeof
134135
| Pjs_function_length
135136
| Pcaml_obj_length

jscomp/core/lam_print.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ let primitive ppf (prim : Lam_primitive.t) =
7878
| Pval_from_option_not_nest -> fprintf ppf "[?unbox-not-nest]"
7979
| Pis_undefined -> fprintf ppf "[?undefined]"
8080
| Pis_null_undefined -> fprintf ppf "[?null?undefined]"
81+
| Pimport -> fprintf ppf "[import]"
8182
| Pmakeblock (tag, _, Immutable) -> fprintf ppf "makeblock %i" tag
8283
| Pmakeblock (tag, _, Mutable) -> fprintf ppf "makemutable %i" tag
8384
| Pfield (n, field_info) -> (

0 commit comments

Comments
 (0)