| author | wenzelm | 
| Tue, 16 Jul 2013 12:31:08 +0200 | |
| changeset 52671 | 9a360530eac8 | 
| parent 39124 | 9bac2f4cfd6e | 
| child 61957 | 301833d9013a | 
| permissions | -rw-r--r-- | 
| 23827 | 1  | 
(* Title: Pure/General/print_mode.ML  | 
2  | 
Author: Makarius  | 
|
3  | 
||
| 
25734
 
b00b903ae8ae
separated into global template vs. thread-local value;
 
wenzelm 
parents: 
25118 
diff
changeset
 | 
4  | 
Generic print mode as thread-local value derived from global template;  | 
| 
 
b00b903ae8ae
separated into global template vs. thread-local value;
 
wenzelm 
parents: 
25118 
diff
changeset
 | 
5  | 
provides implicit configuration for various output mechanisms.  | 
| 39124 | 6  | 
|
7  | 
The special print mode "input" is never enabled for output.  | 
|
| 23827 | 8  | 
*)  | 
9  | 
||
| 23934 | 10  | 
signature BASIC_PRINT_MODE =  | 
| 23827 | 11  | 
sig  | 
| 32738 | 12  | 
val print_mode: string list Unsynchronized.ref (*global template*)  | 
13  | 
val print_mode_value: unit -> string list (*thread-local value*)  | 
|
14  | 
val print_mode_active: string -> bool (*thread-local value*)  | 
|
| 23827 | 15  | 
end;  | 
16  | 
||
| 23934 | 17  | 
signature PRINT_MODE =  | 
18  | 
sig  | 
|
19  | 
include BASIC_PRINT_MODE  | 
|
| 
25118
 
158149a6e95b
added input/internal, which are never active in print_mode_value;
 
wenzelm 
parents: 
24634 
diff
changeset
 | 
20  | 
val input: string  | 
| 
 
158149a6e95b
added input/internal, which are never active in print_mode_value;
 
wenzelm 
parents: 
24634 
diff
changeset
 | 
21  | 
val internal: string  | 
| 24634 | 22  | 
  val setmp: string list -> ('a -> 'b) -> 'a -> 'b
 | 
| 23934 | 23  | 
  val with_modes: string list -> ('a -> 'b) -> 'a -> 'b
 | 
| 
25734
 
b00b903ae8ae
separated into global template vs. thread-local value;
 
wenzelm 
parents: 
25118 
diff
changeset
 | 
24  | 
  val closure: ('a -> 'b) -> 'a -> 'b
 | 
| 23934 | 25  | 
end;  | 
26  | 
||
| 
37146
 
f652333bbf8e
renamed structure PrintMode to Print_Mode, keeping the old name as legacy alias for some time;
 
wenzelm 
parents: 
33223 
diff
changeset
 | 
27  | 
structure Print_Mode: PRINT_MODE =  | 
| 23827 | 28  | 
struct  | 
29  | 
||
| 
25118
 
158149a6e95b
added input/internal, which are never active in print_mode_value;
 
wenzelm 
parents: 
24634 
diff
changeset
 | 
30  | 
val input = "input";  | 
| 
 
158149a6e95b
added input/internal, which are never active in print_mode_value;
 
wenzelm 
parents: 
24634 
diff
changeset
 | 
31  | 
val internal = "internal";  | 
| 24613 | 32  | 
|
| 32738 | 33  | 
val print_mode = Unsynchronized.ref ([]: string list);  | 
| 
25734
 
b00b903ae8ae
separated into global template vs. thread-local value;
 
wenzelm 
parents: 
25118 
diff
changeset
 | 
34  | 
val tag = Universal.tag () : string list option Universal.tag;  | 
| 
 
b00b903ae8ae
separated into global template vs. thread-local value;
 
wenzelm 
parents: 
25118 
diff
changeset
 | 
35  | 
|
| 
 
b00b903ae8ae
separated into global template vs. thread-local value;
 
wenzelm 
parents: 
25118 
diff
changeset
 | 
36  | 
fun print_mode_value () =  | 
| 
 
b00b903ae8ae
separated into global template vs. thread-local value;
 
wenzelm 
parents: 
25118 
diff
changeset
 | 
37  | 
let val modes =  | 
| 28122 | 38  | 
(case Thread.getLocal tag of  | 
| 
25734
 
b00b903ae8ae
separated into global template vs. thread-local value;
 
wenzelm 
parents: 
25118 
diff
changeset
 | 
39  | 
SOME (SOME modes) => modes  | 
| 33223 | 40  | 
| _ => ! print_mode)  | 
| 
25734
 
b00b903ae8ae
separated into global template vs. thread-local value;
 
wenzelm 
parents: 
25118 
diff
changeset
 | 
41  | 
in subtract (op =) [input, internal] modes end;  | 
| 
 
b00b903ae8ae
separated into global template vs. thread-local value;
 
wenzelm 
parents: 
25118 
diff
changeset
 | 
42  | 
|
| 
 
b00b903ae8ae
separated into global template vs. thread-local value;
 
wenzelm 
parents: 
25118 
diff
changeset
 | 
43  | 
fun print_mode_active mode = member (op =) (print_mode_value ()) mode;  | 
| 
25118
 
158149a6e95b
added input/internal, which are never active in print_mode_value;
 
wenzelm 
parents: 
24634 
diff
changeset
 | 
44  | 
|
| 
25734
 
b00b903ae8ae
separated into global template vs. thread-local value;
 
wenzelm 
parents: 
25118 
diff
changeset
 | 
45  | 
fun setmp modes f x =  | 
| 28122 | 46  | 
let val orig_modes = (case Thread.getLocal tag of SOME (SOME ms) => SOME ms | _ => NONE)  | 
| 25798 | 47  | 
in setmp_thread_data tag orig_modes (SOME modes) f x end;  | 
| 23827 | 48  | 
|
| 
25734
 
b00b903ae8ae
separated into global template vs. thread-local value;
 
wenzelm 
parents: 
25118 
diff
changeset
 | 
49  | 
fun with_modes modes f x = setmp (modes @ print_mode_value ()) f x;  | 
| 
 
b00b903ae8ae
separated into global template vs. thread-local value;
 
wenzelm 
parents: 
25118 
diff
changeset
 | 
50  | 
fun closure f = with_modes [] f;  | 
| 23934 | 51  | 
|
| 23827 | 52  | 
end;  | 
53  | 
||
| 
37146
 
f652333bbf8e
renamed structure PrintMode to Print_Mode, keeping the old name as legacy alias for some time;
 
wenzelm 
parents: 
33223 
diff
changeset
 | 
54  | 
structure Basic_Print_Mode: BASIC_PRINT_MODE = Print_Mode;  | 
| 
 
f652333bbf8e
renamed structure PrintMode to Print_Mode, keeping the old name as legacy alias for some time;
 
wenzelm 
parents: 
33223 
diff
changeset
 | 
55  | 
open Basic_Print_Mode;  |