Skip to content

Commit

Permalink
Add package zarith.top with REPL printer
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris00 committed Apr 10, 2018
1 parent 37754ab commit 9ced2ab
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
11 changes: 11 additions & 0 deletions META
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,14 @@ requires = ""
version = "1.5"
archive(byte) = "zarith.cma"
archive(native) = "zarith.cmxa"

package "top" (
version = "1.5"
description = "ZArith toplevel support"
requires = "zarith"
archive(byte) = "zarith_top.cma"
archive(native) = "zarith_top.cmxa"
plugin(byte) = "zarith_top.cma"
plugin(native) = "zarith_top.cmxs"
exists_if = "zarith_top.cma"
)
9 changes: 8 additions & 1 deletion project.mak
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,16 @@ CMIOBJ = $(MLISRC:%.mli=%.cmi)
CMXOBJ = $(MLISRC:%.mli=%.cmx)
CMIDOC = $(MLISRC:%.mli=%.cmti)

TOINSTALL := zarith.h zarith.cma libzarith.$(LIBSUFFIX) $(MLISRC) $(CMIOBJ)
TOINSTALL := zarith.h zarith.cma libzarith.$(LIBSUFFIX) $(MLISRC) $(CMIOBJ) \
zarith_top.cma

ifeq ($(HASOCAMLOPT),yes)
TOINSTALL += zarith.$(LIBSUFFIX) zarith.cmxa $(CMXOBJ)
endif

OCAMLFLAGS = -I +compiler-libs
OCAMLOPTFLAGS = -I +compiler-libs

ifeq ($(HASDYNLINK),yes)
TOINSTALL += zarith.cmxs
endif
Expand Down Expand Up @@ -77,6 +81,9 @@ zarith.cmxs: zarith.cmxa libzarith.$(LIBSUFFIX)
libzarith.$(LIBSUFFIX) dllzarith.$(DLLSUFFIX): $(SSRC:%.S=%.$(OBJSUFFIX)) $(CSRC:%.c=%.$(OBJSUFFIX))
$(OCAMLMKLIB) -failsafe -o zarith $+ $(LIBS)

zarith_top.cma: zarith_top.cmo
$(OCAMLC) -o $@ -a $<

doc: $(MLISRC)
mkdir -p html
$(OCAMLDOC) -html -d html -charset utf8 $+
Expand Down
14 changes: 14 additions & 0 deletions zarith_top.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
open Printf

let eval_string
?(print_outcome = false) ?(err_formatter = Format.err_formatter) str =
let lexbuf = Lexing.from_string str in
let phrase = !Toploop.parse_toplevel_phrase lexbuf in
Toploop.execute_phrase print_outcome err_formatter phrase

let () =
let printers = ["Z.pp_print"; "Q.pp_print"] in
let ok = List.fold_left (fun b p ->
b && eval_string(sprintf "#install_printer %s;;" p))
true printers in
if not ok then Format.eprintf "Problem installing ZArith-printers@."

0 comments on commit 9ced2ab

Please sign in to comment.