]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/software/lambda-delta/toplevel/metaOutput.ml
basic_rg: reduction was not tail recursive by mistake
[helm.git] / helm / software / lambda-delta / toplevel / metaOutput.ml
index 4efee4a6833e511ba53428c3670cc2aec2e79082..21d735d0e187f3f366fc25a475739fa0a84ffeed 100644 (file)
@@ -1,29 +1,20 @@
-(* Copyright (C) 2000, HELM Team.
- * 
- * This file is part of HELM, an Hypertextual, Electronic
- * Library of Mathematics, developed at the Computer Science
- * Department, University of Bologna, Italy.
- * 
- * HELM is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- * 
- * HELM is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with HELM; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
- * MA  02111-1307, USA.
- * 
- * For details, see the HELM World-Wide-Web page,
- * http://cs.unibo.it/helm/.
- *)
-
+(*
+    ||M||  This file is part of HELM, an Hypertextual, Electronic        
+    ||A||  Library of Mathematics, developed at the Computer Science     
+    ||T||  Department, University of Bologna, Italy.                     
+    ||I||                                                                
+    ||T||  HELM is free software; you can redistribute it and/or         
+    ||A||  modify it under the terms of the GNU General Public License   
+    \   /  version 2 or (at your option) any later version.              
+     \ /   This software is distributed as is, NO WARRANTY.              
+      V_______________________________________________________________ *)
+
+module P = Printf
 module F = Format
+module U = NUri
+module C = Cps
+module L = Log
+module Y = Entity
 module M = Meta
 
 type counters = {
@@ -36,79 +27,94 @@ type counters = {
    pappls: int;
    tappls: int;
    tabsts: int;
+   uris  : U.uri list;
+   nodes : int;
+   xnodes: int
 }
 
 let initial_counters = {
    eabsts = 0; eabbrs = 0; pabsts = 0; pappls = 0;
-   tsorts = 0; tlrefs = 0; tgrefs = 0; tappls = 0; tabsts = 0
+   tsorts = 0; tlrefs = 0; tgrefs = 0; tappls = 0; tabsts = 0;
+   uris = []; nodes = 0; xnodes = 0
 }
 
 let rec count_term f c = function
    | M.Sort _          -> 
-      f {c with tsorts = succ c.tsorts}
+      f {c with tsorts = succ c.tsorts; nodes = succ c.nodes}
    | M.LRef _          -> 
-      f {c with tlrefs = succ c.tlrefs}
-   | M.GRef (_, _, ts) -> 
+      f {c with tlrefs = succ c.tlrefs; nodes = succ c.nodes}
+   | M.GRef (_, u, ts) -> 
       let c = {c with tgrefs = succ c.tgrefs} in
       let c = {c with pappls = c.pappls + List.length ts} in
+      let c = {c with nodes = c.nodes + List.length ts} in
+      let c =    
+        if Cps.list_mem ~eq:U.eq u c.uris
+        then {c with nodes = succ c.nodes}
+        else {c with xnodes = succ c.xnodes}
+      in
       Cps.list_fold_left f count_term c ts
    | M.Appl (v, t)     -> 
-      let c = {c with tappls = succ c.tappls} in
+      let c = {c with tappls = succ c.tappls; nodes = succ c.nodes} in
       let f c = count_term f c t in
       count_term f c v
    | M.Abst (_, w, t)  -> 
-      let c = {c with tabsts = succ c.tabsts} in
+      let c = {c with tabsts = succ c.tabsts; nodes = succ c.nodes} in
       let f c = count_term f c t in
       count_term f c w
 
 let count_par f c (_, w) = count_term f c w
 
-let count_item f c = function
-   | _, pars, _, w, None        ->
+let count_xterm f c = function
+   | None   -> f c
+   | Some v -> count_term f c v
+
+let count_entity f c = function
+   | _, u, Y.Abst (pars, w, xv) ->
       let c = {c with eabsts = succ c.eabsts} in
       let c = {c with pabsts = c.pabsts + List.length pars} in
+      let c = {c with uris = u :: c.uris; nodes = succ c.nodes + List.length pars} in
+      let f c = count_xterm f c xv in      
       let f c = count_term f c w in
       Cps.list_fold_left f count_par c pars   
-   | _, pars, _, w, Some (_, v) ->
-      let c = {c with eabbrs = succ c.eabbrs} in
+   | _, _, Y.Abbr (pars, w, xv) ->
+      let c = {c with eabbrs = succ c.eabbrs; xnodes = succ c.xnodes} in
       let c = {c with pabsts = c.pabsts + List.length pars} in
-      let f c = count_term f c v in
+      let c = {c with nodes = c.nodes + List.length pars} in
+      let f c = count_xterm f c xv in
       let f c = count_term f c w in
       Cps.list_fold_left f count_par c pars
-
-let count f c b =
-   Cps.list_fold_left f count_item c b
+   | _, _, Y.Void               -> assert false
 
 let print_counters f c =
-   let terms = c.tsorts + c.tgrefs + c.tgrefs + c.tappls + c.tabsts in
+   let terms = c.tsorts + c.tlrefs + c.tgrefs + c.tappls + c.tabsts in
    let pars = c.pabsts + c.pappls in
-   let items = c.eabsts + c.eabbrs in
-   Printf.printf "  Intermediate representation summary\n";
-   Printf.printf "    Total entry items:        %6u\n" items;
-   Printf.printf "      Declaration items:      %6u\n" c.eabsts;
-   Printf.printf "      Definition items:       %6u\n" c.eabbrs;
-   Printf.printf "    Total parameter items:    %6u\n" pars;
-   Printf.printf "      Application items:      %6u\n" c.pappls;
-   Printf.printf "      Abstraction items:      %6u\n" c.pabsts;
-   Printf.printf "    Total term items:         %6u\n" terms;
-   Printf.printf "      Sort items:             %6u\n" c.tsorts;
-   Printf.printf "      Local reference items:  %6u\n" c.tlrefs;
-   Printf.printf "      Global reference items: %6u\n" c.tgrefs;
-   Printf.printf "      Application items:      %6u\n" c.tappls;
-   Printf.printf "      Abstraction items:      %6u\n" c.tabsts;
-   flush stdout; f ()
+   let entries = c.eabsts + c.eabbrs in
+   let nodes = c.nodes + c.xnodes in
+   L.warn (P.sprintf "  Intermediate representation summary");
+   L.warn (P.sprintf "    Total entries:            %7u" entries);
+   L.warn (P.sprintf "      Declaration items:      %7u" c.eabsts);
+   L.warn (P.sprintf "      Definition items:       %7u" c.eabbrs);
+   L.warn (P.sprintf "    Total parameter items:    %7u" pars);
+   L.warn (P.sprintf "      Application items:      %7u" c.pappls);
+   L.warn (P.sprintf "      Abstraction items:      %7u" c.pabsts);
+   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 "      Application items:      %7u" c.tappls);
+   L.warn (P.sprintf "      Abstraction items:      %7u" c.tabsts);
+   L.warn (P.sprintf "    Global Int. Complexity:   %7u" c.nodes);
+   L.warn (P.sprintf "      + Abbreviation nodes:   %7u" nodes);
+   f ()
 
 let string_of_sort = function
    | true -> "Type"
    | false -> "Prop"
 
