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 *)
17 type attrs = Entity.attrs
19 type bind = Abst of term list (* domains *)
20 | Abbr of term list (* bodies *)
21 | Void of int (* number of exclusions *)
23 and term = TSort of attrs * int (* attrs, hierarchy index *)
24 | TLRef of attrs * int * int (* attrs, position indexes *)
25 | TGRef of attrs * uri (* attrs, reference *)
26 | TCast of attrs * term * term (* attrs, domain, element *)
27 | TAppl of attrs * term list * term (* attrs, arguments, function *)
28 | TProj of attrs * lenv * term (* attrs, closure, member *)
29 | TBind of attrs * bind * term (* attrs, binder, scope *)
31 and lenv = ESort (* top *)
32 | EProj of lenv * attrs * lenv (* environment, attrs, closure *)
33 | EBind of lenv * attrs * bind (* environment, attrs, binder *)
35 type entity = term Entity.entity
37 (* helpers ******************************************************************)
40 String.concat "/" ["ld:"; "crg"; root; s ^ ".ld"]
42 let empty_lenv = ESort
44 let push_bind f lenv a b = f (EBind (lenv, a, b))
46 let push_proj f lenv a e = f (EProj (lenv, a, e))
48 let push2 err f lenv attr ?t = match lenv, t with
49 | EBind (e, a, Abst ws), Some t -> f (EBind (e, (attr :: a), Abst (t :: ws)))
50 | EBind (e, a, Abbr vs), Some t -> f (EBind (e, (attr :: a), Abbr (t :: vs)))
51 | EBind (e, a, Void n), None -> f (EBind (e, (attr :: a), Void (succ n)))
54 (* this id not tail recursive *)
55 let resolve_lref err f id lenv =
56 let rec aux f i k = function
59 let err kk = aux f (succ i) (k + kk) tl in
60 let f j = f i j (k + j) in
61 Entity.resolve err f id a
62 | EProj _ -> assert false (* TODO *)
66 let rec get_name err f i j = function
68 | EBind (tl, a, Abst []) -> get_name err f i j tl
69 | EBind (tl, a, Abbr []) -> get_name err f i j tl
70 | EBind (tl, a, Void 0) -> get_name err f i j tl
71 | EBind (_, a, _) when i = 0 ->
73 Entity.get_name err f j a
75 get_name err f (pred i) j tl
77 let err i = get_name err f i j tl in