- let name,height,metasenv,subst,obj = status.pstatus in
- let db = NCicUnifHint.db () in (* XXX fixme *)
- let coercion_db = NCicCoercion.db () in
- let look_for_coercion = NCicCoercion.look_for_coercion coercion_db in
- let metasenv, subst, t, ty =
- NCicRefiner.typeof db ~look_for_coercion metasenv subst ctx term ty
- in
- { status with pstatus = (name,height,metasenv,subst,obj) },
- (nt,ctx,t), (ne,ctx,ty)
-;;
-
-let get_goal (status : lowtac_status) (g : int) =
- let _,_,metasenv,_,_ = status.pstatus in
- List.assoc g metasenv
-;;
-
-let instantiate status i t =
- let (goalname, context, _ as ety) = get_goal status i in
- let status, (_,_,t), (_,_,ty) = refine status (`Term ety) t (Some ety) in
-
- let name,height,metasenv,subst,obj = status.pstatus in
- let metasenv = List.filter (fun j,_ -> j <> i) metasenv in
- let subst = (i, (goalname, context, t, ty)) :: subst in
- { status with pstatus = (name,height,metasenv,subst,obj) }
-;;
-
-let mk_meta status ?name where bo_or_ty =
- let n,h,metasenv,subst,o = status.pstatus in
- let ctx = match where with `Ctx c -> c | `Term (_,c,_) -> c in
- match bo_or_ty with
- | `Decl ty ->
- let _,_,ty = relocate ctx ty in
- let metasenv, _, instance, _ =
- NCicMetaSubst.mk_meta ?name metasenv ctx (`WithType ty)
- in
- let status = { status with pstatus = n,h,metasenv,subst,o } in
- status, (None,ctx,instance)
- | `Def bo ->
- let _,_,ty = typeof status (`Ctx ctx) bo in
- let metasenv, metano, instance, _ =
- NCicMetaSubst.mk_meta ?name metasenv ctx (`WithType ty)
- in
- let status = { status with pstatus = n,h,metasenv,subst,o } in
- let status = instantiate status metano bo in
- status, (None,ctx,instance)
-;;
-
-let select_term low_status (name,context,term) (wanted,path) =
- let found status ctx t wanted =
- (* we could lift wanted step-by-step *)
- try true, unify status (`Ctx ctx) (None,ctx,t) wanted
- with
- | NCicUnification.UnificationFailure _
- | NCicUnification.Uncertain _ -> false, status
- in
- let match_term status ctx (wanted : cic_term) t =
- let rec aux ctx status t =
- let b, status = found status ctx t wanted in
- if b then
- let status, (_,_,t) =
- mk_meta status ~name:in_scope_tag (`Ctx ctx) (`Def (None,ctx,t))
- in
- status, t
- else NCicUntrusted.map_term_fold_a (fun e c -> e::c) ctx aux status t
- in
- aux ctx status t
- in
- let rec select status ctx pat cic =
- match pat, cic with
- | NCic.LetIn (_,t1,s1,b1), NCic.LetIn (n,t2,s2,b2) ->
- let status, t = select status ctx t1 t2 in
- let status, s = select status ctx s1 s2 in
- let ctx = (n, NCic.Def (s2,t2)) :: ctx in
- let status, b = select status ctx b1 b2 in
- status, NCic.LetIn (n,t,s,b)
- | NCic.Lambda (_,s1,t1), NCic.Lambda (n,s2,t2) ->
- let status, s = select status ctx s1 s2 in
- let ctx = (n, NCic.Decl s2) :: ctx in
- let status, t = select status ctx t1 t2 in
- status, NCic.Lambda (n,s,t)
- | NCic.Prod (_,s1,t1), NCic.Prod (n,s2,t2) ->
- let status, s = select status ctx s1 s2 in
- let ctx = (n, NCic.Decl s2) :: ctx in
- let status, t = select status ctx t1 t2 in
- status, NCic.Prod (n,s,t)
- | NCic.Appl l1, NCic.Appl l2 ->
- let status, l =
- List.fold_left2
- (fun (status,l) x y ->
- let status, x = select status ctx x y in
- status, x::l)
- (status,[]) l1 l2
- in
- status, NCic.Appl (List.rev l)
- | NCic.Match (_,ot1,t1,pl1), NCic.Match (u,ot2,t2,pl2) ->
- let status, t = select status ctx t1 t2 in
- let status, ot = select status ctx ot1 ot2 in
- let status, pl =
- List.fold_left2
- (fun (status,l) x y ->
- let status, x = select status ctx x y in
- status, x::l)
- (status,[]) pl1 pl2
- in
- status, NCic.Match (u,ot,t,List.rev pl)
- | NCic.Implicit `Hole, t ->
- (match wanted with
- | Some wanted ->
- let status, wanted = disambiguate status wanted None (`Ctx ctx) in
- match_term status ctx wanted t
- | None -> match_term status ctx (None,ctx,t) t)
- | NCic.Implicit _, t -> status, t
- | _,t ->
- fail (lazy ("malformed pattern: " ^ NCicPp.ppterm ~metasenv:[]
- ~context:[] ~subst:[] pat))
- in
- let status, term = select low_status context path term in
- let term = (name, context, term) in
- mk_meta status ~name:out_scope_tag (`Ctx context) (`Def term)
-;;
-
-let select ~where status goal =
- let name, _, _ as goalty = get_goal status goal in
- let (wanted,_,where) = GrafiteDisambiguate.disambiguate_npattern where in
- let path =
- match where with None -> NCic.Implicit `Term | Some where -> where