| author | wenzelm | 
| Sun, 14 Jun 2015 23:22:08 +0200 | |
| changeset 60477 | 051b200f7578 | 
| parent 59203 | 5f0bd5afc16d | 
| child 61885 | acdfc76a6c33 | 
| permissions | -rw-r--r-- | 
| 14815 | 1 | (* Title: Pure/General/output.ML | 
| 2 | Author: Makarius, Hagia Maria Sion Abbey (Jerusalem) | |
| 3 | ||
| 56830 
e760242101fc
tuned signature -- channels for diagnostic output for system tools means stderr;
 wenzelm parents: 
56334diff
changeset | 4 | Isabelle channels for diagnostic output. | 
| 14815 | 5 | *) | 
| 6 | ||
| 7 | signature BASIC_OUTPUT = | |
| 8 | sig | |
| 18682 
216692feebab
removed special ERROR handling stuff (transform_error etc.);
 wenzelm parents: 
17539diff
changeset | 9 | val writeln: string -> unit | 
| 
216692feebab
removed special ERROR handling stuff (transform_error etc.);
 wenzelm parents: 
17539diff
changeset | 10 | val tracing: string -> unit | 
| 
216692feebab
removed special ERROR handling stuff (transform_error etc.);
 wenzelm parents: 
17539diff
changeset | 11 | val warning: string -> unit | 
| 59203 
5f0bd5afc16d
explicit message channel for "legacy", which is nonetheless a variant of "warning";
 wenzelm parents: 
59184diff
changeset | 12 | val legacy_feature: string -> unit | 
| 14815 | 13 | end; | 
| 14 | ||
| 15 | signature OUTPUT = | |
| 16 | sig | |
| 17 | include BASIC_OUTPUT | |
| 40131 
7cbebd636e79
explicitly qualify type Output.output, which is a slightly odd internal feature;
 wenzelm parents: 
40125diff
changeset | 18 | type output = string | 
| 23660 
18765718cf62
type output = string indicates raw system output;
 wenzelm parents: 
23616diff
changeset | 19 | val default_output: string -> output * int | 
| 
18765718cf62
type output = string indicates raw system output;
 wenzelm parents: 
23616diff
changeset | 20 | val default_escape: output -> string | 
| 
18765718cf62
type output = string indicates raw system output;
 wenzelm parents: 
23616diff
changeset | 21 | val add_mode: string -> (string -> output * int) -> (output -> string) -> unit | 
| 
18765718cf62
type output = string indicates raw system output;
 wenzelm parents: 
23616diff
changeset | 22 | val output_width: string -> output * int | 
| 
18765718cf62
type output = string indicates raw system output;
 wenzelm parents: 
23616diff
changeset | 23 | val output: string -> output | 
| 
18765718cf62
type output = string indicates raw system output;
 wenzelm parents: 
23616diff
changeset | 24 | val escape: output -> string | 
| 44389 
a3b5fdfb04a3
tuned signature -- contrast physical output primitives versus Output.raw_message;
 wenzelm parents: 
44270diff
changeset | 25 | val physical_stdout: output -> unit | 
| 
a3b5fdfb04a3
tuned signature -- contrast physical output primitives versus Output.raw_message;
 wenzelm parents: 
44270diff
changeset | 26 | val physical_stderr: output -> unit | 
| 
a3b5fdfb04a3
tuned signature -- contrast physical output primitives versus Output.raw_message;
 wenzelm parents: 
44270diff
changeset | 27 | val physical_writeln: output -> unit | 
| 51661 | 28 | exception Protocol_Message of Properties.T | 
| 56334 
6b3739fee456
some shortcuts for chunks, which sometimes avoid bulky string output;
 wenzelm parents: 
56333diff
changeset | 29 | val writelns: string list -> unit | 
| 59184 
830bb7ddb3ab
explicit message channels for "state", "information";
 wenzelm parents: 
58850diff
changeset | 30 | val state: string -> unit | 
| 
830bb7ddb3ab
explicit message channels for "state", "information";
 wenzelm parents: 
58850diff
changeset | 31 | val information: string -> unit | 
| 54387 | 32 | val error_message': serial * string -> unit | 
| 33 | val error_message: string -> unit | |
| 57975 
c657c68a60ab
explicit system message for protocol failure -- show on Syslog panel instead of Raw Output;
 wenzelm parents: 
