Skip to content

Commit

Permalink
Fix compilation with different versions of OCaml
Browse files Browse the repository at this point in the history
  • Loading branch information
let-def committed Sep 5, 2022
1 parent 7044d9c commit 3c446b4
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 17 deletions.
21 changes: 8 additions & 13 deletions lib/lwd/dune
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,12 @@
(modules lwd lwd_seq lwd_table lwd_infix lwd_utils)
(libraries seq)
(inline_tests (backend qtest.lib))
(wrapped false))
(wrapped false)
(preprocess (per_module
; use full to path to pp.exe to work around
; https://github.com/ocaml/dune/issues/6106
((action (run lib/lwd/pp.exe %{input-file})) lwd_infix lwd_seq))))

(rule
(targets lwd_infix.ml lwd_infix.mli)
(deps lwd_infix_compat.ml lwd_infix_compat.mli
lwd_infix_letop.ml lwd_infix_letop.mli)
(action
(progn
(with-stdout-to lwd_infix.mli (run ./select_version.exe intf))
(with-stdout-to lwd_infix.ml (run ./select_version.exe impl)))))

(executable
(modules select_version)
(name select_version))
(executable
(name pp)
(modules pp))
2 changes: 2 additions & 0 deletions lib/lwd/lwd_infix_letop.ml → lib/lwd/lwd_infix.ml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
(*BEGIN LETOP*)
let (let$) : 'a Lwd.t -> ('a -> 'b) -> 'b Lwd.t = Lwd.Infix.(>|=)
let (and$) : 'a Lwd.t -> 'b Lwd.t -> ('a * 'b) Lwd.t = Lwd.pair
let (let$*) : 'a Lwd.t -> ('a -> 'b Lwd.t) -> 'b Lwd.t = Lwd.Infix.(>>=)
(*END*)

let ($=) : 'a Lwd.var -> 'a -> unit = Lwd.set
let ($<-) : 'a Lwd_table.row -> 'a -> unit = Lwd_table.set
2 changes: 2 additions & 0 deletions lib/lwd/lwd_infix_letop.mli → lib/lwd/lwd_infix.mli
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
(*BEGIN LETOP*)
val (let$) : 'a Lwd.t -> ('a -> 'b) -> 'b Lwd.t
(** Alias to {!Lwd.map'} suitable for let-op bindings *)

Expand All @@ -6,6 +7,7 @@ val (let$*) : 'a Lwd.t -> ('a -> 'b Lwd.t) -> 'b Lwd.t

val (and$) : 'a Lwd.t -> 'b Lwd.t -> ('a * 'b) Lwd.t
(** Alias to {!Lwd.pair} suitable for let-op bindings *)
(*END*)

val ($=) : 'a Lwd.var -> 'a -> unit
(** Infix alias to {!Lwd.set} *)
Expand Down
2 changes: 0 additions & 2 deletions lib/lwd/lwd_infix_compat.ml

This file was deleted.

2 changes: 0 additions & 2 deletions lib/lwd/lwd_infix_compat.mli

This file was deleted.

4 changes: 4 additions & 0 deletions lib/lwd/lwd_seq.ml
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
(*BEGIN INJECTIVITY*)
type !+'a t =
(*ELSE*)
type +'a t =
(*END*)
| Nil
| Leaf of { mutable mark: int; v: 'a; }
| Join of { mutable mark: int; l: 'a t; r: 'a t; }
Expand Down
6 changes: 6 additions & 0 deletions lib/lwd/lwd_seq.mli
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,14 @@
element.
*)

(*BEGIN INJECTIVITY*)
type !+'a t
type !+'a seq = 'a t
(*ELSE*)
type +'a t
type +'a seq = 'a t
(*END*)

(** The type of sequences *)

(** {2 Primitive constructors} *)
Expand Down
36 changes: 36 additions & 0 deletions lib/lwd/pp.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
let version =
Scanf.sscanf Sys.ocaml_version "%d.%d" (fun major minor -> (major, minor))

let ic =
if Array.length Sys.argv = 1 then (
Printf.eprintf
"Usage: %s <input-file>\n\
Expecting a filename as argument.\n"
Sys.argv.(0);
exit 1
) else if not (Sys.file_exists Sys.argv.(1)) then (
Printf.eprintf
"Usage: %s <input-file>\n\
Cannot find file %S.\n"
Sys.argv.(0)
Sys.argv.(1);
exit 1
) else
open_in_bin Sys.argv.(1)

let () =
let enable_output = ref true in
let change_output v =
print_newline ();
enable_output := v
in
try
while true do
match input_line ic with
| "(*BEGIN LETOP*)" -> change_output (version >= (4, 08))
| "(*BEGIN INJECTIVITY*)" -> change_output (version >= (4, 12))
| "(*ELSE*)" -> change_output (not !enable_output)
| "(*END*)" -> change_output true
| line -> if !enable_output then print_endline line
done
with End_of_file -> ()

0 comments on commit 3c446b4

Please sign in to comment.