author | wenzelm |
Tue, 31 Mar 2020 14:40:56 +0200 | |
changeset 71853 | ec14ef6dd09b |
parent 71852 | 45c2b8cf1b26 |
child 71855 | 494704309099 |
permissions | -rw-r--r-- |
30173
eabece26b89b
moved isabelle_process.ML, isabelle_process.scala, isar.ML, session.ML to Pure/System/ (together with associated Isar commands);
wenzelm
parents:
29522
diff
changeset
|
1 |
(* Title: Pure/System/isabelle_process.ML |
25528
e67230c2b952
Isabelle process wrapper -- interaction via external program.
wenzelm
parents:
diff
changeset
|
2 |
Author: Makarius |
e67230c2b952
Isabelle process wrapper -- interaction via external program.
wenzelm
parents:
diff
changeset
|
3 |
|
57916 | 4 |
Isabelle process wrapper. |
25528
e67230c2b952
Isabelle process wrapper -- interaction via external program.
wenzelm
parents:
diff
changeset
|
5 |
*) |
e67230c2b952
Isabelle process wrapper -- interaction via external program.
wenzelm
parents:
diff
changeset
|
6 |
|
e67230c2b952
Isabelle process wrapper -- interaction via external program.
wenzelm
parents:
diff
changeset
|
7 |
signature ISABELLE_PROCESS = |
e67230c2b952
Isabelle process wrapper -- interaction via external program.
wenzelm
parents:
diff
changeset
|
8 |
sig |
42897 | 9 |
val is_active: unit -> bool |
46119
0d7172a7672c
tuned signature -- emphasize special nature of protocol commands;
wenzelm
parents:
45666
diff
changeset
|
10 |
val protocol_command: string -> (string list -> unit) -> unit |
52655
3b2b1ef13979
more careful termination of removed execs, leaving running execs undisturbed;
wenzelm
parents:
52584
diff
changeset
|
11 |
val reset_tracing: Document_ID.exec -> unit |
71847 | 12 |
exception EXIT of exn |
43684 | 13 |
val crashes: exn list Synchronized.var |
62563
2e352f63d15f
separate Isabelle_Process.init_options after Options.load_defaults, notably for "isabelle console";
wenzelm
parents:
62505
diff
changeset
|
14 |
val init_options: unit -> unit |
65300 | 15 |
val init_options_interactive: unit -> unit |
69584
09a6a7c04b45
more robust system channel via options that are private to the user;
wenzelm
parents:
69459
diff
changeset
|
16 |
val init: unit -> unit |
25528
e67230c2b952
Isabelle process wrapper -- interaction via external program.
wenzelm
parents:
diff
changeset
|
17 |
end; |
e67230c2b952
Isabelle process wrapper -- interaction via external program.
wenzelm
parents:
diff
changeset
|
18 |
|
31797 | 19 |
structure Isabelle_Process: ISABELLE_PROCESS = |
25528
e67230c2b952
Isabelle process wrapper -- interaction via external program.
wenzelm
parents:
diff
changeset
|
20 |
struct |
e67230c2b952
Isabelle process wrapper -- interaction via external program.
wenzelm
parents:
diff
changeset
|
21 |
|
42897 | 22 |
(* print mode *) |
25554 | 23 |
|
25748 | 24 |
val isabelle_processN = "isabelle_process"; |
25 |
||
42897 | 26 |
fun is_active () = Print_Mode.print_mode_active isabelle_processN; |
27 |
||
26550 | 28 |
val _ = Output.add_mode isabelle_processN Output.default_output Output.default_escape; |
28036 | 29 |
val _ = Markup.add_mode isabelle_processN YXML.output_markup; |
25841 | 30 |
|
71852
45c2b8cf1b26
more robust message_context and shutdown, e.g. after errors in protocol loop (see also 3f02bc5a5a03);
wenzelm
parents:
71847
diff
changeset
|
31 |
val protocol_modes1 = [Syntax_Trans.no_bracketsN, Syntax_Trans.no_type_bracketsN]; |
45c2b8cf1b26
more robust message_context and shutdown, e.g. after errors in protocol loop (see also 3f02bc5a5a03);
wenzelm
parents:
71847
diff
changeset
|
32 |
val protocol_modes2 = [isabelle_processN, Pretty.symbolicN]; |
45c2b8cf1b26
more robust message_context and shutdown, e.g. after errors in protocol loop (see also 3f02bc5a5a03);
wenzelm
parents:
71847
diff
changeset
|
33 |
|
25841 | 34 |
|
46119
0d7172a7672c
tuned signature -- emphasize special nature of protocol commands;
wenzelm
parents:
45666
diff
changeset
|
35 |
(* protocol commands *) |
38270
71bb3c273dd1
native Isabelle_Process commands, based on efficient byte channel protocol for string lists;
wenzelm
parents:
38265
diff
changeset
|
36 |
|
71bb3c273dd1
native Isabelle_Process commands, based on efficient byte channel protocol for string lists;
wenzelm
parents:
38265
diff
changeset
|
37 |
local |
71bb3c273dd1
native Isabelle_Process commands, based on efficient byte channel protocol for string lists;
wenzelm
parents:
38265
diff
changeset
|
38 |
|
43684 | 39 |
val commands = |
52800
1baa5d19ac44
less aggressive flushing: cope with massive amounts of protocol messages, e.g. from threads_trace;
wenzelm
parents:
52799
diff
changeset
|
40 |
Synchronized.var "Isabelle_Process.commands" |
1baa5d19ac44
less aggressive flushing: cope with massive amounts of protocol messages, e.g. from threads_trace;
wenzelm
parents:
52799
diff
changeset
|
41 |
(Symtab.empty: (string list -> unit) Symtab.table); |
38270
71bb3c273dd1
native Isabelle_Process commands, based on efficient byte channel protocol for string lists;
wenzelm
parents:
38265
diff
changeset
|
42 |
|
71bb3c273dd1
native Isabelle_Process commands, based on efficient byte channel protocol for string lists;
wenzelm
parents:
38265
diff
changeset
|
43 |
in |
71bb3c273dd1
native Isabelle_Process commands, based on efficient byte channel protocol for string lists;
wenzelm
parents:
38265
diff
changeset
|
44 |
|
46119
0d7172a7672c
tuned signature -- emphasize special nature of protocol commands;
wenzelm
parents:
45666
diff
changeset
|
45 |
fun protocol_command name cmd = |
43684 | 46 |
Synchronized.change commands (fn cmds => |
38270
71bb3c273dd1
native Isabelle_Process commands, based on efficient byte channel protocol for string lists;
wenzelm
parents:
38265
diff
changeset
|
47 |
(if not (Symtab.defined cmds name) then () |
52582 | 48 |
else warning ("Redefining Isabelle protocol command " ^ quote name); |
43684 | 49 |
Symtab.update (name, cmd) cmds)); |
38270
71bb3c273dd1
native Isabelle_Process commands, based on efficient byte channel protocol for string lists;
wenzelm
parents:
38265
diff
changeset
|
50 |
|
46119
0d7172a7672c
tuned signature -- emphasize special nature of protocol commands;
wenzelm
parents:
45666
diff
changeset
|
51 |
fun run_command name args = |
43684 | 52 |
(case Symtab.lookup (Synchronized.value commands) name of |
52582 | 53 |
NONE => error ("Undefined Isabelle protocol command " ^ quote name) |
46119
0d7172a7672c
tuned signature -- emphasize special nature of protocol commands;
wenzelm
parents:
45666
diff
changeset
|
54 |
| SOME cmd => |
59056
cbe9563c03d1
even more exception traces for Document.update, which goes through additional execution wrappers;
wenzelm
parents:
59055
diff
changeset
|
55 |
(Runtime.exn_trace_system (fn () => cmd args) |
59055
5a7157b8e870
more informative failure of protocol commands, with exception trace;
wenzelm
parents:
58850
diff
changeset
|
56 |
handle _ (*sic!*) => error ("Isabelle protocol command failure: " ^ quote name))); |
38270
71bb3c273dd1
native Isabelle_Process commands, based on efficient byte channel protocol for string lists;
wenzelm
parents:
38265
diff
changeset
|
57 |
|
71bb3c273dd1
native Isabelle_Process commands, based on efficient byte channel protocol for string lists;
wenzelm
parents:
38265
diff
changeset
|
58 |
end; |
71bb3c273dd1
native Isabelle_Process commands, based on efficient byte channel protocol for string lists;
wenzelm
parents:
38265
diff
changeset
|
59 |
|
71bb3c273dd1
native Isabelle_Process commands, based on efficient byte channel protocol for string lists;
wenzelm
parents:
38265
diff
changeset
|
60 |
|
50505
33c92722cc3d
smarter handling of tracing messages: prover process pauses and enters user dialog;
wenzelm
parents:
50503
diff
changeset
|
61 |
(* restricted tracing messages *) |
49647 | 62 |
|
52105 | 63 |
val tracing_messages = |
64 |
Synchronized.var "tracing_messages" (Inttab.empty: int Inttab.table); |
|
49647 | 65 |
|
52655
3b2b1ef13979
more careful termination of removed execs, leaving running execs undisturbed;
wenzelm
parents:
52584
diff
changeset
|
66 |
fun reset_tracing exec_id = |
3b2b1ef13979
more careful termination of removed execs, leaving running execs undisturbed;
wenzelm
parents:
52584
diff
changeset
|
67 |
Synchronized.change tracing_messages (Inttab.delete_safe exec_id); |
49647 | 68 |
|
50505
33c92722cc3d
smarter handling of tracing messages: prover process pauses and enters user dialog;
wenzelm
parents:
50503
diff
changeset
|
69 |
fun update_tracing () = |
50911
ee7fe4230642
more explicit treatment of (optional) exception properties, notably for "serial" -- avoid conflict with startPosition = offset;
wenzelm
parents:
50715
diff
changeset
|
70 |
(case Position.parse_id (Position.thread_data ()) of |
49647 | 71 |
NONE => () |
52655
3b2b1ef13979
more careful termination of removed execs, leaving running execs undisturbed;
wenzelm
parents:
52584
diff
changeset
|
72 |
| SOME exec_id => |
50505
33c92722cc3d
smarter handling of tracing messages: prover process pauses and enters user dialog;
wenzelm
parents:
50503
diff
changeset
|
73 |
let |
52560 | 74 |
val ok = |
52105 | 75 |
Synchronized.change_result tracing_messages (fn tab => |
50505
33c92722cc3d
smarter handling of tracing messages: prover process pauses and enters user dialog;
wenzelm
parents:
50503
diff
changeset
|
76 |
let |
52655
3b2b1ef13979
more careful termination of removed execs, leaving running execs undisturbed;
wenzelm
parents:
52584
diff
changeset
|
77 |
val n = the_default 0 (Inttab.lookup tab exec_id) + 1; |
69103
814a1ab42d70
unbounded tracing for proper termination, e.g. relevant for theory Sequents.Hard_Quantifiers;
wenzelm
parents:
68025
diff
changeset
|
78 |
val limit = Options.default_int "editor_tracing_messages"; |
814a1ab42d70
unbounded tracing for proper termination, e.g. relevant for theory Sequents.Hard_Quantifiers;
wenzelm
parents:
68025
diff
changeset
|
79 |
val ok = limit <= 0 orelse n <= limit; |
52655
3b2b1ef13979
more careful termination of removed execs, leaving running execs undisturbed;
wenzelm
parents:
52584
diff
changeset
|
80 |
in (ok, Inttab.update (exec_id, n) tab) end); |
50505
33c92722cc3d
smarter handling of tracing messages: prover process pauses and enters user dialog;
wenzelm
parents:
50503
diff
changeset
|
81 |
in |
33c92722cc3d
smarter handling of tracing messages: prover process pauses and enters user dialog;
wenzelm
parents:
50503
diff
changeset
|
82 |
if ok then () |
33c92722cc3d
smarter handling of tracing messages: prover process pauses and enters user dialog;
wenzelm
parents:
50503
diff
changeset
|
83 |
else |
33c92722cc3d
smarter handling of tracing messages: prover process pauses and enters user dialog;
wenzelm
parents:
50503
diff
changeset
|
84 |
let |
33c92722cc3d
smarter handling of tracing messages: prover process pauses and enters user dialog;
wenzelm
parents:
50503
diff
changeset
|
85 |
val (text, promise) = Active.dialog_text (); |
33c92722cc3d
smarter handling of tracing messages: prover process pauses and enters user dialog;
wenzelm
parents:
50503
diff
changeset
|
86 |
val _ = |
33c92722cc3d
smarter handling of tracing messages: prover process pauses and enters user dialog;
wenzelm
parents:
50503
diff
changeset
|
87 |
writeln ("Tracing paused. " ^ text "Stop" ^ ", or continue with next " ^ |
51044
890f502f0e89
more generous tracing limit, which is relevant for applications where this occurs routinely (e.g. HO unification trace);
wenzelm
parents:
50911
diff
changeset
|
88 |
text "100" ^ ", " ^ text "1000" ^ ", " ^ text "10000" ^ " messages?") |
63806 | 89 |
val m = Value.parse_int (Future.join promise) |
50505
33c92722cc3d
smarter handling of tracing messages: prover process pauses and enters user dialog;
wenzelm
parents:
50503
diff
changeset
|
90 |
handle Fail _ => error "Stopped"; |
33c92722cc3d
smarter handling of tracing messages: prover process pauses and enters user dialog;
wenzelm
parents:
50503
diff
changeset
|
91 |
in |
52105 | 92 |
Synchronized.change tracing_messages |
52655
3b2b1ef13979
more careful termination of removed execs, leaving running execs undisturbed;
wenzelm
parents:
52584
diff
changeset
|
93 |
(Inttab.map_default (exec_id, 0) (fn k => k - m)) |
50505
33c92722cc3d
smarter handling of tracing messages: prover process pauses and enters user dialog;
wenzelm
parents:
50503
diff
changeset
|
94 |
end |
33c92722cc3d
smarter handling of tracing messages: prover process pauses and enters user dialog;
wenzelm
parents:
50503
diff
changeset
|
95 |
end); |
49647 | 96 |
|
97 |
||
71852
45c2b8cf1b26
more robust message_context and shutdown, e.g. after errors in protocol loop (see also 3f02bc5a5a03);
wenzelm
parents:
71847
diff
changeset
|
98 |
(* init protocol -- uninterruptible *) |
45c2b8cf1b26
more robust message_context and shutdown, e.g. after errors in protocol loop (see also 3f02bc5a5a03);
wenzelm
parents:
71847
diff
changeset
|
99 |
|
45c2b8cf1b26
more robust message_context and shutdown, e.g. after errors in protocol loop (see also 3f02bc5a5a03);
wenzelm
parents:
71847
diff
changeset
|
100 |
exception EXIT of exn; |
45c2b8cf1b26
more robust message_context and shutdown, e.g. after errors in protocol loop (see also 3f02bc5a5a03);
wenzelm
parents:
71847
diff
changeset
|
101 |
|
45c2b8cf1b26
more robust message_context and shutdown, e.g. after errors in protocol loop (see also 3f02bc5a5a03);
wenzelm
parents:
71847
diff
changeset
|
102 |
val crashes = Synchronized.var "Isabelle_Process.crashes" ([]: exn list); |
45c2b8cf1b26
more robust message_context and shutdown, e.g. after errors in protocol loop (see also 3f02bc5a5a03);
wenzelm
parents:
71847
diff
changeset
|
103 |
|
45c2b8cf1b26
more robust message_context and shutdown, e.g. after errors in protocol loop (see also 3f02bc5a5a03);
wenzelm
parents:
71847
diff
changeset
|
104 |
local |
45c2b8cf1b26
more robust message_context and shutdown, e.g. after errors in protocol loop (see also 3f02bc5a5a03);
wenzelm
parents:
71847
diff
changeset
|
105 |
|
45c2b8cf1b26
more robust message_context and shutdown, e.g. after errors in protocol loop (see also 3f02bc5a5a03);
wenzelm
parents:
71847
diff
changeset
|
106 |
fun recover crash = |
45c2b8cf1b26
more robust message_context and shutdown, e.g. after errors in protocol loop (see also 3f02bc5a5a03);
wenzelm
parents:
71847
diff
changeset
|
107 |
(Synchronized.change crashes (cons crash); |
45c2b8cf1b26
more robust message_context and shutdown, e.g. after errors in protocol loop (see also 3f02bc5a5a03);
wenzelm
parents:
71847
diff
changeset
|
108 |
Output.physical_stderr |
45c2b8cf1b26
more robust message_context and shutdown, e.g. after errors in protocol loop (see also 3f02bc5a5a03);
wenzelm
parents:
71847
diff
changeset
|
109 |
"Recovered from Isabelle process crash -- see also Isabelle_Process.crashes\n"); |
45c2b8cf1b26
more robust message_context and shutdown, e.g. after errors in protocol loop (see also 3f02bc5a5a03);
wenzelm
parents:
71847
diff
changeset
|
110 |
|
45c2b8cf1b26
more robust message_context and shutdown, e.g. after errors in protocol loop (see also 3f02bc5a5a03);
wenzelm
parents:
71847
diff
changeset
|
111 |
in |
28188 | 112 |
|
71852
45c2b8cf1b26
more robust message_context and shutdown, e.g. after errors in protocol loop (see also 3f02bc5a5a03);
wenzelm
parents:
71847
diff
changeset
|
113 |
val init_protocol = Thread_Attributes.uninterruptible (fn _ => fn (address, password) => |
45c2b8cf1b26
more robust message_context and shutdown, e.g. after errors in protocol loop (see also 3f02bc5a5a03);
wenzelm
parents:
71847
diff
changeset
|
114 |
let |
45c2b8cf1b26
more robust message_context and shutdown, e.g. after errors in protocol loop (see also 3f02bc5a5a03);
wenzelm
parents:
71847
diff
changeset
|
115 |
val _ = SHA1.test_samples () |
45c2b8cf1b26
more robust message_context and shutdown, e.g. after errors in protocol loop (see also 3f02bc5a5a03);
wenzelm
parents:
71847
diff
changeset
|
116 |
handle exn as Fail msg => (Output.physical_stderr (msg ^ "\n"); Exn.reraise exn); |
45c2b8cf1b26
more robust message_context and shutdown, e.g. after errors in protocol loop (see also 3f02bc5a5a03);
wenzelm
parents:
71847
diff
changeset
|
117 |
|
45c2b8cf1b26
more robust message_context and shutdown, e.g. after errors in protocol loop (see also 3f02bc5a5a03);
wenzelm
parents:
71847
diff
changeset
|
118 |
val _ = Output.physical_stderr Symbol.STX; |
52854
92932931bd82
more general Output.result: allow to update arbitrary properties;
wenzelm
parents:
52852
diff
changeset
|
119 |
|
71852
45c2b8cf1b26
more robust message_context and shutdown, e.g. after errors in protocol loop (see also 3f02bc5a5a03);
wenzelm
parents:
71847
diff
changeset
|
120 |
val _ = Context.put_generic_context NONE; |
45c2b8cf1b26
more robust message_context and shutdown, e.g. after errors in protocol loop (see also 3f02bc5a5a03);
wenzelm
parents:
71847
diff
changeset
|
121 |
|
45c2b8cf1b26
more robust message_context and shutdown, e.g. after errors in protocol loop (see also 3f02bc5a5a03);
wenzelm
parents:
71847
diff
changeset
|
122 |
|
45c2b8cf1b26
more robust message_context and shutdown, e.g. after errors in protocol loop (see also 3f02bc5a5a03);
wenzelm
parents:
71847
diff
changeset
|
123 |
(* streams *) |
45c2b8cf1b26
more robust message_context and shutdown, e.g. after errors in protocol loop (see also 3f02bc5a5a03);
wenzelm
parents:
71847
diff
changeset
|
124 |
|
45c2b8cf1b26
more robust message_context and shutdown, e.g. after errors in protocol loop (see also 3f02bc5a5a03);
wenzelm
parents:
71847
diff
changeset
|
125 |
val (in_stream, out_stream) = Socket_IO.open_streams address; |
45c2b8cf1b26
more robust message_context and shutdown, e.g. after errors in protocol loop (see also 3f02bc5a5a03);
wenzelm
parents:
71847
diff
changeset
|
126 |
val _ = Byte_Message.write_line out_stream password; |
45c2b8cf1b26
more robust message_context and shutdown, e.g. after errors in protocol loop (see also 3f02bc5a5a03);
wenzelm
parents:
71847
diff
changeset
|
127 |
|
40134
8baded087d34
explicit message_output thread, with flushing after timeout, ensure atomic user-operations without the danger of IO Interrupt;
wenzelm
parents:
40133
diff
changeset
|
128 |
val _ = TextIO.StreamIO.setBufferMode (TextIO.getOutstream TextIO.stdOut, IO.LINE_BUF); |
8baded087d34
explicit message_output thread, with flushing after timeout, ensure atomic user-operations without the danger of IO Interrupt;
wenzelm
parents:
40133
diff
changeset
|
129 |
val _ = TextIO.StreamIO.setBufferMode (TextIO.getOutstream TextIO.stdErr, IO.LINE_BUF); |
69459 | 130 |
val _ = BinIO.StreamIO.setBufferMode (BinIO.getOutstream out_stream, IO.BLOCK_BUF); |
40134
8baded087d34
explicit message_output thread, with flushing after timeout, ensure atomic user-operations without the danger of IO Interrupt;
wenzelm
parents:
40133
diff
changeset
|
131 |
|
71852
45c2b8cf1b26
more robust message_context and shutdown, e.g. after errors in protocol loop (see also 3f02bc5a5a03);
wenzelm
parents:
71847
diff
changeset
|
132 |
|
45c2b8cf1b26
more robust message_context and shutdown, e.g. after errors in protocol loop (see also 3f02bc5a5a03);
wenzelm
parents:
71847
diff
changeset
|
133 |
(* messages *) |
45c2b8cf1b26
more robust message_context and shutdown, e.g. after errors in protocol loop (see also 3f02bc5a5a03);
wenzelm
parents:
71847
diff
changeset
|
134 |
|
69459 | 135 |
val msg_channel = Message_Channel.make out_stream; |
52580
36aa39694ab4
fall back on synchronous message output for single-threaded SML/NJ;
wenzelm
parents:
52578
diff
changeset
|
136 |
|
52800
1baa5d19ac44
less aggressive flushing: cope with massive amounts of protocol messages, e.g. from threads_trace;
wenzelm
parents:
52799
diff
changeset
|
137 |
fun message name props body = |
1baa5d19ac44
less aggressive flushing: cope with massive amounts of protocol messages, e.g. from threads_trace;
wenzelm
parents:
52799
diff
changeset
|
138 |
Message_Channel.send msg_channel (Message_Channel.message name props body); |
1baa5d19ac44
less aggressive flushing: cope with massive amounts of protocol messages, e.g. from threads_trace;
wenzelm
parents:
52799
diff
changeset
|
139 |
|
71192
2c17fa0f5187
more direct output of XML material -- bypass Buffer.T;
wenzelm
parents:
71188
diff
changeset
|
140 |
fun standard_message props name ss = |
2c17fa0f5187
more direct output of XML material -- bypass Buffer.T;
wenzelm
parents:
71188
diff
changeset
|
141 |
if forall (fn s => s = "") ss then () |
52580
36aa39694ab4
fall back on synchronous message output for single-threaded SML/NJ;
wenzelm
parents:
52578
diff
changeset
|
142 |
else |
57913 | 143 |
let |
144 |
val props' = |
|
145 |
(case (Properties.defined props Markup.idN, Position.get_id (Position.thread_data ())) of |
|
146 |
(false, SOME id') => props @ [(Markup.idN, id')] |
|
147 |
| _ => props); |
|
71192
2c17fa0f5187
more direct output of XML material -- bypass Buffer.T;
wenzelm
parents:
71188
diff
changeset
|
148 |
in message name props' (XML.blob ss) end; |
71852
45c2b8cf1b26
more robust message_context and shutdown, e.g. after errors in protocol loop (see also 3f02bc5a5a03);
wenzelm
parents:
71847
diff
changeset
|
149 |
|
45c2b8cf1b26
more robust message_context and shutdown, e.g. after errors in protocol loop (see also 3f02bc5a5a03);
wenzelm
parents:
71847
diff
changeset
|
150 |
val serial_props = Markup.serial_properties o serial; |
65212
fd6bc719c98b
more robust startup/init: let Session.stop wait for protocol handler initialization;
wenzelm
parents:
63806
diff
changeset
|
151 |
|
71852
45c2b8cf1b26
more robust message_context and shutdown, e.g. after errors in protocol loop (see also 3f02bc5a5a03);
wenzelm
parents:
71847
diff
changeset
|
152 |
val message_context = |
45c2b8cf1b26
more robust message_context and shutdown, e.g. after errors in protocol loop (see also 3f02bc5a5a03);
wenzelm
parents:
71847
diff
changeset
|
153 |
Unsynchronized.setmp Private_Output.status_fn |
45c2b8cf1b26
more robust message_context and shutdown, e.g. after errors in protocol loop (see also 3f02bc5a5a03);
wenzelm
parents:
71847
diff
changeset
|
154 |
(standard_message [] Markup.statusN) #> |
45c2b8cf1b26
more robust message_context and shutdown, e.g. after errors in protocol loop (see also 3f02bc5a5a03);
wenzelm
parents:
71847
diff
changeset
|
155 |
Unsynchronized.setmp Private_Output.report_fn |
45c2b8cf1b26
more robust message_context and shutdown, e.g. after errors in protocol loop (see also 3f02bc5a5a03);
wenzelm
parents:
71847
diff
changeset
|
156 |
(standard_message [] Markup.reportN) #> |
45c2b8cf1b26
more robust message_context and shutdown, e.g. after errors in protocol loop (see also 3f02bc5a5a03);
wenzelm
parents:
71847
diff
changeset
|
157 |
Unsynchronized.setmp Private_Output.result_fn |
45c2b8cf1b26
more robust message_context and shutdown, e.g. after errors in protocol loop (see also 3f02bc5a5a03);
wenzelm
parents:
71847
diff
changeset
|
158 |
(fn props => fn s => standard_message (props @ serial_props ()) Markup.resultN s) #> |
45c2b8cf1b26
more robust message_context and shutdown, e.g. after errors in protocol loop (see also 3f02bc5a5a03);
wenzelm
parents:
71847
diff
changeset
|
159 |
Unsynchronized.setmp Private_Output.writeln_fn |
45c2b8cf1b26
more robust message_context and shutdown, e.g. after errors in protocol loop (see also 3f02bc5a5a03);
wenzelm
parents:
71847
diff
changeset
|
160 |
(fn s => standard_message (serial_props ()) Markup.writelnN s) #> |
45c2b8cf1b26
more robust message_context and shutdown, e.g. after errors in protocol loop (see also 3f02bc5a5a03);
wenzelm
parents:
71847
diff
changeset
|
161 |
Unsynchronized.setmp Private_Output.state_fn |
45c2b8cf1b26
more robust message_context and shutdown, e.g. after errors in protocol loop (see also 3f02bc5a5a03);
wenzelm
parents:
71847
diff
changeset
|
162 |
(fn s => standard_message (serial_props ()) Markup.stateN s) #> |
45c2b8cf1b26
more robust message_context and shutdown, e.g. after errors in protocol loop (see also 3f02bc5a5a03);
wenzelm
parents:
71847
diff
changeset
|
163 |
Unsynchronized.setmp Private_Output.information_fn |
45c2b8cf1b26
more robust message_context and shutdown, e.g. after errors in protocol loop (see also 3f02bc5a5a03);
wenzelm
parents:
71847
diff
changeset
|
164 |
(fn s => standard_message (serial_props ()) Markup.informationN s) #> |
45c2b8cf1b26
more robust message_context and shutdown, e.g. after errors in protocol loop (see also 3f02bc5a5a03);
wenzelm
parents:
71847
diff
changeset
|
165 |
Unsynchronized.setmp Private_Output.tracing_fn |
45c2b8cf1b26
more robust message_context and shutdown, e.g. after errors in protocol loop (see also 3f02bc5a5a03);
wenzelm
parents:
71847
diff
changeset
|
166 |
(fn s => (update_tracing (); standard_message (serial_props ()) Markup.tracingN s)) #> |
45c2b8cf1b26
more robust message_context and shutdown, e.g. after errors in protocol loop (see also 3f02bc5a5a03);
wenzelm
parents:
71847
diff
changeset
|
167 |
Unsynchronized.setmp Private_Output.warning_fn |
45c2b8cf1b26
more robust message_context and shutdown, e.g. after errors in protocol loop (see also 3f02bc5a5a03);
wenzelm
parents:
71847
diff
changeset
|
168 |
(fn s => standard_message (serial_props ()) Markup.warningN s) #> |
45c2b8cf1b26
more robust message_context and shutdown, e.g. after errors in protocol loop (see also 3f02bc5a5a03);
wenzelm
parents:
71847
diff
changeset
|
169 |
Unsynchronized.setmp Private_Output.legacy_fn |
45c2b8cf1b26
more robust message_context and shutdown, e.g. after errors in protocol loop (see also 3f02bc5a5a03);
wenzelm
parents:
71847
diff
changeset
|
170 |
(fn s => standard_message (serial_props ()) Markup.legacyN s) #> |
45c2b8cf1b26
more robust message_context and shutdown, e.g. after errors in protocol loop (see also 3f02bc5a5a03);
wenzelm
parents:
71847
diff
changeset
|
171 |
Unsynchronized.setmp Private_Output.error_message_fn |
45c2b8cf1b26
more robust message_context and shutdown, e.g. after errors in protocol loop (see also 3f02bc5a5a03);
wenzelm
parents:
71847
diff
changeset
|
172 |
(fn (i, s) => standard_message (Markup.serial_properties i) Markup.errorN s) #> |
45c2b8cf1b26
more robust message_context and shutdown, e.g. after errors in protocol loop (see also 3f02bc5a5a03);
wenzelm
parents:
71847
diff
changeset
|
173 |
Unsynchronized.setmp Private_Output.system_message_fn |
45c2b8cf1b26
more robust message_context and shutdown, e.g. after errors in protocol loop (see also 3f02bc5a5a03);
wenzelm
parents:
71847
diff
changeset
|
174 |
(fn ss => message Markup.systemN [] (XML.blob ss)) #> |
45c2b8cf1b26
more robust message_context and shutdown, e.g. after errors in protocol loop (see also 3f02bc5a5a03);
wenzelm
parents:
71847
diff
changeset
|
175 |
Unsynchronized.setmp Private_Output.protocol_message_fn |
45c2b8cf1b26
more robust message_context and shutdown, e.g. after errors in protocol loop (see also 3f02bc5a5a03);
wenzelm
parents:
71847
diff
changeset
|
176 |
(fn props => fn body => message Markup.protocolN props body) #> |
45c2b8cf1b26
more robust message_context and shutdown, e.g. after errors in protocol loop (see also 3f02bc5a5a03);
wenzelm
parents:
71847
diff
changeset
|
177 |
Unsynchronized.setmp print_mode |
45c2b8cf1b26
more robust message_context and shutdown, e.g. after errors in protocol loop (see also 3f02bc5a5a03);
wenzelm
parents:
71847
diff
changeset
|
178 |
((! print_mode @ protocol_modes1) |> fold (update op =) protocol_modes2); |
25841 | 179 |
|
180 |
||
71852
45c2b8cf1b26
more robust message_context and shutdown, e.g. after errors in protocol loop (see also 3f02bc5a5a03);
wenzelm
parents:
71847
diff
changeset
|
181 |
(* protocol *) |
38270
71bb3c273dd1
native Isabelle_Process commands, based on efficient byte channel protocol for string lists;
wenzelm
parents:
38265
diff
changeset
|
182 |
|
71852
45c2b8cf1b26
more robust message_context and shutdown, e.g. after errors in protocol loop (see also 3f02bc5a5a03);
wenzelm
parents:
71847
diff
changeset
|
183 |
fun protocol_loop () = |
45c2b8cf1b26
more robust message_context and shutdown, e.g. after errors in protocol loop (see also 3f02bc5a5a03);
wenzelm
parents:
71847
diff
changeset
|
184 |
let |
45c2b8cf1b26
more robust message_context and shutdown, e.g. after errors in protocol loop (see also 3f02bc5a5a03);
wenzelm
parents:
71847
diff
changeset
|
185 |
val continue = |
45c2b8cf1b26
more robust message_context and shutdown, e.g. after errors in protocol loop (see also 3f02bc5a5a03);
wenzelm
parents:
71847
diff
changeset
|
186 |
(case Byte_Message.read_message in_stream of |
45c2b8cf1b26
more robust message_context and shutdown, e.g. after errors in protocol loop (see also 3f02bc5a5a03);
wenzelm
parents:
71847
diff
changeset
|
187 |
NONE => false |
45c2b8cf1b26
more robust message_context and shutdown, e.g. after errors in protocol loop (see also 3f02bc5a5a03);
wenzelm
parents:
71847
diff
changeset
|
188 |
| SOME [] => (Output.system_message "Isabelle process: no input"; true) |
45c2b8cf1b26
more robust message_context and shutdown, e.g. after errors in protocol loop (see also 3f02bc5a5a03);
wenzelm
parents:
71847
diff
changeset
|
189 |
| SOME (name :: args) => (run_command name args; true)) |
45c2b8cf1b26
more robust message_context and shutdown, e.g. after errors in protocol loop (see also 3f02bc5a5a03);
wenzelm
parents:
71847
diff
changeset
|
190 |
handle EXIT exn => Exn.reraise exn |
45c2b8cf1b26
more robust message_context and shutdown, e.g. after errors in protocol loop (see also 3f02bc5a5a03);
wenzelm
parents:
71847
diff
changeset
|
191 |
| exn => (Runtime.exn_system_message exn handle crash => recover crash; true); |
45c2b8cf1b26
more robust message_context and shutdown, e.g. after errors in protocol loop (see also 3f02bc5a5a03);
wenzelm
parents:
71847
diff
changeset
|
192 |
in if continue then protocol_loop () else () end; |
38270
71bb3c273dd1
native Isabelle_Process commands, based on efficient byte channel protocol for string lists;
wenzelm
parents:
38265
diff
changeset
|
193 |
|
71852
45c2b8cf1b26
more robust message_context and shutdown, e.g. after errors in protocol loop (see also 3f02bc5a5a03);
wenzelm
parents:
71847
diff
changeset
|
194 |
fun protocol () = |
45c2b8cf1b26
more robust message_context and shutdown, e.g. after errors in protocol loop (see also 3f02bc5a5a03);
wenzelm
parents:
71847
diff
changeset
|
195 |
(Session.init_protocol_handlers (); |
45c2b8cf1b26
more robust message_context and shutdown, e.g. after errors in protocol loop (see also 3f02bc5a5a03);
wenzelm
parents:
71847
diff
changeset
|
196 |
message Markup.initN [] [XML.Text (Session.welcome ())]; |
45c2b8cf1b26
more robust message_context and shutdown, e.g. after errors in protocol loop (see also 3f02bc5a5a03);
wenzelm
parents:
71847
diff
changeset
|
197 |
protocol_loop ()); |
71847 | 198 |
|
71852
45c2b8cf1b26
more robust message_context and shutdown, e.g. after errors in protocol loop (see also 3f02bc5a5a03);
wenzelm
parents:
71847
diff
changeset
|
199 |
val result = Exn.capture (message_context protocol) (); |
45c2b8cf1b26
more robust message_context and shutdown, e.g. after errors in protocol loop (see also 3f02bc5a5a03);
wenzelm
parents:
71847
diff
changeset
|
200 |
|
38270
71bb3c273dd1
native Isabelle_Process commands, based on efficient byte channel protocol for string lists;
wenzelm
parents:
38265
diff
changeset
|
201 |
|
71852
45c2b8cf1b26
more robust message_context and shutdown, e.g. after errors in protocol loop (see also 3f02bc5a5a03);
wenzelm
parents:
71847
diff
changeset
|
202 |
(* shutdown *) |
45c2b8cf1b26
more robust message_context and shutdown, e.g. after errors in protocol loop (see also 3f02bc5a5a03);
wenzelm
parents:
71847
diff
changeset
|
203 |
|
45c2b8cf1b26
more robust message_context and shutdown, e.g. after errors in protocol loop (see also 3f02bc5a5a03);
wenzelm
parents:
71847
diff
changeset
|
204 |
val _ = Future.shutdown (); |
45c2b8cf1b26
more robust message_context and shutdown, e.g. after errors in protocol loop (see also 3f02bc5a5a03);
wenzelm
parents:
71847
diff
changeset
|
205 |
val _ = Execution.reset (); |
45c2b8cf1b26
more robust message_context and shutdown, e.g. after errors in protocol loop (see also 3f02bc5a5a03);
wenzelm
parents:
71847
diff
changeset
|
206 |
val _ = Message_Channel.shutdown msg_channel; |
71853 | 207 |
val _ = BinIO.closeIn in_stream; |
208 |
val _ = BinIO.closeOut out_stream; |
|
71852
45c2b8cf1b26
more robust message_context and shutdown, e.g. after errors in protocol loop (see also 3f02bc5a5a03);
wenzelm
parents:
71847
diff
changeset
|
209 |
|
45c2b8cf1b26
more robust message_context and shutdown, e.g. after errors in protocol loop (see also 3f02bc5a5a03);
wenzelm
parents:
71847
diff
changeset
|
210 |
in Exn.release result end); |
38270
71bb3c273dd1
native Isabelle_Process commands, based on efficient byte channel protocol for string lists;
wenzelm
parents:
38265
diff
changeset
|
211 |
|
71bb3c273dd1
native Isabelle_Process commands, based on efficient byte channel protocol for string lists;
wenzelm
parents:
38265
diff
changeset
|
212 |
end; |
71bb3c273dd1
native Isabelle_Process commands, based on efficient byte channel protocol for string lists;
wenzelm
parents:
38265
diff
changeset
|
213 |
|
71bb3c273dd1
native Isabelle_Process commands, based on efficient byte channel protocol for string lists;
wenzelm
parents:
38265
diff
changeset
|
214 |
|
62563
2e352f63d15f
separate Isabelle_Process.init_options after Options.load_defaults, notably for "isabelle console";
wenzelm
parents:
62505
diff
changeset
|
215 |
(* init options *) |
2e352f63d15f
separate Isabelle_Process.init_options after Options.load_defaults, notably for "isabelle console";
wenzelm
parents:
62505
diff
changeset
|
216 |
|
2e352f63d15f
separate Isabelle_Process.init_options after Options.load_defaults, notably for "isabelle console";
wenzelm
parents:
62505
diff
changeset
|
217 |
fun init_options () = |
62878 | 218 |
(ML_Print_Depth.set_print_depth (Options.default_int "ML_print_depth"); |
62712 | 219 |
Future.ML_statistics := Options.default_bool "ML_statistics"; |
62563
2e352f63d15f
separate Isabelle_Process.init_options after Options.load_defaults, notably for "isabelle console";
wenzelm
parents:
62505
diff
changeset
|
220 |
Multithreading.trace := Options.default_int "threads_trace"; |
2e352f63d15f
separate Isabelle_Process.init_options after Options.load_defaults, notably for "isabelle console";
wenzelm
parents:
62505
diff
changeset
|
221 |
Multithreading.max_threads_update (Options.default_int "threads"); |
68025 | 222 |
Multithreading.parallel_proofs := Options.default_int "parallel_proofs"; |
71104
05c4c6a99b3f
option to export standardized proof terms (not scalable);
wenzelm
parents:
69584
diff
changeset
|
223 |
if Options.default_bool "export_standard_proofs" then Proofterm.proofs := 2 else (); |
65448
9bc3b57c1fa7
added system option record_proofs, which allows to build HOL-Proofs without special Proofs.thy;
wenzelm
parents:
65303
diff
changeset
|
224 |
let val proofs = Options.default_int "record_proofs" |
9bc3b57c1fa7
added system option record_proofs, which allows to build HOL-Proofs without special Proofs.thy;
wenzelm
parents:
65303
diff
changeset
|
225 |
in if proofs < 0 then () else Proofterm.proofs := proofs end; |
65302
3f92d63dad12
clarified init (see also 32755e357a51, ac48def96b69);
wenzelm
parents:
65301
diff
changeset
|
226 |
Printer.show_markup_default := false); |
62563
2e352f63d15f
separate Isabelle_Process.init_options after Options.load_defaults, notably for "isabelle console";
wenzelm
parents:
62505
diff
changeset
|
227 |
|
65300 | 228 |
fun init_options_interactive () = |
229 |
(init_options (); |
|
68025 | 230 |
Multithreading.parallel_proofs := (if Options.default_int "parallel_proofs" > 0 then 3 else 0); |
65302
3f92d63dad12
clarified init (see also 32755e357a51, ac48def96b69);
wenzelm
parents:
65301
diff
changeset
|
231 |
Printer.show_markup_default := true); |
62599
f35858c831e5
clarified session build options: already provided by ML_Process;
wenzelm
parents:
62564
diff
changeset
|
232 |
|
69584
09a6a7c04b45
more robust system channel via options that are private to the user;
wenzelm
parents:
69459
diff
changeset
|
233 |
|
09a6a7c04b45
more robust system channel via options that are private to the user;
wenzelm
parents:
69459
diff
changeset
|
234 |
(* generic init *) |
09a6a7c04b45
more robust system channel via options that are private to the user;
wenzelm
parents:
69459
diff
changeset
|
235 |
|
09a6a7c04b45
more robust system channel via options that are private to the user;
wenzelm
parents:
69459
diff
changeset
|
236 |
fun init () = |
09a6a7c04b45
more robust system channel via options that are private to the user;
wenzelm
parents:
69459
diff
changeset
|
237 |
let |
09a6a7c04b45
more robust system channel via options that are private to the user;
wenzelm
parents:
69459
diff
changeset
|
238 |
val address = Options.default_string \<^system_option>\<open>system_channel_address\<close>; |
09a6a7c04b45
more robust system channel via options that are private to the user;
wenzelm
parents:
69459
diff
changeset
|
239 |
val password = Options.default_string \<^system_option>\<open>system_channel_password\<close>; |
09a6a7c04b45
more robust system channel via options that are private to the user;
wenzelm
parents:
69459
diff
changeset
|
240 |
in |
09a6a7c04b45
more robust system channel via options that are private to the user;
wenzelm
parents:
69459
diff
changeset
|
241 |
if address <> "" andalso password <> "" |
09a6a7c04b45
more robust system channel via options that are private to the user;
wenzelm
parents:
69459
diff
changeset
|
242 |
then init_protocol (address, password) |
09a6a7c04b45
more robust system channel via options that are private to the user;
wenzelm
parents:
69459
diff
changeset
|
243 |
else init_options () |
09a6a7c04b45
more robust system channel via options that are private to the user;
wenzelm
parents:
69459
diff
changeset
|
244 |
end; |
09a6a7c04b45
more robust system channel via options that are private to the user;
wenzelm
parents:
69459
diff
changeset
|
245 |
|
25528
e67230c2b952
Isabelle process wrapper -- interaction via external program.
wenzelm
parents:
diff
changeset
|
246 |
end; |