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)
(** 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 *)
!(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
(* 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)) ->
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)) ->
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)) ->
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 ();
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
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
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
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
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 () =