22 exception UNDEF |
22 exception UNDEF |
23 val node_history_of: state -> node History.T |
23 val node_history_of: state -> node History.T |
24 val node_of: state -> node |
24 val node_of: state -> node |
25 val node_case: (theory -> 'a) -> (Proof.state -> 'a) -> state -> 'a |
25 val node_case: (theory -> 'a) -> (Proof.state -> 'a) -> state -> 'a |
26 val theory_of: state -> theory |
26 val theory_of: state -> theory |
27 val sign_of: state -> Sign.sg |
27 val sign_of: state -> theory (*obsolete*) |
28 val context_of: state -> Proof.context |
28 val context_of: state -> Proof.context |
29 val proof_of: state -> Proof.state |
29 val proof_of: state -> Proof.state |
30 val enter_forward_proof: state -> Proof.state |
30 val enter_forward_proof: state -> Proof.state |
31 type transition |
31 type transition |
32 exception TERMINATE |
32 exception TERMINATE |
95 |
95 |
96 fun str_of_node (Theory _) = "in theory mode" |
96 fun str_of_node (Theory _) = "in theory mode" |
97 | str_of_node _ = "in proof mode"; |
97 | str_of_node _ = "in proof mode"; |
98 |
98 |
99 fun pretty_context thy = [Pretty.block |
99 fun pretty_context thy = [Pretty.block |
100 [Pretty.str "theory", Pretty.brk 1, Pretty.str (PureThy.get_name thy), |
100 [Pretty.str "theory", Pretty.brk 1, Pretty.str (Context.theory_name thy), |
101 Pretty.str " =", Pretty.brk 1, ThyInfo.pretty_theory thy]]; |
101 Pretty.str " =", Pretty.brk 1, ThyInfo.pretty_theory thy]]; |
102 |
102 |
103 fun pretty_prf prf = Proof.pretty_state (ProofHistory.position prf) (ProofHistory.current prf); |
103 fun pretty_prf prf = Proof.pretty_state (ProofHistory.position prf) (ProofHistory.current prf); |
104 |
104 |
105 fun pretty_node_context (Theory thy) = pretty_context thy |
105 fun pretty_node_context (Theory thy) = pretty_context thy |
167 Theory thy => f thy |
167 Theory thy => f thy |
168 | SkipProof (i, thy) => f thy |
168 | SkipProof (i, thy) => f thy |
169 | Proof prf => g (ProofHistory.current prf)); |
169 | Proof prf => g (ProofHistory.current prf)); |
170 |
170 |
171 val theory_of = node_case I Proof.theory_of; |
171 val theory_of = node_case I Proof.theory_of; |
|
172 val sign_of = theory_of; |
172 val context_of = node_case ProofContext.init Proof.context_of; |
173 val context_of = node_case ProofContext.init Proof.context_of; |
173 val sign_of = Theory.sign_of o theory_of; |
|
174 val proof_of = node_case (fn _ => raise UNDEF) I; |
174 val proof_of = node_case (fn _ => raise UNDEF) I; |
175 |
175 |
176 val enter_forward_proof = node_case Proof.init_state Proof.enter_forward; |
176 val enter_forward_proof = node_case Proof.init_state Proof.enter_forward; |
177 |
177 |
178 |
178 |
183 exception RESTART; |
183 exception RESTART; |
184 exception EXCURSION_FAIL of exn * string; |
184 exception EXCURSION_FAIL of exn * string; |
185 exception FAILURE of state * exn; |
185 exception FAILURE of state * exn; |
186 |
186 |
187 |
187 |
188 (* recovery from stale signatures *) |
188 (* recovery from stale theories *) |
189 |
189 |
190 (*note: proof commands should be non-destructive!*) |
190 (*note: proof commands should be non-destructive!*) |
191 |
191 |
192 local |
192 local |
193 |
193 |
194 fun is_stale state = Sign.is_stale (sign_of state) handle UNDEF => false; |
194 fun is_stale state = Context.is_stale (theory_of state) handle UNDEF => false; |
195 |
195 |
196 fun checkpoint_node true (Theory thy) = Theory (PureThy.checkpoint thy) |
196 fun checkpoint_node true (Theory thy) = Theory (Theory.checkpoint thy) |
197 | checkpoint_node _ node = node; |
197 | checkpoint_node _ node = node; |
198 |
198 |
199 fun copy_node true (Theory thy) = Theory (Theory.copy thy) |
199 fun copy_node true (Theory thy) = Theory (Theory.copy thy) |
200 | copy_node _ node = node; |
200 | copy_node _ node = node; |
201 |
201 |
202 fun interruptible f x = |
202 fun interruptible f x = |
203 let val y = ref (NONE: node History.T option); |
203 let val y = ref (NONE: node History.T option); |
204 in raise_interrupt (fn () => y := SOME (f x)) (); the (! y) end; |
204 in raise_interrupt (fn () => y := SOME (f x)) (); the (! y) end; |
205 |
205 |
206 val rollback = ERROR_MESSAGE "Stale signature encountered after succesful execution!"; |
206 val rollback = ERROR_MESSAGE "Stale theory encountered after succesful execution!"; |
207 |
207 |
208 fun return (result, NONE) = result |
208 fun return (result, NONE) = result |
209 | return (result, SOME exn) = raise FAILURE (result, exn); |
209 | return (result, SOME exn) = raise FAILURE (result, exn); |
210 |
210 |
211 in |
211 in |
227 else return (result, opt_exn) |
227 else return (result, opt_exn) |
228 end; |
228 end; |
229 |
229 |
230 fun check_stale state = |
230 fun check_stale state = |
231 if not (is_stale state) then () |
231 if not (is_stale state) then () |
232 else warning "Stale signature encountered!"; |
232 else warning "Stale theory encountered!"; |
233 |
233 |
234 end; |
234 end; |
235 |
235 |
236 |
236 |
237 (* primitive transitions *) |
237 (* primitive transitions *) |
238 |
238 |
239 (*Important note: recovery from stale signatures is provided only for |
239 (*Important note: recovery from stale theories is provided only for |
240 theory-level operations via MapCurrent and AppCurrent. Other node |
240 theory-level operations via MapCurrent and AppCurrent. Other node |
241 or state operations should not touch signatures at all. |
241 or state operations should not touch theories at all. |
242 |
242 |
243 Also note that interrupts are enabled for Keep, MapCurrent, and |
243 Also note that interrupts are enabled for Keep, MapCurrent, and |
244 AppCurrent only.*) |
244 AppCurrent only.*) |
245 |
245 |
246 datatype trans = |
246 datatype trans = |
426 |
426 |
427 local |
427 local |
428 |
428 |
429 fun with_context f xs = |
429 fun with_context f xs = |
430 (case Context.get_context () of NONE => [] |
430 (case Context.get_context () of NONE => [] |
431 | SOME thy => map (f (Theory.sign_of thy)) xs); |
431 | SOME thy => map (f thy) xs); |
432 |
432 |
433 fun raised name [] = "exception " ^ name ^ " raised" |
433 fun raised name [] = "exception " ^ name ^ " raised" |
434 | raised name [msg] = "exception " ^ name ^ " raised: " ^ msg |
434 | raised name [msg] = "exception " ^ name ^ " raised: " ^ msg |
435 | raised name msgs = cat_lines (("exception " ^ name ^ " raised:") :: msgs); |
435 | raised name msgs = cat_lines (("exception " ^ name ^ " raised:") :: msgs); |
436 |
436 |
437 fun exn_msg _ TERMINATE = "Exit." |
437 fun exn_msg _ TERMINATE = "Exit." |
438 | exn_msg _ RESTART = "Restart." |
438 | exn_msg _ RESTART = "Restart." |
439 | exn_msg detailed (EXCURSION_FAIL (exn, msg)) = cat_lines [exn_msg detailed exn, msg] |
|
440 | exn_msg _ Interrupt = "Interrupt." |
439 | exn_msg _ Interrupt = "Interrupt." |
441 | exn_msg _ ERROR = "ERROR." |
440 | exn_msg _ ERROR = "ERROR." |
442 | exn_msg _ (ERROR_MESSAGE msg) = msg |
441 | exn_msg _ (ERROR_MESSAGE msg) = msg |
|
442 | exn_msg detailed (EXCURSION_FAIL (exn, msg)) = cat_lines [exn_msg detailed exn, msg] |
|
443 | exn_msg detailed (Context.DATA_FAIL (exn, msg)) = cat_lines [exn_msg detailed exn, msg] |
443 | exn_msg false (THEORY (msg, _)) = msg |
444 | exn_msg false (THEORY (msg, _)) = msg |
444 | exn_msg true (THEORY (msg, thys)) = |
445 | exn_msg true (THEORY (msg, thys)) = raised "THEORY" (msg :: map Context.str_of_thy thys) |
445 raised "THEORY" (msg :: map (Pretty.string_of o Display.pretty_theory) thys) |
|
446 | exn_msg _ (ProofContext.CONTEXT (msg, _)) = msg |
446 | exn_msg _ (ProofContext.CONTEXT (msg, _)) = msg |
447 | exn_msg _ (Proof.STATE (msg, _)) = msg |
447 | exn_msg _ (Proof.STATE (msg, _)) = msg |
448 | exn_msg _ (ProofHistory.FAIL msg) = msg |
448 | exn_msg _ (ProofHistory.FAIL msg) = msg |
449 | exn_msg detailed (MetaSimplifier.SIMPROC_FAIL (name, exn)) = |
449 | exn_msg detailed (MetaSimplifier.SIMPROC_FAIL (name, exn)) = |
450 fail_msg detailed "simproc" ((name, Position.none), exn) |
450 fail_msg detailed "simproc" ((name, Position.none), exn) |