| author | wenzelm | 
| Wed, 17 Jun 2015 22:30:22 +0200 | |
| changeset 60511 | 5e67a223a141 | 
| parent 59370 | b13ff987c559 | 
| child 62505 | 9e2a65912111 | 
| 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: 
29522diff
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: 
45666diff
changeset | 10 | val protocol_command: string -> (string list -> unit) -> unit | 
| 52655 
3b2b1ef13979
more careful termination of removed execs, leaving running execs undisturbed;
 wenzelm parents: 
52584diff
changeset | 11 | val reset_tracing: Document_ID.exec -> unit | 
| 43684 | 12 | val crashes: exn list Synchronized.var | 
| 59350 
acba5d6fdb2f
discontinued fifo channel, always use portable socket;
 wenzelm parents: 
59211diff
changeset | 13 | val init: string -> unit | 
| 25528 
e67230c2b952
Isabelle process wrapper -- interaction via external program.
 wenzelm parents: diff
changeset | 14 | end; | 
| 
e67230c2b952
Isabelle process wrapper -- interaction via external program.
 wenzelm parents: diff
changeset | 15 | |
| 31797 | 16 | structure Isabelle_Process: ISABELLE_PROCESS = | 
| 25528 
e67230c2b952
Isabelle process wrapper -- interaction via external program.
 wenzelm parents: diff
changeset | 17 | struct | 
| 
e67230c2b952
Isabelle process wrapper -- interaction via external program.
 wenzelm parents: diff
changeset | 18 | |
| 42897 | 19 | (* print mode *) | 
| 25554 | 20 | |
| 25748 | 21 | val isabelle_processN = "isabelle_process"; | 
| 22 | ||
| 42897 | 23 | fun is_active () = Print_Mode.print_mode_active isabelle_processN; | 
| 24 | ||
| 26550 | 25 | val _ = Output.add_mode isabelle_processN Output.default_output Output.default_escape; | 
| 28036 | 26 | val _ = Markup.add_mode isabelle_processN YXML.output_markup; | 
| 25841 | 27 | |
| 28 | ||
| 46119 
0d7172a7672c
tuned signature -- emphasize special nature of protocol commands;
 wenzelm parents: 
45666diff
changeset | 29 | (* protocol commands *) | 
| 38270 
71bb3c273dd1
native Isabelle_Process commands, based on efficient byte channel protocol for string lists;
 wenzelm parents: 
38265diff
changeset | 30 | |
| 
71bb3c273dd1
native Isabelle_Process commands, based on efficient byte channel protocol for string lists;
 wenzelm parents: 
38265diff
changeset | 31 | local | 
| 
71bb3c273dd1
native Isabelle_Process commands, based on efficient byte channel protocol for string lists;
 wenzelm parents: 
38265diff
changeset | 32 | |
| 43684 | 33 | val commands = | 
| 52800 
1baa5d19ac44
less aggressive flushing: cope with massive amounts of protocol messages, e.g. from threads_trace;
 wenzelm parents: 
52799diff
changeset | 34 | Synchronized.var "Isabelle_Process.commands" | 
| 
1baa5d19ac44
less aggressive flushing: cope with massive amounts of protocol messages, e.g. from threads_trace;
 wenzelm parents: 
52799diff
changeset | 35 | (Symtab.empty: (string list -> unit) Symtab.table); | 
| 38270 
71bb3c273dd1
native Isabelle_Process commands, based on efficient byte channel protocol for string lists;
 wenzelm parents: 
38265diff
changeset | 36 | |
| 
71bb3c273dd1
native Isabelle_Process commands, based on efficient byte channel protocol for string lists;
 wenzelm parents: 
38265diff
changeset | 37 | in | 
| 
71bb3c273dd1
native Isabelle_Process commands, based on efficient byte channel protocol for string lists;
 wenzelm parents: 
38265diff
changeset | 38 | |
| 46119 
0d7172a7672c
tuned signature -- emphasize special nature of protocol commands;
 wenzelm parents: 
