1 (* Copyright (C) 2004-2005, HELM Team.
3 * This file is part of HELM, an Hypertextual, Electronic
4 * Library of Mathematics, developed at the Computer Science
5 * Department, University of Bologna, Italy.
7 * HELM is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * HELM is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with HELM; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
22 * For details, see the HELM World-Wide-Web page,
23 * http://helm.cs.unibo.it/
28 exception Option_error of string * string
29 exception Statement_error of string
30 exception Command_error of string
32 let command_error msg = raise (Command_error msg)
34 type incomplete_proof = {
35 proof: ProofEngineTypes.proof;
36 stack: Continuationals.Stack.t;
41 | Incomplete_proof of incomplete_proof
42 | Proof of ProofEngineTypes.proof
43 | Intermediate of Cic.metasenv
44 (* Status in which the proof could be while it is being processed by the
45 * engine. No status entering/exiting the engine could be in it. *)
48 | ProofMode of NTacStatus.tac_status
49 | CommandMode of NEstatus.extra_status
52 moo_content_rev: GrafiteMarshal.moo;
53 proof_status: proof_status;
54 objects: UriManager.uri list;
55 coercions: CoercDb.coerc_db;
56 automation_cache:AutomationCache.cache;
62 match x.ng_status with
63 | ProofMode t -> t.NTacStatus.istatus.NTacStatus.estatus.NEstatus.lstatus
64 | CommandMode e -> e.NEstatus.lstatus
67 let set_lexicon new_lexicon_status new_grafite_status =
68 { new_grafite_status with ng_status =
69 match new_grafite_status.ng_status with
70 | CommandMode estatus ->
72 { estatus with NEstatus.lstatus = new_lexicon_status }
75 { t with NTacStatus.istatus =
76 { t.NTacStatus.istatus with NTacStatus.estatus =
77 { t.NTacStatus.istatus.NTacStatus.estatus with NEstatus.lstatus =
78 new_lexicon_status }}}}
82 match x.ng_status with
83 | ProofMode t -> t.NTacStatus.istatus.NTacStatus.estatus
89 match x.ng_status with
92 {t with NTacStatus.istatus =
93 {t.NTacStatus.istatus with NTacStatus.estatus = e}}
94 | CommandMode _ -> CommandMode e}
97 let get_dstatus x = (get_estatus x).NEstatus.rstatus;;
99 let get_rstatus x = (get_dstatus x).NRstatus.refiner_status;;
101 let get_hstatus x = (get_rstatus x).NRstatus.uhint_db;;
103 let get_library_db x = (get_rstatus x).NRstatus.library_db;;
105 let get_dump x = (get_dstatus x).NRstatus.dump;;
107 let set_dstatus h x =
108 let estatus = get_estatus x in
109 set_estatus { estatus with NEstatus.rstatus = h } x
112 let set_rstatus h x =
113 let dstatus = get_dstatus x in
114 set_dstatus { dstatus with NRstatus.refiner_status = h } x
117 let set_coercions db x =
118 let rstatus = get_rstatus x in
119 set_rstatus { rstatus with NRstatus.coerc_db = db } x
123 let set_hstatus h x =
124 let rstatus = get_rstatus x in
125 set_rstatus { rstatus with NRstatus.uhint_db = h} x
128 let set_library_db h x =
129 let rstatus = get_rstatus x in
130 set_rstatus { rstatus with NRstatus.library_db = h} x
134 let estatus = get_estatus x in
136 { estatus with NEstatus.rstatus =
137 { estatus.NEstatus.rstatus with
142 let get_current_proof status =
143 match status.proof_status with
144 | Incomplete_proof { proof = p } -> p
146 | _ -> raise (Statement_error "no ongoing proof")
148 let get_proof_metasenv status =
149 match status.proof_status with
151 | Proof (_, metasenv, _, _, _, _)
152 | Incomplete_proof { proof = (_, metasenv, _, _, _, _) }
153 | Intermediate metasenv ->
156 let get_stack status =
157 match status.proof_status with
158 | Incomplete_proof p -> p.stack
159 | Proof _ -> Continuationals.Stack.empty
162 let set_stack stack status =
163 match status.proof_status with
164 | Incomplete_proof p ->
165 { status with proof_status = Incomplete_proof { p with stack = stack } }
167 assert (Continuationals.Stack.is_empty stack);
171 let set_metasenv metasenv status =
173 match status.proof_status with
174 | No_proof -> Intermediate metasenv
175 | Incomplete_proof ({ proof = (uri, _, subst, proof, ty, attrs) } as incomplete_proof) ->
177 { incomplete_proof with proof = (uri, metasenv, subst, proof, ty, attrs) }
178 | Intermediate _ -> Intermediate metasenv
179 | Proof (_, metasenv', _, _, _, _) ->
180 assert (metasenv = metasenv');
183 { status with proof_status = proof_status }
185 let get_proof_context status goal =
186 match status.proof_status with
187 | Incomplete_proof { proof = (_, metasenv, _, _, _, _) } ->
188 let (_, context, _) = CicUtil.lookup_meta goal metasenv in
192 let get_proof_conclusion status goal =
193 match status.proof_status with
194 | Incomplete_proof { proof = (_, metasenv, _, _, _, _) } ->
195 let (_, _, conclusion) = CicUtil.lookup_meta goal metasenv in
197 | _ -> raise (Statement_error "no ongoing proof")
199 let add_moo_content cmds status =
200 let content = status.moo_content_rev in
204 (* prerr_endline ("adding to moo command: " ^ GrafiteAstPp.pp_command cmd); *)
206 | GrafiteAst.Default _
208 | GrafiteAst.Coercion _ ->
209 if List.mem cmd content then acc
214 (* prerr_endline ("new moo content: " ^ String.concat " " (List.map
215 GrafiteAstPp.pp_command content')); *)
216 { status with moo_content_rev = content' }
218 let get_baseuri status = status.baseuri;;
221 let get_option status name =
223 StringMap.find name status.options
224 with Not_found -> raise (Option_error (name, "not found"))
226 let set_option status name value =
227 let types = [ (* no set options defined! *) ] in
229 try List.assoc name types
231 command_error (Printf.sprintf "Unknown option \"%s\"" name)
234 match ty_and_mangler with
235 | `String, f -> String (f value)
238 Int (int_of_string (f value))
240 command_error (Printf.sprintf "Not an integer value \"%s\"" value))
242 { status with options = StringMap.add name value status.options }
245 let get_string_option status name =
246 match get_option status name with
248 | _ -> raise (Option_error (name, "not a string value"))
251 let dump_status status =
252 HLog.message "status.aliases:\n";
253 HLog.message "status.proof_status:";
255 (match status.proof_status with
256 | No_proof -> "no proof\n"
257 | Incomplete_proof _ -> "incomplete proof\n"
258 | Proof _ -> "proof\n"
259 | Intermediate _ -> "Intermediate\n");
260 HLog.message "status.options\n";
262 StringMap.iter (fun k v ->
266 | Int i -> string_of_int i
268 HLog.message (k ^ "::=" ^ v)) status.options;
270 HLog.message "status.coercions\n";
271 HLog.message "status.objects:\n";
273 (fun u -> HLog.message (UriManager.string_of_uri u)) status.objects
275 let get_coercions x = (get_rstatus x).NRstatus.coerc_db;;