From: Ferruccio Guidi Date: Thu, 8 Oct 2009 14:43:54 +0000 (+0000) Subject: drgAut: we fixed the order of multi application arguments X-Git-Tag: make_still_working~3348 X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=commitdiff_plain;h=8e40e8ece45938cb8b35d2a997bf50786af5f4df;p=helm.git drgAut: we fixed the order of multi application arguments drgBrg: we started the translation from drg to brg --- diff --git a/helm/software/lambda-delta/.depend.opt b/helm/software/lambda-delta/.depend.opt index eb479838e..19f473c6d 100644 --- a/helm/software/lambda-delta/.depend.opt +++ b/helm/software/lambda-delta/.depend.opt @@ -126,6 +126,11 @@ dual_rg/drgAut.cmo: lib/nUri.cmi common/entity.cmx dual_rg/drg.cmx \ lib/cps.cmx automath/aut.cmx dual_rg/drgAut.cmi dual_rg/drgAut.cmx: lib/nUri.cmx common/entity.cmx dual_rg/drg.cmx \ lib/cps.cmx automath/aut.cmx dual_rg/drgAut.cmi +dual_rg/drgBrg.cmi: dual_rg/drg.cmx basic_rg/brg.cmx +dual_rg/drgBrg.cmo: common/entity.cmx dual_rg/drg.cmx lib/cps.cmx \ + basic_rg/brg.cmx dual_rg/drgBrg.cmi +dual_rg/drgBrg.cmx: common/entity.cmx dual_rg/drg.cmx lib/cps.cmx \ + basic_rg/brg.cmx dual_rg/drgBrg.cmi toplevel/meta.cmo: common/entity.cmx toplevel/meta.cmx: common/entity.cmx toplevel/metaOutput.cmi: toplevel/meta.cmx diff --git a/helm/software/lambda-delta/dual_rg/Make b/helm/software/lambda-delta/dual_rg/Make index 7d70990f5..ca9618905 100644 --- a/helm/software/lambda-delta/dual_rg/Make +++ b/helm/software/lambda-delta/dual_rg/Make @@ -1 +1 @@ -drg drgOutput drgAut +drg drgOutput drgAut drgBrg diff --git a/helm/software/lambda-delta/dual_rg/drgAut.ml b/helm/software/lambda-delta/dual_rg/drgAut.ml index bf42cc2ab..aa6cf5d97 100644 --- a/helm/software/lambda-delta/dual_rg/drgAut.ml +++ b/helm/software/lambda-delta/dual_rg/drgAut.ml @@ -21,14 +21,10 @@ type qid = D.uri * D.id * D.id list type context = Y.attrs * D.term list -type environment = context H.t - type context_node = qid option (* context node: None = root *) type status = { - henv: environment; (* optimized global environment *) path: D.id list; (* current section path *) - hcnt: environment; (* optimized context *) node: context_node; (* current context node *) nodes: context_node list; (* context node list *) line: int; (* line number *) @@ -40,11 +36,15 @@ type resolver = Local of int let henv_size, hcnt_size = 7000, 4300 (* hash tables initial sizes *) +let henv = H.create henv_size (* optimized global environment *) + +let hcnt = H.create hcnt_size (* optimized context *) + (* Internal functions *******************************************************) -let initial_status mk_uri = { - path = []; node = None; nodes = []; line = 1; mk_uri = mk_uri; - henv = H.create henv_size; hcnt = H.create hcnt_size +let initial_status mk_uri = + H.clear henv; H.clear hcnt; { + path = []; node = None; nodes = []; line = 1; mk_uri = mk_uri } let empty_cnt = [], [] @@ -88,7 +88,7 @@ let relax_opt_qid f st = function | Some qid -> let f qid = f (Some qid) in relax_qid f st qid let resolve_gref err f st qid = - try let cnt = H.find st.henv (uri_of_qid qid) in f qid cnt + try let cnt = H.find henv (uri_of_qid qid) in f qid cnt with Not_found -> err qid let resolve_gref_relaxed f st qid = @@ -99,7 +99,7 @@ let resolve_gref_relaxed f st qid = let get_cnt err f st = function | None -> f empty_cnt | Some qid as node -> - try let cnt = H.find st.hcnt (uri_of_qid qid) in f cnt + try let cnt = H.find hcnt (uri_of_qid qid) in f cnt with Not_found -> err node let get_cnt_relaxed f st = @@ -125,22 +125,20 @@ let rec xlate_term f st lenv = function in xlate_term f st lenv w | A.GRef (name, args) -> + let map1 f = function + | Y.Name (id, _) -> f (A.GRef ((id, true, []), [])) + | _ -> C.err () + in + let map2 f = xlate_term f st lenv in let g qid (a, _) = let gref = D.TGRef ([], uri_of_qid qid) in - let map1 f = xlate_term f st lenv in - let map2 f = function - | Y.Name (id, _) -> D.resolve_lref Cps.err (mk_lref f) id lenv - | _ -> assert false - in - let f tail = - let f = function - | [] -> f gref - | args -> f (D.TAppl ([], args, gref)) - in - let f a = C.list_rev_map_append f map2 a ~tail in - C.list_sub_strict f a args - in - C.list_map f map1 args + match args with + | [] -> f gref + | args -> + let f args = f (D.TAppl ([], args, gref)) in + let f args = f (List.rev_map (map2 C.start) args) in + let f a = C.list_rev_map_append f map1 a ~tail:args in + C.list_sub_strict f a args in let g qid = resolve_gref_relaxed g st qid in let err () = complete_qid g st name in @@ -164,11 +162,9 @@ let xlate_entity err f st = function let f qid = let f cnt = let lenv = lenv_of_cnt cnt in - let f ww = - H.add st.hcnt (uri_of_qid qid) (add_abst cnt name ww); - err {st with node = Some qid} - in - xlate_term f st lenv w + let ww = xlate_term C.start st lenv w in + H.add hcnt (uri_of_qid qid) (add_abst cnt name ww); + err {st with node = Some qid} in get_cnt_relaxed f st in @@ -178,13 +174,11 @@ let xlate_entity err f st = function let a, ws = cnt in let lenv = lenv_of_cnt cnt in let f qid = - let f ww = - H.add st.henv (uri_of_qid qid) cnt; - let b = Y.Abst (D.TBind (a, D.Abst ws, ww)) in - let entity = [Y.Mark st.line], uri_of_qid qid, b in - f {st with line = succ st.line} entity - in - xlate_term f st lenv w + let ww = xlate_term C.start st lenv w in + H.add henv (uri_of_qid qid) cnt; + let b = Y.Abst (D.TBind (a, D.Abst ws, ww)) in + let entity = [Y.Mark st.line], uri_of_qid qid, b in + f {st with line = succ st.line} entity in complete_qid f st (name, true, []) in @@ -194,17 +188,13 @@ let xlate_entity err f st = function let a, ws = cnt in let lenv = lenv_of_cnt cnt in let f qid = - let f ww vv = - H.add st.henv (uri_of_qid qid) cnt; - let b = Y.Abbr (D.TBind (a, D.Abst ws, D.TCast ([], ww, vv))) in - let a = - if trans then [Y.Mark st.line] else [Y.Mark st.line; Y.Priv] - in - let entity = a, uri_of_qid qid, b in - f {st with line = succ st.line} entity - in - let f ww = xlate_term (f ww) st lenv v in - xlate_term f st lenv w + let ww = xlate_term C.start st lenv w in + let vv = xlate_term C.start st lenv v in + H.add henv (uri_of_qid qid) cnt; + let b = Y.Abbr (D.TBind (a, D.Abst ws, D.TCast ([], ww, vv))) in + let a = Y.Mark st.line :: if trans then [] else [Y.Priv] in + let entity = a, uri_of_qid qid, b in + f {st with line = succ st.line} entity in complete_qid f st (name, true, []) in diff --git a/helm/software/lambda-delta/dual_rg/drgBrg.ml b/helm/software/lambda-delta/dual_rg/drgBrg.ml new file mode 100644 index 000000000..2510f8920 --- /dev/null +++ b/helm/software/lambda-delta/dual_rg/drgBrg.ml @@ -0,0 +1,48 @@ +(* + ||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 C = Cps +module Y = Entity +module D = Drg +module B = Brg + +let rec lenv_fold_left map1 map2 x = function + | D.ESort -> x + | D.EBind (tl, a, b) -> lenv_fold_left map1 map2 (map1 x a b) tl + | D.EProj (tl, a, e) -> lenv_fold_left map1 map2 (map2 x a e) tl + +let rec xlate_term f = function + | D.TSort (a, l) -> f (B.Sort (a, l)) + | D.TGRef (a, n) -> f (B.GRef (a, n)) + | D.TLRef (a, _, _) -> let f i = f (B.LRef (a, i)) in Y.apix C.err f a + | D.TCast (a, u, t) -> + let f uu tt = f (B.Cast (a, uu, tt)) in + let f uu = xlate_term (f uu) t in + xlate_term f t + | D.TAppl (a, vs, t) -> + let map f v tt = let f vv = f (B.Appl (a, vv, tt)) in xlate_term f v in + let f tt = C.list_fold_right f map vs tt in + xlate_term f t + | D.TProj (ap, e, D.TCast (ac, u, t)) -> + xlate_term f (D.TCast (ac, D.TProj (ap, e, u), D.TProj (ap, e, t))) + | D.TProj (a, e, t) -> + let f tt = f (lenv_fold_left xlate_bind xlate_proj tt e) in + xlate_term f t + | D.TBind (a, b, t) -> + let f tt = f (xlate_bind tt a b) in xlate_term f t + +and xlate_bind x a b = assert false + +and xlate_proj x _ e = + lenv_fold_left xlate_bind xlate_proj x e + +let brg_of_drg f t = + f (xlate_term C.start t) diff --git a/helm/software/lambda-delta/dual_rg/drgBrg.mli b/helm/software/lambda-delta/dual_rg/drgBrg.mli new file mode 100644 index 000000000..900dad95a --- /dev/null +++ b/helm/software/lambda-delta/dual_rg/drgBrg.mli @@ -0,0 +1,12 @@ +(* + ||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_______________________________________________________________ *) + +val brg_of_drg: (Brg.term -> 'a) -> Drg.term -> 'a diff --git a/helm/software/lambda-delta/dual_rg/drgOutput.ml b/helm/software/lambda-delta/dual_rg/drgOutput.ml index 17def3850..e35e82f4e 100644 --- a/helm/software/lambda-delta/dual_rg/drgOutput.ml +++ b/helm/software/lambda-delta/dual_rg/drgOutput.ml @@ -16,12 +16,9 @@ module Y = Entity module X = Library module D = Drg -let list_iter map l out tab = - let rec aux f = function - | [] -> f () - | hd :: tl -> aux (fun () -> map hd out tab; f ()) tl - in - aux C.start l +let rec list_iter map l out tab = match l with + | [] -> () + | hd :: tl -> map hd out tab; list_iter map tl out tab let list_rev_iter map e ns l out tab = let rec aux err f e = function