Skip to content

Commit

Permalink
Merge pull request #355 from pitag-ha/5.0-support-on-0.25
Browse files Browse the repository at this point in the history
Add suport for OCaml 5.0 on ppxlib.0.25
  • Loading branch information
pitag-ha authored Jun 17, 2022
2 parents 2fde140 + e1f1928 commit fe08832
Show file tree
Hide file tree
Showing 12 changed files with 126 additions and 3 deletions.
6 changes: 6 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
unreleased
------------

- Add support for OCaml 5.0 (#355, @pitag-ha)


0.25.0 (03/03/2022)
-------------------

Expand Down
5 changes: 4 additions & 1 deletion ast/supported_version/supported_version.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
10 changes: 10 additions & 0 deletions ast/versions.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand All @@ -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);
(*$*)
]

Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions ast/versions.mli
Original file line number Diff line number Diff line change
Expand Up @@ -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 *)
Expand Down
14 changes: 14 additions & 0 deletions astlib/ast_500.ml
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions astlib/astlib.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 *)
Expand Down Expand Up @@ -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 *)
Expand Down
1 change: 1 addition & 0 deletions astlib/cinaps/astlib_cinaps_helpers.ml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ let supported_versions =
("412", "4.12");
("413", "4.13");
("414", "4.14");
("500", "5.00");
]

let foreach_version f =
Expand Down
3 changes: 3 additions & 0 deletions astlib/config/gen.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
40 changes: 40 additions & 0 deletions astlib/migrate_414_500.ml
Original file line number Diff line number Diff line change
@@ -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
40 changes: 40 additions & 0 deletions astlib/migrate_500_414.ml
Original file line number Diff line number Diff line change
@@ -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
3 changes: 2 additions & 1 deletion dune-project
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down
3 changes: 2 additions & 1 deletion ppxlib.opam
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
Expand Down

0 comments on commit fe08832

Please sign in to comment.