Skip to content

Commit

Permalink
Merge pull request #44 from trepetti/ocaml-4.10.0
Browse files Browse the repository at this point in the history
Enable OCaml 4.10.0. (Fixes #40.)
  • Loading branch information
ihodes authored Oct 26, 2020
2 parents aeb61ee + b15cedd commit 798f3ac
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ env:
- OCAML_VERSION=4.04 PACKAGE="ppx_deriving_cmdliner" TESTS=true
- OCAML_VERSION=4.05 PACKAGE="ppx_deriving_cmdliner" TESTS=true
- OCAML_VERSION=4.06 PACKAGE="ppx_deriving_cmdliner" TESTS=true
- OCAML_VERSION=4.07 PACKAGE="ppx_deriving_cmdliner" TESTS=true
- OCAML_VERSION=4.08 PACKAGE="ppx_deriving_cmdliner" TESTS=true
- OCAML_VERSION=4.09 PACKAGE="ppx_deriving_cmdliner" TESTS=true
- OCAML_VERSION=4.10 PACKAGE="ppx_deriving_cmdliner" TESTS=true
- OCAML_VERSION=4.11 PACKAGE="ppx_deriving_cmdliner" TESTS=true
os:
- linux
- osx
Expand Down
3 changes: 3 additions & 0 deletions dune-workspace.dev
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@
(context (opam (switch 4.06.0)))
(context (opam (switch 4.07.0)))
(context (opam (switch 4.08.0)))
(context (opam (switch 4.09.0)))
(context (opam (switch 4.10.0)))
(context (opam (switch 4.11.0)))
20 changes: 16 additions & 4 deletions src/ppx_deriving_cmdliner.cppo.ml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@
#define Type_Nonrecursive Nonrecursive
#endif

#if OCAML_VERSION < (4, 10, 0)
#define Mknoloc_option(x) x
#else
#define Mknoloc_option(x) (Some x)
#endif

#if OCAML_VERSION < (4, 11, 0)
#define Pconst_string_argument(s, l) (s, None)
#else
#define Pconst_string_argument(s, l) (s, l, None)
#endif

open Longident
open Location
open Asttypes
Expand Down Expand Up @@ -286,7 +298,7 @@ let ser_str_of_type ~options ~path ({ ptype_loc = loc } as type_decl) =
let ser = ser_expr_of_typ manifest [] "" in
let lid = Ppx_deriving.mangle_lid (`PrefixSuffix ("M", "cmdliner_term")) lid in
let orig_mod = Mod.ident (mknoloc lid) in
([Str.module_ (Mb.mk (mknoloc mod_name) orig_mod)],
([Str.module_ (Mb.mk (mknoloc Mknoloc_option(mod_name)) orig_mod)],
[Vb.mk (pvar to_cmdliner_name)
(polymorphize [%expr ([%e ser] : unit -> [%t typ] Cmdliner.Term.t)])])
| Some _ ->
Expand All @@ -301,7 +313,7 @@ let ser_str_of_type ~options ~path ({ ptype_loc = loc } as type_decl) =
let ty = Typ.poly poly_vars (polymorphize_ser [%type: unit -> [%t typ] Cmdliner.Term.t]) in
let default_fun =
let type_path = String.concat "." (path @ [type_decl.ptype_name.txt]) in
let e_type_path = Exp.constant (Pconst_string (type_path, None)) in
let e_type_path = Exp.constant (Pconst_string Pconst_string_argument(type_path, loc)) in
[%expr fun _ ->
invalid_arg ("ppx_deriving_cmdliner: Maybe a [@@deriving cmdliner] is missing when extending the type "^
[%e e_type_path])]
Expand All @@ -318,7 +330,7 @@ let ser_str_of_type ~options ~path ({ ptype_loc = loc } as type_decl) =
let flid = lid (Printf.sprintf "%s.f" mod_name) in
let field = Exp.field (Exp.ident flid) (flid) in
let mod_ =
Str.module_ (Mb.mk (mknoloc mod_name)
Str.module_ (Mb.mk (mknoloc Mknoloc_option(mod_name))
(Mod.structure [
Str.type_ Type_Nonrecursive [typ];
Str.value Nonrecursive [record];
Expand Down Expand Up @@ -448,7 +460,7 @@ let ser_sig_of_type ~options ~path type_decl =
in
let record = Val.mk (mknoloc "f") (Typ.constr (lid "t_cmdliner_term") []) in
let mod_ =
Sig.module_ (Md.mk (mknoloc mod_name)
Sig.module_ (Md.mk (mknoloc Mknoloc_option(mod_name))
(Mty.signature [
Sig.type_ Type_Nonrecursive [typ];
Sig.value record;
Expand Down

0 comments on commit 798f3ac

Please sign in to comment.