X-Git-Url: http://matita.cs.unibo.it/gitweb/?p=helm.git;a=blobdiff_plain;f=components%2Fng_kernel%2FnCic2OCic.ml;fp=components%2Fng_kernel%2FnCic2OCic.ml;h=4686922df1afe6a619e2558b01fdc228d1186477;hp=0000000000000000000000000000000000000000;hb=f61af501fb4608cc4fb062a0864c774e677f0d76;hpb=58ae1809c352e71e7b5530dc41e2bfc834e1aef1 diff --git a/components/ng_kernel/nCic2OCic.ml b/components/ng_kernel/nCic2OCic.ml new file mode 100644 index 000000000..4686922df --- /dev/null +++ b/components/ng_kernel/nCic2OCic.ml @@ -0,0 +1,87 @@ +let nn_2_on = function + | "_" -> Cic.Anonymous + | s -> Cic.Name s +;; + +let convert_term uri n_fl t = + let rec convert_term k = function (* pass k along *) + | NCic.Rel i -> Cic.Rel i + | NCic.Meta _ -> assert false + | NCic.Appl l -> Cic.Appl (List.map (convert_term k) l) + | NCic.Prod (n,s,t) -> + Cic.Prod (nn_2_on n,convert_term k s, convert_term (k+1) t) + | NCic.Lambda (n,s,t) -> + Cic.Lambda(nn_2_on n,convert_term k s, convert_term (k+1) t) + | NCic.LetIn (n,ty_s,s,t) -> + Cic.LetIn (nn_2_on n,convert_term k s,convert_term k ty_s, convert_term (k+1) t) + | NCic.Sort NCic.Prop -> Cic.Sort Cic.Prop + | NCic.Sort NCic.CProp -> Cic.Sort Cic.CProp + | NCic.Sort (NCic.Type _) -> Cic.Sort (Cic.Type (CicUniv.fresh ())) + | NCic.Implicit _ -> assert false + | NCic.Const (NReference.Ref (_,u,NReference.Ind i)) -> + Cic.MutInd (NUri.ouri_of_nuri u,i,[]) + | NCic.Const (NReference.Ref (_,u,NReference.Con (i,j))) -> + Cic.MutConstruct (NUri.ouri_of_nuri u,i,j,[]) + | NCic.Const (NReference.Ref (_,u,NReference.Def)) + | NCic.Const (NReference.Ref (_,u,NReference.Decl)) -> + Cic.Const (NUri.ouri_of_nuri u,[]) + | NCic.Match (NReference.Ref (_,u,NReference.Ind i),oty,t,pl) -> + Cic.MutCase (NUri.ouri_of_nuri u,i, convert_term k oty, convert_term k t, + List.map (convert_term k) pl) + | NCic.Const (NReference.Ref (_,u,NReference.Fix (i,_))) + | NCic.Const (NReference.Ref (_,u,NReference.CoFix i)) -> + if NUri.eq u uri then + Cic.Rel (n_fl - i + k) + else + let ouri = NUri.ouri_of_nuri u in + let ouri = + UriManager.uri_of_string + (UriManager.buri_of_uri ouri ^ "/" ^ + UriManager.name_of_uri ouri ^ string_of_int i ^ ".con") in + Cic.Const (ouri,[]) + | _ -> assert false + in + convert_term 0 t +;; + +let convert_fix is_fix uri k fl = + let n_fl = List.length fl in + if is_fix then + let fl = + List.map + (fun (_, name,recno,ty,bo) -> + name, recno, convert_term uri n_fl ty, convert_term uri n_fl bo) + fl + in + Cic.Fix (k, fl) + else + let fl = + List.map + (fun (_, name,_,ty,bo) -> + name, convert_term uri n_fl ty, convert_term uri n_fl bo) + fl + in + Cic.CoFix (k, fl) +;; + +let convert_nobj = function + | u,_,_,_,NCic.Constant (_, name, Some bo, ty, _) -> + [NUri.ouri_of_nuri u,Cic.Constant + (name, Some (convert_term u 0 bo), convert_term u 0 ty, [],[])] + | u,_,_,_,NCic.Constant (_, name, None, ty, _) -> + [NUri.ouri_of_nuri u,Cic.Constant (name, None, convert_term u 0 ty, [],[])] + | u,_,_,_,NCic.Fixpoint (is_fix, fl, _) -> + List.map + (fun nth -> + let name = + UriManager.name_of_uri (NUri.ouri_of_nuri u) ^ string_of_int nth in + let buri = UriManager.buri_of_uri (NUri.ouri_of_nuri u) in + let uri = UriManager.uri_of_string (buri ^"/"^name^".con") in + uri, + Cic.Constant (name, + Some (convert_fix is_fix u nth fl), + convert_term u 0 (let _,_,_,ty,_ = List.hd fl in ty), [], [])) + (let rec seq = function 0 -> [0]|n -> n::seq (n-1) in + seq (List.length fl-1)) + | _,_,_,_,NCic.Inductive _ -> assert false +;;