Skip to content

Commit 6589731

Browse files
committed
Fix incompatibility with OCaml 5.4
The type of long idents changed in OCaml 5.4. Instead of building longidents by hand, use the same trick as Zarith does: evaluate `#install_printer` directives built as strings. Note: the `Longident.unflatten` API would be great, but we cannot use it since the `Longident` module is not visible in the REPL. Fixes: #45
1 parent 7132b9c commit 6589731

1 file changed

Lines changed: 18 additions & 21 deletions

File tree

toplevel/num_top.ml

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
1-
(* Taken from findlib. Findlib is copyright 1999 by Gerd Stolpmann and
2-
distributed under the terms given in file LICENSE-findlib in this
3-
directory. *)
4-
5-
(*
6-
Printers for types defined in the "num" library. Meant to be used as printers
7-
in the ocaml toplevel. See num_top.mli.
8-
9-
Copyright (C) 2003 Stefano Zacchiroli <zack@debian.org>
10-
11-
Released under the same terms as findlib.
12-
13-
Simplified implementation for OCaml 4 and up, Xavier.Leroy@inria.fr
14-
1+
(* Taken from the Zarith library.
2+
It is distributed under LGPL 2 licensing, with static linking exception.
3+
See the LICENSE file included in the distribution.
4+
Contributed by Christophe Troestler.
5+
Adapted to Num by Xavier Leroy.
156
*)
167

17-
open Longident
8+
open Printf
9+
10+
let eval_string
11+
?(print_outcome = false) ?(err_formatter = Format.err_formatter) str =
12+
let lexbuf = Lexing.from_string str in
13+
let phrase = !Toploop.parse_toplevel_phrase lexbuf in
14+
Toploop.execute_phrase print_outcome err_formatter phrase
1815

1916
let printers = [
2017
"nat_printer";
@@ -23,9 +20,9 @@ let printers = [
2320
"num_printer";
2421
]
2522

26-
let install_num_printer s =
27-
Topdirs.dir_install_printer Format.err_formatter
28-
(Ldot(Lident "Num_top_printers", s))
29-
30-
let _ =
31-
List.iter install_num_printer printers
23+
let () =
24+
let ok =
25+
List.for_all
26+
(fun p -> eval_string(sprintf "#install_printer Num_top_printers.%s;;" p))
27+
printers in
28+
if not ok then Format.eprintf "Problem installing Num printers@."

0 commit comments

Comments
 (0)