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