Skip to content

Commit dd56e61

Browse files
committed
Follow Lprim
1 parent 92e38cb commit dd56e61

17 files changed

+156
-108
lines changed

compiler/core/js_dump.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,8 @@ and expression_desc cxt ~(level : int) f x : cxt =
529529
P.string f "<meh />";
530530
cxt
531531
| Call (e, el, info) ->
532+
Format.fprintf Format.err_formatter "Js_dump Has transformed_jsx %b\n"
533+
(Option.is_some info.call_transformed_jsx);
532534
P.cond_paren_group f (level > 15) (fun _ ->
533535
P.group f 0 (fun _ ->
534536
match (info, el) with

compiler/core/lam.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -723,10 +723,10 @@ let result_wrap loc (result_type : External_ffi_types.return_wrapper) result =
723723
prim ~primitive:Pundefined_to_opt ~args:[result] loc
724724
| Return_unset | Return_identity -> result
725725

726-
let handle_bs_non_obj_ffi (arg_types : External_arg_spec.params)
726+
let handle_bs_non_obj_ffi ?transformed_jsx (arg_types : External_arg_spec.params)
727727
(result_type : External_ffi_types.return_wrapper) ffi args loc prim_name
728728
~dynamic_import =
729729
result_wrap loc result_type
730730
(prim
731-
~primitive:(Pjs_call {prim_name; arg_types; ffi; dynamic_import})
731+
~primitive:(Pjs_call {prim_name; arg_types; ffi; dynamic_import; transformed_jsx})
732732
~args loc)

compiler/core/lam.mli

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ and t = private
9090
val inner_map : t -> (t -> t) -> t
9191

9292
val handle_bs_non_obj_ffi :
93+
?transformed_jsx:Parsetree.jsx_element ->
9394
External_arg_spec.params ->
9495
External_ffi_types.return_wrapper ->
9596
External_ffi_types.external_spec ->

compiler/core/lam_convert.ml

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -348,8 +348,8 @@ let rec rename_optional_parameters map params (body : Lambda.lambda) =
348348
value_kind,
349349
id,
350350
Lifthenelse
351-
( Lprim (p, [Lvar ({name = "*opt*"} as opt)], p_loc),
352-
Lprim (p1, [Lvar ({name = "*opt*"} as opt2)], x_loc),
351+
( Lprim (p, [Lvar ({name = "*opt*"} as opt)], p_loc, p_tj),
352+
Lprim (p1, [Lvar ({name = "*opt*"} as opt2)], x_loc, x_tj),
353353
f ),
354354
rest )
355355
when Ident.same opt opt2 && List.mem opt params ->
@@ -361,8 +361,8 @@ let rec rename_optional_parameters map params (body : Lambda.lambda) =
361361
value_kind,
362362
id,
363363
Lifthenelse
364-
( Lprim (p, [Lvar new_id], p_loc),
365-
Lprim (p1, [Lvar new_id], x_loc),
364+
( Lprim (p, [Lvar new_id], p_loc, p_tj),
365+
Lprim (p1, [Lvar new_id], x_loc, x_tj),
366366
f ),
367367
rest ) )
368368
| _ -> (map, body)
@@ -373,21 +373,22 @@ let convert (exports : Set_ident.t) (lam : Lambda.lambda) :
373373
let exit_map = Hash_int.create 0 in
374374
let may_depends = Lam_module_ident.Hash_set.create 0 in
375375

376-
let rec convert_ccall (a_prim : Primitive.description)
376+
let rec convert_ccall ?(transformed_jsx = None) (a_prim : Primitive.description)
377377
(args : Lambda.lambda list) loc ~dynamic_import : Lam.t =
378378
let prim_name = a_prim.prim_name in
379379
match External_ffi_types.from_string a_prim.prim_native_name with
380380
| Ffi_obj_create labels ->
381381
let args = Ext_list.map args convert_aux in
382382
prim ~primitive:(Pjs_object_create labels) ~args loc
383383
| Ffi_bs (arg_types, result_type, ffi) ->
384+
Format.fprintf Format.err_formatter "Ffi_bs\n";
384385
let arg_types =
385386
match arg_types with
386387
| Params ls -> ls
387388
| Param_number i -> Ext_list.init i (fun _ -> External_arg_spec.dummy)
388389
in
389390
let args = Ext_list.map args convert_aux in
390-
Lam.handle_bs_non_obj_ffi arg_types result_type ffi args loc prim_name
391+
Lam.handle_bs_non_obj_ffi ?transformed_jsx arg_types result_type ffi args loc prim_name
391392
~dynamic_import
392393
| Ffi_inline_const i -> Lam.const i
393394
| Ffi_normal ->
@@ -447,39 +448,42 @@ let convert (exports : Set_ident.t) (lam : Lambda.lambda) :
447448
let lam = Lam.letrec bindings body in
448449
Lam_scc.scc bindings lam body
449450
(* inlining will affect how mututal recursive behave *)
450-
| Lprim (Prevapply, [x; f], outer_loc) | Lprim (Pdirapply, [f; x], outer_loc)
451-
->
451+
| Lprim (Prevapply, [x; f], outer_loc, _)
452+
| Lprim (Pdirapply, [f; x], outer_loc, _) ->
452453
convert_pipe f x outer_loc
453-
| Lprim (Prevapply, _, _) -> assert false
454-
| Lprim (Pdirapply, _, _) -> assert false
455-
| Lprim (Pccall a, args, loc) -> convert_ccall a args loc ~dynamic_import
456-
| Lprim (Pjs_raw_expr, args, loc) -> (
454+
| Lprim (Prevapply, _, _, _) -> assert false
455+
| Lprim (Pdirapply, _, _, _) -> assert false
456+
| Lprim (Pccall a, args, loc, transformed_jsx) ->
457+
Format.fprintf Format.err_formatter
458+
"lam convert Pccall Has transformed_jsx %b\n" (Option.is_some transformed_jsx);
459+
convert_ccall ~transformed_jsx a args loc ~dynamic_import
460+
| Lprim (Pjs_raw_expr, args, loc, _) -> (
457461
match args with
458462
| [Lconst (Const_base (Const_string (code, _)))] ->
459463
(* js parsing here *)
460464
let kind = Classify_function.classify code in
461465
prim ~primitive:(Praw_js_code {code; code_info = Exp kind}) ~args:[] loc
462466
| _ -> assert false)
463-
| Lprim (Pjs_raw_stmt, args, loc) -> (
467+
| Lprim (Pjs_raw_stmt, args, loc, _) -> (
464468
match args with
465469
| [Lconst (Const_base (Const_string (code, _)))] ->
466470
let kind = Classify_function.classify_stmt code in
467471
prim
468472
~primitive:(Praw_js_code {code; code_info = Stmt kind})
469473
~args:[] loc
470474
| _ -> assert false)
471-
| Lprim (Pgetglobal id, args, _) ->
475+
| Lprim (Pgetglobal id, args, _, _) ->
472476
let args = Ext_list.map args convert_aux in
473477
if Ident.is_predef_exn id then
474478
Lam.const (Const_string {s = id.name; unicode = false})
475479
else (
476480
may_depend may_depends (Lam_module_ident.of_ml ~dynamic_import id);
477481
assert (args = []);
478482
Lam.global_module ~dynamic_import id)
479-
| Lprim (Pimport, args, loc) ->
483+
| Lprim (Pimport, args, loc, _) ->
480484
let args = Ext_list.map args (convert_aux ~dynamic_import:true) in
481485
lam_prim ~primitive:Pimport ~args loc
482-
| Lprim (primitive, args, loc) ->
486+
| Lprim (primitive, args, loc, tj) ->
483487
let args = Ext_list.map args (convert_aux ~dynamic_import) in
484488
lam_prim ~primitive ~args loc
485489
| Lswitch (e, s, _loc) -> convert_switch e s

compiler/core/lam_primitive.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ type t =
4646
arg_types: External_arg_spec.params;
4747
ffi: External_ffi_types.external_spec;
4848
dynamic_import: bool;
49+
transformed_jsx: Parsetree.jsx_element option;
4950
}
5051
| Pjs_object_create of External_arg_spec.obj_params
5152
(* Exceptions *)
@@ -250,7 +251,7 @@ let eq_primitive_approx (lhs : t) (rhs : t) =
250251
| Pmakeblock (i1, info1, flag1) ->
251252
i0 = i1 && flag0 = flag1 && eq_tag_info info0 info1
252253
| _ -> false)
253-
| Pjs_call {prim_name; arg_types; ffi; dynamic_import} -> (
254+
| Pjs_call {prim_name; arg_types; ffi; dynamic_import; _} -> (
254255
match rhs with
255256
| Pjs_call rhs ->
256257
prim_name = rhs.prim_name && arg_types = rhs.arg_types && ffi = rhs.ffi

compiler/core/lam_primitive.mli

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ type t =
4242
arg_types: External_arg_spec.params;
4343
ffi: External_ffi_types.external_spec;
4444
dynamic_import: bool;
45+
transformed_jsx: Parsetree.jsx_element option;
4546
}
4647
| Pjs_object_create of External_arg_spec.obj_params
4748
| Praise

compiler/core/polyvar_pattern_match.ml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ let or_list (arg : lam) (hash_names : (int * string) list) =
6565
Lprim
6666
( Pintcomp Ceq,
6767
[arg; Lconst (Const_pointer (hash, Pt_variant {name}))],
68-
Location.none )
68+
Location.none, None )
6969
in
7070
Ext_list.fold_left rest init (fun acc (hash, name) ->
7171
Lambda.Lprim
@@ -75,9 +75,9 @@ let or_list (arg : lam) (hash_names : (int * string) list) =
7575
Lprim
7676
( Pintcomp Ceq,
7777
[arg; Lconst (Const_pointer (hash, Pt_variant {name}))],
78-
Location.none );
78+
Location.none , None );
7979
],
80-
Location.none ))
80+
Location.none, None ))
8181
| _ -> assert false
8282

