@@ -34,6 +34,9 @@ let transl_module =
3434 (fun _cc _rootpath _modl -> assert false
3535 : module_coercion -> Path. t option -> module_expr -> lambda)
3636
37+ let current_root_path = ref None
38+ let current_value_ident = ref None
39+
3740(* Compile an exception/extension definition *)
3841
3942let transl_extension_constructor env path ext =
@@ -244,6 +247,8 @@ let primitives_table =
244247 (" %loc_LINE" , Ploc Loc_LINE );
245248 (" %loc_POS" , Ploc Loc_POS );
246249 (" %loc_MODULE" , Ploc Loc_MODULE );
250+ (" %loc_MODULE_PATH" , Ploc Loc_MODULE_PATH );
251+ (" %loc_VALUE_PATH" , Ploc Loc_VALUE_PATH );
247252 (* BEGIN Triples for ref data type *)
248253 (" %makeref" , Pmakeblock Lambda. ref_tag_info);
249254 (" %refset" , Psetfield (0 , Lambda. ref_field_set_info));
@@ -448,7 +453,10 @@ let transl_primitive loc p env ty =
448453 in
449454 match prim with
450455 | Ploc kind -> (
451- let lam = lam_of_loc kind loc in
456+ let lam =
457+ lam_of_loc ?current_value_ident:! current_value_ident
458+ ?root_path:! current_root_path kind loc
459+ in
452460 match p.prim_arity with
453461 | 0 -> lam
454462 | 1 ->
@@ -741,9 +749,14 @@ and transl_exp0 (e : Typedtree.expression) : Lambda.lambda =
741749 | _ -> k
742750 in
743751 wrap (Lprim (Praise k, [targ], e.exp_loc))
744- | Ploc kind , [] -> lam_of_loc kind e.exp_loc
752+ | Ploc kind , [] ->
753+ lam_of_loc ?current_value_ident:! current_value_ident
754+ ?root_path:! current_root_path kind e.exp_loc
745755 | Ploc kind , [arg1] ->
746- let lam = lam_of_loc kind arg1.exp_loc in
756+ let lam =
757+ lam_of_loc ?current_value_ident:! current_value_ident
758+ ?root_path:! current_root_path kind arg1.exp_loc
759+ in
747760 Lprim (Pmakeblock Blk_tuple , lam :: argl, e.exp_loc)
748761 | Ploc _ , _ -> assert false
749762 | _ , _ -> (
@@ -1055,6 +1068,21 @@ and transl_function loc partial param case =
10551068 is_base_type exp_env exp_type Predef. path_unit )
10561069
10571070and transl_let rec_flag pat_expr_list body =
1071+ let old_value_ident = ! current_value_ident in
1072+
1073+ let binding_name =
1074+ pat_expr_list |> List. rev
1075+ |> List. find_map (fun {vb_pat} ->
1076+ match vb_pat.pat_desc with
1077+ | Tpat_var (id , _ ) -> Some id
1078+ | _ -> None )
1079+ in
1080+ current_value_ident := binding_name;
1081+ let res = transl_let_inner rec_flag pat_expr_list body in
1082+ current_value_ident := old_value_ident;
1083+ res
1084+
1085+ and transl_let_inner rec_flag pat_expr_list body =
10581086 match rec_flag with
10591087 | Nonrecursive ->
10601088 let rec transl = function
0 commit comments