diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..15ed943 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "ocaml.sandbox": { + "kind": "global" + } +} \ No newline at end of file diff --git a/bin/dune b/bin/dune index cb42d58..3f429b4 100644 --- a/bin/dune +++ b/bin/dune @@ -1,4 +1,5 @@ (executable (public_name poplpaper) (name main) - (libraries poplpaper)) + (libraries ppx_poplpaper) + (preprocess (pps ppx_poplpaper))) diff --git a/dune-project b/dune-project index c994249..2c5805c 100644 --- a/dune-project +++ b/dune-project @@ -1 +1,5 @@ (lang dune 2.9) + +(name ppx_poplpaper) + +(generate_opam_files true) \ No newline at end of file diff --git a/flake.nix b/flake.nix index fa27f8e..17cacf9 100644 --- a/flake.nix +++ b/flake.nix @@ -7,7 +7,11 @@ in { devShell = pkgs.mkShell { inputsFrom = with flakePkgs; [ main ]; - packages = with pkgs; [ ocamlPackages.ocaml-lsp ]; + packages = (with pkgs; [ ]) ++ (with pkgs.ocamlPackages; [ocaml-lsp ppxlib + alcotest + yojson + ezjsonm + ]); }; }); } diff --git a/lib/dune b/lib/dune index a2fa703..40f1ec8 100644 --- a/lib/dune +++ b/lib/dune @@ -1,2 +1,6 @@ (library - (name poplpaper)) + (name ppx_poplpaper) + (public_name ppx_poplpaper) + (kind ppx_rewriter) + (libraries ppxlib) + (preprocess (pps ppxlib.metaquot))) diff --git a/lib/ppx_poplpaper.ml b/lib/ppx_poplpaper.ml new file mode 100644 index 0000000..9867680 --- /dev/null +++ b/lib/ppx_poplpaper.ml @@ -0,0 +1,19 @@ +(* 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/poplpaper.opam b/lib/ppx_poplpaper.mli similarity index 100% rename from poplpaper.opam rename to lib/ppx_poplpaper.mli diff --git a/ppx_poplpaper.opam b/ppx_poplpaper.opam new file mode 100644 index 0000000..09ef829 --- /dev/null +++ b/ppx_poplpaper.opam @@ -0,0 +1,22 @@ +# This file is generated by dune, edit dune-project instead +opam-version: "2.0" +depends: [ + "dune" {>= "2.9"} + "odoc" {with-doc} +] +build: [ + ["dune" "subst"] {dev} + [ + "dune" + "build" + "-p" + name + "-j" + jobs + "--promote-install-files=false" + "@install" + "@runtest" {with-test} + "@doc" {with-doc} + ] + ["dune" "install" "-p" name "--create-install-files" name] +] diff --git a/test/bin/dune b/test/bin/dune new file mode 100644 index 0000000..142882a --- /dev/null +++ b/test/bin/dune @@ -0,0 +1,4 @@ +(executable + (name pp) + (modules pp) + (libraries ppx_poplpaper ppxlib)) \ No newline at end of file diff --git a/test/bin/pp.ml b/test/bin/pp.ml new file mode 100644 index 0000000..4efb428 --- /dev/null +++ b/test/bin/pp.ml @@ -0,0 +1 @@ +Ppxlib.Driver.standalone () \ No newline at end of file diff --git a/test/dune b/test/dune index 6597498..8ba5a54 100644 --- a/test/dune +++ b/test/dune @@ -1,2 +1,13 @@ +(rule + (targets test.actual.ml) + (deps test.ml) + (action (run ./bin/pp.exe --impl %{deps} -o %{targets}))) + +(rule + (alias runtest) + (action (diff test.expected.ml test.actual.ml))) + (test - (name poplpaper)) + (name test) + (modules test) + (preprocess (pps ppx_poplpaper))) \ No newline at end of file diff --git a/test/poplpaper.ml b/test/test.expected.ml similarity index 100% rename from test/poplpaper.ml rename to test/test.expected.ml diff --git a/test/test.ml b/test/test.ml new file mode 100644 index 0000000..e9f0a6e --- /dev/null +++ b/test/test.ml @@ -0,0 +1,2 @@ +let%monomorphic prop0 (f : 'a -> 'b) (xs : 'a List.t) : bool = + List.length (List.map f xs) = 0