8383
let make_test_sequence_variant_constant (fail : lam option) (arg : lam)
@@ -111,5 +111,5 @@ let call_switcher_variant_constr (loc : Location.t) (fail : lam option)
111111
( Alias,
112112
Pgenval,
113113
v,
114-
Lprim (Pfield (0, Fld_poly_var_tag), [arg], loc),
114+
Lprim (Pfield (0, Fld_poly_var_tag), [arg], loc, None),
115115
call_switcher_variant_constant loc fail (Lvar v) int_lambda_list names )

compiler/frontend/bs_ast_mapper.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,8 +330,8 @@ module E = struct
330330
fun_ ~loc ~attrs ~arity ~async lab
331331
(map_opt (sub.expr sub) def)
332332
(sub.pat sub p) (sub.expr sub e)
333-
| Pexp_apply {funct = e; args = l; partial} ->
334-
apply ~loc ~attrs ~partial (sub.expr sub e)
333+
| Pexp_apply {funct = e; args = l; partial; transformed_jsx} ->
334+
apply ~loc ~attrs ~partial ?transformed_jsx (sub.expr sub e)
335335
(List.map (map_snd (sub.expr sub)) l)
336336
| Pexp_match (e, pel) ->
337337
match_ ~loc ~attrs (sub.expr sub e) (sub.cases sub pel)

