Skip to content
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
2 changes: 2 additions & 0 deletions dune-project
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

(using menhir 2.0)

(using cinaps 1.2)

(cram enable)

(version 3.17.3)
Expand Down
2 changes: 2 additions & 0 deletions nix/shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
mkShell {
inputsFrom = [ reason ];
nativeBuildInputs = with ocamlPackages; [
cinaps
ocp-indent
utop
merlin
# odoc
Expand Down
5 changes: 2 additions & 3 deletions src/vendored-omp/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,8 @@ all-supported-ocaml-versions:

.PHONY: cinaps
cinaps:
cinaps -styler ocp-indent -i src/migrate_parsetree_versions.ml*
cinaps -styler ocp-indent -i src/migrate_parsetree_4??_4??.ml*
cinaps -styler ocp-indent -i src/migrate_parsetree.ml
-dune build --root ../.. @src/vendored-omp/src/cinaps --auto-promote
dune build --root ../.. @src/vendored-omp/src/cinaps

.PHONY: clean
clean:
Expand Down
12 changes: 6 additions & 6 deletions src/vendored-omp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ Convert OCaml parsetrees between different major versions

This library converts between parsetrees of different OCaml versions.

Supported versions are 4.02, 4.03, 4.04, 4.05, 4.06, 4.07, 4.08 and 4.09.
Supported versions are OCaml 4.08 through 4.14 and OCaml 5.0 through 5.5.
For each version, there is a snapshot of the parsetree and conversion functions
to the next and/or previous version.

## Asts

```ocaml
module Ast_402, Ast_403, Ast_404, Ast_405, Ast_406, Ast_407, Ast_408, Ast_409 : sig
module Ast_VERSION : sig

(* These two modules didn't change between compiler versions.
Just share the ones from compiler-libs. *)
Expand Down Expand Up @@ -44,7 +44,7 @@ These embed copies of AST definitions for each supported OCaml major version.

The AST matching the version of the OCaml toolchain will contain equalities
relating the copy of types to the definitions from compiler-libs. For
instance, when installed with OCaml 4.04.x, `Ast_404.Parsetree` looks
instance, when installed with OCaml 4.14.x, `Ast_414.Parsetree` looks
like.

## Migration modules
Expand All @@ -59,7 +59,7 @@ failure case.

`Migrate_parsetree_versions` abstract versions of the compiler. Each version is
represented as a module with `OCaml_version` signature. Instances are named
`OCaml_402`, `OCaml_403`, ... `OCaml_current` is an alias to the version of the
`OCaml_408`, `OCaml_409`, ... `OCaml_current` is an alias to the version of the
current compiler.
The `Convert` functor takes two versions of OCaml and produce conversion
functions.
Expand Down Expand Up @@ -118,10 +118,10 @@ The library is distributed under LGPL 2.1 and is copyright INRIA.
## Adding a new OCaml version

We use [Cinaps](https://github.com/janestreet/cinaps) to generate boilerplate.
You can install it via opam: `opam install cinaps`.
You can install it via opam: `opam install cinaps ocp-indent`.

Add the new version in
[src/cinaps_helpers](https://github.com/ocaml-ppx/ocaml-migrate-parsetree/blob/master/src/cinaps_helpers)
[src/cinaps_helpers.ml](src/cinaps_helpers.ml)
`supported_versions`.

Copy the last `src/ast_xxx.ml` file to `src/ast_<new_version>.ml`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,6 @@ open Printf
let nl () = printf "\n"

let supported_versions = [
("402", "4.02");
("403", "4.03");
("404", "4.04");
("405", "4.05");
("406", "4.06");
("407", "4.07");
("408", "4.08");
("409", "4.09");
("410", "4.10");
Expand All @@ -24,6 +18,7 @@ let supported_versions = [
("52", "5.2");
("53", "5.3");
("54", "5.4");
("55", "5.5");
]

let qualified_types = [
Expand Down Expand Up @@ -51,6 +46,10 @@ let foreach_version f =
nl ();
List.iter supported_versions ~f:(fun (suffix, version) -> f suffix version)

let version_number suffix =
let version = int_of_string suffix in
if version < 100 then version * 10 else version

let foreach_version_pair f =
nl ();
let rec aux = function
Expand Down
31 changes: 30 additions & 1 deletion src/vendored-omp/src/dune
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
(public_name reason.ocaml-migrate-parsetree)
(wrapped true)
(libraries ppxlib.astlib)
(modules :standard \ migrate_parsetree_driver_main)
(modules :standard \ cinaps_helpers migrate_parsetree_driver_main)
(preprocess
(action
(run %{exe:../tools/pp.exe} %{read:ast-version} %{input-file})))
Expand Down Expand Up @@ -36,3 +36,32 @@
(targets ast-version compiler-functions-file)
(action
(run %{ocaml} %{dep:config/gen.ml} %{ocaml_version})))

(library
(name reason_omp_cinaps_helpers)
(wrapped false)
(modules cinaps_helpers))

(cinaps
(alias cinaps)
(files migrate_parsetree_versions.ml*)
(libraries reason_omp_cinaps_helpers)
(preprocess
(action
(progn
(echo
"let () = let current = ref 0 in Arg.parse_argv ~current [| Sys.argv.(0); \"-styler\"; \"ocp-indent\" |] (Arg.align Cinaps_runtime.args) ignore \"\"\n")
(cat %{input-file}))))
(runtime_deps %{bin:ocp-indent}))

(cinaps
(alias cinaps)
(files reason_omp.ml)
(libraries reason_omp_cinaps_helpers)
(preprocess
(action
(progn
(echo
"let () = let current = ref 0 in Arg.parse_argv ~current [| Sys.argv.(0); \"-styler\"; \"ocp-indent\" |] (Arg.align Cinaps_runtime.args) ignore \"\"\n")
(cat %{input-file}))))
(runtime_deps %{bin:ocp-indent}))
4 changes: 2 additions & 2 deletions src/vendored-omp/src/migrate_parsetree_versions.ml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
(**************************************************************************)

(* BEGIN of BLACK MAGIC *)
(*$ #use "src/cinaps_helpers" $*)
(*$ open StdLabels;; open Printf;; open Cinaps_helpers $*)

type _ witnesses = ..

Expand Down Expand Up @@ -388,7 +388,7 @@ end
printf "module OCaml_%s = struct\n" suffix;
printf " module Ast = Ast_%s\n" suffix;
printf " include Make_witness(Ast_%s)\n" suffix;
printf " let version = %s\n" suffix;
printf " let version = %d\n" (version_number suffix);
printf " let string_version = %S\n" version;
printf "end\n";
printf "let ocaml_%s : OCaml_%s.types ocaml_version = (module OCaml_%s)\n"
Expand Down
2 changes: 1 addition & 1 deletion src/vendored-omp/src/migrate_parsetree_versions.mli
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
(* *)
(**************************************************************************)

(*$ #use "src/cinaps_helpers" $*)
(*$ open StdLabels;; open Printf;; open Cinaps_helpers $*)

(** {1 Abstracting an OCaml frontend} *)

Expand Down
8 changes: 6 additions & 2 deletions src/vendored-omp/src/reason_omp.ml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
(* *)
(**************************************************************************)

(*$ #use "src/cinaps_helpers" $*)
(*$ open StdLabels;; open Printf;; open Cinaps_helpers $*)

(* Shared definitions.
Mostly errors about features missing in older versions. *)
Expand All @@ -34,8 +34,9 @@ module Ast_414 = Ast_414
module Ast_500 = Ast_500
module Ast_51 = Ast_51
module Ast_52 = Ast_52
module Ast_53 = Ast_54
module Ast_53 = Ast_53
module Ast_54 = Ast_54
module Ast_55 = Ast_55
(*$*)

(* Manual migration between versions *)
Expand Down Expand Up @@ -65,6 +66,8 @@ module Migrate_52_53 = Migrate_parsetree_52_53
module Migrate_53_52 = Migrate_parsetree_53_52
module Migrate_53_54 = Migrate_parsetree_53_54
module Migrate_54_53 = Migrate_parsetree_54_53
module Migrate_54_55 = Migrate_parsetree_54_55
module Migrate_55_54 = Migrate_parsetree_55_54
(*$*)

(* An abstraction of OCaml compiler versions *)
Expand All @@ -88,6 +91,7 @@ module OCaml_51 = Versions.OCaml_51
module OCaml_52 = Versions.OCaml_52
module OCaml_53 = Versions.OCaml_53
module OCaml_54 = Versions.OCaml_54
module OCaml_55 = Versions.OCaml_55
(*$*)
module OCaml_current = Versions.OCaml_current

Expand Down
Loading