Skip to content

Commit 69b274e

Browse files
committed
ppx
1 parent a3bd387 commit 69b274e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+3483
-1968
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ env:
66
- OCAML_MIN=4.04.1
77
- OCAML_MAX=4.09.0
88
- PREDEPS="ocamlfind"
9-
- DEPS="camlp5 ocamlfind ppx_deriving ppxlib re dune cmdliner ANSITerminal"
9+
- DEPS="camlp5 ocamlfind ppx_deriving ppxlib stdcompat re dune cmdliner ANSITerminal"
1010
- MINDEPS="camlp5 ocamlfind dune re"
1111
- JOBS=2
1212

CHANGES.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
## v1.11.0 UNRELEASED
22

3+
- PPX:
4+
- new, experimental, elpi.ppx to generate glue code from an ADT declaration
5+
36
- Stdlib:
47
- triple, quadruple and quintuple data types
58
- char builtin

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ build:
3030
dune build $(DUNE_OPTS) @all ; RC=$$?; \
3131
( cp -r _build/default/src/.ppcache src/ 2>/dev/null || true ); \
3232
( echo "FLG -ppx './merlinppx.exe --as-ppx --cookie '\''elpi_trace=\"true\"'\'''" >> src/.merlin );\
33+
( echo "FLG -ppx './pp.exe --as-ppx '" >> ppx_elpi/tests/.merlin );\
3334
exit $$RC
3435

3536
install:
@@ -46,6 +47,7 @@ cleancache:
4647

4748
tests:
4849
$(MAKE) build
50+
dune runtest --diff-command 'diff -w -u'
4951
ulimit -s $(STACK); \
5052
tests/test.exe \
5153
--seed $$RANDOM \

ppx_elpi/dune

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
(name ppx_elpi)
33
(public_name elpi.ppx)
44
(synopsis "[@@elpi]")
5-
(libraries re ppxlib)
5+
(libraries re ppxlib elpi)
66
(preprocess (pps ppxlib.metaquot))
77
(ppx_runtime_libraries elpi)
88
(modules ppx_elpi)

ppx_elpi/ppx_elpi.ml

Lines changed: 721 additions & 443 deletions
Large diffs are not rendered by default.

ppx_elpi/tests/dune

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
(executable
66
(name pp)
77
(modules pp)
8+
(promote)
89
(libraries elpi.ppx ppxlib))
910

1011
(include dune.inc)

ppx_elpi/tests/dune.inc

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,29 @@
6868
(preprocess (pps elpi.ppx)))
6969

7070

