author | wenzelm |
Sat, 01 Jun 2019 11:29:59 +0200 | |
changeset 70299 | 83774d669b51 |
parent 69572 | 09a6a7c04b45 |
child 70914 | 05c4c6a99b3f |
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 |
43684 | 12 |
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
|
13 |
val init_options: unit -> unit |
65300 | 14 |
val init_options_interactive: unit -> unit |
69572
09a6a7c04b45
more robust system channel via options that are private to the user;
wenzelm
parents:
69449
diff
changeset
|
15 |
val init: unit -> unit |
25528
e67230c2b952
Isabelle process wrapper -- interaction via external program.
wenzelm
parents:
diff
changeset
|
16 |
end; |
e67230c2b952
Isabelle process wrapper -- interaction via external program.
wenzelm
parents:
diff
changeset
|
17 |
|
31797 | 18 |
structure Isabelle_Process: ISABELLE_PROCESS = |
25528
e67230c2b952
Isabelle process wrapper -- interaction via external program.
wenzelm
parents:
diff
changeset
|
19 |
struct |
e67230c2b952
Isabelle process wrapper -- interaction via external program.
wenzelm
parents:
diff
changeset
|
20 |
|
42897 | 21 |
(* print mode *) |
25554 | 22 |
|
25748 | 23 |
val isabelle_processN = "isabelle_process"; |
24 |
||
42897 | 25 |
fun is_active () = Print_Mode.print_mode_active isabelle_processN; |
26 |
||
26550 | 27 |
val _ = Output.add_mode isabelle_processN Output.default_output Output.default_escape; |
28036 | 28 |
val _ = Markup.add_mode isabelle_processN YXML.output_markup; |
25841 | 29 |
|
30 |
||
46119
0d7172a7672c
tuned signature -- emphasize special nature of protocol commands;
wenzelm
parents:
45666
diff
changeset
|
31 |
(* protocol commands *) |
38270
71bb3c273dd1
native Isabelle_Process commands, based on efficient byte channel protocol for string lists;
wenzelm
parents:
38265
diff
changeset
|
32 |
|
71bb3c273dd1
native Isabelle_Process commands, based on efficient byte channel protocol for string lists;
wenzelm
parents:
38265
diff
changeset
|
33 |
local |
71bb3c273dd1
native Isabelle_Process commands, based on efficient byte channel protocol for string lists;
wenzelm
parents:
38265
diff
changeset
|
34 |
|
43684 | 35 |
val commands = |
52800
1baa5d19ac44
less aggressive flushing: cope with massive amounts of protocol messages, e.g. from threads_trace;
wenzelm
parents:
52799
diff
changeset
|
36 |
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
|
37 |
(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
|
38 |
|
71bb3c273dd1
native Isabelle_Process commands, based on efficient byte channel protocol for string lists;
wenzelm
parents:
38265
diff
changeset
|
39 |
in |
71bb3c273dd1
native Isabelle_Process commands, based on efficient byte channel protocol for string lists;
wenzelm
parents:
38265
diff
changeset
|
40 |
|
46119
0d7172a7672c
tuned signature -- emphasize special nature of protocol commands;
wenzelm
parents:
45666
diff
changeset
|
41 |
fun protocol_command name cmd = |
43684 | 42 |
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
|
43 |
(if not (Symtab.defined cmds name) then () |
52582 | 44 |
else warning ("Redefining Isabelle protocol command " ^ quote name); |
43684 | 45 |
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
|
46 |
|
46119
0d7172a7672c
tuned signature -- emphasize special nature of protocol commands;
wenzelm
parents:
45666
diff
changeset
|
47 |
fun run_command name args = |
43684 | 48 |
(case Symtab.lookup (Synchronized.value commands) name of |
52582 | 49 |
NONE => error ("Undefined Isabelle protocol command " ^ quote name) |
46119
0d7172a7672c
tuned signature -- emphasize special nature of protocol commands;
wenzelm
parents:
45666
diff
changeset
|
50 |
| SOME cmd => |
59056
cbe9563c03d1
even more exception traces for Document.update, which goes through additional execution wrappers;
wenzelm
parents:
59055
diff
changeset
|
51 |
(Runtime.exn_trace_system (fn () => cmd args) |
59055
5a7157b8e870
more informative failure of protocol commands, with exception trace;
wenzelm
parents:
58850
diff
changeset
|
52 |
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
|
53 |
|
71bb3c273dd1
native Isabelle_Process commands, based on efficient byte channel protocol for string lists;
wenzelm
parents:
38265
diff
changeset
|
54 |
end; |
71bb3c273dd1
native Isabelle_Process commands, based on efficient byte channel protocol for string lists;
wenzelm
parents:
38265
diff
changeset
|
55 |
|
71bb3c273dd1
native Isabelle_Process commands, based on efficient byte channel protocol for string lists;
wenzelm
parents:
38265
diff
changeset
|
56 |
|
50505
33c92722cc3d
smarter handling of tracing messages: prover process pauses and enters user dialog;
wenzelm
parents:
50503
diff
changeset
|
57 |
(* restricted tracing messages *) |
49647 | 58 |
|
52105 | 59 |
val tracing_messages = |
60 |
Synchronized.var "tracing_messages" (Inttab.empty: int Inttab.table); |
|
49647 | 61 |
|
52655
3b2b1ef13979
more careful termination of removed execs, leaving running execs undisturbed;
wenzelm
parents:
52584
diff
changeset
|
62 |
fun reset_tracing exec_id = |
3b2b1ef13979
more careful termination of removed execs, leaving running execs undisturbed;
wenzelm
parents:
52584
diff
changeset
|
63 |
Synchronized.change tracing_messages (Inttab.delete_safe exec_id); |
49647 | 64 |
|
50505
33c92722cc3d
smarter handling of tracing messages: prover process pauses and enters user dialog;
wenzelm
parents:
50503
diff
changeset
|
65 |
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
|
66 |
(case Position.parse_id (Position.thread_data ()) of |
49647 | 67 |
NONE => () |
52655
3b2b1ef13979
more careful termination of removed execs, leaving running execs undisturbed;
wenzelm
parents:
52584
diff
changeset
|
68 |
| SOME exec_id => |
50505
33c92722cc3d
smarter handling of tracing messages: prover process pauses and enters user dialog;
wenzelm
parents:
50503
diff
changeset
|
69 |
let |
52560 | 70 |
val ok = |
52105 | 71 |
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
|
72 |
let |
52655
3b2b1ef13979
more careful termination of removed execs, leaving running execs undisturbed;
wenzelm
parents:
52584
diff
changeset
|
73 |
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
|
74 |
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
|
75 |
val ok = limit <= 0 orelse n <= limit; |
52655
3b2b1ef13979
more careful termination of removed execs, leaving running execs undisturbed;
wenzelm
parents:
52584
diff
changeset
|
76 |
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
|
77 |
in |
33c92722cc3d
smarter handling of tracing messages: prover process pauses and enters user dialog;
wenzelm
parents:
50503
diff
changeset
|
78 |
if ok then () |
33c92722cc3d
smarter handling of tracing messages: prover process pauses and enters user dialog;
wenzelm
parents:
50503
diff
changeset
|
79 |
else |
33c92722cc3d
smarter handling of tracing messages: prover process pauses and enters user dialog;
wenzelm
parents:
50503
diff
changeset
|
80 |
let |
33c92722cc3d
smarter handling of tracing messages: prover process pauses and enters user dialog;
wenzelm
parents:
50503
diff
changeset
|
81 |
val (text, promise) = Active.dialog_text (); |
33c92722cc3d
smarter handling of tracing messages: prover process pauses and enters user dialog;
wenzelm
parents:
50503
diff
changeset
|
82 |
val _ = |
33c92722cc3d
smarter handling of tracing messages: prover process pauses and enters user dialog;
wenzelm
parents:
50503
diff
changeset
|
83 |
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
|
84 |
text "100" ^ ", " ^ text "1000" ^ ", " ^ text "10000" ^ " messages?") |
63806 | 85 |
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
|
86 |
handle Fail _ => error "Stopped"; |
33c92722cc3d
smarter handling of tracing messages: prover process pauses and enters user dialog;
wenzelm
parents:
50503
diff
changeset
|
87 |
in |
52105 | 88 |
Synchronized.change tracing_messages |
52655
3b2b1ef13979
more careful termination of removed execs, leaving running execs undisturbed;
wenzelm
parents:
52584
diff
changeset
|
89 |
(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
|
90 |
end |
33c92722cc3d
smarter handling of tracing messages: prover process pauses and enters user dialog;
wenzelm
parents:
50503
diff
changeset
|
91 |
end); |
49647 | 92 |
|
93 |
||
52800
1baa5d19ac44
less aggressive flushing: cope with massive amounts of protocol messages, e.g. from threads_trace;
wenzelm
parents:
52799
diff
changeset
|
94 |
(* output channels *) |
28188 | 95 |
|
52854
92932931bd82
more general Output.result: allow to update arbitrary properties;
wenzelm
parents:
52852
diff
changeset
|
96 |
val serial_props = Markup.serial_properties o serial; |
92932931bd82
more general Output.result: allow to update arbitrary properties;
wenzelm
parents:
52852
diff
changeset
|
97 |
|
69449 | 98 |
fun init_channels out_stream = |
28189
fbad2eb5be9e
auto_flush: uniform block buffering for all output streams;
wenzelm
parents:
28188
diff
changeset
|
99 |
let |
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
|
100 |
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
|
101 |
val _ = TextIO.StreamIO.setBufferMode (TextIO.getOutstream TextIO.stdErr, IO.LINE_BUF); |
69449 | 102 |
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
|
103 |
|
69449 | 104 |
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
|
105 |
|
52800
1baa5d19ac44
less aggressive flushing: cope with massive amounts of protocol messages, e.g. from threads_trace;
wenzelm
parents:
52799
diff
changeset
|
106 |
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
|
107 |
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
|
108 |
|
52854
92932931bd82
more general Output.result: allow to update arbitrary properties;
wenzelm
parents:
52852
diff
changeset
|
109 |
fun standard_message props name body = |
56333
38f1422ef473
support bulk messages consisting of small string segments, which are more healthy to the Poly/ML RTS and might prevent spurious GC crashes such as MTGCProcessMarkPointers::ScanAddressesInObject;
wenzelm
parents:
56303
diff
changeset
|
110 |
if forall (fn s => s = "") body then () |
52580
36aa39694ab4
fall back on synchronous message output for single-threaded SML/NJ;
wenzelm
parents:
52578
diff
changeset
|
111 |
else |
57913 | 112 |
let |
113 |
val props' = |
|
114 |
(case (Properties.defined props Markup.idN, Position.get_id (Position.thread_data ())) of |
|
115 |
(false, SOME id') => props @ [(Markup.idN, id')] |
|
116 |
| _ => props); |
|
117 |
in message name props' body end; |
|
28044 | 118 |
in |
62930
51ac6bc389e8
shared output primitives of physical/virtual Pure;
wenzelm
parents:
62923
diff
changeset
|
119 |
Private_Output.status_fn := standard_message [] Markup.statusN; |
51ac6bc389e8
shared output primitives of physical/virtual Pure;
wenzelm
parents:
62923
diff
changeset
|
120 |
Private_Output.report_fn := standard_message [] Markup.reportN; |
51ac6bc389e8
shared output primitives of physical/virtual Pure;
wenzelm
parents:
62923
diff
changeset
|
121 |
Private_Output.result_fn := |
52854
92932931bd82
more general Output.result: allow to update arbitrary properties;
wenzelm
parents:
52852
diff
changeset
|
122 |
(fn props => fn s => standard_message (props @ serial_props ()) Markup.resultN s); |
62930
51ac6bc389e8
shared output primitives of physical/virtual Pure;
wenzelm
parents:
62923
diff
changeset
|
123 |
Private_Output.writeln_fn := (fn s => standard_message (serial_props ()) Markup.writelnN s); |
51ac6bc389e8
shared output primitives of physical/virtual Pure;
wenzelm
parents:
62923
diff
changeset
|
124 |
Private_Output.state_fn := (fn s => standard_message (serial_props ()) Markup.stateN s); |
51ac6bc389e8
shared output primitives of physical/virtual Pure;
wenzelm
parents:
62923
diff
changeset
|
125 |
Private_Output.information_fn := |
51ac6bc389e8
shared output primitives of physical/virtual Pure;
wenzelm
parents:
62923
diff
changeset
|
126 |
(fn s => standard_message (serial_props ()) Markup.informationN s); |
51ac6bc389e8
shared output primitives of physical/virtual Pure;
wenzelm
parents:
62923
diff
changeset
|
127 |
Private_Output.tracing_fn := |
52854
92932931bd82
more general Output.result: allow to update arbitrary properties;
wenzelm
parents:
52852
diff
changeset
|
128 |
(fn s => (update_tracing (); standard_message (serial_props ()) Markup.tracingN s)); |
62930
51ac6bc389e8
shared output primitives of physical/virtual Pure;
wenzelm
parents:
62923
diff
changeset
|
129 |
Private_Output.warning_fn := (fn s => standard_message (serial_props ()) Markup.warningN s); |
51ac6bc389e8
shared output primitives of physical/virtual Pure;
wenzelm
parents:
62923
diff
changeset
|
130 |
Private_Output.legacy_fn := (fn s => standard_message (serial_props ()) Markup.legacyN s); |
51ac6bc389e8
shared output primitives of physical/virtual Pure;
wenzelm
parents:
62923
diff
changeset
|
131 |
Private_Output.error_message_fn := |
52854
92932931bd82
more general Output.result: allow to update arbitrary properties;
wenzelm
parents:
52852
diff
changeset
|
132 |
(fn (i, s) => standard_message (Markup.serial_properties i) Markup.errorN s); |
62930
51ac6bc389e8
shared output primitives of physical/virtual Pure;
wenzelm
parents:
62923
diff
changeset
|
133 |
Private_Output.system_message_fn := message Markup.systemN []; |
51ac6bc389e8
shared output primitives of physical/virtual Pure;
wenzelm
parents:
62923
diff
changeset
|
134 |
Private_Output.protocol_message_fn := message Markup.protocolN; |
65212
fd6bc719c98b
more robust startup/init: let Session.stop wait for protocol handler initialization;
wenzelm
parents:
63806
diff
changeset
|
135 |
|
fd6bc719c98b
more robust startup/init: let Session.stop wait for protocol handler initialization;
wenzelm
parents:
63806
diff
changeset
|
136 |
Session.init_protocol_handlers (); |
56333
38f1422ef473
support bulk messages consisting of small string segments, which are more healthy to the Poly/ML RTS and might prevent spurious GC crashes such as MTGCProcessMarkPointers::ScanAddressesInObject;
wenzelm
parents:
56303
diff
changeset
|
137 |
message Markup.initN [] [Session.welcome ()]; |
52584 | 138 |
msg_channel |
28044 | 139 |
end; |
25841 | 140 |
|
141 |
||
39234
d76a2fd129b5
main command loops are supposed to be uninterruptible -- no special treatment here;
wenzelm
parents:
38871
diff
changeset
|
142 |
(* protocol loop -- uninterruptible *) |
38270
71bb3c273dd1
native Isabelle_Process commands, based on efficient byte channel protocol for string lists;
wenzelm
parents:
38265
diff
changeset
|
143 |
|
43684 | 144 |
val crashes = Synchronized.var "Isabelle_Process.crashes" ([]: exn list); |
38270
71bb3c273dd1
native Isabelle_Process commands, based on efficient byte channel protocol for string lists;
wenzelm
parents:
38265
diff
changeset
|
145 |
|
71bb3c273dd1
native Isabelle_Process commands, based on efficient byte channel protocol for string lists;
wenzelm
parents:
38265
diff
changeset
|
146 |
local |
71bb3c273dd1
native Isabelle_Process commands, based on efficient byte channel protocol for string lists;
wenzelm
parents:
38265
diff
changeset
|
147 |
|
71bb3c273dd1
native Isabelle_Process commands, based on efficient byte channel protocol for string lists;
wenzelm
parents:
38265
diff
changeset
|
148 |
fun recover crash = |
43684 | 149 |
(Synchronized.change crashes (cons crash); |
57975
c657c68a60ab
explicit system message for protocol failure -- show on Syslog panel instead of Raw Output;
wenzelm
parents:
56895
diff
changeset
|
150 |
Output.physical_stderr |
c657c68a60ab
explicit system message for protocol failure -- show on Syslog panel instead of Raw Output;
wenzelm
parents:
56895
diff
changeset
|
151 |
"Recovered from Isabelle process crash -- see also Isabelle_Process.crashes\n"); |
38270
71bb3c273dd1
native Isabelle_Process commands, based on efficient byte channel protocol for string lists;
wenzelm
parents:
38265
diff
changeset
|
152 |
|
71bb3c273dd1
native Isabelle_Process commands, based on efficient byte channel protocol for string lists;
wenzelm
parents:
38265
diff
changeset
|
153 |
in |
71bb3c273dd1
native Isabelle_Process commands, based on efficient byte channel protocol for string lists;
wenzelm
parents:
38265
diff
changeset
|
154 |
|
69449 | 155 |
fun loop stream = |
59055
5a7157b8e870
more informative failure of protocol commands, with exception trace;
wenzelm
parents:
58850
diff
changeset
|
156 |
let |
5a7157b8e870
more informative failure of protocol commands, with exception trace;
wenzelm
parents:
58850
diff
changeset
|
157 |
val continue = |
69449 | 158 |
(case Byte_Message.read_message stream of |
59055
5a7157b8e870
more informative failure of protocol commands, with exception trace;
wenzelm
parents:
58850
diff
changeset
|
159 |
NONE => false |
5a7157b8e870
more informative failure of protocol commands, with exception trace;
wenzelm
parents:
58850
diff
changeset
|
160 |
| SOME [] => (Output.system_message "Isabelle process: no input"; true) |
59370
b13ff987c559
refrain from default task_context for all protocol commands, e.g. relevant for "build_theories" to admit Session.shutdown;
wenzelm
parents:
59350
diff
changeset
|
161 |
| SOME (name :: args) => (run_command name args; true)) |
59055
5a7157b8e870
more informative failure of protocol commands, with exception trace;
wenzelm
parents:
58850
diff
changeset
|
162 |
handle exn => (Runtime.exn_system_message exn handle crash => recover crash; true); |
52770
8c7cf864e270
pro-forma Goal.reset_futures, despite lack of final join/commit;
wenzelm
parents:
52712
diff
changeset
|
163 |
in |
69449 | 164 |
if continue then loop stream |
53192 | 165 |
else (Future.shutdown (); Execution.reset (); ()) |
52770
8c7cf864e270
pro-forma Goal.reset_futures, despite lack of final join/commit;
wenzelm
parents:
52712
diff
changeset
|
166 |
end; |
38270
71bb3c273dd1
native Isabelle_Process commands, based on efficient byte channel protocol for string lists;
wenzelm
parents:
38265
diff
changeset
|
167 |
|
71bb3c273dd1
native Isabelle_Process commands, based on efficient byte channel protocol for string lists;
wenzelm
parents:
38265
diff
changeset
|
168 |
end; |
71bb3c273dd1
native Isabelle_Process commands, based on efficient byte channel protocol for string lists;
wenzelm
parents:
38265
diff
changeset
|
169 |
|
71bb3c273dd1
native Isabelle_Process commands, based on efficient byte channel protocol for string lists;
wenzelm
parents:
38265
diff
changeset
|
170 |
|
62564 | 171 |
(* init protocol *) |
25554 | 172 |
|
59211 | 173 |
val default_modes1 = [Syntax_Trans.no_bracketsN, Syntax_Trans.no_type_bracketsN]; |
66020 | 174 |
val default_modes2 = [isabelle_processN, Pretty.symbolicN]; |
49566
66cbf8bb4693
basic integration of graphview into document model;
wenzelm
parents:
49108
diff
changeset
|
175 |
|
69572
09a6a7c04b45
more robust system channel via options that are private to the user;
wenzelm
parents:
69449
diff
changeset
|
176 |
val init_protocol = Thread_Attributes.uninterruptible (fn _ => fn (address, password) => |
38253
3d4e521014f7
Isabelle_Process: separate input fifo for commands (still using the old tty protocol);
wenzelm
parents:
38236
diff
changeset
|
177 |
let |
62666 | 178 |
val _ = SHA1.test_samples () |
62505 | 179 |
handle exn as Fail msg => (Output.physical_stderr (msg ^ "\n"); Exn.reraise exn); |
46548
c54a4a22501c
clarified initial process startup errors: recover image load failure message (cf. 2cb7e34f6096) and suppress accidental output from raw ML toplevel;
wenzelm
parents:
46121
diff
changeset
|
180 |
val _ = Output.physical_stderr Symbol.STX; |
39528
c01d89d18ff0
refined Isabelle_Process startup: emit \002 before rendezvous on fifos, more robust treatment of startup failure with timeout, do not quit() after main loop;
wenzelm
parents:
39513
diff
changeset
|
181 |
|
62889 | 182 |
val _ = Context.put_generic_context NONE; |
43671
a250b092ac66
hard-wired print mode "xsymbols" increases chance that "iff" in HOL will print symbolic arrow;
wenzelm
parents:
42897
diff
changeset
|
183 |
val _ = |
a250b092ac66
hard-wired print mode "xsymbols" increases chance that "iff" in HOL will print symbolic arrow;
wenzelm
parents:
42897
diff
changeset
|
184 |
Unsynchronized.change print_mode |
49566
66cbf8bb4693
basic integration of graphview into document model;
wenzelm
parents:
49108
diff
changeset
|
185 |
(fn mode => (mode @ default_modes1) |> fold (update op =) default_modes2); |
39528
c01d89d18ff0
refined Isabelle_Process startup: emit \002 before rendezvous on fifos, more robust treatment of startup failure with timeout, do not quit() after main loop;
wenzelm
parents:
39513
diff
changeset
|
186 |
|
69572
09a6a7c04b45
more robust system channel via options that are private to the user;
wenzelm
parents:
69449
diff
changeset
|
187 |
val (in_stream, out_stream) = Socket_IO.open_streams address; |
09a6a7c04b45
more robust system channel via options that are private to the user;
wenzelm
parents:
69449
diff
changeset
|
188 |
val _ = Byte_Message.write_line out_stream password; |
69449 | 189 |
val msg_channel = init_channels out_stream; |
190 |
val _ = loop in_stream; |
|
65301
fca593a62785
restore output channels after shutdown, e.g. relevant for saved heap;
wenzelm
parents:
65300
diff
changeset
|
191 |
val _ = Message_Channel.shutdown msg_channel; |
fca593a62785
restore output channels after shutdown, e.g. relevant for saved heap;
wenzelm
parents:
65300
diff
changeset
|
192 |
val _ = Private_Output.init_channels (); |
65303 | 193 |
|
194 |
val _ = print_mode := []; |
|
65301
fca593a62785
restore output channels after shutdown, e.g. relevant for saved heap;
wenzelm
parents:
65300
diff
changeset
|
195 |
in () end); |
25528
e67230c2b952
Isabelle process wrapper -- interaction via external program.
wenzelm
parents:
diff
changeset
|
196 |
|
62563
2e352f63d15f
separate Isabelle_Process.init_options after Options.load_defaults, notably for "isabelle console";
wenzelm
parents:
62505
diff
changeset
|
197 |
|
2e352f63d15f
separate Isabelle_Process.init_options after Options.load_defaults, notably for "isabelle console";
wenzelm
parents:
62505
diff
changeset
|
198 |
(* init options *) |
2e352f63d15f
separate Isabelle_Process.init_options after Options.load_defaults, notably for "isabelle console";
wenzelm
parents:
62505
diff
changeset
|
199 |
|
2e352f63d15f
separate Isabelle_Process.init_options after Options.load_defaults, notably for "isabelle console";
wenzelm
parents:
62505
diff
changeset
|
200 |
fun init_options () = |
62878 | 201 |
(ML_Print_Depth.set_print_depth (Options.default_int "ML_print_depth"); |
62712 | 202 |
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
|
203 |
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
|
204 |
Multithreading.max_threads_update (Options.default_int "threads"); |
68025 | 205 |
Multithreading.parallel_proofs := Options.default_int "parallel_proofs"; |
65448
9bc3b57c1fa7
added system option record_proofs, which allows to build HOL-Proofs without special Proofs.thy;
wenzelm
parents:
65303
diff
changeset
|
206 |
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
|
207 |
in if proofs < 0 then () else Proofterm.proofs := proofs end; |
65302
3f92d63dad12
clarified init (see also 32755e357a51, ac48def96b69);
wenzelm
parents:
65301
diff
changeset
|
208 |
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
|
209 |
|
65300 | 210 |
fun init_options_interactive () = |
211 |
(init_options (); |
|
68025 | 212 |
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
|
213 |
Printer.show_markup_default := true); |
62599
f35858c831e5
clarified session build options: already provided by ML_Process;
wenzelm
parents:
62564
diff
changeset
|
214 |
|
69572
09a6a7c04b45
more robust system channel via options that are private to the user;
wenzelm
parents:
69449
diff
changeset
|
215 |
|
09a6a7c04b45
more robust system channel via options that are private to the user;
wenzelm
parents:
69449
diff
changeset
|
216 |
(* generic init *) |
09a6a7c04b45
more robust system channel via options that are private to the user;
wenzelm
parents:
69449
diff
changeset
|
217 |
|
09a6a7c04b45
more robust system channel via options that are private to the user;
wenzelm
parents:
69449
diff
changeset
|
218 |
fun init () = |
09a6a7c04b45
more robust system channel via options that are private to the user;
wenzelm
parents:
69449
diff
changeset
|
219 |
let |
09a6a7c04b45
more robust system channel via options that are private to the user;
wenzelm
parents:
69449
diff
changeset
|
220 |
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:
69449
diff
changeset
|
221 |
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:
69449
diff
changeset
|
222 |
in |
09a6a7c04b45
more robust system channel via options that are private to the user;
wenzelm
parents:
69449
diff
changeset
|
223 |
if address <> "" andalso password <> "" |
09a6a7c04b45
more robust system channel via options that are private to the user;
wenzelm
parents:
69449
diff
changeset
|
224 |
then init_protocol (address, password) |
09a6a7c04b45
more robust system channel via options that are private to the user;
wenzelm
parents:
69449
diff
changeset
|
225 |
else init_options () |
09a6a7c04b45
more robust system channel via options that are private to the user;
wenzelm
parents:
69449
diff
changeset
|
226 |
end; |
09a6a7c04b45
more robust system channel via options that are private to the user;
wenzelm
parents:
69449
diff
changeset
|
227 |
|
25528
e67230c2b952
Isabelle process wrapper -- interaction via external program.
wenzelm
parents:
diff
changeset
|
228 |
end; |