]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/software/lambda-delta/basic_rg/brgOutput.ml
...
[helm.git] / helm / software / lambda-delta / basic_rg / brgOutput.ml
index 958408303f6e72af13e3aadcb6b43f75e7441ce0..b8fc2d0c2d4ab8a08bbc96797b7c2f057dea66c1 100644 (file)
@@ -17,6 +17,8 @@ module L = Log
 module H = Hierarchy
 module B = Brg
 
+(* nodes count **************************************************************)
+
 type counters = {
    eabsts: int;
    eabbrs: int;
@@ -46,15 +48,15 @@ let rec count_term_binder f c = function
 and count_term f c = function
    | B.Sort _            -> 
       f {c with tsorts = succ c.tsorts}
-   | B.LRef _            -> 
+   | B.LRef _         -> 
       f {c with tlrefs = succ c.tlrefs}
-   | B.GRef _            -> 
+   | B.GRef _         -> 
       f {c with tgrefs = succ c.tgrefs}
-   | B.Cast (v, t)       -> 
+   | B.Cast (_, v, t) -> 
       let c = {c with tcasts = succ c.tcasts} in
       let f c = count_term f c t in
       count_term f c v
-   | B.Appl (v, t)       -> 
+   | B.Appl (_, v, t) -> 
       let c = {c with tappls = succ c.tappls} in
       let f c = count_term f c t in
       count_term f c v
@@ -85,66 +87,98 @@ let print_counters f c =
    in
    let items = c.eabsts + c.eabbrs in
    L.warn (P.sprintf "  Kernel representation summary (basic_rg)");
-   L.warn (P.sprintf "    Total entry items:        %6u" items);
-   L.warn (P.sprintf "      Declaration items:      %6u" c.eabsts);
-   L.warn (P.sprintf "      Definition items:       %6u" c.eabbrs);
-   L.warn (P.sprintf "    Total term items:         %6u" terms);
-   L.warn (P.sprintf "      Sort items:             %6u" c.tsorts);
-   L.warn (P.sprintf "      Local reference items:  %6u" c.tlrefs);
-   L.warn (P.sprintf "      Global reference items: %6u" c.tgrefs);
-   L.warn (P.sprintf "      Explicit Cast items:    %6u" c.tcasts);
-   L.warn (P.sprintf "      Application items:      %6u" c.tappls);
-   L.warn (P.sprintf "      Abstraction items:      %6u" c.tabsts);
-   L.warn (P.sprintf "      Abbreviation items:     %6u" c.tabbrs);
+   L.warn (P.sprintf "    Total entry items:        %7u" items);
+   L.warn (P.sprintf "      Declaration items:      %7u" c.eabsts);
+   L.warn (P.sprintf "      Definition items:       %7u" c.eabbrs);
+   L.warn (P.sprintf "    Total term items:         %7u" terms);
+   L.warn (P.sprintf "      Sort items:             %7u" c.tsorts);
+   L.warn (P.sprintf "      Local reference items:  %7u" c.tlrefs);
+   L.warn (P.sprintf "      Global reference items: %7u" c.tgrefs);
+   L.warn (P.sprintf "      Explicit Cast items:    %7u" c.tcasts);
+   L.warn (P.sprintf "      Application items:      %7u" c.tappls);
+   L.warn (P.sprintf "      Abstraction items:      %7u" c.tabsts);
+   L.warn (P.sprintf "      Abbreviation items:     %7u" c.tabbrs);   
    f ()
 
+(* reductions count *********************************************************)
+
+type reductions = {
+   beta   : int;
+   upsilon: int;
+   tau    : int;
+   ldelta : int;
+   gdelta : int
+}
+
+let initial_reductions = {
+   beta = 0; upsilon = 0; tau = 0; ldelta = 0; gdelta = 0
+}
+
+let add ?(beta=0) ?(upsilon=0) ?(tau=0) ?(ldelta=0) ?(gdelta=0) r = {
+   beta = r.beta + beta;
+   upsilon = r.upsilon + upsilon;
+   tau = r.tau + tau;
+   ldelta = r.ldelta + ldelta;
+   gdelta = r.gdelta + gdelta
+}
+
+(* context/term pretty printing *********************************************)
+
+let indexes = ref false
+
+let id frm a =
+   let f = function
+      | None            -> assert false
+      | Some (true, n)  -> F.fprintf frm "%s" n
+      | Some (false, n) -> F.fprintf frm "^%s" n
+   in      
+   B.name f a
+
 let rec pp_term c frm = function
-   | B.Sort h                 -> 
+   | B.Sort (_, h)           -> 
       let f = function 
          | Some s -> F.fprintf frm "@[%s@]" s
         | None   -> F.fprintf frm "@[*%u@]" h
       in
       H.get_sort f h 
-   | B.LRef i                 -> 
-      let f = function
-         | Some (id, _) -> F.fprintf frm "@[%s@]" id
-         | None         -> F.fprintf frm "@[#%u@]" i
+   | B.LRef (_, i)           -> 
+      let f = function
+         | Some (a, _) -> F.fprintf frm "@[%a@]" id a
+         | None        -> F.fprintf frm "@[#%u@]" i
       in
-      B.get f c i
-   | B.GRef s                 -> F.fprintf frm "@[$%s@]" (U.string_of_uri s)
-   | B.Cast (u, t)            ->
+      if !indexes then f 0 None else B.get f c i
+   | B.GRef (_, s)           -> F.fprintf frm "@[$%s@]" (U.string_of_uri s)
+   | B.Cast (_, u, t)        ->
       F.fprintf frm "@[{%a}.%a@]" (pp_term c) u (pp_term c) t
-   | B.Appl (v, t)            ->
+   | B.Appl (_, v, t)        ->
       F.fprintf frm "@[(%a).%a@]" (pp_term c) v (pp_term c) t
-   | B.Bind (id, B.Abst w, t) ->
+   | B.Bind (a, B.Abst w, t) ->
       let f cc =
-         F.fprintf frm "@[[%s:%a].%a@]" id (pp_term c) w (pp_term cc) t
+         F.fprintf frm "@[[%a:%a].%a@]" id a (pp_term c) w (pp_term cc) t
       in
-      B.push f c id (B.Abst w)
-   | B.Bind (id, B.Abbr v, t) ->
+      B.push f c a (B.Abst w)
+   | B.Bind (a, B.Abbr v, t) ->
       let f cc = 
-         F.fprintf frm "@[[%s=%a].%a@]" id (pp_term c) v (pp_term cc) t
+         F.fprintf frm "@[[%a=%a].%a@]" id a (pp_term c) v (pp_term cc) t
       in
-      B.push f c id (B.Abbr v)
-   | B.Bind (id, B.Void, t)   ->
-      let f cc = F.fprintf frm "@[[%s].%a@]" id (pp_term cc) t in
-      B.push f c id B.Void
+      B.push f c a (B.Abbr v)
+   | B.Bind (a, B.Void, t)   ->
+      let f cc = F.fprintf frm "@[[%a].%a@]" id a (pp_term cc) t in
+      B.push f c a B.Void
 
 let pp_context frm c =
-   let pp_entry f = function
-      | id, B.Abst w -> 
-         F.fprintf frm "%s : %a\n%!" id (pp_term c) w; f ()
-      | id, B.Abbr v -> 
-         F.fprintf frm "%s = %a\n%!" id (pp_term c) v; f ()
-      | id, B.Void   -> 
-         F.fprintf frm "%s\n%!" id; f ()
+   let pp_entry frm = function
+      | a, B.Abst w -> 
+         F.fprintf frm "@,@[%a : %a@]" id a (pp_term c) w
+      | a, B.Abbr v -> 
+         F.fprintf frm "@,@[%a = %a@]" id a (pp_term c) v
+      | a, B.Void   -> 
+         F.fprintf frm "@,%a" id a
    in
-   let f _ es = C.list_iter C.start pp_entry (List.rev es) in
+   let iter map frm l = List.iter (map frm) l in
+   let f es = F.fprintf frm "%a" (iter pp_entry) (List.rev es) in
    B.contents f c
 
-let pp_term frm c t = 
-   F.fprintf frm "%a\n%!" (pp_term c) t
-
 let specs = {
    L.pp_term = pp_term; L.pp_context = pp_context
 }