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