-
Notifications
You must be signed in to change notification settings - Fork 6
/
extension.ml
128 lines (107 loc) · 3 KB
/
extension.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
(* Copyright 2004 INRIA *)
Version.add "$Id$";;
open Mlproof;;
open Printf;;
type translator =
(Expr.expr -> Expr.expr) ->
Mlproof.proof -> (Llproof.prooftree * Expr.expr list) array ->
Llproof.prooftree * Expr.expr list
;;
type t = {
name : string;
newnodes :
Expr.expr -> int -> (Expr.expr * Expr.goalness) list -> Node.node_item list;
make_inst : Expr.expr -> Expr.expr -> Expr.goalness -> Node.node list;
add_formula : Expr.expr -> unit;
remove_formula : Expr.expr -> unit;
iter_open : proof -> bool;
preprocess : Phrase.phrase list -> Phrase.phrase list;
add_phrase : Phrase.phrase -> unit;
postprocess : Llproof.proof -> Llproof.proof;
to_llproof : translator;
declare_context_coq : out_channel -> unit;
p_rule_coq : out_channel -> Llproof.rule -> unit;
predef : unit -> string list;
predecl : unit -> (string * Expr.expr) list;
};;
let theories = ref ([] : t list);;
let active = ref ([] : t list);;
let register t = theories := t :: !theories;;
let activate name =
try
let t = List.find (fun t -> t.name = name) !theories in
active := t :: !active;
with Not_found ->
Error.err (sprintf "no extension named %s" name);
Error.err "The following extensions are available";
List.iter (fun e -> Error.err e.name) !theories;
raise Not_found;
;;
let is_active name = List.exists (fun x -> x.name = name) !active;;
let rec find_extension name l =
match l with
| [] -> assert false
| h::_ when h.name = name -> h
| _::t -> find_extension name t
;;
let get_prefix name =
let rec spin n =
if n >= String.length name then name
else
match name.[n] with
| 'a' .. 'z' | 'A' .. 'Z' -> spin (n+1)
| _ -> String.sub name 0 n
in
spin 0
;;
let newnodes e g fms =
List.map (fun ext -> ext.newnodes e g fms) (List.rev !active)
;;
let make_inst sym m term g =
let ext = get_prefix sym in
if is_active ext
then (find_extension ext !active).make_inst m term g
else []
;;
let add_formula e =
List.iter (fun t -> t.add_formula e) !active
;;
let remove_formula e =
List.iter (fun t -> t.remove_formula e) !active
;;
let iter_open p =
List.exists (fun x -> x) (List.map (fun t -> t.iter_open p) !active)
;;
let preprocess l =
List.fold_left (fun hyps ext -> ext.preprocess hyps) l (List.rev !active)
;;
let add_phrase p =
List.iter (fun ext -> ext.add_phrase p) (List.rev !active)
;;
let postprocess p =
List.fold_left (fun prf ext -> ext.postprocess prf) p !active
;;
let to_llproof tr_expr node subs =
match node.mlrule with
| Ext (th, _, _) ->
let t = find_extension th !active in
t.to_llproof tr_expr node subs
| _ -> assert false
;;
let declare_context_coq oc =
List.iter (fun ext -> ext.declare_context_coq oc) !active
;;
let p_rule_coq ext oc r =
(find_extension ext !active).p_rule_coq oc r
;;
let predef () =
List.flatten (["="] :: List.map (fun ext -> ext.predef ()) !active)
;;
let predecl () =
List.iter
(fun ext ->
List.iter
Typer.declare_constant
(ext.predecl ()))
!active
;;