+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 (Cic.Name n,convert_term k s, convert_term (k+1) t)
+ Cic.Prod (nn_2_on n,convert_term k s, convert_term (k+1) t)
| NCic.Lambda (n,s,t) ->
- Cic.Lambda(Cic.Name n,convert_term k s, convert_term (k+1) t)
+ Cic.Lambda(nn_2_on n,convert_term k s, convert_term (k+1) t)
| NCic.LetIn (n,_,s,t) ->
- Cic.LetIn (Cic.Name n,convert_term k s, convert_term (k+1) t)
+ Cic.LetIn (nn_2_on n,convert_term k 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.Set -> Cic.Sort Cic.Set
let convert_nobj = function
| u,_,_,_,NCic.Constant (_, name, Some bo, ty, _) ->
- Cic.Constant (name, Some (convert_term u 0 bo), convert_term u 0 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, _) ->
- Cic.Constant (name, None, convert_term u 0 ty, [],[])
+ [NUri.ouri_of_nuri u,Cic.Constant (name, None, convert_term u 0 ty, [],[])]
| u,_,_,_,NCic.Fixpoint (is_fix, fl, _) ->
- Cic.Constant (UriManager.name_of_uri (NUri.ouri_of_nuri u),
- Some (convert_fix is_fix u 0 fl),
- convert_term u 0 (let _,_,_,ty,_ = List.hd fl in ty), [], [])
+ List.map
+ (fun nth ->
+ let name = UriManager.name_of_uri (NUri.ouri_of_nuri u) 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
;;
| 0 -> []
| n ->
(match List.nth ctx (n+bound) with
- | Fix (refe, _, _) when n < primo_ce_dopo_fix -> (NCic.Const refe)
+ | Fix (refe, _, _) when (n+bound) < primo_ce_dopo_fix -> (NCic.Const refe)
| Fix _ | Ce _ -> NCic.Rel (n+bound)) :: aux (n-1)
in
NCic.Appl (t:: aux free)
let convert_term uri t =
let rec aux octx (ctx : ctx list) n_fix uri = function
| Cic.CoFix (k, fl) ->
+ let buri =
+ UriManager.uri_of_string
+ (UriManager.buri_of_uri uri^"/"^
+ UriManager.name_of_uri uri ^ string_of_int (List.length ctx)^".con")
+ in
let bctx, fixpoints_tys, tys, _ =
List.fold_right
(fun (name,ty,_) (ctx, fixpoints, tys, idx) ->
let ty, fixpoints_ty = aux octx ctx n_fix uri ty in
- let r = NReference.reference_of_ouri uri(NReference.CoFix idx) in
+ let r = NReference.reference_of_ouri buri(NReference.CoFix idx) in
ctx @ [Fix (r,name,ty)], fixpoints_ty @ fixpoints,ty::tys,idx+1)
- fl (ctx, [], [], 0)
- in
- let buri =
- UriManager.uri_of_string
- (UriManager.string_of_uri uri^string_of_int (List.length ctx)^".con")
+ fl ([], [], [], 0)
in
+ let bctx = bctx @ ctx in
let n_fl = List.length fl in
let boctx,_ =
List.fold_left
let fl, fixpoints =
List.fold_right2
(fun (name,_,bo) ty (l,fixpoints) ->
- let bo, fixpoints_bo = aux boctx bctx (n_fix + n_fl) buri bo in
+ let bo, fixpoints_bo = aux boctx bctx n_fl buri bo in
(([],name,~-1,splat true ctx ty, splat false ctx bo)::l),
fixpoints_bo @ fixpoints)
fl tys ([],fixpoints_tys)
in
let obj =
- NUri.nuri_of_ouri uri,0,[],[],
+ NUri.nuri_of_ouri buri,0,[],[],
NCic.Fixpoint (false, fl, (`Generated, `Definition))
in
- splat_args ctx
- (NCic.Const (NReference.reference_of_ouri uri (NReference.CoFix k))),
- obj::fixpoints
+ splat_args bctx
+ (NCic.Const (NReference.reference_of_ouri buri (NReference.CoFix k))),
+ fixpoints @ [obj]
| Cic.Fix (k, fl) ->
+ let buri =
+ UriManager.uri_of_string
+ (UriManager.buri_of_uri uri^"/"^
+ UriManager.name_of_uri uri ^ string_of_int (List.length ctx)^".con")
+ in
let rno = ref 0 in
let bctx, fixpoints_tys, tys, _ =
List.fold_right
let ty, fixpoints_ty = aux octx ctx n_fix uri ty in
if idx = k then rno := recno;
let r =
- NReference.reference_of_ouri uri (NReference.Fix (idx,recno))
+ NReference.reference_of_ouri buri (NReference.Fix (idx,recno))
in
ctx @ [Fix (r,name,ty)], fixpoints_ty@fixpoints,ty::tys,idx+1)
- fl (ctx, [], [], 0)
- in
- let buri =
- UriManager.uri_of_string
- (UriManager.string_of_uri uri^string_of_int (List.length ctx)^".con")
+ fl ([], [], [], 0)
in
+ let bctx = bctx @ ctx in
let n_fl = List.length fl in
let boctx,_ =
List.fold_left
let fl, fixpoints =
List.fold_right2
(fun (name,rno,_,bo) ty (l,fixpoints) ->
- let bo, fixpoints_bo = aux boctx bctx (n_fix + n_fl) buri bo in
- let rno = rno + List.length ctx - n_fix in
+ let bo, fixpoints_bo = aux boctx bctx n_fl buri bo in
+ let _, free, _ = context_tassonomy bctx in
+ let rno = rno + free in
(([],name,rno,splat true ctx ty, splat false ctx bo)::l),
fixpoints_bo @ fixpoints)
fl tys ([],fixpoints_tys)
in
let obj =
- NUri.nuri_of_ouri uri,0,[],[],
+ NUri.nuri_of_ouri buri,0,[],[],
NCic.Fixpoint (true, fl, (`Generated, `Definition))
in
- splat_args ctx
+ splat_args bctx
(NCic.Const
- (NReference.reference_of_ouri uri (NReference.Fix (k,!rno)))),
- obj::fixpoints
+ (NReference.reference_of_ouri buri (NReference.Fix (k,!rno)))),
+ fixpoints @ [obj]
| Cic.Rel n ->
- let _, _, primo_ce_dopo_fix = context_tassonomy ctx in
- (match List.nth ctx n with
+ let bound, _, primo_ce_dopo_fix = context_tassonomy ctx in
+ (match List.nth ctx (n-1) with
| Fix (r,_,_) when n < primo_ce_dopo_fix ->
splat_args ctx (NCic.Const r), []
- | Fix (_,_,_) | Ce _ -> NCic.Rel (n-n_fix), [])
+ | Ce _ when n <= bound -> NCic.Rel n, []
+ | Fix _ (* BUG 3 fix nested *)
+ | Ce _ -> NCic.Rel (n-n_fix), [])
| Cic.Lambda (name, (s as old_s), t) ->
let s, fixpoints_s = aux octx ctx n_fix uri s in
let ctx = Ce (cn_to_s name, NCic.Decl s) :: ctx in
let convert_obj uri obj =
let o, fixpoints = convert_obj_aux uri obj in
let obj = NUri.nuri_of_ouri uri,0, [], [], o in
- obj, fixpoints
+ fixpoints @ [obj]
;;