]> matita.cs.unibo.it Git - helm.git/blob - helm/software/components/ng_kernel/nCic2OCic.ml
added iterators over NCic terms
[helm.git] / helm / software / components / ng_kernel / nCic2OCic.ml
1 let nn_2_on = function
2   | "_" -> Cic.Anonymous
3   | s -> Cic.Name s
4 ;;
5
6 let convert_term uri n_fl t =
7  let rec convert_term k = function (* pass k along *)
8  | NCic.Rel i -> Cic.Rel i
9  | NCic.Meta _ -> assert false
10  | NCic.Appl l -> Cic.Appl (List.map (convert_term k) l)
11  | NCic.Prod (n,s,t) -> 
12      Cic.Prod (nn_2_on n,convert_term k s, convert_term (k+1) t)
13  | NCic.Lambda  (n,s,t) -> 
14      Cic.Lambda(nn_2_on n,convert_term k s, convert_term (k+1) t)
15  | NCic.LetIn (n,ty_s,s,t) -> 
16      Cic.LetIn (nn_2_on n,convert_term k s,convert_term k ty_s, convert_term (k+1) t)
17  | NCic.Sort NCic.Prop -> Cic.Sort Cic.Prop 
18  | NCic.Sort NCic.CProp -> Cic.Sort Cic.CProp 
19  | NCic.Sort NCic.Set -> Cic.Sort Cic.Set 
20  | NCic.Sort (NCic.Type _) -> Cic.Sort (Cic.Type (CicUniv.fresh ()))
21  | NCic.Implicit _ -> assert false
22  | NCic.Const (NReference.Ref (_,u,NReference.Ind i)) -> 
23      Cic.MutInd (NUri.ouri_of_nuri u,i,[])
24  | NCic.Const (NReference.Ref (_,u,NReference.Con (i,j))) -> 
25      Cic.MutConstruct (NUri.ouri_of_nuri u,i,j,[])
26  | NCic.Const (NReference.Ref (_,u,NReference.Def))
27  | NCic.Const (NReference.Ref (_,u,NReference.Decl)) ->
28      Cic.Const (NUri.ouri_of_nuri u,[])
29  | NCic.Match (NReference.Ref (_,u,NReference.Ind i),oty,t,pl) ->
30      Cic.MutCase (NUri.ouri_of_nuri u,i, convert_term k oty, convert_term k t,
31        List.map (convert_term k) pl)
32  | NCic.Const (NReference.Ref (_,u,NReference.Fix (i,_))) 
33  | NCic.Const (NReference.Ref (_,u,NReference.CoFix i)) ->
34     if NUri.eq u uri then             
35       Cic.Rel (n_fl - i + k)
36     else
37      let ouri = NUri.ouri_of_nuri u in
38      let ouri =
39       UriManager.uri_of_string 
40        (UriManager.buri_of_uri ouri ^ "/" ^
41         UriManager.name_of_uri ouri ^ string_of_int i ^ ".con") in
42       Cic.Const (ouri,[])
43  | _ -> assert false
44  in
45   convert_term 0 t
46 ;;
47
48 let convert_fix is_fix uri k fl = 
49   let n_fl = List.length fl in
50   if is_fix then 
51     let fl = 
52       List.map
53       (fun (_, name,recno,ty,bo) -> 
54         name, recno, convert_term uri n_fl ty, convert_term uri n_fl bo)
55       fl
56     in 
57      Cic.Fix (k, fl) 
58   else 
59     let fl = 
60       List.map
61       (fun (_, name,_,ty,bo) -> 
62         name, convert_term uri n_fl ty, convert_term uri n_fl bo)
63       fl
64     in 
65      Cic.CoFix (k, fl) 
66 ;;
67
68 let convert_nobj = function 
69  | u,_,_,_,NCic.Constant (_, name, Some bo, ty, _) ->
70      [NUri.ouri_of_nuri u,Cic.Constant 
71         (name, Some (convert_term u 0 bo), convert_term u 0 ty, [],[])]
72  | u,_,_,_,NCic.Constant (_, name,  None, ty, _) ->
73      [NUri.ouri_of_nuri u,Cic.Constant (name, None, convert_term u 0 ty, [],[])]
74  | u,_,_,_,NCic.Fixpoint (is_fix, fl, _) ->
75      List.map 
76       (fun nth ->
77         let name =
78          UriManager.name_of_uri (NUri.ouri_of_nuri u) ^ string_of_int nth in
79         let buri = UriManager.buri_of_uri (NUri.ouri_of_nuri u) in
80         let uri = UriManager.uri_of_string (buri ^"/"^name^".con") in
81         uri,
82         Cic.Constant (name, 
83          Some (convert_fix is_fix u nth fl), 
84           convert_term u 0 (let _,_,_,ty,_ = List.hd fl in ty), [], []))
85      (let rec seq = function 0 -> [0]|n -> n::seq (n-1) in 
86       seq (List.length fl-1))
87  | _,_,_,_,NCic.Inductive _ -> assert false
88 ;;