2 ||M|| This file is part of HELM, an Hypertextual, Electronic
3 ||A|| Library of Mathematics, developed at the Computer Science
4 ||T|| Department, University of Bologna, Italy.
6 ||T|| HELM is free software; you can redistribute it and/or
7 ||A|| modify it under the terms of the GNU General Public License
8 \ / version 2 or (at your option) any later version.
9 \ / This software is distributed as is, NO WARRANTY.
10 V_______________________________________________________________ *)
12 (* kernel version: complete, relative, global *)
13 (* note : fragment of complete lambda-delta serving as abstract layer *)
21 type bind = Abst of term list (* domains *)
22 | Abbr of term list (* bodies *)
23 | Void of int (* number of exclusions *)
25 and term = TSort of attrs * int (* attrs, hierarchy index *)
26 | TLRef of attrs * int * int (* attrs, position indexes *)
27 | TGRef of attrs * uri (* attrs, reference *)
28 | TCast of attrs * term * term (* attrs, domain, element *)
29 | TAppl of attrs * term list * term (* attrs, arguments, function *)
30 | TProj of attrs * lenv * term (* attrs, closure, member *)
31 | TBind of attrs * bind * term (* attrs, binder, scope *)
33 and lenv = ESort (* top *)
34 | EProj of lenv * attrs * lenv (* environment, attrs, closure *)
35 | EBind of lenv * attrs * bind (* environment, attrs, binder *)
37 type entity = term E.entity
39 (* helpers ******************************************************************)
41 let mk_uri si root s =
42 let kernel = if si then "crg-si" else "crg" in
43 String.concat "/" ["ld:"; kernel; root; s ^ ".ld"]
45 let empty_lenv = ESort
47 let push_bind f lenv a b = f (EBind (lenv, a, b))
49 let push_proj f lenv a e = f (EProj (lenv, a, e))
51 let push2 err f lenv attr ?t () = match lenv, t with
52 | EBind (e, a, Abst ws), Some t -> f (EBind (e, (attr :: a), Abst (t :: ws)))
53 | EBind (e, a, Abbr vs), Some t -> f (EBind (e, (attr :: a), Abbr (t :: vs)))
54 | EBind (e, a, Void n), None -> f (EBind (e, (attr :: a), Void (succ n)))
57 (* this id not tail recursive *)
58 let resolve_lref err f id lenv =
59 let rec aux f i k = function
61 | EBind (tl, _, Abst [])
62 | EBind (tl, _, Abbr [])
63 | EBind (tl, _, Void 0) -> aux f i k tl
65 let err kk = aux f (succ i) (k + kk) tl in
66 let f j = f i j (k + j) in
68 | EProj _ -> assert false (* TODO *)
72 let rec get_name err f i j = function
74 | EBind (tl, _, Abst [])
75 | EBind (tl, _, Abbr [])
76 | EBind (tl, _, Void 0) -> get_name err f i j tl
77 | EBind (_, a, _) when i = 0 ->
81 get_name err f (pred i) j tl
83 let err i = get_name err f i j tl in
86 let get_index err f i j lenv =
87 let rec aux f i k = function
89 | EBind (tl, _, Abst [])
90 | EBind (tl, _, Abbr [])
91 | EBind (tl, _, Void 0) -> aux f i k tl
92 | EBind (_, a, _) when i = 0 ->
93 if E.count_names a > j then f (k + j) else err i
95 aux f (pred i) (k + E.count_names a) tl
96 | EProj _ -> assert false (* TODO *)
100 let rec names_of_lenv ns = function
102 | EBind (tl, a, _) -> names_of_lenv (E.rev_append_names ns a) tl
103 | EProj (tl, _, e) -> names_of_lenv (names_of_lenv ns e) tl