]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/software/lambda-delta/dual_rg/drgAut.ml
- common/entity: new format for kernel entities
[helm.git] / helm / software / lambda-delta / dual_rg / drgAut.ml
index 3b371afd72a5371a2804d4b623ad4df36f6e2d0f..b6d8b166c472a6f8f7f3f2194f0da8fd3db202d2 100644 (file)
 module U = NUri
 module H = U.UriHash
 module C = Cps
-module E = Entity
+module Y = Entity
 module A = Aut
 module D = Drg
 
 (* qualified identifier: uri, name, qualifiers *)
 type qid = D.uri * D.id * D.id list
 
-type environment = D.lenv H.t
+type context = Y.attrs * D.term list
+
+type environment = context H.t
 
 type context_node = qid option (* context node: None = root *)
 
-type 'b status = {
+type 'a status = {
    henv: environment;        (* optimized global environment *)
    path: D.id list;          (* current section path *) 
    hcnt: environment;        (* optimized context *)   
    node: context_node;       (* current context node *)
    nodes: context_node list; (* context node list *)
    line: int;                (* line number *)
-   mk_uri:'b E.uri_generator (* uri generator *) 
+   mk_uri:'a Y.uri_generator (* uri generator *) 
 }
 
 type resolver = Local of int
-              | Global of D.lenv
+              | Global of context
 
-let hsize = 7000 (* hash tables initial size *)
+let henv_size, hcnt_size = 7000, 4300 (* hash tables initial sizes *)
 
 (* Internal functions *******************************************************)
 
