X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;f=helm%2Fmatita%2FmatitaEngine.ml;h=cb420d267ecf41f866a96dcb2695d1a95a93c00f;hb=b05dceab1903f9d15f214a9ddeaf791cd594e215;hp=354b18ae54cd3156f72a4cdb9b6028c5056e6a80;hpb=0d681e06c6ced0be7f9dbce417684b082229745a;p=helm.git diff --git a/helm/matita/matitaEngine.ml b/helm/matita/matitaEngine.ml index 354b18ae5..cb420d267 100644 --- a/helm/matita/matitaEngine.ml +++ b/helm/matita/matitaEngine.ml @@ -46,7 +46,7 @@ let tactic_of_ast = function | TacticAst.Exact (_, term) -> Tactics.exact term | TacticAst.Exists _ -> Tactics.exists | TacticAst.Fail _ -> Tactics.fail - | TacticAst.Fold (_, reduction_kind, pattern) -> + | TacticAst.Fold (_, reduction_kind, term, pattern) -> let reduction = match reduction_kind with | `Normalize -> CicReduction.normalize ~delta:false ~subst:[] @@ -54,10 +54,10 @@ let tactic_of_ast = function | `Simpl -> ProofEngineReduction.simpl | `Whd -> CicReduction.whd ~delta:false ~subst:[] in - Tactics.fold ~reduction ~pattern + Tactics.fold ~reduction ~term ~pattern | TacticAst.Fourier _ -> Tactics.fourier - | TacticAst.FwdSimpl (_, term) -> - Tactics.fwd_simpl ~what:term ~dbd:(MatitaDb.instance ()) + | TacticAst.FwdSimpl (_, hyp, names) -> + Tactics.fwd_simpl ~mk_fresh_name_callback:(namer_of names) ~dbd:(MatitaDb.instance ()) hyp | TacticAst.Generalize (_,pattern,ident) -> let names = match ident with None -> [] | Some id -> [id] in Tactics.generalize ~mk_fresh_name_callback:(namer_of names) pattern @@ -69,9 +69,9 @@ let tactic_of_ast = function | TacticAst.Intros (_, Some num, names) -> PrimitiveTactics.intros_tac ~howmany:num ~mk_fresh_name_callback:(namer_of names) () - | TacticAst.LApply (_, to_what, what, ident) -> + | TacticAst.LApply (_, how_many, to_what, what, ident) -> let names = match ident with None -> [] | Some id -> [id] in - Tactics.lapply ~mk_fresh_name_callback:(namer_of names) ?to_what what + Tactics.lapply ~mk_fresh_name_callback:(namer_of names) ?how_many ~to_what what | TacticAst.Left _ -> Tactics.left | TacticAst.LetIn (loc,term,name) -> Tactics.letin term ~mk_fresh_name_callback:(namer_of [name]) @@ -84,11 +84,8 @@ let tactic_of_ast = function | TacticAst.Reflexivity _ -> Tactics.reflexivity | TacticAst.Replace (_, pattern, with_what) -> Tactics.replace ~pattern ~with_what - | TacticAst.Rewrite (_, dir, t, pattern) -> - if dir = `Left then - EqualityTactics.rewrite_tac ~where:pattern ~term:t () - else - EqualityTactics.rewrite_back_tac ~where:pattern ~term:t () + | TacticAst.Rewrite (_, direction, t, pattern) -> + EqualityTactics.rewrite_tac ~direction ~pattern t | TacticAst.Right _ -> Tactics.right | TacticAst.Ring _ -> Tactics.ring | TacticAst.Split _ -> Tactics.split @@ -221,9 +218,22 @@ let generate_projections uri fields status = ("Unable to create projection " ^ name ^ " because it requires " ^ depend); status ) status projections + +(* to avoid a long list of recursive functions *) +let eval_from_stream_ref = ref (fun _ _ _ -> assert false);; let eval_command status cmd = match cmd with + | TacticAst.Default (loc, what, uris) as cmd -> + LibraryObjects.set_default what uris; + {status with moo_content_rev = + (TacticAstPp.pp_command cmd ^ "\n") :: status.moo_content_rev} + | TacticAst.Include (loc, path) -> + let path = MatitaMisc.obj_file_of_script path in + let stream = Stream.of_channel (open_in path) in + let status = ref status in + !eval_from_stream_ref status stream (fun _ _ -> ()); + !status | TacticAst.Set (loc, name, value) -> let value = if name = "baseuri" then @@ -251,26 +261,31 @@ let eval_command status cmd = let obj = Cic.Constant (name,Some bo,ty,[],[]) in MatitaSync.add_obj uri obj status | TacticAst.Coercion (loc, coercion) -> - eval_coercion status coercion + let status = eval_coercion status coercion in + let moo_content_rev = + (TacticAstPp.pp_cic_command + (TacticAst.Coercion (CicAst.dummy_floc,coercion)) ^ ".\n") :: + status.moo_content_rev in + {status with moo_content_rev = moo_content_rev} | TacticAst.Alias (loc, spec) -> - (match spec with + let aliases = + match spec with | TacticAst.Ident_alias (id,uri) -> - {status with aliases = - DisambiguateTypes.Environment.add - (DisambiguateTypes.Id id) - ("boh?",(fun _ _ _ -> CicUtil.term_of_uri (UriManager.uri_of_string uri))) - status.aliases } + DisambiguateTypes.Environment.add + (DisambiguateTypes.Id id) + (uri,(fun _ _ _-> CicUtil.term_of_uri (UriManager.uri_of_string uri))) + status.aliases | TacticAst.Symbol_alias (symb, instance, desc) -> - {status with aliases = - DisambiguateTypes.Environment.add - (DisambiguateTypes.Symbol (symb,instance)) - (DisambiguateChoices.lookup_symbol_by_dsc symb desc) - status.aliases } + DisambiguateTypes.Environment.add + (DisambiguateTypes.Symbol (symb,instance)) + (DisambiguateChoices.lookup_symbol_by_dsc symb desc) + status.aliases | TacticAst.Number_alias (instance,desc) -> - {status with aliases = - DisambiguateTypes.Environment.add - (DisambiguateTypes.Num instance) - (DisambiguateChoices.lookup_num_by_dsc desc) status.aliases }) + DisambiguateTypes.Environment.add + (DisambiguateTypes.Num instance) + (DisambiguateChoices.lookup_num_by_dsc desc) status.aliases + in + MatitaSync.set_proof_aliases status aliases | TacticAst.Obj (loc,obj) -> let ext,name = match obj with @@ -346,11 +361,8 @@ let disambiguate_term status term = | Intermediate _ -> Intermediate metasenv | Proof _ -> assert false in - let status = - { status with - aliases = aliases; - proof_status = proof_status } - in + let status = { status with proof_status = proof_status } in + let status = MatitaSync.set_proof_aliases status aliases in status, cic let disambiguate_obj status obj = @@ -376,11 +388,8 @@ let disambiguate_obj status obj = | Intermediate _ | Proof _ -> assert false in - let status = - { status with - aliases = aliases; - proof_status = proof_status } - in + let status = { status with proof_status = proof_status } in + let status = MatitaSync.set_proof_aliases status aliases in status, cic let disambiguate_pattern status (wanted, hyp_paths, goal_path) = @@ -444,12 +453,12 @@ let disambiguate_tactic status = function status, TacticAst.ElimType (loc, cic) | TacticAst.Exists loc -> status, TacticAst.Exists loc | TacticAst.Fail loc -> status,TacticAst.Fail loc - | TacticAst.Fold (loc,reduction_kind, pattern) -> + | TacticAst.Fold (loc,reduction_kind, term, pattern) -> let status, pattern = disambiguate_pattern status pattern in - status, TacticAst.Fold (loc,reduction_kind, pattern) - | TacticAst.FwdSimpl (loc, term) -> let status, term = disambiguate_term status term in - status, TacticAst.FwdSimpl (loc, term) + status, TacticAst.Fold (loc,reduction_kind, term, pattern) + | TacticAst.FwdSimpl (loc, hyp, names) -> + status, TacticAst.FwdSimpl (loc, hyp, names) | TacticAst.Fourier loc -> status, TacticAst.Fourier loc | TacticAst.Generalize (loc,pattern,ident) -> let status, pattern = disambiguate_pattern status pattern in @@ -461,16 +470,14 @@ let disambiguate_tactic status = function status, TacticAst.Injection (loc,term) | TacticAst.Intros (loc, num, names) -> status, TacticAst.Intros (loc, num, names) - | TacticAst.LApply (loc, to_what, what, ident) -> - let status, to_what = - match to_what with - None -> status,None - | Some to_what -> - let status, to_what = disambiguate_term status to_what in - status, Some to_what + | TacticAst.LApply (loc, depth, to_what, what, ident) -> + let f term (status, to_what) = + let status, term = disambiguate_term status term in + status, term :: to_what in + let status, to_what = List.fold_right f to_what (status, []) in let status, what = disambiguate_term status what in - status, TacticAst.LApply (loc, to_what, what, ident) + status, TacticAst.LApply (loc, depth, to_what, what, ident) | TacticAst.Left loc -> status, TacticAst.Left loc | TacticAst.LetIn (loc, term, name) -> let status, term = disambiguate_term status term in @@ -533,12 +540,14 @@ and disambiguate_tacticals status tacticals = status, tacticals let disambiguate_command status = function + | TacticAst.Default _ + | TacticAst.Alias _ + | TacticAst.Include _ as cmd -> status,cmd | TacticAst.Coercion (loc, term) -> let status, term = disambiguate_term status term in status, TacticAst.Coercion (loc,term) | (TacticAst.Set _ | TacticAst.Qed _ | TacticAst.Drop _ ) as cmd -> status, cmd - | TacticAst.Alias _ as x -> status, x | TacticAst.Obj (loc,obj) -> let status,obj = disambiguate_obj status obj in status, TacticAst.Obj (loc,obj) @@ -578,8 +587,13 @@ let eval_ast status ast = let eval_from_stream status str cb = let stl = CicTextualParser2.parse_statements str in - List.iter (fun ast -> cb !status ast;status := eval_ast !status ast) stl + List.iter + (fun ast -> cb !status ast;status := eval_ast !status ast) stl +;; +(* to avoid a long list of recursive functions *) +eval_from_stream_ref := eval_from_stream;; + let eval_from_stream_greedy status str cb = while true do print_string "matita> "; @@ -588,7 +602,8 @@ let eval_from_stream_greedy status str cb = cb !status ast; status := eval_ast !status ast done - +;; + let eval_string status str = eval_from_stream status (Stream.of_string str) (fun _ _ -> ()) @@ -611,6 +626,7 @@ let default_options () = let initial_status = lazy { aliases = DisambiguateTypes.empty_environment; + moo_content_rev = []; proof_status = No_proof; options = default_options (); objects = [];