56830diff
changeset | 34 | val system_message: string -> unit | 
| 27605 | 35 | val status: string -> unit | 
| 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: 
56304diff
changeset | 36 | val report: string list -> unit | 
| 
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: 
56304diff
changeset | 37 | val result: Properties.T -> string list -> unit | 
| 
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: 
56304diff
changeset | 38 | val protocol_message: Properties.T -> string list -> unit | 
| 
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: 
56304diff
changeset | 39 | val try_protocol_message: Properties.T -> string list -> unit | 
| 14815 | 40 | end; | 
| 41 | ||
| 55387 
51f0876f61df
seal system channels at end of Pure bootstrap -- Isabelle/Scala provides official interfaces;
 wenzelm parents: 
54387diff
changeset | 42 | signature PRIVATE_OUTPUT = | 
| 
51f0876f61df
seal system channels at end of Pure bootstrap -- Isabelle/Scala provides official interfaces;
 wenzelm parents: 
54387diff
changeset | 43 | sig | 
| 
51f0876f61df
seal system channels at end of Pure bootstrap -- Isabelle/Scala provides official interfaces;
 wenzelm parents: 
54387diff
changeset | 44 | include OUTPUT | 
| 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: 
56304diff
changeset | 45 | val writeln_fn: (output list -> unit) Unsynchronized.ref | 
| 59184 
830bb7ddb3ab
explicit message channels for "state", "information";
 wenzelm parents: 
58850diff
changeset | 46 | val state_fn: (output list -> unit) Unsynchronized.ref | 
| 
830bb7ddb3ab
explicit message channels for "state", "information";
 wenzelm parents: 
58850diff
changeset | 47 | val information_fn: (output list -> unit) Unsynchronized.ref | 
| 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: 
56304diff
changeset | 48 | val tracing_fn: (output list -> unit) Unsynchronized.ref | 
| 
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: 
56304diff
changeset | 49 | val warning_fn: (output list -> unit) Unsynchronized.ref | 
| 59203 
5f0bd5afc16d
explicit message channel for "legacy", which is nonetheless a variant of "warning";
 wenzelm parents: 
59184diff
changeset | 50 | val legacy_fn: (output list -> unit) Unsynchronized.ref | 
| 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: 
56304diff
changeset | 51 | val error_message_fn: (serial * output list -> unit) Unsynchronized.ref | 
| 57975 
c657c68a60ab
explicit system message for protocol failure -- show on Syslog panel instead of Raw Output;
 wenzelm parents: 
56830diff
changeset | 52 | val system_message_fn: (output list -> unit) Unsynchronized.ref | 
| 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: 
56304diff
changeset | 53 | val status_fn: (output list -> unit) Unsynchronized.ref | 
| 
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: 
56304diff
changeset | 54 | val report_fn: (output list -> unit) Unsynchronized.ref | 
| 
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: 
56304diff
changeset | 55 | val result_fn: (Properties.T -> output list -> unit) Unsynchronized.ref | 
| 
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: 
56304diff
changeset | 56 | val protocol_message_fn: (Properties.T -> output list -> unit) Unsynchronized.ref | 
| 55387 
51f0876f61df
seal system channels at end of Pure bootstrap -- Isabelle/Scala provides official interfaces;
 wenzelm parents: 
54387diff
changeset | 57 | end; | 
| 
51f0876f61df
seal system channels at end of Pure bootstrap -- Isabelle/Scala provides official interfaces;
 wenzelm parents: 
54387diff
changeset | 58 | |
| 
51f0876f61df
seal system channels at end of Pure bootstrap -- Isabelle/Scala provides official interfaces;
 wenzelm parents: 
54387diff
changeset | 59 | structure Output: PRIVATE_OUTPUT = | 
| 14815 | 60 | struct | 
| 61 | ||
| 23616 | 62 | (** print modes **) | 
| 14881 | 63 | |
| 23660 
18765718cf62
type output = string indicates raw system output;
 wenzelm parents: 
23616diff
changeset | 64 | type output = string; (*raw system output*) | 
| 
18765718cf62
type output = string indicates raw system output;
 wenzelm parents: 
