diff --git a/flake.nix b/flake.nix index 17cacf9..4538b63 100644 --- a/flake.nix +++ b/flake.nix @@ -7,10 +7,15 @@ in { devShell = pkgs.mkShell { inputsFrom = with flakePkgs; [ main ]; - packages = (with pkgs; [ ]) ++ (with pkgs.ocamlPackages; [ocaml-lsp ppxlib - alcotest - yojson - ezjsonm + packages = (with pkgs; [ +inotify-tools + ]) ++ (with pkgs.ocamlPackages; [ + ocaml-lsp + ppxlib + ppx_deriving + alcotest + yojson + ezjsonm ]); }; }); diff --git a/lib/dune b/lib/dune index 40f1ec8..0c23ff0 100644 --- a/lib/dune +++ b/lib/dune @@ -1,6 +1,5 @@ (library - (name ppx_poplpaper) - (public_name ppx_poplpaper) - (kind ppx_rewriter) + (name ppx_poplpaper_lib) + (public_name ppx_poplpaper._lib) (libraries ppxlib) (preprocess (pps ppxlib.metaquot))) diff --git a/lib/ppx_poplpaper.ml b/lib/ppx_poplpaper.ml deleted file mode 100644 index 9867680..0000000 --- a/lib/ppx_poplpaper.ml +++ /dev/null @@ -1,19 +0,0 @@ -(* https://tarides.com/blog/2019-05-09-an-introduction-to-ocaml-ppx-ecosystem/ *) - -open Ppxlib - -let expand ~ctxt:_ (expr: expression) = - expr - -let ext = Extension.V3.declare - "monomorphic" - Extension.Context.expression - Ast_pattern.(single_expr_payload __) - expand - -let rule = Context_free.Rule.extension ext - -let () = - Driver.register_transformation - ~rules:[rule] - "monomorphic" diff --git a/rewriter/dune b/rewriter/dune new file mode 100644 index 0000000..8553806 --- /dev/null +++ b/rewriter/dune @@ -0,0 +1,6 @@ +(library + (name ppx_poplpaper) + (public_name ppx_poplpaper) + (kind ppx_deriver) + (libraries ppxlib ppx_deriving.api ppx_poplpaper_lib) + (preprocess (pps ppxlib.metaquot))) \ No newline at end of file diff --git a/rewriter/ppx_poplpaper.ml b/rewriter/ppx_poplpaper.ml new file mode 100644 index 0000000..8b192f5 --- /dev/null +++ b/rewriter/ppx_poplpaper.ml @@ -0,0 +1,20 @@ +(* https://tarides.com/blog/2019-05-09-an-introduction-to-ocaml-ppx-ecosystem/ *) +(* https://ocaml-ppx.github.io/ppxlib/ppxlib/writing-ppxs.html#extenders *) + +open Ppxlib + +let context = Extension.Context.expression + +let extender_name = "monomorphic" + +let extracter () = Ast_pattern.(single_expr_payload __) + +let expander ~ctxt (_: expression) = + let loc = Expansion_context.Extension.extension_point_loc ctxt in + [%expr 5] + +let my_extender = Extension.V3.declare extender_name context (extracter()) expander + +let extender_rule = Context_free.Rule.extension my_extender + +let _ = Driver.register_transformation ~rules:[extender_rule] "polycheck" \ No newline at end of file diff --git a/lib/ppx_poplpaper.mli b/rewriter/ppx_poplpaper.mli similarity index 100% rename from lib/ppx_poplpaper.mli rename to rewriter/ppx_poplpaper.mli diff --git a/test/bin/dune b/test/rewriter/bin/dune similarity index 100% rename from test/bin/dune rename to test/rewriter/bin/dune diff --git a/test/bin/pp.ml b/test/rewriter/bin/pp.ml similarity index 100% rename from test/bin/pp.ml rename to test/rewriter/bin/pp.ml diff --git a/test/dune b/test/rewriter/dune similarity index 100% rename from test/dune rename to test/rewriter/dune diff --git a/test/test.expected.ml b/test/rewriter/test.expected.ml similarity index 100% rename from test/test.expected.ml rename to test/rewriter/test.expected.ml diff --git a/test/rewriter/test.ml b/test/rewriter/test.ml new file mode 100644 index 0000000..b818729 --- /dev/null +++ b/test/rewriter/test.ml @@ -0,0 +1,4 @@ +let prop0 (f : 'a -> 'b) (xs : 'a List.t) : bool = + List.length (List.map f xs) = 0 + +let mono_prop0 = [%monomorphic prop0] \ No newline at end of file diff --git a/test/test.ml b/test/test.ml deleted file mode 100644 index e9f0a6e..0000000 --- a/test/test.ml +++ /dev/null @@ -1,2 +0,0 @@ -let%monomorphic prop0 (f : 'a -> 'b) (xs : 'a List.t) : bool = - List.length (List.map f xs) = 0