X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;f=helm%2Fmatita%2FmatitaProof.ml;h=99214e724d85cbd061f927e3c9f9f303ebaed866;hb=fdd8107cc53f5e862004aa5fcd48593ee5634234;hp=6c73b4b14d9cf20bc057d678add9ab036ebb14c2;hpb=481992ea591bf53cba758a96e7d42e9cdce7e129;p=helm.git diff --git a/helm/matita/matitaProof.ml b/helm/matita/matitaProof.ml index 6c73b4b14..99214e724 100644 --- a/helm/matita/matitaProof.ml +++ b/helm/matita/matitaProof.ml @@ -23,33 +23,61 @@ * http://helm.cs.unibo.it/ *) -class proofStatus ~typ ~metasenv ~uri () = +open MatitaCicMisc + +let init_metadata _ = () +let compute_metadata _ _ = () + +(* +let init_metadata status = + let ((_, metasenv, _, _) as proof, _) = status in + let proof_object_metadata = (* compute proof annotations *) + Cic2acic.acic_object_of_cic_object (cicCurrentProof proof) + in + let sequents_metadata = (* compute all sequent annotations from scratch *) + List.map + (fun ((metano, context, term) as sequent) -> + (metano, Cic2acic.asequent_of_sequent metasenv sequent)) + metasenv + in + (proof_object_metadata, sequents_metadata) + +let compute_metadata (old_status, old_metadata) new_status = + let ((_, new_metasenv, _, _) as new_proof, goal_opt) = new_status in + let proof_object_metadata = (* compute proof annotations *) + let obj = + match goal_opt with + | Some _ -> cicCurrentProof new_proof + | None -> cicConstant new_proof + in + Cic2acic.acic_object_of_cic_object obj + in + let sequents_metadata = (* compute all sequent annotations from scratch *) + (** TODO Zack could we reuse some of the annotations from the previous + * status to avoid recomputing all of them? uhm ... we have to which + * sequents haven't been changed by last tactic applications ... doh! *) + List.map + (fun ((metano, context, term) as sequent) -> + (metano, Cic2acic.asequent_of_sequent new_metasenv sequent)) + new_metasenv + in + (proof_object_metadata, sequents_metadata) +*) + +class proof ?uri ~typ ~metasenv ~body () = object (self) - inherit MatitaTypes.subject - - val mutable _proof = (uri, (1, [], typ) :: metasenv, Cic.Meta (1, []), typ) - val mutable _goal = Some 1 - - method proof = _proof - method setProof p = _proof <- p - method goal = _goal - method setGoal g = _goal <- g - method status = - _proof, - (match _goal with Some g -> g | None -> raise MatitaTypes.No_proof) - method setStatus (p, g) = - _proof <- p; - _goal <- Some g + + inherit [unit] + StatefulProofEngine.status + ~history_size:BuildTimeConf.undo_history_size ?uri ~typ ~body ~metasenv + init_metadata compute_metadata () method toXml = - let (uri, metasenv, bo, ty) = _proof in - let currentproof = - (* TODO CSC: Wrong: [] is just plainly wrong *) - Cic.CurrentProof (UriManager.name_of_uri uri,metasenv, bo, ty, []) - in + let currentproof = cicCurrentProof self#proof in let (acurrentproof,_,_,ids_to_inner_sorts,_,_,_) = Cic2acic.acic_object_of_cic_object ~eta_fix:false currentproof in + let uri = MatitaTypes.unopt_uri self#uri in let xml, bodyxml = match Cic2Xml.print_object uri ~ids_to_inner_sorts ~ask_dtd_to_the_getter:true acurrentproof @@ -62,71 +90,66 @@ class proofStatus ~typ ~metasenv ~uri () = method toString = let (xml, bodyxml) = self#toXml in let buf = Buffer.create 10240 in - Buffer.add_string buf "\n"; - Buffer.add_string buf "\n"; - Buffer.add_string buf "\n"; - Buffer.add_string buf (Misc.strip_xml_headings (Xml.pp_to_string xml)); - Buffer.add_string buf (Misc.strip_xml_headings(Xml.pp_to_string bodyxml)); - Buffer.add_string buf - (match _goal with - | None -> "" - | Some goal -> Printf.sprintf "%d" goal); - Buffer.add_string buf "\n"; + List.iter (Buffer.add_string buf) + [ "\n"; + "\n"; + "\n"; + (Misc.strip_xml_headings (Xml.pp_to_string xml)); + (Misc.strip_xml_headings(Xml.pp_to_string bodyxml)); + (if not (self#proof_completed) then + Printf.sprintf "%d" self#goal + else + ""); + "\n" + ]; Buffer.contents buf end -let proofStatus ~typ ?(metasenv = []) ?(uri = MatitaTypes.untitled_con_uri) () = - new proofStatus ~typ ~metasenv ~uri () - -let proofStatus_of_string s = - MatitaTypes.not_implemented "MatitaProof.proofStatus_of_string" - -class proof ~typ ?metasenv ?uri () = - object - val mutable _status = proofStatus ~typ ?metasenv ?uri () - method status = _status - method setStatus s = _status <- s - end - -let proof = new proof - -class tacticCommand ~(tactic:ProofEngineTypes.tactic) (status: proofStatus) = - object - val statusBackup = status#status - - method execute () = - let (new_proof, new_goals) = tactic status#status in - status#setProof new_proof; - status#setGoal - (match new_goals, new_proof with - | goal :: _, _ -> Some goal - | [], (_, (goal, _, _) :: _, _, _) -> - (* the tactic left no open goal: let's choose the first open goal *) - (* TODO CSC: here we could implement and use a proof-tree like - * notion... *) - Some goal - | _, _ -> None); - status#notify () - - method undo () = - status#setStatus statusBackup; - status#notify () +class currentProof = + let fail () = failwith "No current proof" in + object (self) + val mutable _proof: MatitaTypes.proof option = None + val mutable observers = [] + val mutable callbacks = [] + + initializer self#connect `Abort (fun () -> _proof <- None; false) + + (** execute all callbacks related to a given event until one of them + * return true or the end of the callback list is reached *) + method private do_callbacks event = + let rec aux = function + | [] -> () + | (event', f) :: tl when event' = event -> if not (f ()) then aux tl + | _ :: tl -> aux tl + in + aux callbacks + + method addObserver o = observers <- o :: observers + + method connect (event:[`Abort|`Quit]) f = + callbacks <- (event, f) :: callbacks + + method onGoing () = _proof <> None + method proof = match _proof with None -> fail () | Some proof -> proof + method start (proof: MatitaTypes.proof) = + List.iter + (fun observer -> + ignore (proof#attach_observer + ~interested_in:StatefulProofEngine.all_events observer)) + observers; + proof#notify; + _proof <- Some proof + method abort () = self#do_callbacks `Abort + method quit () = self#do_callbacks `Quit end -let intros ?namer = - new tacticCommand - ~tactic:(PrimitiveTactics.intros_tac ?mk_fresh_name_callback:namer ()) - -let reflexivity = new tacticCommand ~tactic:EqualityTactics.reflexivity_tac -let symmetry = new tacticCommand ~tactic:EqualityTactics.symmetry_tac -let transitivity term = - new tacticCommand ~tactic:(EqualityTactics.transitivity_tac ~term) - -let exists = new tacticCommand ~tactic:IntroductionTactics.exists_tac -let split = new tacticCommand ~tactic:IntroductionTactics.split_tac -let left = new tacticCommand ~tactic:IntroductionTactics.left_tac -let right = new tacticCommand ~tactic:IntroductionTactics.right_tac +let proof ?uri ~metasenv ~typ () = + let metasenv = (1, [], typ) :: metasenv in + let body = Cic.Meta (1,[]) in + let _ = CicTypeChecker.type_of_aux' metasenv [] typ in + new proof ~typ ~metasenv ~body ?uri () -let assumption = new tacticCommand ~tactic:VariousTactics.assumption_tac +let currentProof () = new currentProof +let instance = MatitaMisc.singleton currentProof