23616diff
changeset | 65 | |
| 23616 | 66 | fun default_output s = (s, size s); | 
| 23660 
18765718cf62
type output = string indicates raw system output;
 wenzelm parents: 
23616diff
changeset | 67 | fun default_escape (s: output) = s; | 
| 14815 | 68 | |
| 23616 | 69 | local | 
| 70 |   val default = {output = default_output, escape = default_escape};
 | |
| 43684 | 71 |   val modes = Synchronized.var "Output.modes" (Symtab.make [("", default)]);
 | 
| 23616 | 72 | in | 
| 43684 | 73 | fun add_mode name output escape = | 
| 74 |     Synchronized.change modes (Symtab.update_new (name, {output = output, escape = escape}));
 | |
| 23616 | 75 | fun get_mode () = | 
| 43684 | 76 | the_default default | 
| 77 | (Library.get_first (Symtab.lookup (Synchronized.value modes)) (print_mode_value ())); | |
| 23616 | 78 | end; | 
| 14815 | 79 | |
| 19265 | 80 | fun output_width x = #output (get_mode ()) x; | 
| 14815 | 81 | val output = #1 o output_width; | 
| 23727 | 82 | |
| 23616 | 83 | fun escape x = #escape (get_mode ()) x; | 
| 14815 | 84 | |
| 85 | ||
| 86 | ||
| 87 | (** output channels **) | |
| 88 | ||
| 39733 
6d373e9dcb9d
renamed raw output primitives to emphasize their meaning -- not to be used in user-space;
 wenzelm parents: 
38839diff
changeset | 89 | (* raw output primitives -- not to be used in user-space *) | 
| 14984 | 90 | |
| 44389 
a3b5fdfb04a3
tuned signature -- contrast physical output primitives versus Output.raw_message;
 wenzelm parents: 
44270diff
changeset | 91 | fun physical_stdout s = (TextIO.output (TextIO.stdOut, s); TextIO.flushOut TextIO.stdOut); | 
| 
a3b5fdfb04a3
tuned signature -- contrast physical output primitives versus Output.raw_message;
 wenzelm parents: 
44270diff
changeset | 92 | fun physical_stderr s = (TextIO.output (TextIO.stdErr, s); TextIO.flushOut TextIO.stdErr); | 
| 14815 | 93 | |
| 44389 
a3b5fdfb04a3
tuned signature -- contrast physical output primitives versus Output.raw_message;
 wenzelm parents: 
44270diff
changeset | 94 | fun physical_writeln "" = () | 
| 
a3b5fdfb04a3
tuned signature -- contrast physical output primitives versus Output.raw_message;
 wenzelm parents: 
44270diff
changeset | 95 | | physical_writeln s = physical_stdout (suffix "\n" s); (*atomic output!*) | 
| 14815 | 96 | |
| 14984 | 97 | |
| 98 | (* Isabelle output channels *) | |
| 99 | ||
| 51661 | 100 | exception Protocol_Message of Properties.T; | 
| 101 | ||
| 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: 
56304diff
changeset | 102 | val writeln_fn = Unsynchronized.ref (physical_writeln o implode); | 
| 59184 
830bb7ddb3ab
explicit message channels for "state", "information";
 wenzelm parents: 
58850diff
changeset | 103 | val state_fn = Unsynchronized.ref (fn ss => ! writeln_fn ss); | 
| 
830bb7ddb3ab
explicit message channels for "state", "information";
 wenzelm parents: 
58850diff
changeset | 104 | val information_fn = Unsynchronized.ref (fn ss => ! writeln_fn ss); | 
| 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: 
56304diff
changeset | 105 | val tracing_fn = Unsynchronized.ref (fn ss => ! writeln_fn ss); | 
| 
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: 
56304diff
changeset | 106 | val warning_fn = Unsynchronized.ref (physical_writeln o prefix_lines "### " o implode); | 
| 59203 
5f0bd5afc16d
explicit message channel for "legacy", which is nonetheless a variant of "warning";
 wenzelm parents: 