71+
(rule
72+
(targets test_mutual_contextual.actual.ml)
73+
(deps (:pp pp.exe) (:input test_mutual_contextual.ml))
74+
(action (run ./%{pp} -deriving-keep-w32 both --impl %{input} -o %{targets})))
75+
76+
(rule
77+
(alias runtest)
78+
(action (diff test_mutual_contextual.expected.ml test_mutual_contextual.actual.ml)))
79+
80+
(rule
81+
(alias runtest)
82+
(action (diff test_mutual_contextual.expected.elpi test_mutual_contextual.actual.elpi)))
83+
84+
(rule
85+
(target test_mutual_contextual.actual.elpi)
86+
(action (run ./test_mutual_contextual.exe %{target})))
87+
88+
(executable
89+
(name test_mutual_contextual)
90+
(modules test_mutual_contextual)
91+
(preprocess (pps elpi.ppx)))
92+
93+
7194
(rule
7295
(targets test_opaque_type.actual.ml)
7396
(deps (:pp pp.exe) (:input test_opaque_type.ml))

ppx_elpi/tests/test_alias_type.expected.elpi

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22

33
typeabbrev simple int. % simple
44

5-
pred map.simple i:simple, o:simple.
6-
map.simple A B :- ((=) A B).
7-
85

96

107

ppx_elpi/tests/test_alias_type.expected.ml

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,30 @@
11
let elpi_stuff = ref []
22
let pp_simple _ _ = ()
3-
type simple = int[@@deriving elpi { append = elpi_stuff }]
3+
type simple = int[@@deriving elpi { declaration = elpi_stuff }]
44
include
55
struct
66
[@@@warning "-26-27-32-39-60"]
77
let elpi_constant_type_simple = "simple"
88
let elpi_constant_type_simplec =
99
Elpi.API.RawData.Constants.declare_global_symbol
1010
elpi_constant_type_simple
11+
module Ctx_for_simple =
12+
struct class type t = object inherit Elpi.API.Conversion.ctx end end
1113
let rec elpi_embed_simple :
12-
'elpi__param__poly_hyps 'elpi__param__poly_csts .
13-
(simple, 'elpi__param__poly_hyps, 'elpi__param__poly_csts)
14-
Elpi.API.ContextualConversion.embedding
15-
=
14+
'c . (simple, #Ctx_for_simple.t as 'c) Elpi.API.Conversion.embedding =
1615
fun ~depth ->
1716
fun h ->
1817
fun c -> fun s -> fun t -> Elpi.API.PPX.embed_int ~depth h c s t
1918
let rec elpi_readback_simple :
20-
'elpi__param__poly_hyps 'elpi__param__poly_csts .
21-
(simple, 'elpi__param__poly_hyps, 'elpi__param__poly_csts)
22-
Elpi.API.ContextualConversion.readback
23-
=
19+
'c . (simple, #Ctx_for_simple.t as 'c) Elpi.API.Conversion.readback =
2420
fun ~depth ->
2521
fun h ->
2622
fun c -> fun s -> fun t -> Elpi.API.PPX.readback_int ~depth h c s t
27-
let simple :
28-
'elpi__param__poly_hyps 'elpi__param__poly_csts .
29-
(simple, 'elpi__param__poly_hyps, 'elpi__param__poly_csts)
30-
Elpi.API.ContextualConversion.t
23+
let simple : 'c . (simple, #Ctx_for_simple.t as 'c) Elpi.API.Conversion.t
3124
=
32-
let kind = Elpi.API.ContextualConversion.TyName "simple" in
25+
let kind = Elpi.API.Conversion.TyName "simple" in
3326
{
34-
Elpi.API.ContextualConversion.ty = kind;
27+
Elpi.API.Conversion.ty = kind;
3528
pp_doc =
3629
(fun fmt ->
3730
fun () -> Elpi.API.PPX.Doc.kind fmt kind ~doc:"simple"; ());
@@ -45,18 +38,17 @@ include
4538
("simple" ^
4639
(" " ^
4740
(((Elpi.API.PPX.Doc.show_ty_ast ~outer:false) @@
48-
(Elpi.API.ContextualConversion.(!>)
49-
Elpi.API.BuiltInData.int).Elpi.API.ContextualConversion.ty)
41+
Elpi.API.BuiltInData.int.Elpi.API.Conversion.ty)
5042
^ (". % " ^ "simple")))))
51-
let () =
52-
elpi_stuff :=
53-
((!elpi_stuff) @
54-
([elpi_simple] @
55-
[Elpi.API.BuiltIn.LPCode
56-
(String.concat "\n"
57-
["pred map.simple i:simple, o:simple.";
58-
Printf.sprintf "map.%s %sA B :- %s." "simple" ""
59-
("(" ^ ("(=)" ^ (" " ^ ("A" ^ (" " ^ ("B" ^ ")"))))))])]))
43+
class ctx_for_simple (h : Elpi.API.Data.hyps) (s : Elpi.API.Data.state)
44+
: Ctx_for_simple.t =
45+
object (_) inherit ((Elpi.API.Conversion.ctx) h) end
46+
let (in_ctx_for_simple :
47+
Ctx_for_simple.t Elpi.API.Conversion.ctx_readback) =
48+
fun ~depth ->
49+
fun h ->
50+
fun c -> fun s -> (s, ((new ctx_for_simple) h s), (List.concat []))
51+
let () = elpi_stuff := ((!elpi_stuff) @ [elpi_simple])
6052
end[@@ocaml.doc "@inline"][@@merlin.hide ]
6153
open Elpi.API
6254
let builtin =

ppx_elpi/tests/test_alias_type.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ let elpi_stuff = ref []
22

33
let pp_simple _ _ = ()
44
type simple = int
5-
[@@deriving elpi { append = elpi_stuff }]
5+
[@@deriving elpi { declaration = elpi_stuff }]
66

77
open Elpi.API
88

@@ -15,4 +15,4 @@ let main () =
1515
exit 0
1616
;;
1717

18-
main ()
18+
main ()

0 commit comments

Comments
 (0)