Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for OCaml 4.14 #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions dune-project
Original file line number Diff line number Diff line change
Expand Up @@ -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)))))
1 change: 1 addition & 0 deletions metaquot.opam
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down
7 changes: 7 additions & 0 deletions metaquot/dune
Original file line number Diff line number Diff line change
Expand Up @@ -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}))))
16 changes: 12 additions & 4 deletions metaquot/metaquot.ml → metaquot/metaquot.ml.in
Original file line number Diff line number Diff line change
Expand Up @@ -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) ->
Expand Down Expand Up @@ -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" ->
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 =
Expand Down