59184diff
changeset | 107 | val legacy_fn = Unsynchronized.ref (fn ss => ! warning_fn ss); | 
| 
5f0bd5afc16d
explicit message channel for "legacy", which is nonetheless a variant of "warning";
 wenzelm parents: 
59184diff
changeset | 108 | |
| 55387 
51f0876f61df
seal system channels at end of Pure bootstrap -- Isabelle/Scala provides official interfaces;
 wenzelm parents: 
54387diff
changeset | 109 | val error_message_fn = | 
| 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: 
56304diff
changeset | 110 | Unsynchronized.ref (fn (_: serial, ss) => physical_writeln (prefix_lines "*** " (implode ss))); | 
| 57975 
c657c68a60ab
explicit system message for protocol failure -- show on Syslog panel instead of Raw Output;
 wenzelm parents: 
56830diff
changeset | 111 | val system_message_fn = Unsynchronized.ref (fn ss => ! writeln_fn ss); | 
| 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: 
56304diff
changeset | 112 | val status_fn = Unsynchronized.ref (fn _: output list => ()); | 
| 
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: 
56304diff
changeset | 113 | val report_fn = Unsynchronized.ref (fn _: output list => ()); | 
| 
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: 
56304diff
changeset | 114 | val result_fn = Unsynchronized.ref (fn _: Properties.T => fn _: output list => ()); | 
| 
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: 
56304diff
changeset | 115 | val protocol_message_fn: (Properties.T -> output list -> unit) Unsynchronized.ref = | 
| 55387 
51f0876f61df
seal system channels at end of Pure bootstrap -- Isabelle/Scala provides official interfaces;
 wenzelm parents: 
54387diff
changeset | 116 | Unsynchronized.ref (fn props => fn _ => raise Protocol_Message props); | 
| 14815 | 117 | |
| 56334 
6b3739fee456
some shortcuts for chunks, which sometimes avoid bulky string output;
 wenzelm parents: 
56333diff
changeset | 118 | fun writelns ss = ! writeln_fn (map output ss); | 
| 
6b3739fee456
some shortcuts for chunks, which sometimes avoid bulky string output;
 wenzelm parents: 
56333diff
changeset | 119 | fun writeln s = writelns [s]; | 
| 59184 
830bb7ddb3ab
explicit message channels for "state", "information";
 wenzelm parents: 
58850diff
changeset | 120 | fun state s = ! state_fn [output s]; | 
| 
830bb7ddb3ab
explicit message channels for "state", "information";
 wenzelm parents: 
58850diff
changeset | 121 | fun information s = ! information_fn [output s]; | 
| 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: 
56304diff
changeset | 122 | fun tracing s = ! tracing_fn [output s]; | 
| 
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: 
56304diff
changeset | 123 | fun warning s = ! warning_fn [output s]; | 
| 59203 
5f0bd5afc16d
explicit message channel for "legacy", which is nonetheless a variant of "warning";
 wenzelm parents: 
59184diff
changeset | 124 | fun legacy_feature s = ! legacy_fn [output ("Legacy feature! " ^ s)];
 | 
| 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: 
56304diff
changeset | 125 | fun error_message' (i, s) = ! error_message_fn (i, [output s]); | 
| 54387 | 126 | fun error_message s = error_message' (serial (), s); | 
| 57975 
c657c68a60ab
explicit system message for protocol failure -- show on Syslog panel instead of Raw Output;
 wenzelm parents: 
56830diff
changeset | 127 | fun system_message s = ! system_message_fn [output s]; | 
| 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: 
56304diff
changeset | 128 | fun status s = ! status_fn [output s]; | 
| 
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: 
56304diff
changeset | 129 | fun report ss = ! report_fn (map output ss); | 
| 
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: 
56304diff
changeset | 130 | fun result props ss = ! result_fn props (map output ss); | 
| 
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: 
56304diff
changeset | 131 | fun protocol_message props ss = ! protocol_message_fn props (map output ss); | 
| 
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: 
56304diff
changeset | 132 | fun try_protocol_message props ss = protocol_message props ss handle Protocol_Message _ => (); | 
| 15190 | 133 | |
| 14815 | 134 | end; | 
| 135 | ||
| 32738 | 136 | structure Basic_Output: BASIC_OUTPUT = Output; | 
| 137 | open Basic_Output; |