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 Y.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
62 let err kk = aux f (succ i) (k + kk) tl in
63 let f j = f i j (k + j) in
65 | EProj _ -> assert false (* TODO *)
69 let rec get_name err f i j = function
71 | EBind (_, a, _) when i = 0 ->
75 get_name err f (pred i) j tl
77 let err i = get_name err f i j tl in
80 let get_index err f i j lenv =
81 let rec aux f i k = function
83 | EBind (_, a, _) when i = 0 ->
84 if Y.count_names a > j then f (k + j) else err i
86 aux f (pred i) (k + Y.count_names a) tl
87 | EProj _ -> assert false (* TODO *)
91 let rec names_of_lenv ns = function
93 | EBind (tl, a, _) -> names_of_lenv (Y.rev_append_names ns a) tl
94 | EProj (tl, _, e) -> names_of_lenv (names_of_lenv ns e) tl