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 moo_content_rev: GrafiteMarshal.moo;
49 proof_status: proof_status;
50 objects: UriManager.uri list;
51 coercions: CoercDb.coerc_db;
52 universe:Universe.universe;
54 ng_status: NTactics.tac_status option;
57 let get_current_proof status =
58 match status.proof_status with
59 | Incomplete_proof { proof = p } -> p
61 | _ -> raise (Statement_error "no ongoing proof")
63 let get_proof_metasenv status =
64 match status.proof_status with
66 | Proof (_, metasenv, _, _, _, _)
67 | Incomplete_proof { proof = (_, metasenv, _, _, _, _) }
68 | Intermediate metasenv ->
71 let get_stack status =
72 match status.proof_status with
73 | Incomplete_proof p -> p.stack
74 | Proof _ -> Continuationals.Stack.empty
77 let set_stack stack status =
78 match status.proof_status with
79 | Incomplete_proof p ->
80 { status with proof_status = Incomplete_proof { p with stack = stack } }
82 assert (Continuationals.Stack.is_empty stack);
86 let set_metasenv metasenv status =
88 match status.proof_status with
89 | No_proof -> Intermediate metasenv
90 | Incomplete_proof ({ proof = (uri, _, subst, proof, ty, attrs) } as incomplete_proof) ->
92 { incomplete_proof with proof = (uri, metasenv, subst, proof, ty, attrs) }
93 | Intermediate _ -> Intermediate metasenv
94 | Proof (_, metasenv', _, _, _, _) ->
95 assert (metasenv = metasenv');
98 { status with proof_status = proof_status }
100 let get_proof_context status goal =
101 match status.proof_status with
102 | Incomplete_proof { proof = (_, metasenv, _, _, _, _) } ->
103 let (_, context, _) = CicUtil.lookup_meta goal metasenv in
107 let get_proof_conclusion status goal =
108 match status.proof_status with
109 | Incomplete_proof { proof = (_, metasenv, _, _, _, _) } ->
110 let (_, _, conclusion) = CicUtil.lookup_meta goal metasenv in
112 | _ -> raise (Statement_error "no ongoing proof")
114 let add_moo_content cmds status =
115 let content = status.moo_content_rev in
119 (* prerr_endline ("adding to moo command: " ^ GrafiteAstPp.pp_command cmd); *)
121 | GrafiteAst.Default _
123 | GrafiteAst.Coercion _ ->
124 if List.mem cmd content then acc
129 (* prerr_endline ("new moo content: " ^ String.concat " " (List.map
130 GrafiteAstPp.pp_command content')); *)
131 { status with moo_content_rev = content' }
133 let get_baseuri status = status.baseuri;;
136 let get_option status name =
138 StringMap.find name status.options
139 with Not_found -> raise (Option_error (name, "not found"))
141 let set_option status name value =
142 let types = [ (* no set options defined! *) ] in
144 try List.assoc name types
146 command_error (Printf.sprintf "Unknown option \"%s\"" name)
149 match ty_and_mangler with
150 | `String, f -> String (f value)
153 Int (int_of_string (f value))
155 command_error (Printf.sprintf "Not an integer value \"%s\"" value))
157 { status with options = StringMap.add name value status.options }
160 let get_string_option status name =
161 match get_option status name with
163 | _ -> raise (Option_error (name, "not a string value"))
166 let dump_status status =
167 HLog.message "status.aliases:\n";
168 HLog.message "status.proof_status:";
170 (match status.proof_status with
171 | No_proof -> "no proof\n"
172 | Incomplete_proof _ -> "incomplete proof\n"
173 | Proof _ -> "proof\n"
174 | Intermediate _ -> "Intermediate\n");
175 HLog.message "status.options\n";
177 StringMap.iter (fun k v ->
181 | Int i -> string_of_int i
183 HLog.message (k ^ "::=" ^ v)) status.options;
185 HLog.message "status.coercions\n";
186 HLog.message "status.objects:\n";
188 (fun u -> HLog.message (UriManager.string_of_uri u)) status.objects