X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;f=helm%2Fsoftware%2Fcomponents%2Fgrafite_engine%2FgrafiteEngine.ml;h=98bfef9d6f5c60a6b445e2c2feb400032e1955f6;hb=8a119afd68f41a644904de45357b9b4ce441d7ee;hp=4ab7412d832c60f4e0c0c0aab339e5ef9f2a652e;hpb=1bd6b7d2637d765f11ddbd1218d63474e9d0c63b;p=helm.git diff --git a/helm/software/components/grafite_engine/grafiteEngine.ml b/helm/software/components/grafite_engine/grafiteEngine.ml index 4ab7412d8..98bfef9d6 100644 --- a/helm/software/components/grafite_engine/grafiteEngine.ml +++ b/helm/software/components/grafite_engine/grafiteEngine.ml @@ -470,9 +470,23 @@ let coercion_moo_statement_of (uri,arity, saturations,_) = GrafiteAst.Coercion (HExtlib.dummy_floc, CicUtil.term_of_uri uri, false, arity, saturations) +let basic_eval_unification_hint (t,n) status = + let hstatus = + NCicUnifHint.add_user_provided_hint (status.NRstatus.uhint_db) t n + in + { status with NRstatus.uhint_db = hstatus } +;; + +let inject_unification_hint = + NRstatus.Serializer.register "unification_hints" basic_eval_unification_hint +;; + let eval_unification_hint status t n = - (* XXX no undo *) - NCicUnifHint.add_user_provided_hint t n; + let rstatus = + basic_eval_unification_hint (t,n) (GrafiteTypes.get_rstatus status) in + let status = GrafiteTypes.set_rstatus rstatus status in + let dump = inject_unification_hint (t,n)::(GrafiteTypes.get_dump status) in + let status = GrafiteTypes.set_dump dump status in status,`Old [] ;; @@ -597,6 +611,10 @@ let eval_ng_tac (text, prefix_len, tac) = ) hyps, (text,prefix_len,concl)) ) seqs) + | GrafiteAst.NAuto (_loc, (l,a)) -> + NTactics.auto_tac + ~params:(List.map (fun x -> "",0,x) l,a) + | GrafiteAst.NBranch _ -> NTactics.branch_tac | GrafiteAst.NCases (_loc, what, where) -> NTactics.cases_tac ~what:(text,prefix_len,what) @@ -605,12 +623,12 @@ let eval_ng_tac (text, prefix_len, tac) = | GrafiteAst.NChange (_loc, pat, ww) -> NTactics.change_tac ~where:(text,prefix_len,pat) ~with_what:(text,prefix_len,ww) + | GrafiteAst.NDot _ -> NTactics.dot_tac | GrafiteAst.NElim (_loc, what, where) -> NTactics.elim_tac ~what:(text,prefix_len,what) ~where:(text,prefix_len,where) - | GrafiteAst.NEval (_loc, where, reduction) -> - NTactics.eval_tac ~reduction ~where:(text,prefix_len,where) + | GrafiteAst.NFocus (_,l) -> NTactics.focus_tac l | GrafiteAst.NGeneralize (_loc, where) -> NTactics.generalize_tac ~where:(text,prefix_len,where) | GrafiteAst.NId _ -> (fun x -> x) @@ -618,9 +636,29 @@ let eval_ng_tac (text, prefix_len, tac) = | GrafiteAst.NLetIn (_loc,where,what,name) -> NTactics.letin_tac ~where:(text,prefix_len,where) ~what:(text,prefix_len,what) name + | GrafiteAst.NMerge _ -> NTactics.merge_tac + | GrafiteAst.NPos (_,l) -> NTactics.pos_tac l + | GrafiteAst.NReduce (_loc, reduction, where) -> + NTactics.reduce_tac ~reduction ~where:(text,prefix_len,where) | GrafiteAst.NRewrite (_loc,dir,what,where) -> NTactics.rewrite_tac ~dir ~what:(text,prefix_len,what) ~where:(text,prefix_len,where) + | GrafiteAst.NSemicolon _ -> fun x -> x + | GrafiteAst.NShift _ -> NTactics.shift_tac + | GrafiteAst.NSkip _ -> NTactics.skip_tac + | GrafiteAst.NUnfocus _ -> NTactics.unfocus_tac + | GrafiteAst.NWildcard _ -> NTactics.wildcard_tac +;; + +let subst_metasenv_and_fix_names s = + let u,h,metasenv, subst,o = s.NTacStatus.istatus.NTacStatus.pstatus in + let o = + NCicUntrusted.map_obj_kind ~skip_body:true + (NCicUntrusted.apply_subst subst []) o + in + { s with NTacStatus.istatus = + { s.NTacStatus.istatus with NTacStatus.pstatus = + u,h,NCicUntrusted.apply_subst_metasenv subst metasenv,subst,o}} ;; let rec eval_command = {ec_go = fun ~disambiguate_command opts status @@ -689,7 +727,7 @@ 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) -> + | GrafiteAst.Include (loc, _, baseuri) -> let moopath_rw, moopath_r = LibraryMisc.obj_file_of_baseuri ~must_exist:false ~baseuri ~writable:true, @@ -702,6 +740,11 @@ let rec eval_command = {ec_go = fun ~disambiguate_command opts status raise (IncludedFileNotCompiled (moopath_rw,baseuri)) in let status = eval_from_moo.efm_go status moopath in + let rstatus = GrafiteTypes.get_rstatus status in + let rstatus = + NRstatus.Serializer.require ~baseuri:(NUri.uri_of_string baseuri) rstatus + in + let status = GrafiteTypes.set_rstatus rstatus status in (* debug let lt_uri = UriManager.uri_of_string "cic:/matita/nat/orders/lt.con" in let nat_uri = UriManager.uri_of_string "cic:/matita/nat/nat/nat.ind" in @@ -742,64 +785,91 @@ let rec eval_command = {ec_go = fun ~disambiguate_command opts status let name = UriManager.name_of_uri uri in let obj = Cic.Constant (name,Some (Lazy.force bo),ty,[],attrs) in let status, lemmas = add_obj uri obj status in - {status with - GrafiteTypes.proof_status = GrafiteTypes.No_proof}, + {status with GrafiteTypes.proof_status = GrafiteTypes.No_proof}, (*CSC: I throw away the arities *) `Old (uri::lemmas) | GrafiteAst.NQed loc -> (match status.GrafiteTypes.ng_status with | GrafiteTypes.ProofMode { NTacStatus.istatus = - {NTacStatus.pstatus = pstatus; lstatus=lexicon_status} } -> - let uri,height,menv,subst,obj = pstatus in + { NTacStatus.pstatus = pstatus; estatus = estatus } } -> + let uri,height,menv,subst,obj_kind = pstatus in if menv <> [] then raise (GrafiteTypes.Command_error"You can't Qed an incomplete theorem") else - let obj = -prerr_endline "CSC: here we should fix the height!!!"; - uri,height,[],[], - NCicUntrusted.map_obj_kind (NCicUntrusted.apply_subst subst) obj + 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 + (* fix the height inside the object *) + let rec fix () = function + | NCic.Const (NReference.Ref (u,spec)) when NUri.eq u uri -> + NCic.Const (NReference.reference_of_spec u + (match spec with + | NReference.Def _ -> NReference.Def height + | NReference.Fix (i,j,_) -> NReference.Fix(i,j,height) + | NReference.CoFix _ -> NReference.CoFix height + | NReference.Ind _ | NReference.Con _ + | NReference.Decl as s -> s)) + | t -> NCicUtils.map (fun _ () -> ()) () fix t in - NCicLibrary.add_obj uri obj; - {status with - GrafiteTypes.ng_status = - GrafiteTypes.CommandMode lexicon_status },`New [uri] + let obj_kind = + match obj_kind with + | NCic.Fixpoint _ -> + NCicUntrusted.map_obj_kind (fix ()) obj_kind + | _ -> obj_kind + in + let obj = uri,height,[],[],obj_kind in + NCicTypeChecker.typecheck_obj obj; + let timestamp = NCicLibrary.add_obj uri obj in + let objs = NCicElim.mk_elims obj in + let timestamp,uris_rev = + List.fold_left + (fun (timestamp,uris_rev) (uri,_,_,_,_) as obj -> + NCicTypeChecker.typecheck_obj obj; + let timestamp = NCicLibrary.add_obj uri obj in + timestamp,uri::uris_rev + ) (timestamp,[]) objs in + let uris = uri::List.rev uris_rev in + GrafiteTypes.set_library_db timestamp + {status with + GrafiteTypes.ng_status = + GrafiteTypes.CommandMode estatus },`New uris | _ -> raise (GrafiteTypes.Command_error "Not in proof mode")) | GrafiteAst.Relation (loc, id, a, aeq, refl, sym, trans) -> Setoids.add_relation id a aeq refl sym trans; status, `Old [] (*CSC: TO BE FIXED *) | GrafiteAst.Set (loc, name, value) -> status, `Old [] (* GrafiteTypes.set_option status name value,[] *) + | GrafiteAst.NUnivConstraint (loc,strict,u1,u2) -> + NCicEnvironment.add_constraint strict [false,u1] [false,u2]; + status, `New [u1;u2] | GrafiteAst.NObj (loc,obj) -> - let lexicon_status = + let estatus = match status.GrafiteTypes.ng_status with | GrafiteTypes.ProofMode _ -> assert false - | GrafiteTypes.CommandMode ls -> ls in - let lexicon_status,obj = - GrafiteDisambiguate.disambiguate_nobj lexicon_status + | GrafiteTypes.CommandMode es -> es + in + let estatus,obj = + GrafiteDisambiguate.disambiguate_nobj estatus ~baseuri:(GrafiteTypes.get_baseuri status) (text,prefix_len,obj) in let uri,height,nmenv,nsubst,nobj = obj in + let ninitial_stack = Continuationals.Stack.of_nmetasenv nmenv in + let status = + { status with + GrafiteTypes.ng_status = + GrafiteTypes.ProofMode + (subst_metasenv_and_fix_names + { NTacStatus.gstatus = ninitial_stack; + istatus = { NTacStatus.pstatus = obj; estatus = estatus}}) + } + in (match nmenv with - [] -> - (* CSC: cut&paste code from NQed *) - let obj = -prerr_endline "CSC: here we should fix the height!!!"; - uri,height,[],[], - NCicUntrusted.map_obj_kind (NCicUntrusted.apply_subst nsubst) nobj - in - NCicLibrary.add_obj uri obj; - {status with - GrafiteTypes.ng_status=GrafiteTypes.CommandMode lexicon_status }, - `New [uri] - | _ -> - let ninitial_stack = Continuationals.Stack.of_nmetasenv nmenv in - { status with - GrafiteTypes.ng_status = - GrafiteTypes.ProofMode - { NTacStatus.gstatus = ninitial_stack; - istatus = { NTacStatus.pstatus = obj; lstatus = lexicon_status}} - },`New []) + [] -> + eval_command.ec_go ~disambiguate_command opts status + ("",0,GrafiteAst.NQed Stdpp.dummy_loc) + | _ -> status,`New []) | GrafiteAst.Obj (loc,obj) -> let ext,name = match obj with @@ -889,12 +959,17 @@ prerr_endline "CSC: here we should fix the height!!!"; | GrafiteAst.Tactic (_, None, punct) -> eval_tactical status (punctuation_tactical_of_ast (text,prefix_len,punct)),`Old [] - | GrafiteAst.NTactic (_(*loc*), tac, punct) -> + | GrafiteAst.NTactic (_(*loc*), tacl) -> (match status.GrafiteTypes.ng_status with | GrafiteTypes.CommandMode _ -> assert false | GrafiteTypes.ProofMode nstatus -> - let nstatus = eval_ng_tac (text,prefix_len,tac) nstatus in - let nstatus = eval_ng_punct (text,prefix_len,punct) nstatus in + let nstatus = + List.fold_left + (fun nstatus tac -> + let nstatus = eval_ng_tac (text,prefix_len,tac) nstatus in + subst_metasenv_and_fix_names nstatus) + nstatus tacl + in NTacStatus.pp_tac_status nstatus; { status with GrafiteTypes.ng_status= GrafiteTypes.ProofMode nstatus }, `New [])