Skip to content

Commit 6666c31

Browse files
committed
Elpi Accumulate Plugin
1 parent ef06ac5 commit 6666c31

16 files changed

+135
-3
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,8 @@ and `ocaml-lsp-server` (version 1.15).
148148
- [open terms](examples/example_open_terms.v) implements
149149
a tactic like `replace` that receives terms containing free variables, i.e.
150150
variables bound in the goal but not in the proof context.
151+
- [builtins](examples/example_plugin/) adds builtin predicates
152+
(hence implemented in OCaml) to Elpi via a Rocq plugin
151153

152154
### Applications written in Coq-Elpi
153155

examples/example_plugin/doc/dune

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
(executable
2+
(name gen_doc)
3+
(libraries elpi_example_plugin))
4+
5+
(rule
6+
(targets
7+
elpi_example_plugin.elpi)
8+
(deps gen_doc.exe)
9+
(mode promote)
10+
(action (run ./gen_doc.exe)))
11+
12+
(install
13+
(files
14+
elpi_example_plugin.elpi)
15+
(section doc)
16+
(package rocq-elpi))
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
3+
% doc
4+
kind stuff type.
5+
external symbol stuff : int -> stuff = "1".
6+
7+
% [q xxx] bla
8+
external func q stuff.
9+
10+
11+
12+
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
let _ = Elpi.API.BuiltIn.document_file ~header:"% Generated"
3+
Elpi_example_plugin.Rocq_elpi_example_plugin.builtins

examples/example_plugin/src/dune

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
(library
2+
(name elpi_example_plugin)
3+
(public_name rocq-elpi.elpi_example_plugin)
4+
(flags :standard -w -27)
5+
(preprocess (pps ppx_optcomp -- -cookie "ppx_optcomp.env=env ~coq:(Defined \"%{coq:version.major}.%{coq:version.minor}\")"))
6+
(libraries rocq-runtime.plugins.ltac rocq-runtime.vernac rocq-elpi.elpi elpi))
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Rocq_elpi_example_plugin
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
open Elpi.API
2+
let c = AlgebraicData.(declare {
3+
ty = Conversion.TyName "stuff";
4+
doc = "doc";
5+
pp = (fun fmt (x : int) -> ());
6+
constructors = [
7+
K("stuff","",A(BuiltInData.int,N),B (fun x -> x),M (fun ~ok ~ko:_ x -> ok x));
8+
];
9+
}
10+
) |> ContextualConversion.(!<)
11+
12+
let builtins =
13+
let open BuiltIn in
14+
let open BuiltInPredicate in
15+
let cx = MLData c in
16+
let q = MLCode(Pred("q",In(c,"xxx",Easy "bla"),(fun i ~depth -> Printf.eprintf "ok %d\n%!" i)),DocAbove) in
17+
declare ~file_name:"elpi_example_plugin.elpi" [ cx; q ]
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
(coq.theory
2+
(name example_plugin)
3+
(theories elpi)
4+
(plugins rocq-elpi.elpi_example_plugin))
5+
6+
(include_subdirs qualified)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
Declare ML Module "rocq-elpi.elpi_example_plugin".
2+
3+
From elpi Require Import elpi.
4+
5+
Elpi Command test.
6+
7+
Fail Elpi Query lp:{{
8+
q (stuff 46)
9+
}}.
10+
11+
Elpi Accumulate Plugin "elpi_example_plugin.elpi".
12+
13+
Elpi Query lp:{{
14+
q (stuff 46)
15+
}}.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
From elpi Require Import elpi.
3+
From example_plugin Require Import example_plugin.
4+
5+
Elpi Command test2.
6+
Elpi Accumulate Plugin "elpi_example_plugin.elpi".
7+
Elpi Query lp:{{
8+
q (stuff 46)
9+
}}.

0 commit comments

Comments
 (0)