compiler/ml/lambda.ml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ type lambda =
357357
| Lfunction of lfunction
358358
| Llet of let_kind * value_kind * Ident.t * lambda * lambda
359359
| Lletrec of (Ident.t * lambda) list * lambda
360-
| Lprim of primitive * lambda list * Location.t
360+
| Lprim of primitive * lambda list * Location.t * Parsetree.jsx_element option
361361
| Lswitch of lambda * lambda_switch * Location.t
362362
| Lstringswitch of
363363
lambda * (string * lambda) list * lambda option * Location.t
@@ -462,7 +462,7 @@ let make_key e =
462462
let ex = tr_rec env ex in
463463
let y = make_key x in
464464
Llet (str, k, y, ex, tr_rec (Ident.add x (Lvar y) env) e)
465-
| Lprim (p, es, _) -> Lprim (p, tr_recs env es, Location.none)
465+
| Lprim (p, es, _, tj) -> Lprim (p, tr_recs env es, Location.none, tj)
466466
| Lswitch (e, sw, loc) -> Lswitch (tr_rec env e, tr_sw env sw, loc)
467467
| Lstringswitch (e, sw, d, _) ->
468468
Lstringswitch
@@ -520,7 +520,7 @@ let iter f = function
520520
| Lletrec (decl, body) ->
521521
f body;
522522
List.iter (fun (_id, exp) -> f exp) decl
523-
| Lprim (_p, args, _loc) -> List.iter f args
523+
| Lprim (_p, args, _loc, _tj) -> List.iter f args
524524
| Lswitch (arg, sw, _) ->
525525
f arg;
526526
List.iter (fun (_key, case) -> f case) sw.sw_consts;
@@ -618,13 +618,13 @@ let rec patch_guarded patch = function
618618

619619
let rec transl_normal_path = function
620620
| Path.Pident id ->
621-
if Ident.global id then Lprim (Pgetglobal id, [], Location.none)
621+
if Ident.global id then Lprim (Pgetglobal id, [], Location.none, None)
622622
else Lvar id
623623
| Pdot (p, s, pos) ->
624624
Lprim
625625
( Pfield (pos, Fld_module {name = s}),
626626
[transl_normal_path p],
627-
Location.none )
627+
Location.none , None)
628628
| Papply _ -> assert false
629629

630630
(* Translation of identifiers *)
@@ -658,7 +658,7 @@ let subst_lambda s lam =
658658
Lfunction {params; body = subst body; attr; loc}
659659
| Llet (str, k, id, arg, body) -> Llet (str, k, id, subst arg, subst body)
660660
| Lletrec (decl, body) -> Lletrec (List.map subst_decl decl, subst body)
661-
| Lprim (p, args, loc) -> Lprim (p, List.map subst args, loc)
661+
| Lprim (p, args, loc, tj) -> Lprim (p, List.map subst args, loc, tj)
662662
| Lswitch (arg, sw, loc) ->
663663
Lswitch
664664
( subst arg,

compiler/ml/lambda.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ type lambda =
324324
| Lfunction of lfunction
325325
| Llet of let_kind * value_kind * Ident.t * lambda * lambda
326326
| Lletrec of (Ident.t * lambda) list * lambda
327-
| Lprim of primitive * lambda list * Location.t
327+
| Lprim of primitive * lambda list * Location.t * Parsetree.jsx_element option
328328
| Lswitch of lambda * lambda_switch * Location.t
329329
(* switch on strings, clauses are sorted by string order,
330330
strings are pairwise distinct *)

0 commit comments

Comments
 (0)