45666diff
changeset | 39 | fun protocol_command name cmd = | 
| 43684 | 40 | Synchronized.change commands (fn cmds => | 
| 38270 
71bb3c273dd1
native Isabelle_Process commands, based on efficient byte channel protocol for string lists;
 wenzelm parents: 
38265diff
changeset | 41 | (if not (Symtab.defined cmds name) then () | 
| 52582 | 42 |     else warning ("Redefining Isabelle protocol command " ^ quote name);
 | 
| 43684 | 43 | Symtab.update (name, cmd) cmds)); | 
| 38270 
71bb3c273dd1
native Isabelle_Process commands, based on efficient byte channel protocol for string lists;
 wenzelm parents: 
38265diff
changeset | 44 | |
| 46119 
0d7172a7672c
tuned signature -- emphasize special nature of protocol commands;
 wenzelm parents: 
45666diff
changeset | 45 | fun run_command name args = | 
| 43684 | 46 | (case Symtab.lookup (Synchronized.value commands) name of | 
| 52582 | 47 |     NONE => error ("Undefined Isabelle protocol command " ^ quote name)
 | 
| 46119 
0d7172a7672c
tuned signature -- emphasize special nature of protocol commands;
 wenzelm parents: 
45666diff
changeset | 48 | | SOME cmd => | 
| 59056 
cbe9563c03d1
even more exception traces for Document.update, which goes through additional execution wrappers;
 wenzelm parents: 
59055diff
changeset | 49 | (Runtime.exn_trace_system (fn () => cmd args) | 
| 59055 
5a7157b8e870
more informative failure of protocol commands, with exception trace;
 wenzelm parents: 
58850diff
changeset | 50 |         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: 
38265diff
changeset | 51 | |
| 
71bb3c273dd1
native Isabelle_Process commands, based on efficient byte channel protocol for string lists;
 wenzelm parents: 
38265diff
changeset | 52 | end; | 
| 
71bb3c273dd1
native Isabelle_Process commands, based on efficient byte channel protocol for string lists;
 wenzelm parents: 
38265diff
changeset | 53 | |
| 
71bb3c273dd1
native Isabelle_Process commands, based on efficient byte channel protocol for string lists;
 wenzelm parents: 
38265diff
changeset | 54 | |
| 50505 
33c92722cc3d
smarter handling of tracing messages: prover process pauses and enters user dialog;
 wenzelm parents: 
50503diff
changeset | 55 | (* restricted tracing messages *) | 
| 49647 | 56 | |
| 52105 | 57 | val tracing_messages = | 
| 58 | Synchronized.var "tracing_messages" (Inttab.empty: int Inttab.table); | |
| 49647 | 59 | |
| 52655 
3b2b1ef13979
more careful termination of removed execs, leaving running execs undisturbed;
 wenzelm parents: 
52584diff
changeset | 60 | fun reset_tracing exec_id = | 
| 
3b2b1ef13979
more careful termination of removed execs, leaving running execs undisturbed;
 wenzelm parents: 
52584diff
changeset | 61 | Synchronized.change tracing_messages (Inttab.delete_safe exec_id); | 
| 49647 | 62 | |
| 50505 
33c92722cc3d
smarter handling of tracing messages: prover process pauses and enters user dialog;
 wenzelm parents: 
50503diff
changeset | 63 | fun update_tracing () = | 
| 50911 
ee7fe4230642
more explicit treatment of (optional) exception properties, notably for "serial" -- avoid conflict with startPosition = offset;
 wenzelm parents: 
50715diff
changeset | 64 | (case Position.parse_id (Position.thread_data ()) of | 
| 49647 | 65 | NONE => () | 
| 52655 
3b2b1ef13979
more careful termination of removed execs, leaving running execs undisturbed;
 wenzelm parents: 
52584diff
changeset | 66 | | SOME exec_id => | 
| 50505 
33c92722cc3d
smarter handling of tracing messages: prover process pauses and enters user dialog;
 wenzelm parents: 
50503diff
changeset | 67 | let | 
| 52560 | 68 | val ok = | 
| 52105 | 69 | Synchronized.change_result tracing_messages (fn tab => | 
| 50505 
33c92722cc3d
smarter handling of tracing messages: prover process pauses and enters user dialog;
 wenzelm parents: 
50503diff
changeset | 70 | let | 
| 52655 
3b2b1ef13979
more careful termination of removed execs, leaving running execs undisturbed;
 wenzelm parents: 
52584diff
changeset | 71 | val n = the_default 0 (Inttab.lookup tab exec_id) + 1; | 
| 52105 | 72 | val ok = n <= Options.default_int "editor_tracing_messages"; | 
| 52655 
3b2b1ef13979
more careful termination of removed execs, leaving running execs undisturbed;
 wenzelm parents: 
52584diff
changeset | 73 | 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: 
50503diff
changeset | 74 | in | 
| 
33c92722cc3d
smarter handling of tracing messages: prover process pauses and enters user dialog;
 wenzelm parents: 
50503diff
changeset | 75 | if ok then () | 
| 
33c92722cc3d
smarter handling of tracing messages: prover process pauses and enters user dialog;
 wenzelm parents: 
50503diff
changeset | 76 | else | 
| 
33c92722cc3d
smarter handling of tracing messages: prover process pauses and enters user dialog;
 wenzelm parents: 
50503diff
changeset | 77 | let | 
| 
33c92722cc3d
smarter handling of tracing messages: prover process pauses and enters user dialog;
 wenzelm parents: 
50503diff
changeset | 78 | val (text, promise) = Active.dialog_text (); | 
| 
33c92722cc3d
smarter handling of tracing messages: prover process pauses and enters user dialog;
 wenzelm parents: 
50503diff
changeset | 79 | val _ = | 
| 
33c92722cc3d
smarter handling of tracing messages: prover process pauses and enters user dialog;
 wenzelm parents: 
50503diff
changeset | 80 |               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: 
50911diff
changeset | 81 | text "100" ^ ", " ^ text "1000" ^ ", " ^ text "10000" ^ " messages?") | 
| 50505 
33c92722cc3d
smarter handling of tracing messages: prover process pauses and enters user dialog;
 wenzelm parents: 
50503diff
changeset | 82 | val m = Markup.parse_int (Future.join promise) | 
| 
33c92722cc3d
smarter handling of tracing messages: prover process pauses and enters user dialog;
 wenzelm parents: 
50503diff
changeset | 83 | handle Fail _ => error "Stopped"; | 
| 
33c92722cc3d
smarter handling of tracing messages: prover process pauses and enters user dialog;
 wenzelm parents: 
50503diff
changeset | 84 | in | 
| 52105 | 85 | Synchronized.change tracing_messages | 
| 52655 
3b2b1ef13979
more careful termination of removed execs, leaving running execs undisturbed;
 wenzelm parents: 
52584diff
changeset | 86 | (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: 
50503diff
changeset | 87 | end | 
| 
33c92722cc3d
smarter handling of tracing messages: prover process pauses and enters user dialog;
 wenzelm parents: 
50503diff
changeset | 88 | end); | 
| 49647 | 89 | |
| 90 | ||
| 52800 
1baa5d19ac44
less aggressive flushing: cope with massive amounts of protocol messages, e.g. from threads_trace;
 wenzelm parents: 
52799diff
changeset | 91 | (* output channels *) | 
| 28188 | 92 | |
| 52854 
92932931bd82
more general Output.result: allow to update arbitrary properties;
 wenzelm parents: 
52852diff
changeset | 93 | val serial_props = Markup.serial_properties o serial; | 
| 
92932931bd82
more general Output.result: allow to update arbitrary properties;
 wenzelm parents: 
52852diff
changeset | 94 | |
| 48712 
6b7a9bcc0bae
simplified process startup phases: INIT suffices for is_ready;
 wenzelm parents: 
48710diff
changeset | 95 | fun init_channels channel = | 
| 28189 
fbad2eb5be9e
auto_flush: uniform block buffering for all output streams;
 wenzelm parents: 
28188diff
changeset | 96 | let | 
| 40134 
8baded087d34
explicit message_output thread, with flushing after timeout, ensure atomic user-operations without the danger of IO Interrupt;
 wenzelm parents: 
40133diff
changeset | 97 | 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: 
40133diff
changeset | 98 | val _ = TextIO.StreamIO.setBufferMode (TextIO.getOutstream TextIO.stdErr, IO.LINE_BUF); | 
| 
8baded087d34
explicit message_output thread, with flushing after timeout, ensure atomic user-operations without the danger of IO Interrupt;
 wenzelm parents: 
40133diff
changeset | 99 | |
| 52584 | 100 | val msg_channel = Message_Channel.make channel; | 
| 52580 
36aa39694ab4
fall back on synchronous message output for single-threaded SML/NJ;
 wenzelm parents: 
52578diff
changeset | 101 | |
| 52800 
1baa5d19ac44
less aggressive flushing: cope with massive amounts of protocol messages, e.g. from threads_trace;
 wenzelm parents: 
52799diff
changeset | 102 | fun message name props body = | 
| 
1baa5d19ac44
less aggressive flushing: cope with massive amounts of protocol messages, e.g. from threads_trace;
 wenzelm parents: 
52799diff
changeset | 103 | 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: 
52799diff
changeset | 104 | |
| 52854 
92932931bd82
more general Output.result: allow to update arbitrary properties;
 wenzelm parents: 
52852diff
changeset | 105 | 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: 
56303diff
changeset | 106 | if forall (fn s => s = "") body then () | 
| 52580 
36aa39694ab4
fall back on synchronous message output for single-threaded SML/NJ;
 wenzelm parents: 
52578diff
changeset | 107 | else | 
| 57913 | 108 | let | 
| 109 | val props' = | |
| 110 | (case (Properties.defined props Markup.idN, Position.get_id (Position.thread_data ())) of | |
| 111 | (false, SOME id') => props @ [(Markup.idN, id')] | |
| 112 | | _ => props); | |
| 113 | in message name props' body end; | |
| 28044 | 114 | in | 
| 55387 
51f0876f61df
seal system channels at end of Pure bootstrap -- Isabelle/Scala provides official interfaces;
 wenzelm parents: 
54671diff
changeset | 115 | Output.status_fn := standard_message [] Markup.statusN; | 
| 
51f0876f61df
seal system channels at end of Pure bootstrap -- Isabelle/Scala provides official interfaces;
 wenzelm parents: 
54671diff
changeset | 116 | Output.report_fn := standard_message [] Markup.reportN; | 
| 
51f0876f61df
seal system channels at end of Pure bootstrap -- Isabelle/Scala provides official interfaces;
 wenzelm parents: 
54671diff
changeset | 117 | Output.result_fn := | 
| 52854 
92932931bd82
more general Output.result: allow to update arbitrary properties;
 wenzelm parents: 
52852diff
changeset | 118 | (fn props => fn s => standard_message (props @ serial_props ()) Markup.resultN s); | 
| 55387 
51f0876f61df
seal system channels at end of Pure bootstrap -- Isabelle/Scala provides official interfaces;
 wenzelm parents: 
54671diff
changeset | 119 | Output.writeln_fn := (fn s => standard_message (serial_props ()) Markup.writelnN s); | 
| 59184 
830bb7ddb3ab
explicit message channels for "state", "information";
 wenzelm parents: 
59056diff
changeset | 120 | Output.state_fn := (fn s => standard_message (serial_props ()) Markup.stateN s); | 
| 
830bb7ddb3ab
explicit message channels for "state", "information";
 wenzelm parents: 
59056diff
changeset | 121 | Output.information_fn := (fn s => standard_message (serial_props ()) Markup.informationN s); | 
| 55387 
51f0876f61df
seal system channels at end of Pure bootstrap -- Isabelle/Scala provides official interfaces;
 wenzelm parents: 
54671diff
changeset | 122 | Output.tracing_fn := | 
| 52854 
92932931bd82
more general Output.result: allow to update arbitrary properties;
 wenzelm parents: 
52852diff
changeset | 123 | (fn s => (update_tracing (); standard_message (serial_props ()) Markup.tracingN s)); | 
| 55387 
51f0876f61df
seal system channels at end of Pure bootstrap -- Isabelle/Scala provides official interfaces;
 wenzelm parents: 
54671diff
changeset | 124 | Output.warning_fn := (fn s => standard_message (serial_props ()) Markup.warningN s); | 
| 59203 
5f0bd5afc16d
explicit message channel for "legacy", which is nonetheless a variant of "warning";
 wenzelm parents: 
59184diff
changeset | 125 | Output.legacy_fn := (fn s => standard_message (serial_props ()) Markup.legacyN s); | 
| 55387 
51f0876f61df
seal system channels at end of Pure bootstrap -- Isabelle/Scala provides official interfaces;
 wenzelm parents: 
54671diff
changeset | 126 | Output.error_message_fn := | 
| 52854 
92932931bd82
more general Output.result: allow to update arbitrary properties;
 wenzelm parents: 
52852diff
changeset | 127 | (fn (i, s) => standard_message (Markup.serial_properties i) Markup.errorN s); | 
| 57975 
c657c68a60ab
explicit system message for protocol failure -- show on Syslog panel instead of Raw Output;
 wenzelm parents: 
56895diff
changeset | 128 | Output.system_message_fn := message Markup.systemN []; | 
| 55387 
51f0876f61df
seal system channels at end of Pure bootstrap -- Isabelle/Scala provides official interfaces;
 wenzelm parents: 
54671diff
changeset | 129 | Output.protocol_message_fn := message Markup.protocolN; | 
| 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: 
56303diff
changeset | 130 | message Markup.initN [] [Session.welcome ()]; | 
| 52584 | 131 | msg_channel | 
| 28044 | 132 | end; | 
| 25841 | 133 | |
| 134 | ||
| 39234 
d76a2fd129b5
main command loops are supposed to be uninterruptible -- no special treatment here;
 wenzelm parents: 
38871diff
changeset | 135 | (* protocol loop -- uninterruptible *) | 
| 38270 
71bb3c273dd1
native Isabelle_Process commands, based on efficient byte channel protocol for string lists;
 wenzelm parents: 
38265diff
changeset | 136 | |
| 43684 | 137 | 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: 
38265diff
changeset | 138 | |
| 
71bb3c273dd1
native Isabelle_Process commands, based on efficient byte channel protocol for string lists;
 wenzelm parents: 
38265diff
changeset | 139 | local | 
| 
71bb3c273dd1
native Isabelle_Process commands, based on efficient byte channel protocol for string lists;
 wenzelm parents: 
38265diff
changeset | 140 | |
| 
71bb3c273dd1
native Isabelle_Process commands, based on efficient byte channel protocol for string lists;
 wenzelm parents: 
38265diff
changeset | 141 | fun recover crash = | 
| 43684 | 142 | (Synchronized.change crashes (cons crash); | 
| 57975 
c657c68a60ab
explicit system message for protocol failure -- show on Syslog panel instead of Raw Output;
 wenzelm parents: 
56895diff
changeset | 143 | Output.physical_stderr | 
| 
c657c68a60ab
explicit system message for protocol failure -- show on Syslog panel instead of Raw Output;
 wenzelm parents: 
56895diff
changeset | 144 | "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: 
38265diff
changeset | 145 | |
| 45029 
63144ea111f7
abstract System_Channel in ML (cf. Scala version);
 wenzelm parents: 
45028diff
changeset | 146 | fun read_chunk channel len = | 
| 38270 
71bb3c273dd1
native Isabelle_Process commands, based on efficient byte channel protocol for string lists;
 wenzelm parents: 
38265diff
changeset | 147 | let | 
| 
71bb3c273dd1
native Isabelle_Process commands, based on efficient byte channel protocol for string lists;
 wenzelm parents: 
38265diff
changeset | 148 | val n = | 
| 
71bb3c273dd1
native Isabelle_Process commands, based on efficient byte channel protocol for string lists;
 wenzelm parents: 
38265diff
changeset | 149 | (case Int.fromString len of | 
| 
71bb3c273dd1
native Isabelle_Process commands, based on efficient byte channel protocol for string lists;
 wenzelm parents: 
38265diff
changeset | 150 | SOME n => n | 
| 52799 | 151 |       | NONE => error ("Isabelle process: malformed header " ^ quote len));
 | 
| 45029 
63144ea111f7
abstract System_Channel in ML (cf. Scala version);
 wenzelm parents: 
45028diff
changeset | 152 | val chunk = System_Channel.inputN channel n; | 
| 52799 | 153 | val i = size chunk; | 
| 38270 
71bb3c273dd1
native Isabelle_Process commands, based on efficient byte channel protocol for string lists;
 wenzelm parents: 
38265diff
changeset | 154 | in | 
| 52799 | 155 | if i <> n then | 
| 156 |       error ("Isabelle process: bad chunk (unexpected EOF after " ^
 | |
| 157 | string_of_int i ^ " of " ^ string_of_int n ^ " bytes)") | |
| 158 | else chunk | |
| 38270 
71bb3c273dd1
native Isabelle_Process commands, based on efficient byte channel protocol for string lists;
 wenzelm parents: 
38265diff
changeset | 159 | end; | 
| 
71bb3c273dd1
native Isabelle_Process commands, based on efficient byte channel protocol for string lists;
 wenzelm parents: 
38265diff
changeset | 160 | |
| 45029 
63144ea111f7
abstract System_Channel in ML (cf. Scala version);
 wenzelm parents: 
45028diff
changeset | 161 | fun read_command channel = | 
| 59055 
5a7157b8e870
more informative failure of protocol commands, with exception trace;
 wenzelm parents: 
58850diff
changeset | 162 | System_Channel.input_line channel | 
| 
5a7157b8e870
more informative failure of protocol commands, with exception trace;
 wenzelm parents: 
58850diff
changeset | 163 | |> Option.map (fn line => map (read_chunk channel) (space_explode "," line)); | 
| 38270 
71bb3c273dd1
native Isabelle_Process commands, based on efficient byte channel protocol for string lists;
 wenzelm parents: 
38265diff
changeset | 164 | |
| 
71bb3c273dd1
native Isabelle_Process commands, based on efficient byte channel protocol for string lists;
 wenzelm parents: 
38265diff
changeset | 165 | in | 
| 
71bb3c273dd1
native Isabelle_Process commands, based on efficient byte channel protocol for string lists;
 wenzelm parents: 
38265diff
changeset | 166 | |
| 45029 
63144ea111f7
abstract System_Channel in ML (cf. Scala version);
 wenzelm parents: 
45028diff
changeset | 167 | fun loop channel = | 
| 59055 
5a7157b8e870
more informative failure of protocol commands, with exception trace;
 wenzelm parents: 
58850diff
changeset | 168 | let | 
| 
5a7157b8e870
more informative failure of protocol commands, with exception trace;
 wenzelm parents: 
58850diff
changeset | 169 | val continue = | 
| 
5a7157b8e870
more informative failure of protocol commands, with exception trace;
 wenzelm parents: 
58850diff
changeset | 170 | (case read_command channel of | 
| 
5a7157b8e870
more informative failure of protocol commands, with exception trace;
 wenzelm parents: 
58850diff
changeset | 171 | NONE => false | 
| 
5a7157b8e870
more informative failure of protocol commands, with exception trace;
 wenzelm parents: 
58850diff
changeset | 172 | | 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: 
59350diff
changeset | 173 | | SOME (name :: args) => (run_command name args; true)) | 
| 59055 
5a7157b8e870
more informative failure of protocol commands, with exception trace;
 wenzelm parents: 
58850diff
changeset | 174 | 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: 
52712diff
changeset | 175 | in | 
| 
8c7cf864e270
pro-forma Goal.reset_futures, despite lack of final join/commit;
 wenzelm parents: 
52712diff
changeset | 176 | if continue then loop channel | 
| 53192 | 177 | else (Future.shutdown (); Execution.reset (); ()) | 
| 52770 
8c7cf864e270
pro-forma Goal.reset_futures, despite lack of final join/commit;
 wenzelm parents: 
52712diff
changeset | 178 | end; | 
| 38270 
71bb3c273dd1
native Isabelle_Process commands, based on efficient byte channel protocol for string lists;
 wenzelm parents: 
38265diff
changeset | 179 | |
| 
71bb3c273dd1
native Isabelle_Process commands, based on efficient byte channel protocol for string lists;
 wenzelm parents: 
38265diff
changeset | 180 | end; | 
| 
71bb3c273dd1
native Isabelle_Process commands, based on efficient byte channel protocol for string lists;
 wenzelm parents: 
38265diff
changeset | 181 | |
| 
71bb3c273dd1
native Isabelle_Process commands, based on efficient byte channel protocol for string lists;
 wenzelm parents: 
38265diff
changeset | 182 | |
| 25554 | 183 | (* init *) | 
| 184 | ||
| 59211 | 185 | val default_modes1 = [Syntax_Trans.no_bracketsN, Syntax_Trans.no_type_bracketsN]; | 
| 50715 
8cfd585b9162
prefer old graph browser in Isabelle/jEdit, which still produces better layout;
 wenzelm parents: 
50698diff
changeset | 186 | val default_modes2 = [Symbol.xsymbolsN, isabelle_processN, Pretty.symbolicN]; | 
| 49566 
66cbf8bb4693
basic integration of graphview into document model;
 wenzelm parents: 
49108diff
changeset | 187 | |
| 59350 
acba5d6fdb2f
discontinued fifo channel, always use portable socket;
 wenzelm parents: 
59211diff
changeset | 188 | val init = uninterruptible (fn _ => fn socket => | 
| 38253 
3d4e521014f7
Isabelle_Process: separate input fifo for commands (still using the old tty protocol);
 wenzelm parents: 
38236diff
changeset | 189 | let | 
| 53212 
387b9f7cb0ac
added SHA1 library integrity test, which is invoked at compile time and Isabelle_Process run-time;
 wenzelm parents: 
53192diff
changeset | 190 | val _ = SHA1_Samples.test () | 
| 
387b9f7cb0ac
added SHA1 library integrity test, which is invoked at compile time and Isabelle_Process run-time;
 wenzelm parents: 
53192diff
changeset | 191 | handle exn as Fail msg => (Output.physical_stderr (msg ^ "\n"); 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: 
46121diff
changeset | 192 | 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: 
39513diff
changeset | 193 | |
| 49661 
ac48def96b69
enable show_markup by default (approx. double output size);
 wenzelm parents: 
49647diff
changeset | 194 | val _ = Printer.show_markup_default := true; | 
| 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: 
39513diff
changeset | 195 | val _ = Context.set_thread_data NONE; | 
| 43671 
a250b092ac66
hard-wired print mode "xsymbols" increases chance that "iff" in HOL will print symbolic arrow;
 wenzelm parents: 
42897diff
changeset | 196 | val _ = | 
| 
a250b092ac66
hard-wired print mode "xsymbols" increases chance that "iff" in HOL will print symbolic arrow;
 wenzelm parents: 
42897diff
changeset | 197 | Unsynchronized.change print_mode | 
| 49566 
66cbf8bb4693
basic integration of graphview into document model;
 wenzelm parents: 
49108diff
changeset | 198 | (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: 
39513diff
changeset | 199 | |
| 59350 
acba5d6fdb2f
discontinued fifo channel, always use portable socket;
 wenzelm parents: 
59211diff
changeset | 200 | val channel = System_Channel.rendezvous socket; | 
| 52584 | 201 | val msg_channel = init_channels channel; | 
| 52111 
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
 wenzelm parents: 
52105diff
changeset | 202 | val _ = Session.init_protocol_handlers (); | 
| 58848 | 203 | val _ = loop channel; | 
| 52584 | 204 | in Message_Channel.shutdown msg_channel end); | 
| 25528 
e67230c2b952
Isabelle process wrapper -- interaction via external program.
 wenzelm parents: diff
changeset | 205 | |
| 
e67230c2b952
Isabelle process wrapper -- interaction via external program.
 wenzelm parents: diff
changeset | 206 | end; | 
| 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: 
39513diff
changeset | 207 |