-let string_of_qid (id, path) =
-   let path = String.concat "/" path in
-   Filename.concat path id
-
-let string_of_transparent = function
-   | true  -> "="
-   | false -> "~"
+let pp_transparent frm a =
+   let err () = F.fprintf frm "%s" "=" in
+   let f () = F.fprintf frm "%s" "~" in
+   Y.priv err f a
 
 let pp_list pp opend sep closed frm l =
    let rec aux frm = function
@@ -118,33 +124,39 @@ let pp_list pp opend sep closed frm l =
    in
    if l = [] then () else F.fprintf frm "%s%a%s" opend aux l closed
 
+let pp_rev_list pp opend sep closed frm l =
+   pp_list pp opend sep closed frm (List.rev l)
+
 let rec pp_args frm args = pp_list pp_term "(" "," ")" frm args
 
 and pp_term frm = function
    | M.Sort s            -> 
       F.fprintf frm "@[*%s@]" (string_of_sort s)
-   | M.LRef i            ->
-      F.fprintf frm "@[#%u@]" i
-   | M.GRef (l, qid, ts) ->
-      F.fprintf frm "@[%u@@$%s%a@]" l (string_of_qid qid) pp_args ts
+   | M.LRef (l, i)       ->
+      F.fprintf frm "@[%u@@#%u@]" l i
+   | M.GRef (l, uri, ts) ->
+      F.fprintf frm "@[%u@@$%s%a@]" l (U.string_of_uri uri) pp_args ts
    | M.Appl (v, t)       ->
       F.fprintf frm "@[(%a).%a@]" pp_term v pp_term t
    | M.Abst (id, w, t)   ->
       F.fprintf frm "@[[%s:%a].%a@]" id pp_term w pp_term t
 
-let pp_par frm (qid, w) =
-    F.fprintf frm "%s:%a" (string_of_qid qid) pp_term w
+let pp_par frm (id, w) =
+   F.fprintf frm "%s:%a" id pp_term w
 
-let pp_pars = pp_list pp_par "[" "," "]"
+let pp_pars = pp_rev_list pp_par "[" "," "]"
 
-let pp_body frm = function
-   | None            -> ()
-   | Some (trans, t) ->
-      F.fprintf frm "%s%a" (string_of_transparent trans) pp_term t
+let pp_body a frm = function
+   | None   -> ()
+   | Some t -> F.fprintf frm "%a%a" pp_transparent a pp_term t
 
-let pp_item frm (l, pars, qid, u, body) =
-   F.fprintf frm "@[%u@@%s%a%a:%a@]@\n%!" 
-      l (string_of_qid qid) pp_pars pars pp_body body pp_term u
+let pp_entity frm = function
+   | a, uri, Y.Abst (pars, u, body)
+   | a, uri, Y.Abbr (pars, u, body) ->
+      F.fprintf frm "@[%u@@%s%a%a:%a@]@\n%!" 
+         (Y.mark C.err C.start a) (U.string_of_uri uri) 
+        pp_pars pars (pp_body a) body pp_term u
+   | _, _, Y.Void                   -> assert false
 
-let pp_environment f frm genv =
-   List.iter (pp_item frm) genv; f ()
+let pp_entity f frm entity =
+   pp_entity frm entity; f ()