]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/software/lambda-delta/basic_rg/brgOutput.ml
- new semantic log system
[helm.git] / helm / software / lambda-delta / basic_rg / brgOutput.ml
index e29b3f4953bddeead3251d5c46957e7c5b361589..4c100375d381e11411312a3f80f7084100a84775 100644 (file)
       V_______________________________________________________________ *)
 
 module P = Printf
+module F = Format
+module U = NUri
+module C = Cps
 module L = Log
 module B = Brg
+module R = BrgReduction
 
 type counters = {
    eabsts: int;
@@ -30,11 +34,16 @@ let initial_counters = {
    tcasts = 0; tappls = 0; tabsts = 0; tabbrs = 0
 }
 
-let count_term_binder f c = function
-   | B.Abst -> f {c with tabsts = succ c.tabsts}
-   | B.Abbr -> f {c with tabbrs = succ c.tabbrs}
+let rec count_term_binder f c = function
+   | B.Abst w ->
+      let c = {c with tabsts = succ c.tabsts} in
+      count_term f c w
+   | B.Abbr v -> 
+      let c = {c with tabbrs = succ c.tabbrs} in
+      count_term f c v
+   | B.Void   -> f c
 
-let rec count_term f c = function
+and count_term f c = function
    | B.Sort _            -> 
       f {c with tsorts = succ c.tsorts}
    | B.LRef _            -> 
@@ -49,18 +58,21 @@ let rec count_term f c = function
       let c = {c with tappls = succ c.tappls} in
       let f c = count_term f c t in
       count_term f c v
-   | B.Bind (_, b, u, t) -> 
+   | B.Bind (_, b, t) -> 
       let f c = count_term_binder f c b in
-      let f c = count_term f c t in
-      count_term f c u
+      count_term f c t
 
 let count_obj_binder f c = function
-   | B.Abst -> f {c with eabsts = succ c.eabsts}
-   | B.Abbr -> f {c with eabbrs = succ c.eabbrs}
+   | B.Abst w -> 
+      let c = {c with eabsts = succ c.eabsts} in
+      count_term f c w
+   | B.Abbr v -> 
+      let c = {c with eabbrs = succ c.eabbrs} in
+      count_term f c v
+   | B.Void   -> f c
 
-let count_obj f c (_, _, b, t) =
-   let f c = count_obj_binder f c b in
-   count_term f c t
+let count_obj f c (_, _, b) =
+   count_obj_binder f c b
 
 let count_item f c = function
    | Some obj -> count_obj f c obj
@@ -85,3 +97,36 @@ let print_counters f c =
    L.warn (P.sprintf "      Abstraction items:      %6u" c.tabsts);
    L.warn (P.sprintf "      Abbreviation items:     %6u" c.tabbrs);
    f ()
+
+let rec pp_term c frm = function
+   | B.Sort h                 -> F.fprintf frm "@[*%u@]" h
+   | B.LRef i                 -> F.fprintf frm "@[#%u@]" 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)            ->
+      F.fprintf frm "@[(%a).%a@]" (pp_term c) v (pp_term c) t
+   | B.Bind (id, B.Abst w, t) ->
+      F.fprintf frm "@[[%s:%a].%a@]" id (pp_term c) w (pp_term c) t
+   | B.Bind (id, B.Abbr v, t) ->
+      F.fprintf frm "@[[%s=%a].%a@]" id (pp_term c) v (pp_term c) t
+   | B.Bind (id, B.Void, t)   ->
+      F.fprintf frm "@[[%s].%a@]" id (pp_term c) t
+
+let pp_context frm c =
+   let pp_entry f = function
+      | B.Abst w -> 
+         F.fprintf frm "%s %a\n%!" "\\decl" (pp_term c) w; f ()
+      | B.Abbr v -> 
+         F.fprintf frm "%s %a\n%!" "\\def " (pp_term c) v; f ()
+      | B.Void   -> 
+         F.fprintf frm "%s\n%!" "\\void"; f ()
+   in
+   R.iter C.start pp_entry 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
+}