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