Skip to content

Commit df4e3cc

Browse files
Fix compilation with older versions of OCaml
1 parent 5d1167e commit df4e3cc

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

lib/top/compat_top.ml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,3 +167,15 @@ let ctype_get_desc ty =
167167
#else
168168
(Ctype.repr ty).Types.desc
169169
#endif
170+
171+
exception Exit_with_status of int
172+
173+
let execute_phrase print_outcome ppf phr =
174+
#if OCAML_VERSION >= (4, 12, 0)
175+
match Toploop.execute_phrase print_outcome ppf phr with
176+
| v -> v
177+
| exception Compenv.Exit_with_status status ->
178+
raise (Exit_with_status status)
179+
#else
180+
Toploop.execute_phrase print_outcome ppf phr
181+
#endif

lib/top/compat_top.mli

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,8 @@ val ctype_is_equal :
5959

6060
val ctype_expand_head_and_get_desc : Env.t -> Types.type_expr -> Types.type_desc
6161
val ctype_get_desc : Types.type_expr -> Types.type_desc
62+
63+
exception Exit_with_status of int
64+
65+
val execute_phrase :
66+
bool -> Format.formatter -> Parsetree.toplevel_phrase -> bool

lib/top/mdx_top.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ module Rewrite = struct
305305
let preload verbose ppf =
306306
let require pkg =
307307
let p = top_directive_require pkg in
308-
let _ = Toploop.execute_phrase verbose ppf p in
308+
let _ = execute_phrase verbose ppf p in
309309
()
310310
in
311311
match active_rewriters () with
@@ -356,8 +356,8 @@ let toplevel_exec_phrase t ppf p =
356356
if !Clflags.dump_parsetree then Printast.top_phrase ppf phrase;
357357
if !Clflags.dump_source then Pprintast.top_phrase ppf phrase;
358358
Env.reset_cache_toplevel ();
359-
try Toploop.execute_phrase t.verbose ppf phrase
360-
with Compenv.Exit_with_status code ->
359+
try execute_phrase t.verbose ppf phrase
360+
with Exit_with_status code ->
361361
Format.fprintf ppf "[%d]@." code;
362362
false)
363363

0 commit comments

Comments
 (0)