]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/software/lambda-delta/src/complete_rg/crg.ml
Matitaweb: layout change in the matitaweb inteface, in order to allow better
[helm.git] / helm / software / lambda-delta / src / complete_rg / crg.ml
index cc93d6dc3fdac485a014a5e046cd698978e18b1c..5a394f4f8372f3411430137b45e3da9f9a61d827 100644 (file)
 (* kernel version: complete, relative, global *)
 (* note          : fragment of complete lambda-delta serving as abstract layer *) 
 
+module C = Cps
 module E = Entity
+module N = Level
 
 type uri = E.uri
 type id = E.id
 type attrs = E.attrs
 
-type bind = Abst of term list (* domains *)
-          | Abbr of term list (* bodies  *)
-          | Void of int       (* number of exclusions *)
+type bind = Abst of N.level * term list (* level, domains *)
+          | Abbr of term list           (* bodies *)
+          | Void of int                 (* number of exclusions *)
 
 and term = TSort of attrs * int              (* attrs, hierarchy index *)
          | TLRef of attrs * int * int        (* attrs, position indexes *)
@@ -38,9 +40,17 @@ type entity = term E.entity
 
 (* helpers ******************************************************************)
 
-let mk_uri si root s =
-   let kernel = if si then "crg-si" else "crg" in
-   String.concat "/" ["ld:"; kernel; root; s ^ ".ld"]
+let rec tshift t = function
+   | ESort           -> t
+   | EBind (e, a, b) -> tshift (TBind (a, b, t)) e
+   | EProj (e, a, d) -> tshift (TProj (a, d, t)) e
+
+let tshift c t = tshift t c
+
+let rec eshift f c = function
+   | ESort           -> f c
+   | EBind (e, a, b) -> let f ee = f (EBind (ee, a, b)) in eshift f c e
+   | EProj (e, a, d) -> let f ee = f (EProj (ee, a, d)) in eshift f c e
 
 let empty_lenv = ESort
 
@@ -48,30 +58,39 @@ let push_bind f lenv a b = f (EBind (lenv, a, b))
 
 let push_proj f lenv a e = f (EProj (lenv, a, e))
 
-let push2 err f lenv attr ?t () = match lenv, t with
-   | EBind (e, a, Abst ws), Some t -> f (EBind (e, (attr :: a), Abst (t :: ws)))
-   | EBind (e, a, Abbr vs), Some t -> f (EBind (e, (attr :: a), Abbr (t :: vs)))
-   | EBind (e, a, Void n), None    -> f (EBind (e, (attr :: a), Void (succ n)))
-   | _                             -> err ()
+let push2 err f lenv ?attr ?t () = match lenv, attr, t with
+   | EBind (e, a, Abst (n, ws)), Some attr, Some t -> 
+      f (EBind (e, (attr :: a), Abst (n, t :: ws)))
+   | EBind (e, a, Abst (n, ws)), None, Some t      -> 
+      f (EBind (e, a, Abst (n, t :: ws)))
+   | EBind (e, a, Abbr vs), Some attr, Some t      ->
+      f (EBind (e, (attr :: a), Abbr (t :: vs)))
+   | EBind (e, a, Abbr vs), None, Some t           ->
+      f (EBind (e, a, Abbr (t :: vs)))
+   | EBind (e, a, Void n), Some attr, None         ->
+      f (EBind (e, (attr :: a), Void (succ n)))
+   | EBind (e, a, Void n), None, None              ->
+      f (EBind (e, a, Void (succ n)))
+   | _                                             -> err ()
 
 (* this id not tail recursive *)
 let resolve_lref err f id lenv =
    let rec aux f i k = function
      | ESort                  -> err ()
-     | EBind (tl, _, Abst [])
+     | EBind (tl, _, Abst (_, []))
      | EBind (tl, _, Abbr [])
      | EBind (tl, _, Void 0)  -> aux f i k tl
-     | EBind (tl, a, _)       ->
-        let err kk = aux f (succ i) (k + kk) tl in
+     | EBind (tl, a, b)       ->
+       let err kk = aux f (succ i) (k + kk) tl in
        let f j = f i j (k + j) in
        E.resolve err f id a
-     | EProj _                -> assert false (* TODO *)
+     | EProj (tl, _, d)       -> aux f i k (eshift C.start tl d)
    in
    aux f 0 0 lenv
 
 let rec get_name err f i j = function
    | ESort                      -> err i
-   | EBind (tl, _, Abst [])
+   | EBind (tl, _, Abst (_, []))
    | EBind (tl, _, Abbr [])
    | EBind (tl, _, Void 0)      -> get_name err f i j tl
    | EBind (_, a, _) when i = 0 -> 
@@ -86,14 +105,14 @@ let rec get_name err f i j = function
 let get_index err f i j lenv =
    let rec aux f i k = function
       | ESort                      -> err i
-      | EBind (tl, _, Abst [])
+      | EBind (tl, _, Abst (_, []))
       | EBind (tl, _, Abbr [])
       | EBind (tl, _, Void 0)      -> aux f i k tl
       | EBind (_, a, _) when i = 0 ->
         if E.count_names a > j then f (k + j) else err i
       | EBind (tl, a, _)           -> 
          aux f (pred i) (k + E.count_names a) tl
-      | EProj _                    -> assert false (* TODO *)
+      | EProj (tl, _, d)           -> aux f i k (eshift C.start tl d)
    in
    aux f i 0 lenv
 
@@ -101,3 +120,14 @@ let rec names_of_lenv ns = function
    | ESort            -> ns
    | EBind (tl, a, _) -> names_of_lenv (E.rev_append_names ns a) tl
    | EProj (tl, _, e) -> names_of_lenv (names_of_lenv ns e) tl
+
+let rec get i = function
+   | ESort                      -> ESort, [], Void 0 
+   | EBind (e, _, Abst (_, []))
+   | EBind (e, _, Abbr [])
+   | EBind (e, _, Void 0)       -> get i e
+   | EBind (e, a, b) when i = 0 -> e, a, b
+   | EBind (e, _, _)            -> get (pred i) e
+   | EProj (e, _, d)            -> get i (eshift C.start e d)
+let get e i = get i e