X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;f=helm%2Fmatita%2FmatitaInterpreter.ml;h=e578a3eb039a44612b163b0f422b216c258ebbc3;hb=7e9904185ceff75884783dbf0bad506b8521b857;hp=4d3137d55e74e56bea5de9e36979a7993b2a2e74;hpb=ad87baf78fb145517c4151c7a3f61d6b5e5fc550;p=helm.git diff --git a/helm/matita/matitaInterpreter.ml b/helm/matita/matitaInterpreter.ml index 4d3137d55..e578a3eb0 100644 --- a/helm/matita/matitaInterpreter.ml +++ b/helm/matita/matitaInterpreter.ml @@ -63,7 +63,8 @@ let split_obj = function class virtual interpreterState = (* static values, shared by all states inheriting this class *) let loc = ref None in - let history = ref [] in + let last_item = ref None in + let evalAstCallback = ref None in fun ~(console: #MatitaTypes.console) -> object (self) @@ -74,34 +75,36 @@ class virtual interpreterState = (** eval a toplevel phrase in the current state and return the new state *) method parsePhrase s = - match CicTextualParser2.parse_tactical s with + match disambiguator#parserr#parseTactical s with | (TacticAst.LocatedTactical (loc', tac)) as tactical -> loc := Some loc'; - (match tac with (* update interpreter history *) - | TacticAst.Command (TacticAst.Qed None) -> - history := `Qed :: !history - | TacticAst.Command (TacticAst.Theorem (_, Some name, _, None)) -> - history := `Theorem name :: !history - | TacticAst.Command (TacticAst.Qed _) - | TacticAst.Command (TacticAst.Theorem _) -> assert false - | _ -> history := `Tactic :: !history); tactical | _ -> assert false method virtual evalTactical: (CicAst.term, string) TacticAst.tactical -> outcome + method private _evalTactical ast = + self#setLastItem None; + let res = self#evalTactical ast in + (match !evalAstCallback with Some f -> f ast | None -> ()); + res + method evalPhrase s = - debug_print (sprintf "evaluating '%s'" s); - self#evalTactical (self#parsePhrase (Stream.of_string s)) + self#_evalTactical (self#parsePhrase (Stream.of_string s)) - method evalAst ast = self#evalTactical ast + method evalAst ast = self#_evalTactical ast method endOffset = match !loc with | Some (start_pos, end_pos) -> end_pos.Lexing.pos_cnum | None -> failwith "MatitaInterpreter: no offset recorded" + method lastItem: script_item option = !last_item + method private setLastItem item = last_item := item + + method setEvalAstCallback f = evalAstCallback := Some f + end (** Implements phrases that should be accepted in all states *) @@ -136,10 +139,10 @@ class sharedState !(Lazy.force basedir)); Quiet | TacticAst.Command (TacticAst.Check term) -> - let (_, _, term,ugraph) = + let (_, metasenv, term,ugraph) = MatitaCicMisc.disambiguate ~disambiguator ~currentProof term in - let (context, metasenv) = + let (context, _) = MatitaCicMisc.get_context_and_metasenv currentProof in (* this is the Eval Compute @@ -152,7 +155,7 @@ class sharedState (* TASSI: here ugraph1 is unused.... FIXME *) let expr = Cic.Cast (term, ty) in (match mathViewer with - | Some v -> v#checkTerm (`Cic expr) + | Some v -> v#checkTerm (`Cic (expr, metasenv)) | _ -> ()); Quiet | TacticAst.Command (TacticAst.Search_pat (search_kind, pat)) -> @@ -380,6 +383,7 @@ class commandState ~(console: #MatitaTypes.console) ?mathViewer () = let uri = UriManager.uri_of_string (qualify name ^ ".con") in let proof = MatitaProof.proof ~typ:expr ~uri ~metasenv () in currentProof#start proof; + self#setLastItem (Some `Theorem); New_state Proof | TacticAst.Command (TacticAst.Theorem (_, Some name, type_ast, Some body_ast)) -> @@ -399,6 +403,7 @@ class commandState ~(console: #MatitaTypes.console) ?mathViewer () = let body = CicMetaSubst.apply_subst subst body_cic in let ty = CicMetaSubst.apply_subst subst type_cic in add_constant_to_world ~console ~dbd ~uri ~body ~ty ~ugraph (); + self#setLastItem (Some (`Def uri)); Quiet | TacticAst.Command (TacticAst.Inductive (params, indTypes)) -> @@ -412,6 +417,7 @@ class commandState ~(console: #MatitaTypes.console) ?mathViewer () = in add_inductive_def_to_world ~console ~dbd ~uri ~indTypes ~params ~leftno ~ugraph (); + self#setLastItem (Some (`Inductive uri)); Quiet | TacticAst.Command TacticAst.Quit -> currentProof#quit (); @@ -471,8 +477,7 @@ class commandState ~(console: #MatitaTypes.console) ?mathViewer () = UriManager.uri_of_string (base ^ xp) | Cic.Appl (he::_) -> uri_of_term he | t -> - prerr_endline ("Fallisco a estrarre la uri di " ^ - (CicPp.ppterm t)); + error ("can't extract uri from " ^ (CicPp.ppterm t)); assert false in let ty_src,ty_tgt = extract_last_two_p coer_ty in @@ -556,6 +561,13 @@ class proofState ~(console: #MatitaTypes.console) ?mathViewer () = Tactics.replace ~what:(self#disambiguate what) ~with_what:(self#disambiguate with_what) | TacticAst.Auto -> Tactics.auto_new ~dbd + | TacticAst.Hint -> + let l = List.map fst + (MetadataQuery.experimental_hint ~dbd + (currentProof#proof#proof,currentProof#proof#goal)) + in + let u = console#choose_uri l in + Tactics.apply (CicUtil.term_of_uri u) | TacticAst.Change (what, with_what, _) -> let what = self#disambiguate what in let with_what = self#disambiguate with_what in @@ -605,14 +617,21 @@ class proofState ~(console: #MatitaTypes.console) ?mathViewer () = add_constant_to_world ~console ~dbd ~uri ~body:bo ~ty ~ugraph (); currentProof#abort (); console#echo_message (sprintf "%s defined" suri); + self#setLastItem (Some (`Qed uri)); New_state Command | TacticAst.Seq tacticals -> - (* TODO Zack check for proof completed at each step? *) + (* TODO ZACK check for proof completed at each step? *) + (* TODO ZACK code completely broken here: we must build logic level + * tacticals instead of iterating interpreter evaluation *) + if (List.length tacticals > 1) then + warning "tacticals are broken: see matitaInterpreter.ml"; List.iter (fun t -> ignore (self#evalTactical t)) tacticals; + self#setLastItem (Some `Tactic); New_state Proof | TacticAst.Tactic tactic_phrase -> let tactic = self#lookup_tactic tactic_phrase in currentProof#proof#apply_tactic tactic; + self#setLastItem (Some `Tactic); New_state Proof | tactical -> shared#evalTactical tactical end @@ -623,7 +642,10 @@ class interpreter ~(console: #MatitaTypes.console) ?mathViewer () = object (self) val mutable state = commandState - method reset = state <- commandState + method setState (tag: [`Proof | `Command]) = + match tag with + | `Proof -> (state <- proofState) + | `Command -> (state <- commandState) method endOffset = state#endOffset @@ -643,6 +665,12 @@ class interpreter ~(console: #MatitaTypes.console) ?mathViewer () = method evalPhrase s = self#eval (fun () -> state#evalPhrase s) method evalAst ast = self#eval (fun () -> state#evalAst ast) + + (** {2 methods delegated to current state} *) + + method endOffset = state#endOffset + method lastItem = state#lastItem + method setEvalAstCallback = state#setEvalAstCallback end let interpreter ~(console: #MatitaTypes.console) ?mathViewer () =