diff --git a/dune-project b/dune-project index 7c50247..ea3dcad 100644 --- a/dune-project +++ b/dune-project @@ -25,4 +25,5 @@ metaquot allows to quote OCaml code. (ocamlfind (>= 1.8.1)) (dune (>= 1.11.0)) (metapp (>= 0.4.1)) + (cppo (and :build (>= 1.1.0))) (odoc (and :with-doc (>= 1.5.1))))) diff --git a/metaquot.opam b/metaquot.opam index d4f365e..5ee2918 100644 --- a/metaquot.opam +++ b/metaquot.opam @@ -18,6 +18,7 @@ depends: [ "ocamlfind" {>= "1.8.1"} "dune" {>= "1.11.0"} "metapp" {>= "0.4.1"} + "cppo" {build & >= "1.1.0"} "odoc" {with-doc & >= "1.5.1"} ] build: [ diff --git a/metaquot/dune b/metaquot/dune index a463740..ef8572b 100644 --- a/metaquot/dune +++ b/metaquot/dune @@ -6,3 +6,10 @@ ; -warning 40: Constructor or label name used out of scope. (OCaml <=4.06.0) (flags -open Stdcompat -w +32+34-40) (libraries compiler-libs metapp stdcompat)) + +(rule + (target metaquot.ml) + (deps (:dep metaquot.ml.in)) + (action + (with-stdout-to %{target} + (run %{bin:cppo} -V OCAML:%{ocaml_version} %{dep})))) diff --git a/metaquot/metaquot.ml b/metaquot/metaquot.ml.in similarity index 98% rename from metaquot/metaquot.ml rename to metaquot/metaquot.ml.in index e1caf46..3cfa528 100644 --- a/metaquot/metaquot.ml +++ b/metaquot/metaquot.ml.in @@ -78,6 +78,14 @@ let ppxlib = Longident.Lident "Ppxlib" let asttypes = Longident.Ldot (ppxlib, "Asttypes") +module Compat = struct +#if OCAML_VERSION >= (4,14,0) + let get_desc = Types.get_desc +#else + let get_desc x = x.Types.desc +#endif +end + let find_module module_name (signature : Types.signature) : Types.signature option = signature |> List.find_map (fun (item : Types.signature_item) -> @@ -107,7 +115,7 @@ let index_variables args = List.mapi (fun i arg -> Printf.sprintf "x%d" i, arg) args let rec quote_of_type_expr (ty : Types.type_expr) : Ppxlib.expression = - match ty.desc with + match Compat.get_desc ty with | Tvar x -> Metapp.Exp.var (quote_name (Option.get x)) | Tconstr (Pident list, [arg], _) when Ident.name list = "list" -> @@ -183,8 +191,8 @@ let quote_of_record (prefix : Longident.t) value]))] in let exp = match labels |> List.find_map (fun (x, (label : Types.label_declaration)) -> - match label.ld_type with - | { desc = Tconstr (Pident ident, [], _)} + match Compat.get_desc label.ld_type with + | Tconstr (Pident ident, [], _) when Ident.name ident = "attributes" -> Some x | _ -> None) with | None -> exp @@ -296,7 +304,7 @@ let quote_of_declaration (prefix : Longident.t) (name : string) (Metapp.mkloc (Longident.Ldot (Lident "Target", "t"))) [] in let param_names = declaration.type_params |> List.map (fun (ty : Types.type_expr) -> - match ty.desc with + match Compat.get_desc ty with | Tvar (Some name) -> name | _ -> assert false) in let typ =