X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;f=helm%2Fsoftware%2Flambda-delta%2Fbasic_rg%2FbrgOutput.ml;h=4d3eb0ff7f093d6dbd6bdba51ddbef183552c4a7;hb=41bf338d7e638ebb5d97e525055bff05b1f0f045;hp=741a2567dbb41fdb4dd8b56acdfdc28b825c5fa7;hpb=e86383ae4805a526b3acca2ef3c936b3f22daaad;p=helm.git diff --git a/helm/software/lambda-delta/basic_rg/brgOutput.ml b/helm/software/lambda-delta/basic_rg/brgOutput.ml index 741a2567d..4d3eb0ff7 100644 --- a/helm/software/lambda-delta/basic_rg/brgOutput.ml +++ b/helm/software/lambda-delta/basic_rg/brgOutput.ml @@ -9,6 +9,11 @@ \ / 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 B = Brg type counters = { @@ -28,11 +33,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 _ -> @@ -47,22 +57,25 @@ 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_entry_binder f c = function - | B.Abst -> f {c with eabsts = succ c.eabsts} - | B.Abbr -> f {c with eabbrs = succ c.eabbrs} +let count_obj_binder f c = function + | 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_entry f c (_, b, t) = - let f c = count_entry_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 e -> count_entry f c e - | None -> f c + | Some obj -> count_obj f c obj + | None -> f c let print_counters f c = let terms = @@ -70,16 +83,62 @@ let print_counters f c = c.tabbrs in let items = c.eabsts + c.eabbrs in - Printf.printf " Kernel representation summary (basic_rg)\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 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 " Explicit Cast items: %6u\n" c.tcasts; - Printf.printf " Application items: %6u\n" c.tappls; - Printf.printf " Abstraction items: %6u\n" c.tabsts; - Printf.printf " Abbreviation items: %6u\n" c.tabbrs; - flush stdout; f () + 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); + f () + +let rec pp_term c frm = function + | B.Sort h -> F.fprintf frm "@[*%u@]" h + | B.LRef i -> + let f = function + | Some (id, _) -> F.fprintf frm "@[%s@]" id + | 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) -> + 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) -> + let f cc = + F.fprintf frm "@[[%s:%a].%a@]" id (pp_term c) w (pp_term cc) t + in + B.push f c id (B.Abst w) + | B.Bind (id, B.Abbr v, t) -> + let f cc = + F.fprintf frm "@[[%s=%a].%a@]" id (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 + +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 () + in + let f _ es = C.list_iter C.start 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 +}