Skip to content

Commit 1311b75

Browse files
committed
wip
1 parent f36e255 commit 1311b75

File tree

9 files changed

+49
-15
lines changed

9 files changed

+49
-15
lines changed

src/common/error.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,6 @@ let handle_exceptions : (unit -> unit) -> unit = fun f ->
7373
try f () with
7474
| Fatal(None, msg) -> exit_with "%s" msg
7575
| Fatal(Some(p), msg) -> exit_with "[%a] %s" Pos.pp p msg
76+
(*
7677
| e -> exit_with "Uncaught [%s]." (Printexc.to_string e)
78+
*)

src/core/elpi_lambdapi.ml

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ module Elpi_AUX = struct
2222
| Some x ->
2323
let { Common.Pos.fname; start_line; start_col; _ } = x in
2424
{
25-
Ast.Loc.source_name = (match fname with None -> "(.)" | Some x -> x);
25+
Ast.Loc.source_name =
26+
(match fname with None -> "(.)" | Some x -> x);
2627
source_start = 0;
2728
source_stop = 0;
2829
line = start_line;
@@ -116,7 +117,16 @@ let embed_term : Term.term Conversion.embedding = fun ~depth st t ->
116117
State.update metamap st (MM.add flex meta), flex in
117118
let st, args = Elpi_AUX.array_map_fold (aux ~depth ctx) st args in
118119
st, mkUnifVar flex ~args:(Array.to_list args) st
119-
| Plac _ -> Common.Error.fatal_no_pos "embed_term: Plac not implemented"
120+
| Plac _ ->
121+
let args = List.map (fun (_,x,_) -> mkBound x) ctx in
122+
let st, flex = FlexibleData.Elpi.make st in
123+
let st, meta = State.update_return pb st (fun pb ->
124+
let m1 = LibMeta.fresh pb mk_Type 0 in
125+
let m2 = LibMeta.fresh pb (mk_Meta (m1,[||]))
126+
(List.length args) in (* empty context is surely wrong *)
127+
pb, m2) in
128+
let st = State.update metamap st (MM.add flex meta) in
129+
st, mkUnifVar flex ~args st
120130
| Patt _ -> Common.Error.fatal_no_pos "embed_term: Patt not implemented"
121131
| TEnv _ -> Common.Error.fatal_no_pos "embed_term: TEnv not implemented"
122132
| Wild -> Common.Error.fatal_no_pos "embed_term: Wild not implemented"
@@ -167,7 +177,8 @@ fun ~depth st t ->
167177
with Not_found ->
168178
let st, m2 = State.update_return pb st (fun pb ->
169179
let m1 = LibMeta.fresh pb mk_Type 0 in
170-
let m2 = LibMeta.fresh pb (mk_Meta (m1,[||])) (List.length args) in (* empty context is surely wrong *)
180+
let m2 = LibMeta.fresh pb (mk_Meta (m1,[||]))
181+
(List.length args) in (* empty context is surely wrong *)
171182
pb, m2) in
172183
State.update metamap st (MM.add flex m2), m2
173184
in

src/handle/command.ml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,8 @@ let get_proof_data : compiler -> sig_state -> p_command -> cmd_output =
195195
Console.out 3 (Color.cya "%a") Pos.pp pos;
196196
Console.out 4 "%a" Pretty.command cmd;
197197
match elt with
198+
| P_elpi(file,pred,arg) ->
199+
(ss, None, (Elpi_handle.run ss file pred arg; None))
198200
| P_query(q) -> (ss, None, Query.handle ss None q)
199201
| P_require(b,ps) ->
200202
(List.fold_left (handle_require compile b) ss ps, None, None)
@@ -547,8 +549,10 @@ let get_proof_data : compiler -> sig_state -> p_command -> cmd_output =
547549
| Fatal(Some(Some(_)),_) as e -> raise e
548550
| Fatal(None ,m) -> fatal pos "Error on command.@.%s" m
549551
| Fatal(Some(None) ,m) -> fatal pos "Error on command.@.%s" m
552+
(*
550553
| e ->
551554
fatal pos "Uncaught exception: %s." (Printexc.to_string e)
555+
*)
552556

553557
(** [handle compile_mod ss cmd] retrieves proof data from [cmd] (with
554558
{!val:get_proof_data}) and handles proofs using functions from

src/handle/elpi_handle.ml

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,10 @@ let document () =
4646
let elpi = ref None
4747

4848
let init () =
49-
let e = Setup.init ~builtins:[lambdapi_builtins] ~legacy_parser:false () in
49+
let e = Setup.init
50+
~builtins:[lambdapi_builtins]
51+
~legacy_parser:false
52+
~file_resolver:(Parse.std_resolver ~paths:[] ()) () in
5053
elpi := Some e;
5154
document ()
5255

@@ -61,21 +64,27 @@ fun ss file predicate arg ->
6164

6265
let ast = Parse.program ~elpi ~files:[file] in
6366
let prog =
64-
Elpi.API.Compile.program
65-
~flags:Elpi.API.Compile.default_flags ~elpi [ast] in
67+
let flags = Elpi.API.Compile.default_flags in
68+
ast |>
69+
Elpi.API.Compile.unit ~flags ~elpi |>
70+
(fun u -> Elpi.API.Compile.assemble ~elpi ~flags [u]) in
71+
6672
let query =
6773
let open Query in
68-
compile prog loc (Query { predicate; arguments = D(term,arg,N) }) in
74+
compile prog loc
75+
(Query { predicate; arguments = (D(term,arg,Q(term,"it",N))) }) in
6976

7077
if not (Elpi.API.Compile.static_check
7178
~checker:(Elpi.Builtin.default_checker ()) query) then
7279
Common.Error.fatal pos "elpi: type error in %s" file;
7380

7481
Common.Console.out 1 "\nelpi: before: %a\n" Print.term arg;
7582
match Execute.once (Elpi.API.Compile.optimize query) with
76-
| Execute.Success { Data.state; pp_ctx; constraints; _ } ->
83+
| Execute.Success {
84+
Data.state; pp_ctx; constraints; output = (arg1,()); _
85+
} ->
7786
let _ = readback_assignments state in
78-
Common.Console.out 1 "\nelpi: after: %a\n" Print.term arg;
87+
Common.Console.out 1 "\nelpi: after: %a\n" Print.term arg1;
7988
Common.Console.out 1 "elpi: constraints:@ @[<v>%a@]\n"
8089
Pp.(constraints pp_ctx) constraints
8190
| Failure -> Common.Error.fatal_no_pos "elpi: failure"

src/parsing/lpLexer.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ type token =
4545
| COMPUTE
4646
| CONSTANT
4747
| DEBUG
48+
| ELPI
4849
| END
4950
| FAIL
5051
| FLAG
@@ -208,6 +209,7 @@ let rec token lb =
208209
| "compute" -> COMPUTE
209210
| "constant" -> CONSTANT
210211
| "debug" -> DEBUG
212+
| "elpi" -> ELPI
211213
| "end" -> END
212214
| "fail" -> FAIL
213215
| "flag" -> FLAG

src/parsing/lpParser.mly

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
%token COMPUTE
3939
%token CONSTANT
4040
%token DEBUG
41+
%token ELPI
4142
%token END
4243
%token FAIL
4344
%token FLAG
@@ -162,6 +163,8 @@ command:
162163
| NOTATION i=qid_or_nat n=notation SEMICOLON
163164
{ make_pos $loc (P_notation(i,n)) }
164165
| q=query SEMICOLON { make_pos $sloc (P_query(q)) }
166+
| ELPI f=STRINGLIT p=STRINGLIT a=term SEMICOLON
167+
{ make_pos $sloc (P_elpi(f,p,a)) }
165168
| EOF { raise End_of_file }
166169

167170
query:

src/parsing/syntax.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ type p_command_aux =
266266
| P_unif_rule of p_rule
267267
| P_coercion of p_rule
268268
| P_query of p_query
269+
| P_elpi of string * string * p_term
269270

270271
(** Parser-level representation of a single (located) command. *)
271272
type p_command = p_command_aux loc

tests/OK/elpitest.elpi

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
main T :-
1+
main T T1 :-
22
print "before type inference" T,
33
of T _,
4-
print "\nafter type inference" T.
4+
print "\nafter type inference" T,
5+
T1 = T.
56

67

78
pred of i:term, o:term.

tests/OK/elpitest.lp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
require open tests.OK.logic
2-
require open tests.OK.bool
3-
require open tests.OK.nat
1+
require open tests.OK.logic;
2+
require open tests.OK.bool;
3+
4+
asserttrue : B;
45

56
elpi "tests/OK/elpitest.elpi" "main"
6-
(Πx y, P (eq ?T[x;y] x y) → P (eq ?T[x;y] y x))
7+
(Π x y , P (x = y) → P (y = x));

0 commit comments

Comments
 (0)