]> matita.cs.unibo.it Git - helm.git/blob - helm/software/lambda-delta/basic_rg/brgOutput.ml
- new semantic log system
[helm.git] / helm / software / lambda-delta / basic_rg / brgOutput.ml
1 (*
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.                     
5     ||I||                                                                
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_______________________________________________________________ *)
11
12 module P = Printf
13 module F = Format
14 module U = NUri
15 module C = Cps
16 module L = Log
17 module B = Brg
18 module R = BrgReduction
19
20 type counters = {
21    eabsts: int;
22    eabbrs: int;
23    tsorts: int;
24    tlrefs: int;
25    tgrefs: int;
26    tcasts: int;
27    tappls: int;
28    tabsts: int;
29    tabbrs: int
30 }
31
32 let initial_counters = {
33    eabsts = 0; eabbrs = 0; tsorts = 0; tlrefs = 0; tgrefs = 0;
34    tcasts = 0; tappls = 0; tabsts = 0; tabbrs = 0
35 }
36
37 let rec count_term_binder f c = function
38    | B.Abst w ->
39       let c = {c with tabsts = succ c.tabsts} in
40       count_term f c w
41    | B.Abbr v -> 
42       let c = {c with tabbrs = succ c.tabbrs} in
43       count_term f c v
44    | B.Void   -> f c
45
46 and count_term f c = function
47    | B.Sort _            -> 
48       f {c with tsorts = succ c.tsorts}
49    | B.LRef _            -> 
50       f {c with tlrefs = succ c.tlrefs}
51    | B.GRef _            -> 
52       f {c with tgrefs = succ c.tgrefs}
53    | B.Cast (v, t)       -> 
54       let c = {c with tcasts = succ c.tcasts} in
55       let f c = count_term f c t in
56       count_term f c v
57    | B.Appl (v, t)       -> 
58       let c = {c with tappls = succ c.tappls} in
59       let f c = count_term f c t in
60       count_term f c v
61    | B.Bind (_, b, t) -> 
62       let f c = count_term_binder f c b in
63       count_term f c t
64
65 let count_obj_binder f c = function
66    | B.Abst w -> 
67       let c = {c with eabsts = succ c.eabsts} in
68       count_term f c w
69    | B.Abbr v -> 
70       let c = {c with eabbrs = succ c.eabbrs} in
71       count_term f c v
72    | B.Void   -> f c
73
74 let count_obj f c (_, _, b) =
75    count_obj_binder f c b
76
77 let count_item f c = function
78    | Some obj -> count_obj f c obj
79    | None     -> f c
80
81 let print_counters f c =
82    let terms =
83       c.tsorts + c.tgrefs + c.tgrefs + c.tcasts + c.tappls + c.tabsts +
84       c.tabbrs
85    in
86    let items = c.eabsts + c.eabbrs in
87    L.warn (P.sprintf "  Kernel representation summary (basic_rg)");
88    L.warn (P.sprintf "    Total entry items:        %6u" items);
89    L.warn (P.sprintf "      Declaration items:      %6u" c.eabsts);
90    L.warn (P.sprintf "      Definition items:       %6u" c.eabbrs);
91    L.warn (P.sprintf "    Total term items:         %6u" terms);
92    L.warn (P.sprintf "      Sort items:             %6u" c.tsorts);
93    L.warn (P.sprintf "      Local reference items:  %6u" c.tlrefs);
94    L.warn (P.sprintf "      Global reference items: %6u" c.tgrefs);
95    L.warn (P.sprintf "      Explicit Cast items:    %6u" c.tcasts);
96    L.warn (P.sprintf "      Application items:      %6u" c.tappls);
97    L.warn (P.sprintf "      Abstraction items:      %6u" c.tabsts);
98    L.warn (P.sprintf "      Abbreviation items:     %6u" c.tabbrs);
99    f ()
100
101 let rec pp_term c frm = function
102    | B.Sort h                 -> F.fprintf frm "@[*%u@]" h
103    | B.LRef i                 -> F.fprintf frm "@[#%u@]" i
104    | B.GRef s                 -> F.fprintf frm "@[$%s@]" (U.string_of_uri s)
105    | B.Cast (u, t)            ->
106       F.fprintf frm "@[{%a}.%a@]" (pp_term c) u (pp_term c) t
107    | B.Appl (v, t)            ->
108       F.fprintf frm "@[(%a).%a@]" (pp_term c) v (pp_term c) t
109    | B.Bind (id, B.Abst w, t) ->
110       F.fprintf frm "@[[%s:%a].%a@]" id (pp_term c) w (pp_term c) t
111    | B.Bind (id, B.Abbr v, t) ->
112       F.fprintf frm "@[[%s=%a].%a@]" id (pp_term c) v (pp_term c) t
113    | B.Bind (id, B.Void, t)   ->
114       F.fprintf frm "@[[%s].%a@]" id (pp_term c) t
115
116 let pp_context frm c =
117    let pp_entry f = function
118       | B.Abst w -> 
119          F.fprintf frm "%s %a\n%!" "\\decl" (pp_term c) w; f ()
120       | B.Abbr v -> 
121          F.fprintf frm "%s %a\n%!" "\\def " (pp_term c) v; f ()
122       | B.Void   -> 
123          F.fprintf frm "%s\n%!" "\\void"; f ()
124    in
125    R.iter C.start pp_entry c
126
127 let pp_term frm c t = 
128    F.fprintf frm "%a\n%!" (pp_term c) t
129
130 let specs = {
131    L.pp_term = pp_term; L.pp_context = pp_context
132 }