| author | blanchet | 
| Wed, 18 Jun 2014 14:19:42 +0200 | |
| changeset 57273 | 01b68f625550 | 
| parent 56830 | e760242101fc | 
| child 57975 | c657c68a60ab | 
| 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 | 
| 14815 | 12 | end; | 
| 13 | ||
| 14 | signature OUTPUT = | |
| 15 | sig | |
| 16 | include BASIC_OUTPUT | |
| 40131 
7cbebd636e79
explicitly qualify type Output.output, which is a slightly odd internal feature;
 wenzelm parents: 
40125diff
changeset | 17 | type output = string | 
| 23660 
18765718cf62
type output = string indicates raw system output;
 wenzelm parents: 
23616diff
changeset | 18 | val default_output: string -> output * int | 
| 
18765718cf62
type output = string indicates raw system output;
 wenzelm parents: 
23616diff
changeset | 19 | val default_escape: output -> string | 
| 
18765718cf62
type output = string indicates raw system output;
 wenzelm parents: 
23616diff
changeset | 20 | val add_mode: string -> (string -> output * int) -> (output -> string) -> unit | 
| 
18765718cf62
type output = string indicates raw system output;
 wenzelm parents: 
23616diff
changeset | 21 | val output_width: string -> output * int | 
| 
18765718cf62
type output = string indicates raw system output;
 wenzelm parents: 
23616diff
changeset | 22 | val output: string -> output | 
| 
18765718cf62
type output = string indicates raw system output;
 wenzelm parents: 
23616diff
changeset | 23 | val escape: output -> string | 
| 44389 
a3b5fdfb04a3
tuned signature -- contrast physical output primitives versus Output.raw_message;
 wenzelm parents: 
44270diff
changeset | 24 | val physical_stdout: output -> unit | 
| 
a3b5fdfb04a3
tuned signature -- contrast physical output primitives versus Output.raw_message;
 wenzelm parents: 
44270diff
changeset | 25 | val physical_stderr: output -> unit | 
| 
a3b5fdfb04a3
tuned signature -- contrast physical output primitives versus Output.raw_message;
 wenzelm parents: 
44270diff
changeset | 26 | val physical_writeln: output -> unit | 
| 51661 | 27 | exception Protocol_Message of Properties.T | 
| 56334 
6b3739fee456
some shortcuts for chunks, which sometimes avoid bulky string output;
 wenzelm parents: 
56333diff
changeset | 28 | val writelns: string list -> unit | 
| 40132 
7ee65dbffa31
renamed Output.priority to Output.urgent_message to emphasize its special role more clearly;
 wenzelm parents: 
40131diff
changeset | 29 | val urgent_message: string -> unit | 
| 54387 | 30 | val error_message': serial * string -> unit | 
| 31 | val error_message: string -> unit | |
| 25845 
c448a5f15f31
added explicit prompt channel (prompt_fn/prompt);
 wenzelm parents: 
25686diff
changeset | 32 | val prompt: string -> unit | 
| 27605 | 33 | 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 | 34 | 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 | 35 | 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 | 36 | 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 | 37 | val try_protocol_message: Properties.T -> string list -> unit | 
| 14815 | 38 | end; | 
| 39 | ||
| 55387 
51f0876f61df
seal system channels at end of Pure bootstrap -- Isabelle/Scala provides official interfaces;
 wenzelm parents: 
54387diff
changeset | 40 | signature PRIVATE_OUTPUT = | 
| 
51f0876f61df
seal system channels at end of Pure bootstrap -- Isabelle/Scala provides official interfaces;
 wenzelm parents: 
54387diff
changeset | 41 | sig | 
| 
51f0876f61df
seal system channels at end of Pure bootstrap -- Isabelle/Scala provides official interfaces;
 wenzelm parents: 
54387diff
changeset | 42 | 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 | 43 | val writeln_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 | 44 | val urgent_message_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 | 45 | 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 | 46 | val warning_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 | 47 | val error_message_fn: (serial * output list -> unit) Unsynchronized.ref | 
| 55387 
51f0876f61df
seal system channels at end of Pure bootstrap -- Isabelle/Scala provides official interfaces;
 wenzelm parents: 
