;;
let inject_unification_hint =
- let basic_eval_unification_hint (t,n) ~refresh_uri_in_term =
+ let basic_eval_unification_hint (t,n)
+ ~refresh_uri_in_universe
+ ~refresh_uri_in_term
+ =
let t = refresh_uri_in_term t in basic_eval_unification_hint (t,n)
in
NRstatus.Serializer.register "unification_hints" basic_eval_unification_hint
let t = NCicUntrusted.apply_subst subst [] t in
let status = basic_eval_unification_hint (t,n) status in
let dump = inject_unification_hint (t,n)::status#dump in
+ let status = status#set_dump dump in
+ status,`New []
+;;
+
+let basic_eval_ncoercion (name,t,s,d,p,a) status =
+ NCicCoercion.index_coercion status t s d a p
+;;
+
+let inject_ncoercion =
+ let basic_eval_ncoercion x ~refresh_uri_in_universe ~refresh_uri_in_term =
+ basic_eval_ncoercion x
+ in
+ NRstatus.Serializer.register "ncoercion" basic_eval_ncoercion
+;;
+
+let eval_ncoercion status name t ty (id,src) tgt =
+
+ let metasenv,subst,status,ty =
+ GrafiteDisambiguate.disambiguate_nterm None status [] [] [] ("",0,ty) in
+ assert (metasenv=[]);
+ let ty = NCicUntrusted.apply_subst subst [] ty in
+ let metasenv,subst,status,t =
+ GrafiteDisambiguate.disambiguate_nterm (Some ty) status [] [] [] ("",0,t) in
+ assert (metasenv=[]);
+ let t = NCicUntrusted.apply_subst subst [] t in
+
+ let src, cpos =
+ let rec aux cpos ctx = function
+ | NCic.Prod (name,ty,bo) ->
+ if name <> id then aux (cpos+1) ((name,NCic.Decl ty)::ctx) bo
+ else
+ let metasenv,subst,status,src =
+ GrafiteDisambiguate.disambiguate_nterm
+ None status ctx [] [] ("",0,src) in
+ let src = NCicUntrusted.apply_subst subst [] src in
+ (* HMM: ma tanto se ignori l'informazione, a che serve?? *)
+ let _ = NCicUnification.unify status metasenv subst ctx ty src in
+ src, cpos
+ | _ -> assert false
+ in
+ aux 0 [] ty
+ in
+ let tgt, arity =
+ let metasenv,subst,status,tgt =
+ GrafiteDisambiguate.disambiguate_nterm
+ None status [] [] [] ("",0,tgt) in
+ let tgt = NCicUntrusted.apply_subst subst [] tgt in
+ (* CHECK *)
+ let rec count_prod = function
+ | NCic.Prod (_,_,x) -> 1 + count_prod x
+ | _ -> 0
+ in
+ tgt, count_prod tgt
+ in
+
+ let status = basic_eval_ncoercion (name,t,src,tgt,cpos,arity) status in
+ let dump = inject_ncoercion (name,t,src,tgt,cpos,arity)::status#dump in
+ let status = status#set_dump dump in
+ status,`New []
+;;
+
+let basic_eval_add_constraint (s,u1,u2) status =
+ NCicLibrary.add_constraint status s u1 u2
+;;
+
+let inject_constraint =
+ let basic_eval_add_constraint (s,u1,u2)
+ ~refresh_uri_in_universe
+ ~refresh_uri_in_term
+ =
+ let u1 = refresh_uri_in_universe u1 in
+ let u2 = refresh_uri_in_universe u2 in
+ basic_eval_add_constraint (s,u1,u2)
+ in
+ NRstatus.Serializer.register "constraints" basic_eval_add_constraint
+;;
+
+let eval_add_constraint status s u1 u2 =
+ let status = basic_eval_add_constraint (s,u1,u2) status in
+ let dump = inject_constraint (s,u1,u2)::status#dump in
let status = status#set_dump dump in
status,`Old []
;;
| GrafiteAst.Merge _ -> NTactics.merge_tac
;;
-let rec eval_ng_tac (text, prefix_len, tac) =
+let eval_ng_tac tac =
+ let rec aux f (text, prefix_len, tac) =
match tac with
| GrafiteAst.NApply (_loc, t) -> NTactics.apply_tac (text,prefix_len,t)
| GrafiteAst.NAssert (_loc, seqs) ->
| GrafiteAst.NUnfocus _ -> NTactics.unfocus_tac
| GrafiteAst.NWildcard _ -> NTactics.wildcard_tac
| GrafiteAst.NTry (_,tac) -> NTactics.try_tac
- (eval_ng_tac (text, prefix_len, tac))
+ (aux f (text, prefix_len, tac))
| GrafiteAst.NAssumption _ -> NTactics.assumption_tac
+ | GrafiteAst.NBlock (_,l) ->
+ NTactics.block_tac (List.map (fun x -> aux f (text,prefix_len,x)) l)
+ |GrafiteAst.NRepeat (_,tac) ->
+ NTactics.repeat_tac (f f (text, prefix_len, tac))
+ in
+ aux aux tac (* trick for non uniform recursion call *)
;;
let subst_metasenv_and_fix_names status =
let rec eval_ncommand opts status (text,prefix_len,cmd) =
match cmd with
| GrafiteAst.UnificationHint (loc, t, n) -> eval_unification_hint status t n
+ | GrafiteAst.NCoercion (loc, name, t, ty, source, target) ->
+ eval_ncoercion status name t ty source target
| GrafiteAst.NQed loc ->
if status#ng_mode <> `ProofMode then
raise (GrafiteTypes.Command_error "Not in proof mode")
let obj_kind =
NCicUntrusted.map_obj_kind
(NCicUntrusted.apply_subst subst []) obj_kind in
- let height = NCicTypeChecker.height_of_obj_kind uri obj_kind in
+ let height = NCicTypeChecker.height_of_obj_kind uri [] obj_kind in
(* fix the height inside the object *)
let rec fix () = function
| NCic.Const (NReference.Ref (u,spec)) when NUri.eq u uri ->
| _ -> obj_kind
in
let obj = uri,height,[],[],obj_kind in
- NCicTypeChecker.typecheck_obj obj;
- let status = NCicLibrary.add_obj status uri obj in
+ let status = NCicLibrary.add_obj status obj in
let objs = NCicElim.mk_elims obj in
let timestamp,uris_rev =
List.fold_left
(fun (status,uris_rev) (uri,_,_,_,_) as obj ->
- NCicTypeChecker.typecheck_obj obj;
- let status = NCicLibrary.add_obj status uri obj in
+ let status = NCicLibrary.add_obj status obj in
status,uri::uris_rev
) (status,[]) objs in
let uris = uri::List.rev uris_rev in
eval_ncommand opts status ("",0,GrafiteAst.NQed Stdpp.dummy_loc)
| _ -> status,`New [])
| GrafiteAst.NUnivConstraint (loc,strict,u1,u2) ->
- NCicEnvironment.add_constraint strict [false,u1] [false,u2];
- status, `New [u1;u2]
+ eval_add_constraint status strict [false,u1] [false,u2]
;;
let rec eval_command = {ec_go = fun ~disambiguate_command opts status
LibraryObjects.set_default what uris;
GrafiteTypes.add_moo_content [cmd] status,`Old []
| GrafiteAst.Drop loc -> raise Drop
- | GrafiteAst.Include (loc, _, baseuri) ->
- let moopath_rw, moopath_r =
- LibraryMisc.obj_file_of_baseuri
- ~must_exist:false ~baseuri ~writable:true,
- LibraryMisc.obj_file_of_baseuri
- ~must_exist:false ~baseuri ~writable:false
- in
- let moopath =
- if Sys.file_exists moopath_r then moopath_r else
- if Sys.file_exists moopath_rw then moopath_rw else
- raise (IncludedFileNotCompiled (moopath_rw,baseuri))
- in
- let status = eval_from_moo.efm_go status moopath in
+ | GrafiteAst.Include (loc, mode, new_or_old, baseuri) ->
+ (* Old Include command is not recursive; new one is *)
let status =
- NRstatus.Serializer.require ~baseuri:(NUri.uri_of_string baseuri)
- status
+ if new_or_old = `OldAndNew then
+ let moopath_rw, moopath_r =
+ LibraryMisc.obj_file_of_baseuri
+ ~must_exist:false ~baseuri ~writable:true,
+ LibraryMisc.obj_file_of_baseuri
+ ~must_exist:false ~baseuri ~writable:false in
+ let moopath =
+ if Sys.file_exists moopath_r then moopath_r else
+ if Sys.file_exists moopath_rw then moopath_rw else
+ raise (IncludedFileNotCompiled (moopath_rw,baseuri))
+ in
+ eval_from_moo.efm_go status moopath
+ else
+ status
in
- status,`Old []
+ let status =
+ NRstatus.Serializer.require ~baseuri:(NUri.uri_of_string baseuri)
+ status in
+ let status =
+ GrafiteTypes.add_moo_content
+ [GrafiteAst.Include (loc,mode,`New,baseuri)] status
+ in
+ status,`Old []
| GrafiteAst.Print (_,"proofterm") ->
let _,_,_,p,_, _ = GrafiteTypes.get_current_proof status in
prerr_endline (Auto.pp_proofterm (Lazy.force p));