]> matita.cs.unibo.it Git - helm.git/blob - helm/software/components/grafite_engine/grafiteTypes.ml
1) grafiteWalker removed
[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.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_estatus x = 
62   match x.ng_status with
63   | ProofMode t -> t.NTacStatus.istatus.NTacStatus.estatus
64   | CommandMode e -> e
65 ;;
66
67 let set_estatus e x =
68  { x with ng_status =
69    match x.ng_status with
70       ProofMode t ->
71        ProofMode
72         {t with NTacStatus.istatus =
73          {t.NTacStatus.istatus with NTacStatus.estatus = e}}
74     | CommandMode _ -> CommandMode e}
75 ;;
76
77 let get_current_proof status =
78   match status.proof_status with
79   | Incomplete_proof { proof = p } -> p
80   | Proof p -> p
81   | _ -> raise (Statement_error "no ongoing proof")
82
83 let get_proof_metasenv status =
84   match status.proof_status with
85   | No_proof -> []
86   | Proof (_, metasenv, _, _, _, _)
87   | Incomplete_proof { proof = (_, metasenv, _, _, _, _) }
88   | Intermediate metasenv ->
89       metasenv
90
91 let get_stack status =
92   match status.proof_status with
93   | Incomplete_proof p -> p.stack
94   | Proof _ -> Continuationals.Stack.empty
95   | _ -> assert false
96
97 let set_stack stack status =
98   match status.proof_status with
99   | Incomplete_proof p ->
100       { status with proof_status = Incomplete_proof { p with stack = stack } }
101   | Proof _ ->
102       assert (Continuationals.Stack.is_empty stack);
103       status
104   | _ -> assert false
105
106 let set_metasenv metasenv status =
107   let proof_status =
108     match status.proof_status with
109     | No_proof -> Intermediate metasenv
110     | Incomplete_proof ({ proof = (uri, _, subst, proof, ty, attrs) } as incomplete_proof) ->
111         Incomplete_proof
112           { incomplete_proof with proof = (uri, metasenv, subst, proof, ty, attrs) }
113     | Intermediate _ -> Intermediate metasenv 
114     | Proof (_, metasenv', _, _, _, _) ->
115        assert (metasenv = metasenv');
116        status.proof_status
117   in
118   { status with proof_status = proof_status }
119
120 let get_proof_context status goal =
121   match status.proof_status with
122   | Incomplete_proof { proof = (_, metasenv, _, _, _, _) } ->
123       let (_, context, _) = CicUtil.lookup_meta goal metasenv in
124       context
125   | _ -> []
126
127 let get_proof_conclusion status goal =
128   match status.proof_status with
129   | Incomplete_proof { proof = (_, metasenv, _, _, _, _) } ->
130       let (_, _, conclusion) = CicUtil.lookup_meta goal metasenv in
131       conclusion
132   | _ -> raise (Statement_error "no ongoing proof")
133  
134 let add_moo_content cmds status =
135   let content = status.moo_content_rev in
136   let content' =
137     List.fold_right
138       (fun cmd acc ->
139 (*         prerr_endline ("adding to moo command: " ^ GrafiteAstPp.pp_command cmd); *)
140         match cmd with
141         | GrafiteAst.Default _ 
142         | GrafiteAst.Index _
143         | GrafiteAst.Coercion _ ->
144             if List.mem cmd content then acc
145             else cmd :: acc
146         | _ -> cmd :: acc)
147       cmds content
148   in
149 (*   prerr_endline ("new moo content: " ^ String.concat " " (List.map
150     GrafiteAstPp.pp_command content')); *)
151   { status with moo_content_rev = content' }
152
153 let get_baseuri status = status.baseuri;;
154
155 (*
156 let get_option status name =
157   try
158     StringMap.find name status.options
159   with Not_found -> raise (Option_error (name, "not found"))
160  
161 let set_option status name value =
162   let types = [ (* no set options defined! *) ] in
163   let ty_and_mangler =
164     try List.assoc name types
165     with Not_found ->
166      command_error (Printf.sprintf "Unknown option \"%s\"" name)
167   in
168   let value =
169     match ty_and_mangler with
170     | `String, f -> String (f value)
171     | `Int, f ->
172         (try
173           Int (int_of_string (f value))
174         with Failure _ ->
175           command_error (Printf.sprintf "Not an integer value \"%s\"" value))
176   in
177     { status with options = StringMap.add name value status.options }
178
179
180 let get_string_option status name =
181   match get_option status name with
182   | String s -> s
183   | _ -> raise (Option_error (name, "not a string value"))
184 *)
185
186 let dump_status status = 
187   HLog.message "status.aliases:\n";
188   HLog.message "status.proof_status:"; 
189   HLog.message
190     (match status.proof_status with
191     | No_proof -> "no proof\n"
192     | Incomplete_proof _ -> "incomplete proof\n"
193     | Proof _ -> "proof\n"
194     | Intermediate _ -> "Intermediate\n");
195   HLog.message "status.options\n";
196 (* REMOVEME
197   StringMap.iter (fun k v -> 
198     let v = 
199       match v with
200       | String s -> s
201       | Int i -> string_of_int i
202     in
203     HLog.message (k ^ "::=" ^ v)) status.options;
204 *)
205   HLog.message "status.coercions\n";
206   HLog.message "status.objects:\n";
207   List.iter 
208     (fun u -> HLog.message (UriManager.string_of_uri u)) status.objects