| author | wenzelm | 
| Mon, 17 Jan 2011 20:20:51 +0100 | |
| changeset 41651 | c78b786fe060 | 
| parent 40133 | b61d52de66f0 | 
| child 42012 | 2c3fe3cbebae | 
| permissions | -rw-r--r-- | 
| 14815 | 1  | 
(* Title: Pure/General/output.ML  | 
2  | 
Author: Makarius, Hagia Maria Sion Abbey (Jerusalem)  | 
|
3  | 
||
| 22585 | 4  | 
Output channels and timing messages.  | 
| 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  | 
| 22826 | 12  | 
val legacy_feature: string -> unit  | 
| 
25686
 
bfa774974b6c
cond_timeit: added message argument, use Exn.capture/release;
 
wenzelm 
parents: 
25682 
diff
changeset
 | 
13  | 
val cond_timeit: bool -> string -> (unit -> 'a) -> 'a  | 
| 14815 | 14  | 
val timeit: (unit -> 'a) -> 'a  | 
15  | 
  val timeap: ('a -> 'b) -> 'a -> 'b
 | 
|
16  | 
  val timeap_msg: string -> ('a -> 'b) -> 'a -> 'b
 | 
|
| 32738 | 17  | 
val timing: bool Unsynchronized.ref  | 
| 14815 | 18  | 
end;  | 
19  | 
||
20  | 
signature OUTPUT =  | 
|
21  | 
sig  | 
|
22  | 
include BASIC_OUTPUT  | 
|
| 
40131
 
7cbebd636e79
explicitly qualify type Output.output, which is a slightly odd internal feature;
 
wenzelm 
parents: 
40125 
diff
changeset
 | 
23  | 
type output = string  | 
| 
23660
 
18765718cf62
type output = string indicates raw system output;
 
wenzelm 
parents: 
23616 
diff
changeset
 | 
24  | 
val default_output: string -> output * int  | 
| 
 
18765718cf62
type output = string indicates raw system output;
 
wenzelm 
parents: 
23616 
diff
changeset
 | 
25  | 
val default_escape: output -> string  | 
| 
 
18765718cf62
type output = string indicates raw system output;
 
wenzelm 
parents: 
23616 
diff
changeset
 | 
26  | 
val add_mode: string -> (string -> output * int) -> (output -> string) -> unit  | 
| 
 
18765718cf62
type output = string indicates raw system output;
 
wenzelm 
parents: 
23616 
diff
changeset
 | 
27  | 
val output_width: string -> output * int  | 
| 
 
18765718cf62
type output = string indicates raw system output;
 
wenzelm 
parents: 
23616 
diff
changeset
 | 
28  | 
val output: string -> output  | 
| 
 
18765718cf62
type output = string indicates raw system output;
 
wenzelm 
parents: 
23616 
diff
changeset
 | 
29  | 
val escape: output -> string  | 
| 
39733
 
6d373e9dcb9d
renamed raw output primitives to emphasize their meaning -- not to be used in user-space;
 
wenzelm 
parents: 
38839 
diff
changeset
 | 
30  | 
val raw_stdout: output -> unit  | 
| 
 
6d373e9dcb9d
renamed raw output primitives to emphasize their meaning -- not to be used in user-space;
 
wenzelm 
parents: 
38839 
diff
changeset
 | 
31  | 
val raw_stderr: output -> unit  | 
| 
 
6d373e9dcb9d
renamed raw output primitives to emphasize their meaning -- not to be used in user-space;
 
wenzelm 
parents: 
38839 
diff
changeset
 | 
32  | 
val raw_writeln: output -> unit  | 
| 
40133
 
b61d52de66f0
more explicit indication of Output.Private_Hooks (still public to accomodate clones of Proof General for now);
 
wenzelm 
parents: 
40132 
diff
changeset
 | 
33  | 
structure Private_Hooks:  | 
| 
 
b61d52de66f0
more explicit indication of Output.Private_Hooks (still public to accomodate clones of Proof General for now);
 
wenzelm 
parents: 
40132 
diff
changeset
 | 
34  | 
sig  | 
| 
 
b61d52de66f0
more explicit indication of Output.Private_Hooks (still public to accomodate clones of Proof General for now);
 
wenzelm 
parents: 
40132 
diff
changeset
 | 
35  | 
val writeln_fn: (output -> unit) Unsynchronized.ref  | 
| 
 
b61d52de66f0
more explicit indication of Output.Private_Hooks (still public to accomodate clones of Proof General for now);
 
wenzelm 
parents: 
40132 
diff
changeset
 | 
36  | 
val urgent_message_fn: (output -> unit) Unsynchronized.ref  | 
| 
 
b61d52de66f0
more explicit indication of Output.Private_Hooks (still public to accomodate clones of Proof General for now);
 
wenzelm 
parents: 
40132 
diff
changeset
 | 
37  | 
val tracing_fn: (output -> unit) Unsynchronized.ref  | 
| 
 
b61d52de66f0
more explicit indication of Output.Private_Hooks (still public to accomodate clones of Proof General for now);
 
wenzelm 
parents: 
40132 
diff
changeset
 | 
38  | 
val warning_fn: (output -> unit) Unsynchronized.ref  | 
| 
 
b61d52de66f0
more explicit indication of Output.Private_Hooks (still public to accomodate clones of Proof General for now);
 
wenzelm 
parents: 
40132 
diff
changeset
 | 
39  | 
val error_fn: (output -> unit) Unsynchronized.ref  | 
| 
 
b61d52de66f0
more explicit indication of Output.Private_Hooks (still public to accomodate clones of Proof General for now);
 
wenzelm 
parents: 
40132 
diff
changeset
 | 
40  | 
val prompt_fn: (output -> unit) Unsynchronized.ref  | 
| 
 
b61d52de66f0
more explicit indication of Output.Private_Hooks (still public to accomodate clones of Proof General for now);
 
wenzelm 
parents: 
40132 
diff
changeset
 | 
41  | 
val status_fn: (output -> unit) Unsynchronized.ref  | 
| 
 
b61d52de66f0
more explicit indication of Output.Private_Hooks (still public to accomodate clones of Proof General for now);
 
wenzelm 
parents: 
40132 
diff
changeset
 | 
42  | 
val report_fn: (output -> unit) Unsynchronized.ref  | 
| 
 
b61d52de66f0
more explicit indication of Output.Private_Hooks (still public to accomodate clones of Proof General for now);
 
wenzelm 
parents: 
40132 
diff
changeset
 | 
43  | 
end  | 
| 
40132
 
7ee65dbffa31
renamed Output.priority to Output.urgent_message to emphasize its special role more clearly;
 
wenzelm 
parents: 
40131 
diff
changeset
 | 
44  | 
val urgent_message: string -> unit  | 
| 
25845
 
c448a5f15f31
added explicit prompt channel (prompt_fn/prompt);
 
wenzelm 
parents: 
25686 
diff
changeset
 | 
45  | 
val error_msg: string -> unit  | 
| 
 
c448a5f15f31
added explicit prompt channel (prompt_fn/prompt);
 
wenzelm 
parents: 
25686 
diff
changeset
 | 
46  | 
val prompt: string -> unit  | 
| 27605 | 47  | 
val status: string -> unit  | 
| 
38236
 
d8c7be27e01d
explicitly distinguish Output.status (essential feedback) vs. Output.report (useful markup);
 
wenzelm 
parents: 
37784 
diff
changeset
 | 
48  | 
val report: string -> unit  | 
| 14815 | 49  | 
end;  | 
50  | 
||
51  | 
structure Output: OUTPUT =  | 
|
52  | 
struct  | 
|
53  | 
||
| 23616 | 54  | 
(** print modes **)  | 
| 14881 | 55  | 
|
| 
23660
 
18765718cf62
type output = string indicates raw system output;
 
wenzelm 
parents: 
23616 
diff
changeset
 | 
56  | 
type output = string; (*raw system output*)  | 
| 
 
18765718cf62
type output = string indicates raw system output;
 
wenzelm 
parents: 
23616 
diff
changeset
 | 
57  | 
|
| 23616 | 58  | 
fun default_output s = (s, size s);  | 
| 
23660
 
18765718cf62
type output = string indicates raw system output;
 
wenzelm 
parents: 
23616 
diff
changeset
 | 
59  | 
fun default_escape (s: output) = s;  | 
| 14815 | 60  | 
|
| 23616 | 61  | 
local  | 
62  | 
  val default = {output = default_output, escape = default_escape};
 | 
|
| 32738 | 63  | 
  val modes = Unsynchronized.ref (Symtab.make [("", default)]);
 | 
| 23616 | 64  | 
in  | 
| 
23922
 
707639e9497d
marked some CRITICAL sections (for multithreading);
 
wenzelm 
parents: 
23862 
diff
changeset
 | 
65  | 
fun add_mode name output escape = CRITICAL (fn () =>  | 
| 32738 | 66  | 
    Unsynchronized.change modes (Symtab.update_new (name, {output = output, escape = escape})));
 | 
| 23616 | 67  | 
fun get_mode () =  | 
| 24612 | 68  | 
the_default default (Library.get_first (Symtab.lookup (! modes)) (print_mode_value ()));  | 
| 23616 | 69  | 
end;  | 
| 14815 | 70  | 
|
| 19265 | 71  | 
fun output_width x = #output (get_mode ()) x;  | 
| 14815 | 72  | 
val output = #1 o output_width;  | 
| 23727 | 73  | 
|
| 23616 | 74  | 
fun escape x = #escape (get_mode ()) x;  | 
| 14815 | 75  | 
|
76  | 
||
77  | 
||
78  | 
(** output channels **)  | 
|
79  | 
||
| 
39733
 
6d373e9dcb9d
renamed raw output primitives to emphasize their meaning -- not to be used in user-space;
 
wenzelm 
parents: 
38839 
diff
changeset
 | 
80  | 
(* raw output primitives -- not to be used in user-space *)  | 
| 14984 | 81  | 
|
| 
39733
 
6d373e9dcb9d
renamed raw output primitives to emphasize their meaning -- not to be used in user-space;
 
wenzelm 
parents: 
38839 
diff
changeset
 | 
82  | 
fun raw_stdout s = (TextIO.output (TextIO.stdOut, s); TextIO.flushOut TextIO.stdOut);  | 
| 
 
6d373e9dcb9d
renamed raw output primitives to emphasize their meaning -- not to be used in user-space;
 
wenzelm 
parents: 
38839 
diff
changeset
 | 
83  | 
fun raw_stderr s = (TextIO.output (TextIO.stdErr, s); TextIO.flushOut TextIO.stdErr);  | 
| 14815 | 84  | 
|
| 
39733
 
6d373e9dcb9d
renamed raw output primitives to emphasize their meaning -- not to be used in user-space;
 
wenzelm 
parents: 
38839 
diff
changeset
 | 
85  | 
fun raw_writeln "" = ()  | 
| 
 
6d373e9dcb9d
renamed raw output primitives to emphasize their meaning -- not to be used in user-space;
 
wenzelm 
parents: 
38839 
diff
changeset
 | 
86  | 
| raw_writeln s = raw_stdout (suffix "\n" s); (*atomic output!*)  | 
| 14815 | 87  | 
|
| 14984 | 88  | 
|
89  | 
(* Isabelle output channels *)  | 
|
90  | 
||
| 
40133
 
b61d52de66f0
more explicit indication of Output.Private_Hooks (still public to accomodate clones of Proof General for now);
 
wenzelm 
parents: 
40132 
diff
changeset
 | 
91  | 
structure Private_Hooks =  | 
| 
 
b61d52de66f0
more explicit indication of Output.Private_Hooks (still public to accomodate clones of Proof General for now);
 
wenzelm 
parents: 
40132 
diff
changeset
 | 
92  | 
struct  | 
| 
 
b61d52de66f0
more explicit indication of Output.Private_Hooks (still public to accomodate clones of Proof General for now);
 
wenzelm 
parents: 
40132 
diff
changeset
 | 
93  | 
val writeln_fn = Unsynchronized.ref raw_writeln;  | 
| 
 
b61d52de66f0
more explicit indication of Output.Private_Hooks (still public to accomodate clones of Proof General for now);
 
wenzelm 
parents: 
40132 
diff
changeset
 | 
94  | 
val urgent_message_fn = Unsynchronized.ref (fn s => ! writeln_fn s);  | 
| 
 
b61d52de66f0
more explicit indication of Output.Private_Hooks (still public to accomodate clones of Proof General for now);
 
wenzelm 
parents: 
40132 
diff
changeset
 | 
95  | 
val tracing_fn = Unsynchronized.ref (fn s => ! writeln_fn s);  | 
| 
 
b61d52de66f0
more explicit indication of Output.Private_Hooks (still public to accomodate clones of Proof General for now);
 
wenzelm 
parents: 
40132 
diff
changeset
 | 
96  | 
val warning_fn = Unsynchronized.ref (raw_stdout o suffix "\n" o prefix_lines "### ");  | 
| 
 
b61d52de66f0
more explicit indication of Output.Private_Hooks (still public to accomodate clones of Proof General for now);
 
wenzelm 
parents: 
40132 
diff
changeset
 | 
97  | 
val error_fn = Unsynchronized.ref (raw_stdout o suffix "\n" o prefix_lines "*** ");  | 
| 
 
b61d52de66f0
more explicit indication of Output.Private_Hooks (still public to accomodate clones of Proof General for now);
 
wenzelm 
parents: 
40132 
diff
changeset
 | 
98  | 
val prompt_fn = Unsynchronized.ref raw_stdout;  | 
| 
 
b61d52de66f0
more explicit indication of Output.Private_Hooks (still public to accomodate clones of Proof General for now);
 
wenzelm 
parents: 
40132 
diff
changeset
 | 
99  | 
val status_fn = Unsynchronized.ref (fn _: string => ());  | 
| 
 
b61d52de66f0
more explicit indication of Output.Private_Hooks (still public to accomodate clones of Proof General for now);
 
wenzelm 
parents: 
40132 
diff
changeset
 | 
100  | 
val report_fn = Unsynchronized.ref (fn _: string => ());  | 
| 
 
b61d52de66f0
more explicit indication of Output.Private_Hooks (still public to accomodate clones of Proof General for now);
 
wenzelm 
parents: 
40132 
diff
changeset
 | 
101  | 
end;  | 
| 14815 | 102  | 
|
| 
40133
 
b61d52de66f0
more explicit indication of Output.Private_Hooks (still public to accomodate clones of Proof General for now);
 
wenzelm 
parents: 
40132 
diff
changeset
 | 
103  | 
fun writeln s = ! Private_Hooks.writeln_fn (output s);  | 
| 
 
b61d52de66f0
more explicit indication of Output.Private_Hooks (still public to accomodate clones of Proof General for now);
 
wenzelm 
parents: 
40132 
diff
changeset
 | 
104  | 
fun urgent_message s = ! Private_Hooks.urgent_message_fn (output s);  | 
| 
 
b61d52de66f0
more explicit indication of Output.Private_Hooks (still public to accomodate clones of Proof General for now);
 
wenzelm 
parents: 
40132 
diff
changeset
 | 
105  | 
fun tracing s = ! Private_Hooks.tracing_fn (output s);  | 
| 
 
b61d52de66f0
more explicit indication of Output.Private_Hooks (still public to accomodate clones of Proof General for now);
 
wenzelm 
parents: 
40132 
diff
changeset
 | 
106  | 
fun warning s = ! Private_Hooks.warning_fn (output s);  | 
| 
 
b61d52de66f0
more explicit indication of Output.Private_Hooks (still public to accomodate clones of Proof General for now);
 
wenzelm 
parents: 
40132 
diff
changeset
 | 
107  | 
fun error_msg s = ! Private_Hooks.error_fn (output s);  | 
| 
 
b61d52de66f0
more explicit indication of Output.Private_Hooks (still public to accomodate clones of Proof General for now);
 
wenzelm 
parents: 
40132 
diff
changeset
 | 
108  | 
fun prompt s = ! Private_Hooks.prompt_fn (output s);  | 
| 
 
b61d52de66f0
more explicit indication of Output.Private_Hooks (still public to accomodate clones of Proof General for now);
 
wenzelm 
parents: 
40132 
diff
changeset
 | 
109  | 
fun status s = ! Private_Hooks.status_fn (output s);  | 
| 
 
b61d52de66f0
more explicit indication of Output.Private_Hooks (still public to accomodate clones of Proof General for now);
 
wenzelm 
parents: 
40132 
diff
changeset
 | 
110  | 
fun report s = ! Private_Hooks.report_fn (output s);  | 
| 15190 | 111  | 
|
| 
37784
 
1d639d28832c
removed impractical tolerate_legacy_features flag;
 
wenzelm 
parents: 
32966 
diff
changeset
 | 
112  | 
fun legacy_feature s = warning ("Legacy feature! " ^ s);
 | 
| 22826 | 113  | 
|
| 14815 | 114  | 
|
115  | 
||
116  | 
(** timing **)  | 
|
117  | 
||
| 
25686
 
bfa774974b6c
cond_timeit: added message argument, use Exn.capture/release;
 
wenzelm 
parents: 
25682 
diff
changeset
 | 
118  | 
(*conditional timing with message*)  | 
| 
 
bfa774974b6c
cond_timeit: added message argument, use Exn.capture/release;
 
wenzelm 
parents: 
25682 
diff
changeset
 | 
119  | 
fun cond_timeit flag msg e =  | 
| 14815 | 120  | 
if flag then  | 
| 23862 | 121  | 
let  | 
122  | 
val start = start_timing ();  | 
|
| 
25686
 
bfa774974b6c
cond_timeit: added message argument, use Exn.capture/release;
 
wenzelm 
parents: 
25682 
diff
changeset
 | 
123  | 
val result = Exn.capture e ();  | 
| 
30187
 
b92b3375e919
end_timing: generalized result -- message plus with explicit time values;
 
wenzelm 
parents: 
29606 
diff
changeset
 | 
124  | 
val end_msg = #message (end_timing start);  | 
| 
25686
 
bfa774974b6c
cond_timeit: added message argument, use Exn.capture/release;
 
wenzelm 
parents: 
25682 
diff
changeset
 | 
125  | 
val _ = warning (if msg = "" then end_msg else msg ^ "\n" ^ end_msg);  | 
| 
 
bfa774974b6c
cond_timeit: added message argument, use Exn.capture/release;
 
wenzelm 
parents: 
25682 
diff
changeset
 | 
126  | 
in Exn.release result end  | 
| 
 
bfa774974b6c
cond_timeit: added message argument, use Exn.capture/release;
 
wenzelm 
parents: 
25682 
diff
changeset
 | 
127  | 
else e ();  | 
| 25667 | 128  | 
|
| 23862 | 129  | 
(*unconditional timing*)  | 
| 
25686
 
bfa774974b6c
cond_timeit: added message argument, use Exn.capture/release;
 
wenzelm 
parents: 
25682 
diff
changeset
 | 
130  | 
fun timeit e = cond_timeit true "" e;  | 
| 14815 | 131  | 
|
132  | 
(*timed application function*)  | 
|
133  | 
fun timeap f x = timeit (fn () => f x);  | 
|
| 
25686
 
bfa774974b6c
cond_timeit: added message argument, use Exn.capture/release;
 
wenzelm 
parents: 
25682 
diff
changeset
 | 
134  | 
fun timeap_msg msg f x = cond_timeit true msg (fn () => f x);  | 
| 
 
bfa774974b6c
cond_timeit: added message argument, use Exn.capture/release;
 
wenzelm 
parents: 
25682 
diff
changeset
 | 
135  | 
|
| 
 
bfa774974b6c
cond_timeit: added message argument, use Exn.capture/release;
 
wenzelm 
parents: 
25682 
diff
changeset
 | 
136  | 
(*global timing mode*)  | 
| 32738 | 137  | 
val timing = Unsynchronized.ref false;  | 
| 14815 | 138  | 
|
139  | 
end;  | 
|
140  | 
||
| 32738 | 141  | 
structure Basic_Output: BASIC_OUTPUT = Output;  | 
142  | 
open Basic_Output;  |