X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;f=helm%2Fsoftware%2Flambda-delta%2Fbasic_rg%2FbrgOutput.ml;h=1a0b0650e544cf8b9d79b711fcd1c9023483d58a;hb=32f2a8f8016b2c6c7fb88189fc0ea0c7f9336555;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..1a0b0650e 100644 --- a/helm/software/lambda-delta/basic_rg/brgOutput.ml +++ b/helm/software/lambda-delta/basic_rg/brgOutput.ml @@ -9,60 +9,103 @@ \ / This software is distributed as is, NO WARRANTY. V_______________________________________________________________ *) +module P = Printf +module F = Format +module C = Cps +module U = NUri +module L = Log +module H = Hierarchy +module O = Output module B = Brg +(* nodes count **************************************************************) + type counters = { eabsts: int; eabbrs: int; + evoids: int; tsorts: int; tlrefs: int; tgrefs: int; tcasts: int; tappls: int; tabsts: int; - tabbrs: int + tabbrs: int; + tvoids: int; + uris : B.uri list; + nodes : int; + xnodes: int } let initial_counters = { - eabsts = 0; eabbrs = 0; tsorts = 0; tlrefs = 0; tgrefs = 0; - tcasts = 0; tappls = 0; tabsts = 0; tabbrs = 0 + eabsts = 0; eabbrs = 0; evoids = 0; + tsorts = 0; tlrefs = 0; tgrefs = 0; tcasts = 0; tappls = 0; + tabsts = 0; tabbrs = 0; tvoids = 0; + uris = []; nodes = 0; xnodes = 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 e = function + | B.Abst (_, w) -> + let c = {c with tabsts = succ c.tabsts; nodes = succ c.nodes} in + count_term f c e w + | B.Abbr (_, v) -> + let c = {c with tabbrs = succ c.tabbrs; xnodes = succ c.xnodes} in + count_term f c e v + | B.Void _ -> + let c = {c with tvoids = succ c.tvoids; xnodes = succ c.xnodes} in + f c -let rec count_term f c = function - | B.Sort _ -> - f {c with tsorts = succ c.tsorts} - | B.LRef _ -> - f {c with tlrefs = succ c.tlrefs} - | B.GRef _ -> +and count_term f c e = function + | B.Sort _ -> + f {c with tsorts = succ c.tsorts; nodes = succ c.nodes} + | B.LRef (_, i) -> + let err _ = f {c with tlrefs = succ c.tlrefs; nodes = succ c.nodes} in + let f _ = function + | B.Abst _ + | B.Void _ -> + f {c with tlrefs = succ c.tlrefs; nodes = succ c.nodes} + | B.Abbr _ -> + f {c with tlrefs = succ c.tlrefs; xnodes = succ c.xnodes} + in + B.get err f e i + | B.GRef (_, u) -> + 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 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) -> - 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) -> - let f c = count_term_binder f c b in - let f c = count_term f c t in - count_term f c u - -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_entry f c (_, b, t) = - let f c = count_entry_binder f c b in - count_term f c t - -let count_item f c = function - | Some e -> count_entry f c e - | None -> f c + let f c = count_term f c e t in + count_term f c e v + | B.Appl (_, v, t) -> + let c = {c with tappls = succ c.tappls; nodes = succ c.nodes} in + let f c = count_term f c e t in + count_term f c e v + | B.Bind (b, t) -> + let f c e = count_term f c e t in + let f c = B.push (f c) e b in + count_term_binder f c e b + +let count_entry f c = function + | (_, u, B.Abst (_, w)) -> + let c = {c with + eabsts = succ c.eabsts; nodes = succ c.nodes; uris = u :: c.uris + } in + count_term f c B.empty_lenv w + | (_, _, B.Abbr (_, v)) -> + let c = {c with eabbrs = succ c.eabbrs; xnodes = succ c.xnodes} in + count_term f c B.empty_lenv v + | (_, u, B.Void _) -> + let c = {c with + evoids = succ c.evoids; nodes = succ c.nodes; uris = u :: c.uris + } in + f c + +let count_unit f c = function + | Some entry -> count_entry f c entry + | None -> f c let print_counters f c = let terms = @@ -70,16 +113,181 @@ 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 () + let nodes = c.nodes + c.xnodes in + L.warn (P.sprintf " Kernel representation summary (basic_rg)"); + 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); + L.warn (P.sprintf " Global Int. Complexity: %7u" c.nodes); + L.warn (P.sprintf " + Abbreviation nodes: %7u" nodes); + f () + +(* supplementary annotation *************************************************) + +let attrs_of_binder f = function + | B.Abst (a, _) + | B.Abbr (a, _) + | B.Void a -> f a + +let rec does_not_occur f n r = function + | B.Null -> f true + | B.Cons (c, _, b) -> + let f n1 r1 = + if n1 = n && r1 = r then f false else does_not_occur f n r c + in + attrs_of_binder (B.name C.err f) b + +let rename f c a = + let rec aux f c n r = + let f = function + | true -> f n r + | false -> aux f c (n ^ "'") r + in + does_not_occur f n r c + in + let f n0 r0 = + let f n r = if n = n0 && r = r0 then f a else f (B.Name (r, n) :: a) in + aux f c n0 r0 + in + B.name C.err f a + +let rename_bind f c = function + | B.Abst (a, w) -> let f a = f (B.abst a w) in rename f c a + | B.Abbr (a, v) -> let f a = f (B.abbr a v) in rename f c a + | B.Void a -> let f a = f (B.Void a) in rename f c a + +(* lenv/term pretty printing ************************************************) + +let id frm a = + let f n = function + | true -> F.fprintf frm "%s" n + | false -> F.fprintf frm "^%s" n + in + B.name C.err f a + +let rec pp_term c frm = function + | B.Sort (_, h) -> + let err _ = F.fprintf frm "@[*%u@]" h in + let f s = F.fprintf frm "@[%s@]" s in + H.get_sort err f h + | B.LRef (_, i) -> + let err _ = F.fprintf frm "@[#%u@]" i in + let f _ = function + | B.Abst (a, _) + | B.Abbr (a, _) + | B.Void a -> F.fprintf frm "@[%a@]" id a + in + if !O.indexes then err () else B.get err 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 (B.Abst (a, w), t) -> + let f a cc = + F.fprintf frm "@[[%a:%a].%a@]" id a (pp_term c) w (pp_term cc) t + in + let f a = B.push (f a) c (B.abst a w) in + rename f c a + | B.Bind (B.Abbr (a, v), t) -> + let f a cc = + F.fprintf frm "@[[%a=%a].%a@]" id a (pp_term c) v (pp_term cc) t + in + let f a = B.push (f a) c (B.abbr a v) in + rename f c a + | B.Bind (B.Void a, t) -> + let f a cc = F.fprintf frm "@[[%a].%a@]" id a (pp_term cc) t in + let f a = B.push (f a) c (B.Void a) in + rename f c a + +let pp_lenv frm c = + let pp_entry f c = function + | B.Abst (a, w) -> + let f a = F.fprintf frm "@,@[%a : %a@]" id a (pp_term c) w; f () in + rename f c a + | B.Abbr (a, v) -> + let f a = F.fprintf frm "@,@[%a = %a@]" id a (pp_term c) v; f () in + rename f c a + | B.Void a -> + let f a = F.fprintf frm "@,%a" id a; f () in + rename f c a + in + B.rev_iter C.start pp_entry c + +let specs = { + L.pp_term = pp_term; L.pp_lenv = pp_lenv +} + +(* term xml printing ********************************************************) + +let id frm a = + let f s = function + | true -> F.fprintf frm " name=%S" s + | false -> F.fprintf frm " name=%S" ("^" ^ s) + in + B.name C.start f a + +let rec exp_term c frm = function + | B.Sort (a, l) -> + let a = + let err _ = a in + let f s = B.Name (true, s) :: a in + H.get_sort err f l + in + F.fprintf frm "" (string_of_int l) id a + | B.LRef (a, i) -> + let a = + let err _ = a in + let f n r = B.Name (r, n) :: a in + let f _ b = attrs_of_binder (B.name err f) b in + B.get err f c i + in + F.fprintf frm "" (string_of_int i) id a + | B.GRef (a, u) -> + let a = B.Name (true, U.name_of_uri u) :: a in + F.fprintf frm "" (U.string_of_uri u) id a + | B.Cast (a, w, t) -> + F.fprintf frm "%a@,%a" id a (exp_boxed c) w (exp_term c) t + | B.Appl (a, v, t) -> + F.fprintf frm "%a@,%a" id a (exp_boxed c) v (exp_term c) t + | B.Bind (b, t) -> + let f b cc = F.fprintf frm "%a@,%a" (exp_bind c) b (exp_term cc) t in + let f b = B.push (f b) c b in + rename_bind f c b + +and exp_boxed c frm t = + F.fprintf frm "@,@[ %a@]@," (exp_term c) t + +and exp_bind c frm = function + | B.Abst (a, w) -> + F.fprintf frm "%a" id a (exp_boxed c) w + | B.Abbr (a, v) -> + F.fprintf frm "%a" id a (exp_boxed c) v + | B.Void a -> + F.fprintf frm "" id a + +let exp_entry c frm = function + | _, u, B.Abst (a, w) -> + let str = U.string_of_uri u in + let a = B.Name (true, U.name_of_uri u) :: a in + F.fprintf frm "%a" str id a (exp_boxed c) w + | _, u, B.Abbr (a, v) -> + let str = U.string_of_uri u in + let a = B.Name (true, U.name_of_uri u) :: a in + F.fprintf frm "%a" str id a (exp_boxed c) v + | _, u, B.Void a -> + let str = U.string_of_uri u in + let a = B.Name (true, U.name_of_uri u) :: a in + F.fprintf frm "" str id a + +let export_entry frm entry = + F.fprintf frm "@,@[ %a@]@," (exp_entry B.empty_lenv) entry