X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;f=helm%2Fsoftware%2Fcomponents%2Facic_procedural%2FproceduralHelpers.ml;h=a9fa6473f280ac7e12fc50422181b99cf0a248cf;hb=5b45f78ed4293ebbe8cc73ad925bca11a300d021;hp=54e8ebe050fb5a59cad06150b1c4238daa9da784;hpb=9ece6e414b255f519426d5643782af4f7dfc584f;p=helm.git diff --git a/helm/software/components/acic_procedural/proceduralHelpers.ml b/helm/software/components/acic_procedural/proceduralHelpers.ml index 54e8ebe05..a9fa6473f 100644 --- a/helm/software/components/acic_procedural/proceduralHelpers.ml +++ b/helm/software/components/acic_procedural/proceduralHelpers.ml @@ -67,6 +67,19 @@ let mk_fresh_name context = function (* helper functions *********************************************************) +let rec list_fold_right_cps g map l a = + match l with + | [] -> g a + | hd :: tl -> + let h a = map g hd a in + list_fold_right_cps h map tl a + +let rec list_fold_left_cps g map a = function + | [] -> g a + | hd :: tl -> + let h a = list_fold_left_cps g map a tl in + map h a hd + let rec list_map_cps g map = function | [] -> g [] | hd :: tl -> @@ -83,31 +96,46 @@ let compose f g x = f (g x) let fst3 (x, _, _) = x let refine c t = - try let t, _, _, _ = Rf.type_of_aux' [] c t Un.oblivion_ugraph in t - with e -> - Printf.eprintf "REFINE EROR: %s\n" (Printexc.to_string e); + let error e = Printf.eprintf "Ref: context: %s\n" (Pp.ppcontext c); Printf.eprintf "Ref: term : %s\n" (Pp.ppterm t); raise e + in + try let t, _, _, _ = Rf.type_of_aux' [] c t Un.default_ugraph in t with + | Rf.RefineFailure s as e -> + Printf.eprintf "REFINE FAILURE: %s\n" (Lazy.force s); + error e + | e -> + Printf.eprintf "REFINE ERROR: %s\n" (Printexc.to_string e); + error e -let get_type c t = - try let ty, _ = TC.type_of_aux' [] c t Un.oblivion_ugraph in ty - with e -> - Printf.eprintf "TC: context: %s\n" (Pp.ppcontext c); - Printf.eprintf "TC: term : %s\n" (Pp.ppterm t); - raise e +let get_type msg c t = + let log s = + prerr_endline ("TC: " ^ s); + prerr_endline ("TC: context: " ^ Pp.ppcontext c); + prerr_string "TC: term : "; Ut.pp_term prerr_string [] c t; + prerr_newline (); prerr_endline ("TC: location: " ^ msg) + in + try let ty, _ = TC.type_of_aux' [] c t Un.default_ugraph in ty with + | TC.TypeCheckerFailure s as e -> + log ("failure: " ^ Lazy.force s); raise e + | TC.AssertFailure s as e -> + log ("assert : " ^ Lazy.force s); raise e let get_tail c t = match PEH.split_with_whd (c, t) with | (_, hd) :: _, _ -> hd | _ -> assert false -let is_proof c t = - match get_tail c (get_type c (get_type c t)) with +let is_prop c t = + match get_tail c (get_type "is_prop" c t) with | C.Sort C.Prop -> true | C.Sort _ -> false | _ -> assert false +let is_proof c t = + is_prop c (get_type "is_prop" c t) + let is_sort = function | C.Sort _ -> true | _ -> false @@ -126,18 +154,28 @@ let is_not_atomic = function let is_atomic t = not (is_not_atomic t) let get_ind_type uri tyno = - match E.get_obj Un.oblivion_ugraph uri with + match E.get_obj Un.default_ugraph uri with | C.InductiveDefinition (tys, _, lpsno, _), _ -> lpsno, List.nth tys tyno | _ -> assert false +let get_ind_names uri tno = +try + let ts = match E.get_obj Un.default_ugraph uri with + | C.InductiveDefinition (ts, _, _, _), _ -> ts + | _ -> assert false + in + match List.nth ts tno with + | (_, _, _, cs) -> List.map fst cs +with Invalid_argument _ -> failwith "get_ind_names" + let get_default_eliminator context uri tyno ty = let _, (name, _, _, _) = get_ind_type uri tyno in - let ext = match get_tail context (get_type context ty) with - | C.Sort C.Prop -> "_ind" - | C.Sort C.Set -> "_rec" - | C.Sort (C.CProp _) -> "_rect" - | C.Sort (C.Type _) -> "_rect" - | t -> + let ext = match get_tail context (get_type "get_def_elim" context ty) with + | C.Sort C.Prop -> "_ind" + | C.Sort C.Set -> "_rec" + | C.Sort (C.CProp _) -> "_rect" + | C.Sort (C.Type _) -> "_rect" + | t -> Printf.eprintf "CicPPP get_default_eliminator: %s\n" (Pp.ppterm t); assert false in @@ -146,13 +184,13 @@ let get_default_eliminator context uri tyno ty = C.Const (uri, []) let get_ind_parameters c t = - let ty = get_type c t in + let ty = get_type "get_ind_pars 1" c t in let ps = match get_tail c ty with | C.MutInd _ -> [] | C.Appl (C.MutInd _ :: args) -> args | _ -> assert false in - let disp = match get_tail c (get_type c ty) with + let disp = match get_tail c (get_type "get_ind_pars 2" c ty) with | C.Sort C.Prop -> 0 | C.Sort _ -> 1 | _ -> assert false @@ -171,6 +209,20 @@ let occurs c ~what ~where = let _ = PER.replace_lifting ~equality ~context ~what ~with_what ~where in !result +let name_of_uri uri tyno cno = + let get_ind_type tys tyno = + let s, _, _, cs = List.nth tys tyno in s, cs + in + match (fst (E.get_obj Un.default_ugraph uri)), tyno, cno with + | C.Variable (s, _, _, _, _), _, _ -> s + | C.Constant (s, _, _, _, _), _, _ -> s + | C.InductiveDefinition (tys, _, _, _), Some i, None -> + let s, _ = get_ind_type tys i in s + | C.InductiveDefinition (tys, _, _, _), Some i, Some j -> + let _, cs = get_ind_type tys i in + let s, _ = List.nth cs (pred j) in s + | _ -> assert false + (* Ensuring Barendregt convenction ******************************************) let rec add_entries map c = function