-let initial_status size mk_uri = {
+let initial_status mk_uri = {
    path = []; node = None; nodes = []; line = 1; mk_uri = mk_uri;
-   henv = H.create size; hcnt = H.create size
+   henv = H.create henv_size; hcnt = H.create hcnt_size
 }
 
-let mk_lref f i = f (D.LRef ([], i))
+let empty_cnt = [], []
+
+let add_abst (a, ws) id w = 
+   Y.Name (id, true) :: a, w :: ws 
+
+let lenv_of_cnt (a, ws) = 
+   D.push C.start D.empty_lenv a (D.Abst ws)
 
-let mk_abst id w = D.Abst ([D.Name (id, true)], w)
+let mk_lref f i j k = f (D.LRef ([Y.Apix k], i, j))
 
 let id_of_name (id, _, _) = id
 
@@ -88,7 +96,7 @@ let resolve_gref_relaxed f st qid =
    resolve_gref err f st qid
 
 let get_cnt err f st = function
-   | None              -> f []
+   | None              -> f empty_cnt
    | Some qid as node ->
       try let cnt = H.find st.hcnt (uri_of_qid qid) in f cnt
       with Not_found -> err node
@@ -107,22 +115,23 @@ let rec xlate_term f st lenv = function
       xlate_term f st lenv v
    | A.Abst (name, w, t) ->
       let f ww = 
-         let b = mk_abst name ww in
-        let f tt = f (D.Bind ([b], tt)) in
-         xlate_term f st (b :: lenv) t
+         let a, b = [Y.Name (name, true)], (D.Abst [ww]) in
+        let f tt = f (D.Bind (a, b, tt)) in
+         let f lenv = xlate_term f st lenv t in
+        D.push f lenv a b
       in
       xlate_term f st lenv w
    | A.GRef (name, args) ->
-      let g qid cnt =
+      let g qid (a, _) =
         let map1 f = xlate_term f st lenv in       
-        let map2 f b =
-           let f id _ = D.resolve_lref Cps.err (mk_lref f) id lenv in
-           D.name_of_binder C.err f b
+        let map2 f = function
+           | Y.Name (id, _) -> D.resolve_lref Cps.err (mk_lref f) id lenv
+           | _              -> assert false
         in
          let f tail = 
            let f args = f (D.Appl ([], args, D.GRef ([], uri_of_qid qid))) in
-            let f cnt = C.list_rev_map_append f map2 cnt ~tail in
-           C.list_sub_strict f cnt args
+            let f a = C.list_rev_map_append f map2 a ~tail in
+           C.list_sub_strict f a args
         in   
         C.list_map f map1 args
       in
@@ -130,58 +139,65 @@ let rec xlate_term f st lenv = function
       let err () = complete_qid g st name in
       D.resolve_lref err (mk_lref f) (id_of_name name) lenv
 
-let xlate_entity f st = function
+let xlate_entity err f st = function
    | A.Section (Some (_, name))     ->
-      f {st with path = name :: st.path; nodes = st.node :: st.nodes} None
+      err {st with path = name :: st.path; nodes = st.node :: st.nodes}
    | A.Section None            ->
       begin match st.path, st.nodes with
         | _ :: ptl, nhd :: ntl -> 
-           f {st with path = ptl; node = nhd; nodes = ntl} None
+           err {st with path = ptl; node = nhd; nodes = ntl}
          | _                    -> assert false
       end
    | A.Context None            ->
-      f {st with node = None} None
+      err {st with node = None}
    | A.Context (Some name)     ->
-      let f name = f {st with node = Some name} None in
+      let f name = err {st with node = Some name} in
       complete_qid f st name 
    | A.Block (name, w)         ->
       let f qid = 
          let f cnt =
+           let lenv = lenv_of_cnt cnt in
            let f ww = 
-              H.add st.hcnt (uri_of_qid qid) (mk_abst name ww :: cnt);
-              f {st with node = Some qid} None
+              H.add st.hcnt (uri_of_qid qid) (add_abst cnt name ww);
+              err {st with node = Some qid}
            in
-            xlate_term f st cnt w
+            xlate_term f st lenv w
         in
          get_cnt_relaxed f st
       in
       complete_qid f st (name, true, [])
    | A.Decl (name, w)          ->
-      let f cnt = 
-         let f qid = 
+      let f cnt =
+         let a, ws = cnt in
+         let lenv = lenv_of_cnt cnt in
+        let f qid = 
             let f ww =
-               let b = D.Abst ([], D.Bind (cnt, ww)) in
-              let entry = st.line, uri_of_qid qid, b in
-              H.add st.henv (uri_of_qid qid) cnt;
-              f {st with line = succ st.line} (Some entry)
+              H.add st.henv (uri_of_qid qid) cnt;            
+              let b = Y.Abst (D.Bind (a, D.Abst ws, ww)) in
+              let entity = [Y.Mark st.line], uri_of_qid qid, b in
+              f {st with line = succ st.line} entity
            in
-           xlate_term f st cnt w
+           xlate_term f st lenv w
         in
          complete_qid f st (name, true, [])
       in
       get_cnt_relaxed f st
    | A.Def (name, w, trans, v) ->
       let f cnt = 
+        let a, ws = cnt in
+        let lenv = lenv_of_cnt cnt in
          let f qid = 
             let f ww vv = 
-              let a = if trans then [] else [D.Priv] in
-              let b = D.Abbr (a, D.Bind (cnt, D.Cast ([], ww, vv))) in
-              let entry = st.line, uri_of_qid qid, b in
               H.add st.henv (uri_of_qid qid) cnt;
-              f {st with line = succ st.line} (Some entry)
+               let b = Y.Abbr (D.Bind (a, D.Abst ws, D.Cast ([], ww, vv))) in
+              let a =
+                 if trans then [Y.Mark st.line] else [Y.Mark st.line; Y.Priv]
+              in
+              let entity = a, uri_of_qid qid, b in
+              f {st with line = succ st.line} entity
            in
-           let f ww = xlate_term (f ww) st cnt v in
-           xlate_term f st cnt w
+           let f ww = xlate_term (f ww) st lenv v in
+           xlate_term f st lenv w
         in
          complete_qid f st (name, true, [])
       in
@@ -190,6 +206,6 @@ let xlate_entity f st = function
 (* Interface functions ******************************************************)
 
 let initial_status mk_uri =
-   initial_status hsize mk_uri
+   initial_status mk_uri
 
 let drg_of_aut = xlate_entity