diff --git a/CHANGES.md b/CHANGES.md index 381cf76c..4d23da4a 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,9 @@ +unreleased +------------ + +- Add support for OCaml 5.0 (#355, @pitag-ha) + + 0.25.0 (03/03/2022) ------------------- diff --git a/ast/supported_version/supported_version.ml b/ast/supported_version/supported_version.ml index f8838dde..1e63e0e6 100644 --- a/ast/supported_version/supported_version.ml +++ b/ast/supported_version/supported_version.ml @@ -15,9 +15,12 @@ let all = (4, 12); (4, 13); (4, 14); + (5, 0); ] -let to_string (a, b) = Printf.sprintf "%d.%02d" a b +let to_string (a, b) = + if a < 5 then Printf.sprintf "%d.%02d" a b else Printf.sprintf "%d.%d" a b + let to_int (a, b) = (a * 100) + b let of_string s = diff --git a/ast/versions.ml b/ast/versions.ml index e6163b11..322981e4 100644 --- a/ast/versions.ml +++ b/ast/versions.ml @@ -499,6 +499,13 @@ module OCaml_414 = struct let string_version = "4.14" end let ocaml_414 : OCaml_414.types ocaml_version = (module OCaml_414) +module OCaml_500 = struct + module Ast = Astlib.Ast_500 + include Make_witness(Astlib.Ast_500) + let version = 500 + let string_version = "5.0" +end +let ocaml_500 : OCaml_500.types ocaml_version = (module OCaml_500) (*$*) let all_versions : (module OCaml_version) list = [ @@ -517,6 +524,7 @@ let all_versions : (module OCaml_version) list = [ (module OCaml_412 : OCaml_version); (module OCaml_413 : OCaml_version); (module OCaml_414 : OCaml_version); +(module OCaml_500 : OCaml_version); (*$*) ] @@ -549,6 +557,8 @@ include Register_migration(OCaml_412)(OCaml_413) (Astlib.Migrate_412_413)(Astlib.Migrate_413_412) include Register_migration(OCaml_413)(OCaml_414) (Astlib.Migrate_413_414)(Astlib.Migrate_414_413) +include Register_migration(OCaml_414)(OCaml_500) + (Astlib.Migrate_414_500)(Astlib.Migrate_500_414) (*$*) module OCaml_current = OCaml_OCAML_VERSION diff --git a/ast/versions.mli b/ast/versions.mli index d27437f7..2418e022 100644 --- a/ast/versions.mli +++ b/ast/versions.mli @@ -128,6 +128,7 @@ module OCaml_411 : OCaml_version with module Ast = Astlib.Ast_411 module OCaml_412 : OCaml_version with module Ast = Astlib.Ast_412 module OCaml_413 : OCaml_version with module Ast = Astlib.Ast_413 module OCaml_414 : OCaml_version with module Ast = Astlib.Ast_414 +module OCaml_500 : OCaml_version with module Ast = Astlib.Ast_500 (*$*) (* An alias to the current compiler version *) diff --git a/astlib/ast_500.ml b/astlib/ast_500.ml new file mode 100644 index 00000000..36e769e4 --- /dev/null +++ b/astlib/ast_500.ml @@ -0,0 +1,14 @@ +(* The only difference between 4.14 and 5.0 from a Parsetree point of view are the magic numbers *) + +module Asttypes = struct + include Ast_414.Asttypes +end + +module Parsetree = struct + include Ast_414.Parsetree +end + +module Config = struct + let ast_impl_magic_number = "Caml1999M032" + let ast_intf_magic_number = "Caml1999N032" +end diff --git a/astlib/astlib.ml b/astlib/astlib.ml index 7e5ac259..a7791840 100644 --- a/astlib/astlib.ml +++ b/astlib/astlib.ml @@ -35,6 +35,7 @@ module Ast_411 = Ast_411 module Ast_412 = Ast_412 module Ast_413 = Ast_413 module Ast_414 = Ast_414 +module Ast_500 = Ast_500 (*$*) (* Manual migration between versions *) @@ -67,6 +68,8 @@ module Migrate_412_413 = Migrate_412_413 module Migrate_413_412 = Migrate_413_412 module Migrate_413_414 = Migrate_413_414 module Migrate_414_413 = Migrate_414_413 +module Migrate_414_500 = Migrate_414_500 +module Migrate_500_414 = Migrate_500_414 (*$*) (* Compiler modules *) diff --git a/astlib/cinaps/astlib_cinaps_helpers.ml b/astlib/cinaps/astlib_cinaps_helpers.ml index 687fae9c..15ebcfac 100644 --- a/astlib/cinaps/astlib_cinaps_helpers.ml +++ b/astlib/cinaps/astlib_cinaps_helpers.ml @@ -20,6 +20,7 @@ let supported_versions = ("412", "4.12"); ("413", "4.13"); ("414", "4.14"); + ("500", "5.00"); ] let foreach_version f = diff --git a/astlib/config/gen.ml b/astlib/config/gen.ml index 9af7982c..572d0b6c 100644 --- a/astlib/config/gen.ml +++ b/astlib/config/gen.ml @@ -23,6 +23,9 @@ let () = | 4, 12 -> "412" | 4, 13 -> "413" | 4, 14 -> "414" + | 5, 0 -> + "414" + (* Ast_500 aliases Ast_414, since the AST hasn't changed between those two *) | _ -> Printf.eprintf "Unkown OCaml version %s\n" ocaml_version_str; exit 1) diff --git a/astlib/migrate_414_500.ml b/astlib/migrate_414_500.ml new file mode 100644 index 00000000..6a81b073 --- /dev/null +++ b/astlib/migrate_414_500.ml @@ -0,0 +1,40 @@ +module From = Ast_414 +module To = Ast_500 + +let copy_structure : Ast_414.Parsetree.structure -> Ast_500.Parsetree.structure + = + fun x -> x + +let copy_signature : Ast_414.Parsetree.signature -> Ast_500.Parsetree.signature + = + fun x -> x + +let copy_toplevel_phrase : + Ast_414.Parsetree.toplevel_phrase -> Ast_500.Parsetree.toplevel_phrase = + fun x -> x + +let copy_core_type : Ast_414.Parsetree.core_type -> Ast_500.Parsetree.core_type + = + fun x -> x + +let copy_expression : + Ast_414.Parsetree.expression -> Ast_500.Parsetree.expression = + fun x -> x + +let copy_pattern : Ast_414.Parsetree.pattern -> Ast_500.Parsetree.pattern = + fun x -> x + +let copy_case : Ast_414.Parsetree.case -> Ast_500.Parsetree.case = fun x -> x + +let copy_type_declaration : + Ast_414.Parsetree.type_declaration -> Ast_500.Parsetree.type_declaration = + fun x -> x + +let copy_type_extension : + Ast_414.Parsetree.type_extension -> Ast_500.Parsetree.type_extension = + fun x -> x + +let copy_extension_constructor : + Ast_414.Parsetree.extension_constructor -> + Ast_500.Parsetree.extension_constructor = + fun x -> x diff --git a/astlib/migrate_500_414.ml b/astlib/migrate_500_414.ml new file mode 100644 index 00000000..ac0f27bd --- /dev/null +++ b/astlib/migrate_500_414.ml @@ -0,0 +1,40 @@ +module From = Ast_500 +module To = Ast_414 + +let copy_structure : Ast_500.Parsetree.structure -> Ast_414.Parsetree.structure + = + fun x -> x + +let copy_signature : Ast_500.Parsetree.signature -> Ast_414.Parsetree.signature + = + fun x -> x + +let copy_toplevel_phrase : + Ast_500.Parsetree.toplevel_phrase -> Ast_414.Parsetree.toplevel_phrase = + fun x -> x + +let copy_core_type : Ast_500.Parsetree.core_type -> Ast_414.Parsetree.core_type + = + fun x -> x + +let copy_expression : + Ast_500.Parsetree.expression -> Ast_414.Parsetree.expression = + fun x -> x + +let copy_pattern : Ast_500.Parsetree.pattern -> Ast_414.Parsetree.pattern = + fun x -> x + +let copy_case : Ast_500.Parsetree.case -> Ast_414.Parsetree.case = fun x -> x + +let copy_type_declaration : + Ast_500.Parsetree.type_declaration -> Ast_414.Parsetree.type_declaration = + fun x -> x + +let copy_type_extension : + Ast_500.Parsetree.type_extension -> Ast_414.Parsetree.type_extension = + fun x -> x + +let copy_extension_constructor : + Ast_500.Parsetree.extension_constructor -> + Ast_414.Parsetree.extension_constructor = + fun x -> x diff --git a/dune-project b/dune-project index 80816376..6fed1e2d 100644 --- a/dune-project +++ b/dune-project @@ -15,10 +15,11 @@ (package (name ppxlib) (depends - (ocaml (and (>= 4.04.1) (< 4.15))) + (ocaml (and (>= 4.04.1) (< 5.1.0))) (ocaml-compiler-libs (>= v0.11.0)) (ppx_derivers (>= 1.0)) (sexplib0 (>= v0.12)) + (sexplib0 (and :with-test (< "v0.15"))) ; Printexc.register_printer in sexplib0 changed stdlib-shims (ocamlfind :with-test) (re (and :with-test (>= 1.9.0))) diff --git a/ppxlib.opam b/ppxlib.opam index 3aa95af8..3c16deb8 100644 --- a/ppxlib.opam +++ b/ppxlib.opam @@ -21,10 +21,11 @@ doc: "https://ocaml-ppx.github.io/ppxlib/" bug-reports: "https://github.com/ocaml-ppx/ppxlib/issues" depends: [ "dune" {>= "2.7"} - "ocaml" {>= "4.04.1" & < "4.15"} + "ocaml" {>= "4.04.1" & < "5.1.0"} "ocaml-compiler-libs" {>= "v0.11.0"} "ppx_derivers" {>= "1.0"} "sexplib0" {>= "v0.12"} + "sexplib0" {with-test & < "v0.15"} "stdlib-shims" "ocamlfind" {with-test} "re" {with-test & >= "1.9.0"}