author | wenzelm |
Tue, 01 Jul 2008 18:38:44 +0200 | |
changeset 27428 | f92d47cdc0de |
parent 26643 | 99f5407c05ef |
child 27432 | c5ec309c6de8 |
permissions | -rw-r--r-- |
26605
24e60e823d22
The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff
changeset
|
1 |
(* Title: Pure/Isar/isar.ML |
24e60e823d22
The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff
changeset
|
2 |
ID: $Id$ |
24e60e823d22
The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff
changeset
|
3 |
Author: Makarius |
24e60e823d22
The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff
changeset
|
4 |
|
24e60e823d22
The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff
changeset
|
5 |
The global Isabelle/Isar state and main read-eval-print loop. |
24e60e823d22
The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff
changeset
|
6 |
*) |
24e60e823d22
The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff
changeset
|
7 |
|
24e60e823d22
The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff
changeset
|
8 |
signature ISAR = |
24e60e823d22
The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff
changeset
|
9 |
sig |
24e60e823d22
The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff
changeset
|
10 |
val state: unit -> Toplevel.state |
24e60e823d22
The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff
changeset
|
11 |
val exn: unit -> (exn * string) option |
24e60e823d22
The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff
changeset
|
12 |
val context: unit -> Proof.context |
24e60e823d22
The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff
changeset
|
13 |
val goal: unit -> thm |
24e60e823d22
The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff
changeset
|
14 |
val >> : Toplevel.transition -> bool |
24e60e823d22
The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff
changeset
|
15 |
val >>> : Toplevel.transition list -> unit |
24e60e823d22
The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff
changeset
|
16 |
val crashes: exn list ref |
26643 | 17 |
val toplevel_loop: {init: bool, welcome: bool, sync: bool, secure: bool} -> unit |
26605
24e60e823d22
The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff
changeset
|
18 |
val loop: unit -> unit |
26606
379596d12f25
replaced Isar loop variants by generic toplevel_loop;
wenzelm
parents:
26605
diff
changeset
|
19 |
val main: unit -> unit |
26605
24e60e823d22
The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff
changeset
|
20 |
end; |
24e60e823d22
The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff
changeset
|
21 |
|
24e60e823d22
The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff
changeset
|
22 |
structure Isar: ISAR = |
24e60e823d22
The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff
changeset
|
23 |
struct |
24e60e823d22
The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff
changeset
|
24 |
|
27428
f92d47cdc0de
explicit identification of toplevel commands, with status etc.;
wenzelm
parents:
26643
diff
changeset
|
25 |
(** individual toplevel commands **) |
f92d47cdc0de
explicit identification of toplevel commands, with status etc.;
wenzelm
parents:
26643
diff
changeset
|
26 |
|
f92d47cdc0de
explicit identification of toplevel commands, with status etc.;
wenzelm
parents:
26643
diff
changeset
|
27 |
(* unique identification *) |
f92d47cdc0de
explicit identification of toplevel commands, with status etc.;
wenzelm
parents:
26643
diff
changeset
|
28 |
|
f92d47cdc0de
explicit identification of toplevel commands, with status etc.;
wenzelm
parents:
26643
diff
changeset
|
29 |
type id = string; |
f92d47cdc0de
explicit identification of toplevel commands, with status etc.;
wenzelm
parents:
26643
diff
changeset
|
30 |
val no_id : id = ""; |
f92d47cdc0de
explicit identification of toplevel commands, with status etc.;
wenzelm
parents:
26643
diff
changeset
|
31 |
|
f92d47cdc0de
explicit identification of toplevel commands, with status etc.;
wenzelm
parents:
26643
diff
changeset
|
32 |
fun identify tr = |
f92d47cdc0de
explicit identification of toplevel commands, with status etc.;
wenzelm
parents:
26643
diff
changeset
|
33 |
(case Toplevel.get_id tr of |
f92d47cdc0de
explicit identification of toplevel commands, with status etc.;
wenzelm
parents:
26643
diff
changeset
|
34 |
SOME id => (id, tr) |
f92d47cdc0de
explicit identification of toplevel commands, with status etc.;
wenzelm
parents:
26643
diff
changeset
|
35 |
| NONE => |
f92d47cdc0de
explicit identification of toplevel commands, with status etc.;
wenzelm
parents:
26643
diff
changeset
|
36 |
let val id = "isabelle:" ^ serial_string () |
f92d47cdc0de
explicit identification of toplevel commands, with status etc.;
wenzelm
parents:
26643
diff
changeset
|
37 |
in (id, Toplevel.put_id id tr) end); |
f92d47cdc0de
explicit identification of toplevel commands, with status etc.;
wenzelm
parents:
26643
diff
changeset
|
38 |
|
f92d47cdc0de
explicit identification of toplevel commands, with status etc.;
wenzelm
parents:
26643
diff
changeset
|
39 |
|
f92d47cdc0de
explicit identification of toplevel commands, with status etc.;
wenzelm
parents:
26643
diff
changeset
|
40 |
(* execution status *) |
f92d47cdc0de
explicit identification of toplevel commands, with status etc.;
wenzelm
parents:
26643
diff
changeset
|
41 |
|
f92d47cdc0de
explicit identification of toplevel commands, with status etc.;
wenzelm
parents:
26643
diff
changeset
|
42 |
datatype status = |
f92d47cdc0de
explicit identification of toplevel commands, with status etc.;
wenzelm
parents:
26643
diff
changeset
|
43 |
Initial of Toplevel.transition | |
f92d47cdc0de
explicit identification of toplevel commands, with status etc.;
wenzelm
parents:
26643
diff
changeset
|
44 |
Final of Toplevel.state * (exn * string) option; |
f92d47cdc0de
explicit identification of toplevel commands, with status etc.;
wenzelm
parents:
26643
diff
changeset
|
45 |
|
f92d47cdc0de
explicit identification of toplevel commands, with status etc.;
wenzelm
parents:
26643
diff
changeset
|
46 |
|
f92d47cdc0de
explicit identification of toplevel commands, with status etc.;
wenzelm
parents:
26643
diff
changeset
|
47 |
(* datatype command *) |
f92d47cdc0de
explicit identification of toplevel commands, with status etc.;
wenzelm
parents:
26643
diff
changeset
|
48 |
|
f92d47cdc0de
explicit identification of toplevel commands, with status etc.;
wenzelm
parents:
26643
diff
changeset
|
49 |
datatype kind = Theory | Proof | Other; |
f92d47cdc0de
explicit identification of toplevel commands, with status etc.;
wenzelm
parents:
26643
diff
changeset
|
50 |
|
f92d47cdc0de
explicit identification of toplevel commands, with status etc.;
wenzelm
parents:
26643
diff
changeset
|
51 |
datatype command = Command of |
f92d47cdc0de
explicit identification of toplevel commands, with status etc.;
wenzelm
parents:
26643
diff
changeset
|
52 |
{prev: id, |
f92d47cdc0de
explicit identification of toplevel commands, with status etc.;
wenzelm
parents:
26643
diff
changeset
|
53 |
up: id, |
f92d47cdc0de
explicit identification of toplevel commands, with status etc.;
wenzelm
parents:
26643
diff
changeset
|
54 |
kind: kind, |
f92d47cdc0de
explicit identification of toplevel commands, with status etc.;
wenzelm
parents:
26643
diff
changeset
|
55 |
status: status}; |
f92d47cdc0de
explicit identification of toplevel commands, with status etc.;
wenzelm
parents:
26643
diff
changeset
|
56 |
|
f92d47cdc0de
explicit identification of toplevel commands, with status etc.;
wenzelm
parents:
26643
diff
changeset
|
57 |
fun make_command (prev, up, kind, status) = |
f92d47cdc0de
explicit identification of toplevel commands, with status etc.;
wenzelm
parents:
26643
diff
changeset
|
58 |
Command {prev = prev, up = up, kind = kind, status = status}; |
f92d47cdc0de
explicit identification of toplevel commands, with status etc.;
wenzelm
parents:
26643
diff
changeset
|
59 |
|
f92d47cdc0de
explicit identification of toplevel commands, with status etc.;
wenzelm
parents:
26643
diff
changeset
|
60 |
val empty_command = make_command (no_id, no_id, Other, Final (Toplevel.toplevel, NONE)); |
f92d47cdc0de
explicit identification of toplevel commands, with status etc.;
wenzelm
parents:
26643
diff
changeset
|
61 |
|
f92d47cdc0de
explicit identification of toplevel commands, with status etc.;
wenzelm
parents:
26643
diff
changeset
|
62 |
fun map_command f (Command {prev, up, kind, status}) = make_command (f (prev, up, kind, status)); |
f92d47cdc0de
explicit identification of toplevel commands, with status etc.;
wenzelm
parents:
26643
diff
changeset
|
63 |
fun map_status f = map_command (fn (prev, up, kind, status) => (prev, up, kind, f status)); |
f92d47cdc0de
explicit identification of toplevel commands, with status etc.;
wenzelm
parents:
26643
diff
changeset
|
64 |
|
26605
24e60e823d22
The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff
changeset
|
65 |
|
27428
f92d47cdc0de
explicit identification of toplevel commands, with status etc.;
wenzelm
parents:
26643
diff
changeset
|
66 |
(* table of identified commands *) |
f92d47cdc0de
explicit identification of toplevel commands, with status etc.;
wenzelm
parents:
26643
diff
changeset
|
67 |
|
f92d47cdc0de
explicit identification of toplevel commands, with status etc.;
wenzelm
parents:
26643
diff
changeset
|
68 |
local |
f92d47cdc0de
explicit identification of toplevel commands, with status etc.;
wenzelm
parents:
26643
diff
changeset
|
69 |
|
f92d47cdc0de
explicit identification of toplevel commands, with status etc.;
wenzelm
parents:
26643
diff
changeset
|
70 |
val empty_commands = Symtab.empty: command Symtab.table; |
f92d47cdc0de
explicit identification of toplevel commands, with status etc.;
wenzelm
parents:
26643
diff
changeset
|
71 |
val global_commands = ref empty_commands; |
f92d47cdc0de
explicit identification of toplevel commands, with status etc.;
wenzelm
parents:
26643
diff
changeset
|
72 |
|
f92d47cdc0de
explicit identification of toplevel commands, with status etc.;
wenzelm
parents:
26643
diff
changeset
|
73 |
in |
f92d47cdc0de
explicit identification of toplevel commands, with status etc.;
wenzelm
parents:
26643
diff
changeset
|
74 |
|
f92d47cdc0de
explicit identification of toplevel commands, with status etc.;
wenzelm
parents:
26643
diff
changeset
|
75 |
fun change_commands f = NAMED_CRITICAL "Isar" (fn () => change global_commands f); |
f92d47cdc0de
explicit identification of toplevel commands, with status etc.;
wenzelm
parents:
26643
diff
changeset
|
76 |
fun init_commands () = change_commands (K empty_commands); |
f92d47cdc0de
explicit identification of toplevel commands, with status etc.;
wenzelm
parents:
26643
diff
changeset
|
77 |
|
f92d47cdc0de
explicit identification of toplevel commands, with status etc.;
wenzelm
parents:
26643
diff
changeset
|
78 |
fun the_command id = |
f92d47cdc0de
explicit identification of toplevel commands, with status etc.;
wenzelm
parents:
26643
diff
changeset
|
79 |
if id = no_id then empty_command |
f92d47cdc0de
explicit identification of toplevel commands, with status etc.;
wenzelm
parents:
26643
diff
changeset
|
80 |
else |
f92d47cdc0de
explicit identification of toplevel commands, with status etc.;
wenzelm
parents:
26643
diff
changeset
|
81 |
(case Symtab.lookup (! global_commands) id of |
f92d47cdc0de
explicit identification of toplevel commands, with status etc.;
wenzelm
parents:
26643
diff
changeset
|
82 |
SOME cmd => cmd |
f92d47cdc0de
explicit identification of toplevel commands, with status etc.;
wenzelm
parents:
26643
diff
changeset
|
83 |
| NONE => sys_error ("Unknown command " ^ quote id)); |
26605
24e60e823d22
The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff
changeset
|
84 |
|
27428
f92d47cdc0de
explicit identification of toplevel commands, with status etc.;
wenzelm
parents:
26643
diff
changeset
|
85 |
fun the_state id = |
f92d47cdc0de
explicit identification of toplevel commands, with status etc.;
wenzelm
parents:
26643
diff
changeset
|
86 |
(case the_command id of |
f92d47cdc0de
explicit identification of toplevel commands, with status etc.;
wenzelm
parents:
26643
diff
changeset
|
87 |
Command {status = Final res, ...} => res |
f92d47cdc0de
explicit identification of toplevel commands, with status etc.;
wenzelm
parents:
26643
diff
changeset
|
88 |
| _ => sys_error ("Unfinished command " ^ quote id)); |
f92d47cdc0de
explicit identification of toplevel commands, with status etc.;
wenzelm
parents:
26643
diff
changeset
|
89 |
|
f92d47cdc0de
explicit identification of toplevel commands, with status etc.;
wenzelm
parents:
26643
diff
changeset
|
90 |
end; |
f92d47cdc0de
explicit identification of toplevel commands, with status etc.;
wenzelm
parents:
26643
diff
changeset
|
91 |
|
f92d47cdc0de
explicit identification of toplevel commands, with status etc.;
wenzelm
parents:
26643
diff
changeset
|
92 |
|
f92d47cdc0de
explicit identification of toplevel commands, with status etc.;
wenzelm
parents:
26643
diff
changeset
|
93 |
|
f92d47cdc0de
explicit identification of toplevel commands, with status etc.;
wenzelm
parents:
26643
diff
changeset
|
94 |
(** TTY interaction **) |
f92d47cdc0de
explicit identification of toplevel commands, with status etc.;
wenzelm
parents:
26643
diff
changeset
|
95 |
|
f92d47cdc0de
explicit identification of toplevel commands, with status etc.;
wenzelm
parents:
26643
diff
changeset
|
96 |
(* global point *) |
f92d47cdc0de
explicit identification of toplevel commands, with status etc.;
wenzelm
parents:
26643
diff
changeset
|
97 |
|
f92d47cdc0de
explicit identification of toplevel commands, with status etc.;
wenzelm
parents:
26643
diff
changeset
|
98 |
local val global_point = ref no_id in |
f92d47cdc0de
explicit identification of toplevel commands, with status etc.;
wenzelm
parents:
26643
diff
changeset
|
99 |
|
f92d47cdc0de
explicit identification of toplevel commands, with status etc.;
wenzelm
parents:
26643
diff
changeset
|
100 |
fun change_point f = NAMED_CRITICAL "Isar" (fn () => change global_point f); |
f92d47cdc0de
explicit identification of toplevel commands, with status etc.;
wenzelm
parents:
26643
diff
changeset
|
101 |
|
f92d47cdc0de
explicit identification of toplevel commands, with status etc.;
wenzelm
parents:
26643
diff
changeset
|
102 |
fun point_state () = NAMED_CRITICAL "Isar" (fn () => |
f92d47cdc0de
explicit identification of toplevel commands, with status etc.;
wenzelm
parents:
26643
diff
changeset
|
103 |
let val id = ! global_point in (id, the_state id) end); |
f92d47cdc0de
explicit identification of toplevel commands, with status etc.;
wenzelm
parents:
26643
diff
changeset
|
104 |
|
f92d47cdc0de
explicit identification of toplevel commands, with status etc.;
wenzelm
parents:
26643
diff
changeset
|
105 |
fun state () = #1 (#2 (point_state ())); |
f92d47cdc0de
explicit identification of toplevel commands, with status etc.;
wenzelm
parents:
26643
diff
changeset
|
106 |
fun exn () = #2 (#2 (point_state ())); |
26605
24e60e823d22
The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff
changeset
|
107 |
|
24e60e823d22
The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff
changeset
|
108 |
fun context () = |
24e60e823d22
The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff
changeset
|
109 |
Toplevel.context_of (state ()) |
24e60e823d22
The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff
changeset
|
110 |
handle Toplevel.UNDEF => error "Unknown context"; |
24e60e823d22
The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff
changeset
|
111 |
|
24e60e823d22
The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff
changeset
|
112 |
fun goal () = |
24e60e823d22
The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff
changeset
|
113 |
#2 (#2 (Proof.get_goal (Toplevel.proof_of (state ())))) |
24e60e823d22
The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff
changeset
|
114 |
handle Toplevel.UNDEF => error "No goal present"; |
24e60e823d22
The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff
changeset
|
115 |
|
27428
f92d47cdc0de
explicit identification of toplevel commands, with status etc.;
wenzelm
parents:
26643
diff
changeset
|
116 |
end; |
f92d47cdc0de
explicit identification of toplevel commands, with status etc.;
wenzelm
parents:
26643
diff
changeset
|
117 |
|
26605
24e60e823d22
The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff
changeset
|
118 |
|
24e60e823d22
The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff
changeset
|
119 |
(* interactive state transformations --- NOT THREAD-SAFE! *) |
24e60e823d22
The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff
changeset
|
120 |
|
24e60e823d22
The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff
changeset
|
121 |
nonfix >> >>>; |
24e60e823d22
The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff
changeset
|
122 |
|
27428
f92d47cdc0de
explicit identification of toplevel commands, with status etc.;
wenzelm
parents:
26643
diff
changeset
|
123 |
fun >> raw_tr = |
f92d47cdc0de
explicit identification of toplevel commands, with status etc.;
wenzelm
parents:
26643
diff
changeset
|
124 |
let |
f92d47cdc0de
explicit identification of toplevel commands, with status etc.;
wenzelm
parents:
26643
diff
changeset
|
125 |
val (id, tr) = identify raw_tr; |
f92d47cdc0de
explicit identification of toplevel commands, with status etc.;
wenzelm
parents:
26643
diff
changeset
|
126 |
val (prev, (prev_state, _)) = point_state (); |
f92d47cdc0de
explicit identification of toplevel commands, with status etc.;
wenzelm
parents:
26643
diff
changeset
|
127 |
val up = no_id; (* FIXME *) |
f92d47cdc0de
explicit identification of toplevel commands, with status etc.;
wenzelm
parents:
26643
diff
changeset
|
128 |
val kind = Other; (* FIXME *) |
f92d47cdc0de
explicit identification of toplevel commands, with status etc.;
wenzelm
parents:
26643
diff
changeset
|
129 |
val _ = change_commands (Symtab.update (id, make_command (prev, up, kind, Initial tr))); |
f92d47cdc0de
explicit identification of toplevel commands, with status etc.;
wenzelm
parents:
26643
diff
changeset
|
130 |
in |
f92d47cdc0de
explicit identification of toplevel commands, with status etc.;
wenzelm
parents:
26643
diff
changeset
|
131 |
(case Toplevel.transition true tr prev_state of |
f92d47cdc0de
explicit identification of toplevel commands, with status etc.;
wenzelm
parents:
26643
diff
changeset
|
132 |
NONE => (change_commands (Symtab.delete_safe id); false) |
f92d47cdc0de
explicit identification of toplevel commands, with status etc.;
wenzelm
parents:
26643
diff
changeset
|
133 |
| SOME result => |
f92d47cdc0de
explicit identification of toplevel commands, with status etc.;
wenzelm
parents:
26643
diff
changeset
|
134 |
(change_commands (Symtab.map_entry id (map_status (K (Final result)))); |
f92d47cdc0de
explicit identification of toplevel commands, with status etc.;
wenzelm
parents:
26643
diff
changeset
|
135 |
change_point (K id); |
f92d47cdc0de
explicit identification of toplevel commands, with status etc.;
wenzelm
parents:
26643
diff
changeset
|
136 |
(case #2 result of |
f92d47cdc0de
explicit identification of toplevel commands, with status etc.;
wenzelm
parents:
26643
diff
changeset
|
137 |
NONE => () |
f92d47cdc0de
explicit identification of toplevel commands, with status etc.;
wenzelm
parents:
26643
diff
changeset
|
138 |
| SOME err => Toplevel.error_msg tr err); |
f92d47cdc0de
explicit identification of toplevel commands, with status etc.;
wenzelm
parents:
26643
diff
changeset
|
139 |
true)) |
f92d47cdc0de
explicit identification of toplevel commands, with status etc.;
wenzelm
parents:
26643
diff
changeset
|
140 |
end; |
26605
24e60e823d22
The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff
changeset
|
141 |
|
24e60e823d22
The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff
changeset
|
142 |
fun >>> [] = () |
24e60e823d22
The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff
changeset
|
143 |
| >>> (tr :: trs) = if >> tr then >>> trs else (); |
24e60e823d22
The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff
changeset
|
144 |
|
24e60e823d22
The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff
changeset
|
145 |
|
26606
379596d12f25
replaced Isar loop variants by generic toplevel_loop;
wenzelm
parents:
26605
diff
changeset
|
146 |
(* toplevel loop *) |
26605
24e60e823d22
The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff
changeset
|
147 |
|
24e60e823d22
The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff
changeset
|
148 |
val crashes = ref ([]: exn list); |
24e60e823d22
The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff
changeset
|
149 |
|
24e60e823d22
The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff
changeset
|
150 |
local |
24e60e823d22
The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff
changeset
|
151 |
|
24e60e823d22
The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff
changeset
|
152 |
fun raw_loop secure src = |
24e60e823d22
The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff
changeset
|
153 |
let |
24e60e823d22
The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff
changeset
|
154 |
fun check_secure () = |
24e60e823d22
The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff
changeset
|
155 |
(if secure then warning "Secure loop -- cannot exit to ML" else (); secure); |
27428
f92d47cdc0de
explicit identification of toplevel commands, with status etc.;
wenzelm
parents:
26643
diff
changeset
|
156 |
val prev = #1 (point_state ()); |
f92d47cdc0de
explicit identification of toplevel commands, with status etc.;
wenzelm
parents:
26643
diff
changeset
|
157 |
val prompt_markup = |
f92d47cdc0de
explicit identification of toplevel commands, with status etc.;
wenzelm
parents:
26643
diff
changeset
|
158 |
if prev = no_id then I |
f92d47cdc0de
explicit identification of toplevel commands, with status etc.;
wenzelm
parents:
26643
diff
changeset
|
159 |
else Markup.markup (Markup.properties [(Markup.idN, prev)] Markup.position); |
26605
24e60e823d22
The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff
changeset
|
160 |
in |
27428
f92d47cdc0de
explicit identification of toplevel commands, with status etc.;
wenzelm
parents:
26643
diff
changeset
|
161 |
(case Source.get_single (Source.set_prompt (prompt_markup Source.default_prompt) src) of |
26606
379596d12f25
replaced Isar loop variants by generic toplevel_loop;
wenzelm
parents:
26605
diff
changeset
|
162 |
NONE => if secure then quit () else () |
379596d12f25
replaced Isar loop variants by generic toplevel_loop;
wenzelm
parents:
26605
diff
changeset
|
163 |
| SOME (tr, src') => if >> tr orelse check_secure () then raw_loop secure src' else ()) |
26605
24e60e823d22
The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff
changeset
|
164 |
handle exn => (Output.error_msg (Toplevel.exn_message exn) handle crash => |
24e60e823d22
The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff
changeset
|
165 |
(CRITICAL (fn () => change crashes (cons crash)); |
24e60e823d22
The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff
changeset
|
166 |
warning "Recovering after Isar toplevel crash -- see also Isar.crashes"); |
24e60e823d22
The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff
changeset
|
167 |
raw_loop secure src) |
24e60e823d22
The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff
changeset
|
168 |
end; |
24e60e823d22
The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff
changeset
|
169 |
|
24e60e823d22
The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff
changeset
|
170 |
in |
24e60e823d22
The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff
changeset
|
171 |
|
27428
f92d47cdc0de
explicit identification of toplevel commands, with status etc.;
wenzelm
parents:
26643
diff
changeset
|
172 |
fun toplevel_loop {init, welcome, sync, secure} = |
26605
24e60e823d22
The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff
changeset
|
173 |
(Context.set_thread_data NONE; |
27428
f92d47cdc0de
explicit identification of toplevel commands, with status etc.;
wenzelm
parents:
26643
diff
changeset
|
174 |
if init then init_commands () else (); |
26643 | 175 |
if welcome then writeln (Session.welcome ()) else (); |
26606
379596d12f25
replaced Isar loop variants by generic toplevel_loop;
wenzelm
parents:
26605
diff
changeset
|
176 |
uninterruptible (fn _ => fn () => raw_loop secure (OuterSyntax.isar sync)) ()); |
26605
24e60e823d22
The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff
changeset
|
177 |
|
24e60e823d22
The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff
changeset
|
178 |
end; |
24e60e823d22
The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff
changeset
|
179 |
|
26643 | 180 |
fun loop () = |
181 |
toplevel_loop {init = false, welcome = false, sync = false, secure = Secure.is_secure ()}; |
|
182 |
fun main () = |
|
183 |
toplevel_loop {init = true, welcome = true, sync = false, secure = Secure.is_secure ()}; |
|
26605
24e60e823d22
The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff
changeset
|
184 |
|
24e60e823d22
The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff
changeset
|
185 |
end; |
24e60e823d22
The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff
changeset
|
186 |