54387diff
changeset | 48 | val prompt_fn: (output -> 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 | 49 | 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 | 50 | 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 | 51 | 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 | 52 | 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 | 53 | end; | 
| 
51f0876f61df
seal system channels at end of Pure bootstrap -- Isabelle/Scala provides official interfaces;
 wenzelm parents: 
54387diff
changeset | 54 | |
| 
51f0876f61df
seal system channels at end of Pure bootstrap -- Isabelle/Scala provides official interfaces;
 wenzelm parents: 
54387diff
changeset | 55 | structure Output: PRIVATE_OUTPUT = | 
| 14815 | 56 | struct | 
| 57 | ||
| 23616 | 58 | (** print modes **) | 
| 14881 | 59 | |
| 23660 
18765718cf62
type output = string indicates raw system output;
 wenzelm parents: 
23616diff
changeset | 60 | type output = string; (*raw system output*) | 
| 
18765718cf62
type output = string indicates raw system output;
 wenzelm parents: 
23616diff
changeset | 61 | |
| 23616 | 62 | fun default_output s = (s, size s); | 
| 23660 
18765718cf62
type output = string indicates raw system output;
 wenzelm parents: 
23616diff
changeset | 63 | fun default_escape (s: output) = s; | 
| 14815 | 64 | |
| 23616 | 65 | local | 
| 66 |   val default = {output = default_output, escape = default_escape};
 | |
| 43684 | 67 |   val modes = Synchronized.var "Output.modes" (Symtab.make [("", default)]);
 | 
| 23616 | 68 | in | 
| 43684 | 69 | fun add_mode name output escape = | 
| 70 |     Synchronized.change modes (Symtab.update_new (name, {output = output, escape = escape}));
 | |
| 23616 | 71 | fun get_mode () = | 
| 43684 | 72 | the_default default | 
| 73 | (Library.get_first (Symtab.lookup (Synchronized.value modes)) (print_mode_value ())); | |
| 23616 | 74 | end; | 
| 14815 | 75 | |
| 19265 | 76 | fun output_width x = #output (get_mode ()) x; | 
| 14815 | 77 | val output = #1 o output_width; | 
| 23727 | 78 | |
| 23616 | 79 | fun escape x = #escape (get_mode ()) x; | 
| 14815 | 80 | |
| 81 | ||
| 82 | ||
| 83 | (** output channels **) | |
| 84 | ||
| 39733 
6d373e9dcb9d
renamed raw output primitives to emphasize their meaning -- not to be used in user-space;
 wenzelm parents: 
38839diff
changeset | 85 | (* raw output primitives -- not to be used in user-space *) | 
| 14984 | 86 | |
| 44389 
a3b5fdfb04a3
tuned signature -- contrast physical output primitives versus Output.raw_message;
 wenzelm parents: 
44270diff
changeset | 87 | 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 | 88 | fun physical_stderr s = (TextIO.output (TextIO.stdErr, s); TextIO.flushOut TextIO.stdErr); | 
| 14815 | 89 | |
| 44389 
a3b5fdfb04a3
tuned signature -- contrast physical output primitives versus Output.raw_message;
 wenzelm parents: 
44270diff
changeset | 90 | fun physical_writeln "" = () | 
| 
a3b5fdfb04a3
tuned signature -- contrast physical output primitives versus Output.raw_message;
 wenzelm parents: 
44270diff
changeset | 91 | | physical_writeln s = physical_stdout (suffix "\n" s); (*atomic output!*) | 
| 14815 | 92 | |
| 14984 | 93 | |
| 94 | (* Isabelle output channels *) | |
| 95 | ||
| 51661 | 96 | exception Protocol_Message of Properties.T; | 
| 97 | ||
| 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 | 98 | val writeln_fn = Unsynchronized.ref (physical_writeln o implode); | 
| 
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 | 99 | val urgent_message_fn = Unsynchronized.ref (fn ss => ! writeln_fn ss); (*Proof General legacy*) | 
| 
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 | 100 | 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 | 101 | val warning_fn = Unsynchronized.ref (physical_writeln o prefix_lines "### " o implode); | 
| 55387 
51f0876f61df
seal system channels at end of Pure bootstrap -- Isabelle/Scala provides official interfaces;
 wenzelm parents: 
54387diff
changeset | 102 | 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 | 103 | Unsynchronized.ref (fn (_: serial, ss) => physical_writeln (prefix_lines "*** " (implode 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 | 104 | val prompt_fn = Unsynchronized.ref physical_stdout; (*Proof General legacy*) | 
| 
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 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 | 106 | 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 | 107 | 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 | 108 | 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 | 109 | Unsynchronized.ref (fn props => fn _ => raise Protocol_Message props); | 
| 14815 | 110 | |
| 56334 
6b3739fee456
some shortcuts for chunks, which sometimes avoid bulky string output;
 wenzelm parents: 
56333diff
changeset | 111 | fun writelns ss = ! writeln_fn (map output ss); | 
| 
6b3739fee456
some shortcuts for chunks, which sometimes avoid bulky string output;
 wenzelm parents: 
56333diff
changeset | 112 | fun writeln s = writelns [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 | 113 | fun urgent_message s = ! urgent_message_fn [output s]; (*Proof General legacy*) | 
| 
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 | 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 | 115 | fun warning s = ! warning_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 | 116 | fun error_message' (i, s) = ! error_message_fn (i, [output s]); | 
| 54387 | 117 | fun error_message s = error_message' (serial (), s); | 
| 55387 
51f0876f61df
seal system channels at end of Pure bootstrap -- Isabelle/Scala provides official interfaces;
 wenzelm parents: 
54387diff
changeset | 118 | fun prompt s = ! prompt_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 | 119 | 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 | 120 | 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 | 121 | 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 | 122 | 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 | 123 | fun try_protocol_message props ss = protocol_message props ss handle Protocol_Message _ => (); | 
| 15190 | 124 | |
| 14815 | 125 | end; | 
| 126 | ||
| 32738 | 127 | structure Basic_Output: BASIC_OUTPUT = Output; | 
| 128 | open Basic_Output; |