author | wenzelm |
Thu, 27 Mar 2014 17:56:13 +0100 | |
changeset 56304 | 40274e4f5ebf |
parent 56297 | 3925634718fb |
child 56333 | 38f1422ef473 |
permissions | -rw-r--r-- |
14815 | 1 |
(* Title: Pure/General/output.ML |
2 |
Author: Makarius, Hagia Maria Sion Abbey (Jerusalem) |
|
3 |
||
42012
2c3fe3cbebae
structure Timing: covers former start_timing/end_timing and Output.timeit etc;
wenzelm
parents:
40133
diff
changeset
|
4 |
Isabelle output channels. |
14815 | 5 |
*) |
6 |
||
7 |
signature BASIC_OUTPUT = |
|
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 | 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:
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 | 27 |
exception Protocol_Message of Properties.T |
40132
7ee65dbffa31
renamed Output.priority to Output.urgent_message to emphasize its special role more clearly;
wenzelm
parents:
40131
diff
changeset
|
28 |
val urgent_message: string -> unit |
54387 | 29 |
val error_message': serial * string -> unit |
30 |
val error_message: string -> unit |
|
25845
c448a5f15f31
added explicit prompt channel (prompt_fn/prompt);
wenzelm
parents:
25686
diff
changeset
|
31 |
val prompt: string -> unit |
27605 | 32 |
val status: string -> unit |
38236
d8c7be27e01d
explicitly distinguish Output.status (essential feedback) vs. Output.report (useful markup);
wenzelm
parents:
37784
diff
changeset
|
33 |
val report: string -> unit |
52854
92932931bd82
more general Output.result: allow to update arbitrary properties;
wenzelm
parents:
52852
diff
changeset
|
34 |
val result: Properties.T -> string -> unit |
46774 | 35 |
val protocol_message: Properties.T -> string -> unit |
51661 | 36 |
val try_protocol_message: Properties.T -> string -> unit |
14815 | 37 |
end; |
38 |
||
55387
51f0876f61df
seal system channels at end of Pure bootstrap -- Isabelle/Scala provides official interfaces;
wenzelm
parents:
54387
diff
changeset
|
39 |
signature PRIVATE_OUTPUT = |
51f0876f61df
seal system channels at end of Pure bootstrap -- Isabelle/Scala provides official interfaces;
wenzelm
parents:
54387
diff
changeset
|
40 |
sig |
51f0876f61df
seal system channels at end of Pure bootstrap -- Isabelle/Scala provides official interfaces;
wenzelm
parents:
54387
diff
changeset
|
41 |
include OUTPUT |
51f0876f61df
seal system channels at end of Pure bootstrap -- Isabelle/Scala provides official interfaces;
wenzelm
parents:
54387
diff
changeset
|
42 |
val writeln_fn: (output -> unit) Unsynchronized.ref |
51f0876f61df
seal system channels at end of Pure bootstrap -- Isabelle/Scala provides official interfaces;
wenzelm
parents:
54387
diff
changeset
|
43 |
val urgent_message_fn: (output -> unit) Unsynchronized.ref |
51f0876f61df
seal system channels at end of Pure bootstrap -- Isabelle/Scala provides official interfaces;
wenzelm
parents:
54387
diff
changeset
|
44 |
val tracing_fn: (output -> unit) Unsynchronized.ref |
51f0876f61df
seal system channels at end of Pure bootstrap -- Isabelle/Scala provides official interfaces;
wenzelm
parents:
54387
diff
changeset
|
45 |
val warning_fn: (output -> unit) Unsynchronized.ref |
51f0876f61df
seal system channels at end of Pure bootstrap -- Isabelle/Scala provides official interfaces;
wenzelm
parents:
54387
diff
changeset
|
46 |
val error_message_fn: (serial * output -> unit) Unsynchronized.ref |
51f0876f61df
seal system channels at end of Pure bootstrap -- Isabelle/Scala provides official interfaces;
wenzelm
parents:
54387
diff
changeset
|
47 |
val prompt_fn: (output -> unit) Unsynchronized.ref |
51f0876f61df
seal system channels at end of Pure bootstrap -- Isabelle/Scala provides official interfaces;
wenzelm
parents:
54387
diff
changeset
|
48 |
val status_fn: (output -> unit) Unsynchronized.ref |
51f0876f61df
seal system channels at end of Pure bootstrap -- Isabelle/Scala provides official interfaces;
wenzelm
parents:
54387
diff
changeset
|
49 |
val report_fn: (output -> unit) Unsynchronized.ref |
51f0876f61df
seal system channels at end of Pure bootstrap -- Isabelle/Scala provides official interfaces;
wenzelm
parents:
54387
diff
changeset
|
50 |
val result_fn: (Properties.T -> output -> unit) Unsynchronized.ref |
51f0876f61df
seal system channels at end of Pure bootstrap -- Isabelle/Scala provides official interfaces;
wenzelm
parents:
54387
diff
changeset
|
51 |
val protocol_message_fn: (Properties.T -> output -> unit) Unsynchronized.ref |
51f0876f61df
seal system channels at end of Pure bootstrap -- Isabelle/Scala provides official interfaces;
wenzelm
parents:
54387
diff
changeset
|
52 |
end; |
51f0876f61df
seal system channels at end of Pure bootstrap -- Isabelle/Scala provides official interfaces;
wenzelm
parents:
54387
diff
changeset
|
53 |
|
51f0876f61df
seal system channels at end of Pure bootstrap -- Isabelle/Scala provides official interfaces;
wenzelm
parents:
54387
diff
changeset
|
54 |
structure Output: PRIVATE_OUTPUT = |
14815 | 55 |
struct |
56 |
||
23616 | 57 |
(** print modes **) |
14881 | 58 |
|
23660
18765718cf62
type output = string indicates raw system output;
wenzelm
parents:
23616
diff
changeset
|
59 |
type output = string; (*raw system output*) |
18765718cf62
type output = string indicates raw system output;
wenzelm
parents:
23616
diff
changeset
|
60 |
|
23616 | 61 |
fun default_output s = (s, size s); |
23660
18765718cf62
type output = string indicates raw system output;
wenzelm
parents:
23616
diff
changeset
|
62 |
fun default_escape (s: output) = s; |
14815 | 63 |
|
23616 | 64 |
local |
65 |
val default = {output = default_output, escape = default_escape}; |
|
43684 | 66 |
val modes = Synchronized.var "Output.modes" (Symtab.make [("", default)]); |
23616 | 67 |
in |
43684 | 68 |
fun add_mode name output escape = |
69 |
Synchronized.change modes (Symtab.update_new (name, {output = output, escape = escape})); |
|
23616 | 70 |
fun get_mode () = |
43684 | 71 |
the_default default |
72 |
(Library.get_first (Symtab.lookup (Synchronized.value modes)) (print_mode_value ())); |
|
23616 | 73 |
end; |
14815 | 74 |
|
19265 | 75 |
fun output_width x = #output (get_mode ()) x; |
14815 | 76 |
val output = #1 o output_width; |
23727 | 77 |
|
23616 | 78 |
fun escape x = #escape (get_mode ()) x; |
14815 | 79 |
|
80 |
||
81 |
||
82 |
(** output channels **) |
|
83 |
||
39733
6d373e9dcb9d
renamed raw output primitives to emphasize their meaning -- not to be used in user-space;
wenzelm
parents:
38839
diff
changeset
|
84 |
(* raw output primitives -- not to be used in user-space *) |
14984 | 85 |
|
44389
a3b5fdfb04a3
tuned signature -- contrast physical output primitives versus Output.raw_message;
wenzelm
parents:
44270
diff
changeset
|
86 |
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
|
87 |
fun physical_stderr s = (TextIO.output (TextIO.stdErr, s); TextIO.flushOut TextIO.stdErr); |
14815 | 88 |
|
44389
a3b5fdfb04a3
tuned signature -- contrast physical output primitives versus Output.raw_message;
wenzelm
parents:
44270
diff
changeset
|
89 |
fun physical_writeln "" = () |
a3b5fdfb04a3
tuned signature -- contrast physical output primitives versus Output.raw_message;
wenzelm
parents:
44270
diff
changeset
|
90 |
| physical_writeln s = physical_stdout (suffix "\n" s); (*atomic output!*) |
14815 | 91 |
|
14984 | 92 |
|
93 |
(* Isabelle output channels *) |
|
94 |
||
51661 | 95 |
exception Protocol_Message of Properties.T; |
96 |
||
55387
51f0876f61df
seal system channels at end of Pure bootstrap -- Isabelle/Scala provides official interfaces;
wenzelm
parents:
54387
diff
changeset
|
97 |
val writeln_fn = Unsynchronized.ref physical_writeln; |
51f0876f61df
seal system channels at end of Pure bootstrap -- Isabelle/Scala provides official interfaces;
wenzelm
parents:
54387
diff
changeset
|
98 |
val urgent_message_fn = Unsynchronized.ref (fn s => ! writeln_fn s); (*Proof General legacy*) |
51f0876f61df
seal system channels at end of Pure bootstrap -- Isabelle/Scala provides official interfaces;
wenzelm
parents:
54387
diff
changeset
|
99 |
val tracing_fn = Unsynchronized.ref (fn s => ! writeln_fn s); |
51f0876f61df
seal system channels at end of Pure bootstrap -- Isabelle/Scala provides official interfaces;
wenzelm
parents:
54387
diff
changeset
|
100 |
val warning_fn = Unsynchronized.ref (physical_writeln o prefix_lines "### "); |
51f0876f61df
seal system channels at end of Pure bootstrap -- Isabelle/Scala provides official interfaces;
wenzelm
parents:
54387
diff
changeset
|
101 |
val error_message_fn = |
51f0876f61df
seal system channels at end of Pure bootstrap -- Isabelle/Scala provides official interfaces;
wenzelm
parents:
54387
diff
changeset
|
102 |
Unsynchronized.ref (fn (_: serial, s) => physical_writeln (prefix_lines "*** " s)); |
51f0876f61df
seal system channels at end of Pure bootstrap -- Isabelle/Scala provides official interfaces;
wenzelm
parents:
54387
diff
changeset
|
103 |
val prompt_fn = Unsynchronized.ref physical_stdout; |
51f0876f61df
seal system channels at end of Pure bootstrap -- Isabelle/Scala provides official interfaces;
wenzelm
parents:
54387
diff
changeset
|
104 |
val status_fn = Unsynchronized.ref (fn _: output => ()); |
51f0876f61df
seal system channels at end of Pure bootstrap -- Isabelle/Scala provides official interfaces;
wenzelm
parents:
54387
diff
changeset
|
105 |
val report_fn = Unsynchronized.ref (fn _: output => ()); |
51f0876f61df
seal system channels at end of Pure bootstrap -- Isabelle/Scala provides official interfaces;
wenzelm
parents:
54387
diff
changeset
|
106 |
val result_fn = Unsynchronized.ref (fn _: Properties.T => fn _: output => ()); |
51f0876f61df
seal system channels at end of Pure bootstrap -- Isabelle/Scala provides official interfaces;
wenzelm
parents:
54387
diff
changeset
|
107 |
val protocol_message_fn: (Properties.T -> output -> unit) Unsynchronized.ref = |
51f0876f61df
seal system channels at end of Pure bootstrap -- Isabelle/Scala provides official interfaces;
wenzelm
parents:
54387
diff
changeset
|
108 |
Unsynchronized.ref (fn props => fn _ => raise Protocol_Message props); |
14815 | 109 |
|
55387
51f0876f61df
seal system channels at end of Pure bootstrap -- Isabelle/Scala provides official interfaces;
wenzelm
parents:
54387
diff
changeset
|
110 |
fun writeln s = ! writeln_fn (output s); |
51f0876f61df
seal system channels at end of Pure bootstrap -- Isabelle/Scala provides official interfaces;
wenzelm
parents:
54387
diff
changeset
|
111 |
fun urgent_message s = ! urgent_message_fn (output s); (*Proof General legacy*) |
51f0876f61df
seal system channels at end of Pure bootstrap -- Isabelle/Scala provides official interfaces;
wenzelm
parents:
54387
diff
changeset
|
112 |
fun tracing s = ! tracing_fn (output s); |
51f0876f61df
seal system channels at end of Pure bootstrap -- Isabelle/Scala provides official interfaces;
wenzelm
parents:
54387
diff
changeset
|
113 |
fun warning s = ! warning_fn (output s); |
51f0876f61df
seal system channels at end of Pure bootstrap -- Isabelle/Scala provides official interfaces;
wenzelm
parents:
54387
diff
changeset
|
114 |
fun error_message' (i, s) = ! error_message_fn (i, output s); |
54387 | 115 |
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:
54387
diff
changeset
|
116 |
fun prompt s = ! prompt_fn (output s); |
51f0876f61df
seal system channels at end of Pure bootstrap -- Isabelle/Scala provides official interfaces;
wenzelm
parents:
54387
diff
changeset
|
117 |
fun status s = ! status_fn (output s); |
56304
40274e4f5ebf
redirect ML_Compiler reports more directly: only the (big) parse tree report is deferred via Execution.print (NB: this does not work for asynchronous "diag" commands);
wenzelm
parents:
56297
diff
changeset
|
118 |
fun report s = ! report_fn (output s); |
55387
51f0876f61df
seal system channels at end of Pure bootstrap -- Isabelle/Scala provides official interfaces;
wenzelm
parents:
54387
diff
changeset
|
119 |
fun result props s = ! result_fn props (output s); |
51f0876f61df
seal system channels at end of Pure bootstrap -- Isabelle/Scala provides official interfaces;
wenzelm
parents:
54387
diff
changeset
|
120 |
fun protocol_message props s = ! protocol_message_fn props (output s); |
51661 | 121 |
fun try_protocol_message props s = protocol_message props s handle Protocol_Message _ => (); |
15190 | 122 |
|
14815 | 123 |
end; |
124 |
||
32738 | 125 |
structure Basic_Output: BASIC_OUTPUT = Output; |
126 |
open Basic_Output; |