@@ -19,11 +19,21 @@ let toploop_all_directive_names () =
19
19
Hashtbl. fold (fun dir _ acc -> dir::acc) Toploop. directive_table []
20
20
#endif
21
21
22
- let set_load_path path =
23
- #if OCAML_VERSION > = (5 , 0 , 0 )
24
- Load_path. init path ~auto_include: Load_path. no_auto_include
22
+ let get_load_path () =
23
+ #if OCAML_VERSION > = (5 , 2 , 0 )
24
+ let {Load_path. visible; hidden} = Load_path. get_paths () in
25
+ visible @ hidden
26
+ #else
27
+ Load_path. get_paths ()
28
+ #endif
29
+
30
+ let set_load_path visible =
31
+ #if OCAML_VERSION > = (5 , 2 , 0 )
32
+ Load_path. init ~auto_include: Load_path. no_auto_include ~visible ~hidden: []
33
+ #elif OCAML_VERSION > = (5 , 0 , 0 )
34
+ Load_path. init ~auto_include: Load_path. no_auto_include visible
25
35
#else
26
- Load_path. init path
36
+ Load_path. init visible
27
37
#endif
28
38
29
39
let toploop_use_silently fmt name =
@@ -55,3 +65,80 @@ let rec is_persistent_path = function
55
65
#if OCAML_VERSION > = (5 , 1 , 0 )
56
66
| Path. Pextra_ty (p , _ ) -> is_persistent_path p
57
67
#endif
68
+
69
+ let invalid_package_error_to_string err =
70
+ #if OCAML_VERSION > = (5 , 2 , 0 )
71
+ (* NOTE: from https://github.com/ocaml/ocaml/blob/9b059b1e7a66e9d2f04d892a4de34c418cd96f69/parsing/parse.ml#L149 *)
72
+ let invalid ppf ipt = match ipt with
73
+ | Syntaxerr. Parameterized_types ->
74
+ Format. fprintf ppf " parametrized types are not supported"
75
+ | Constrained_types ->
76
+ Format. fprintf ppf " constrained types are not supported"
77
+ | Private_types ->
78
+ Format. fprintf ppf " private types are not supported"
79
+ | Not_with_type ->
80
+ Format. fprintf ppf " only %a constraints are supported"
81
+ Misc.Style. inline_code " with type t ="
82
+ | Neither_identifier_nor_with_type ->
83
+ Format. fprintf ppf
84
+ " only module type identifier and %a constraints are supported"
85
+ Misc.Style. inline_code " with type"
86
+ in
87
+ let buf = Buffer. create 128 in
88
+ let fmt = Format. formatter_of_buffer buf in
89
+ Format. fprintf fmt " Invalid package type: %a%!" invalid err;
90
+ Buffer. contents buf
91
+ #else
92
+ err
93
+ #endif
94
+
95
+ module Exp = struct
96
+ open Ast_helper
97
+ #if OCAML_VERSION > = (5 , 2 , 0 )
98
+ open Parsetree
99
+ let fun_ ~loc p e =
100
+ let args = [{
101
+ pparam_loc= loc;
102
+ pparam_desc= Pparam_val (Nolabel , None , p);
103
+ }] in
104
+ (Exp. function_ args None (Pfunction_body e))
105
+ #else
106
+ let fun_ ~loc p e = Exp. fun_ ~loc Nolabel None p e
107
+ #endif
108
+ end
109
+
110
+ let abstract_type_kind =
111
+ #if OCAML_VERSION > = (5 , 2 , 0 )
112
+ Types. (Type_abstract Definition )
113
+ #else
114
+ Types. Type_abstract
115
+ #endif
116
+
117
+ let find_in_path_normalized =
118
+ #if OCAML_VERSION > = (5 , 2 , 0 )
119
+ Misc. find_in_path_normalized
120
+ #else
121
+ Misc. find_in_path_uncap
122
+ #endif
123
+
124
+ let visible_paths_for_cmt_infos (cmt_infos : Cmt_format.cmt_infos ) =
125
+ #if OCAML_VERSION > = (5 , 2 , 0 )
126
+ cmt_infos.cmt_loadpath.visible
127
+ #else
128
+ cmt_infos.cmt_loadpath
129
+ #endif
130
+
131
+ let add_cmi_hook f =
132
+ let default_load = ! Persistent_env.Persistent_signature. load in
133
+ #if OCAML_VERSION > = (5 , 2 , 0 )
134
+ let load ~allow_hidden ~unit_name =
135
+ let res = default_load ~unit_name ~allow_hidden in
136
+ #else
137
+ let load ~unit_name =
138
+ let res = default_load ~unit_name in
139
+ #endif
140
+ (match res with None -> () | Some x -> f x.cmi);
141
+ res
142
+ in
143
+ Persistent_env.Persistent_signature. load := load
144
+
0 commit comments