]> matita.cs.unibo.it Git - helm.git/blob - helm/software/components/grafite_engine/grafiteTypes.ml
EXPERIMENTAL COMMIT (by CSC,actuall :-)
[helm.git] / helm / software / components / grafite_engine / grafiteTypes.ml
1 (* Copyright (C) 2004-2005, HELM Team.
2  * 
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.
6  * 
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.
11  * 
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.
16  *
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,
20  * MA  02111-1307, USA.
21  * 
22  * For details, see the HELM World-Wide-Web page,
23  * http://helm.cs.unibo.it/
24  *)
25
26 (* $Id$ *)
27
28 exception Option_error of string * string
29 exception Statement_error of string
30 exception Command_error of string
31
32 let command_error msg = raise (Command_error msg)
33
34 type incomplete_proof = {
35   proof: ProofEngineTypes.proof;
36   stack: Continuationals.Stack.t;
37 }
38
39 type proof_status =
40   | No_proof
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. *)
46
47 type ng_status =
48   | ProofMode of NTacStatus.tac_status
49   | CommandMode of NEstatus.extra_status
50
51 type 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;  
57   baseuri: string;
58   ng_status: ng_status;
59 }
60
61 let get_lexicon x = 
62   match x.ng_status with
63   | ProofMode t -> t.NTacStatus.istatus.NTacStatus.estatus.NEstatus.lstatus
64   | CommandMode e -> e.NEstatus.lstatus
65 ;;
66  
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 -> 
71       CommandMode 
72         { estatus with NEstatus.lstatus = new_lexicon_status }
73    | ProofMode t -> 
74        ProofMode 
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 }}}}
79 ;; 
80
81 let set_coercions db new_grafite_status = 
82   { new_grafite_status with ng_status =
83    match new_grafite_status.ng_status with
84    | CommandMode estatus -> 
85       CommandMode 
86         { estatus with NEstatus.rstatus = 
87           { estatus.NEstatus.rstatus with NRstatus.coerc_db = db }}
88    | ProofMode t -> 
89        ProofMode 
90         { t with NTacStatus.istatus = 
91           { t.NTacStatus.istatus with NTacStatus.estatus = 
92             { t.NTacStatus.istatus.NTacStatus.estatus with NEstatus.rstatus =
93               { t.NTacStatus.istatus.NTacStatus.estatus.NEstatus.rstatus with NRstatus.coerc_db = db
94         }}}}}
95 ;; 
96
97 let get_estatus x = 
98   match x.ng_status with
99   | ProofMode t -> t.NTacStatus.istatus.NTacStatus.estatus
100   | CommandMode e -> e
101 ;;
102
103 let set_estatus e x =
104  { x with ng_status =
105    match x.ng_status with
106       ProofMode t ->
107        ProofMode
108         {t with NTacStatus.istatus =
109          {t.NTacStatus.istatus with NTacStatus.estatus = e}}
110     | CommandMode _ -> CommandMode e}
111 ;;
112
113 let get_rstatus x = (get_estatus x).NEstatus.rstatus;;
114
115 let get_hstatus x = (get_rstatus x).NRstatus.uhint_db;;
116
117 let get_library_db x = (get_rstatus x).NRstatus.library_db;;
118
119 let get_dump x = (get_rstatus x).NRstatus.dump;;
120
121 let set_rstatus h x =
122  let estatus = get_estatus x in
123   set_estatus { estatus with NEstatus.rstatus = h } x
124 ;;
125
126 let set_hstatus h x =
127  let rstatus = get_rstatus x in
128   set_rstatus { rstatus with NRstatus.uhint_db = h} x
129 ;;
130
131 let set_library_db h x =
132  let rstatus = get_rstatus x in
133   set_rstatus { rstatus with NRstatus.library_db = h} x
134 ;;
135
136 let set_dump h x =
137  let estatus = get_estatus x in
138   set_estatus
139   { estatus with NEstatus.rstatus =
140      { estatus.NEstatus.rstatus with
141         NRstatus.dump = h}}
142   x
143 ;;
144
145 let get_current_proof status =
146   match status.proof_status with
147   | Incomplete_proof { proof = p } -> p
148   | Proof p -> p
149   | _ -> raise (Statement_error "no ongoing proof")
150
151 let get_proof_metasenv status =
152   match status.proof_status with
153   | No_proof -> []
154   | Proof (_, metasenv, _, _, _, _)
155   | Incomplete_proof { proof = (_, metasenv, _, _, _, _) }
156   | Intermediate metasenv ->
157       metasenv
158
159 let get_stack status =
160   match status.proof_status with
161   | Incomplete_proof p -> p.stack
162   | Proof _ -> Continuationals.Stack.empty
163   | _ -> assert false
164
165 let set_stack stack status =
166   match status.proof_status with
167   | Incomplete_proof p ->
168       { status with proof_status = Incomplete_proof { p with stack = stack } }
169   | Proof _ ->
170       assert (Continuationals.Stack.is_empty stack);
171       status
172   | _ -> assert false
173
174 let set_metasenv metasenv status =
175   let proof_status =
176     match status.proof_status with
177     | No_proof -> Intermediate metasenv
178     | Incomplete_proof ({ proof = (uri, _, subst, proof, ty, attrs) } as incomplete_proof) ->
179         Incomplete_proof
180           { incomplete_proof with proof = (uri, metasenv, subst, proof, ty, attrs) }
181     | Intermediate _ -> Intermediate metasenv 
182     | Proof (_, metasenv', _, _, _, _) ->
183        assert (metasenv = metasenv');
184        status.proof_status
185   in
186   { status with proof_status = proof_status }
187
188 let get_proof_context status goal =
189   match status.proof_status with
190   | Incomplete_proof { proof = (_, metasenv, _, _, _, _) } ->
191       let (_, context, _) = CicUtil.lookup_meta goal metasenv in
192       context
193   | _ -> []
194
195 let get_proof_conclusion status goal =
196   match status.proof_status with
197   | Incomplete_proof { proof = (_, metasenv, _, _, _, _) } ->
198       let (_, _, conclusion) = CicUtil.lookup_meta goal metasenv in
199       conclusion
200   | _ -> raise (Statement_error "no ongoing proof")
201  
202 let add_moo_content cmds status =
203   let content = status.moo_content_rev in
204   let content' =
205     List.fold_right
206       (fun cmd acc ->
207 (*         prerr_endline ("adding to moo command: " ^ GrafiteAstPp.pp_command cmd); *)
208         match cmd with
209         | GrafiteAst.Default _ 
210         | GrafiteAst.Index _
211         | GrafiteAst.Coercion _ ->
212             if List.mem cmd content then acc
213             else cmd :: acc
214         | _ -> cmd :: acc)
215       cmds content
216   in
217 (*   prerr_endline ("new moo content: " ^ String.concat " " (List.map
218     GrafiteAstPp.pp_command content')); *)
219   { status with moo_content_rev = content' }
220
221 let get_baseuri status = status.baseuri;;
222
223 (*
224 let get_option status name =
225   try
226     StringMap.find name status.options
227   with Not_found -> raise (Option_error (name, "not found"))
228  
229 let set_option status name value =
230   let types = [ (* no set options defined! *) ] in
231   let ty_and_mangler =
232     try List.assoc name types
233     with Not_found ->
234      command_error (Printf.sprintf "Unknown option \"%s\"" name)
235   in
236   let value =
237     match ty_and_mangler with
238     | `String, f -> String (f value)
239     | `Int, f ->
240         (try
241           Int (int_of_string (f value))
242         with Failure _ ->
243           command_error (Printf.sprintf "Not an integer value \"%s\"" value))
244   in
245     { status with options = StringMap.add name value status.options }
246
247
248 let get_string_option status name =
249   match get_option status name with
250   | String s -> s
251   | _ -> raise (Option_error (name, "not a string value"))
252 *)
253
254 let dump_status status = 
255   HLog.message "status.aliases:\n";
256   HLog.message "status.proof_status:"; 
257   HLog.message
258     (match status.proof_status with
259     | No_proof -> "no proof\n"
260     | Incomplete_proof _ -> "incomplete proof\n"
261     | Proof _ -> "proof\n"
262     | Intermediate _ -> "Intermediate\n");
263   HLog.message "status.options\n";
264 (* REMOVEME
265   StringMap.iter (fun k v -> 
266     let v = 
267       match v with
268       | String s -> s
269       | Int i -> string_of_int i
270     in
271     HLog.message (k ^ "::=" ^ v)) status.options;
272 *)
273   HLog.message "status.coercions\n";
274   HLog.message "status.objects:\n";
275   List.iter 
276     (fun u -> HLog.message (UriManager.string_of_uri u)) status.objects 
277   
278 let get_coercions new_grafite_status = 
279    let e = get_estatus new_grafite_status in
280    e.NEstatus.rstatus.NRstatus.coerc_db 
281 ;;
282