src/Pure/General/print_mode.ML
author wenzelm
Fri, 23 May 2008 21:18:47 +0200
changeset 26977 e736139b553d
parent 25798 1e6eafbb466f
child 28122 3d099ce624e7
permissions -rw-r--r--
added theory_nameN;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
23827
0f0d1cf4992d Generic print mode.
wenzelm
parents:
diff changeset
     1
(*  Title:      Pure/General/print_mode.ML
0f0d1cf4992d Generic print mode.
wenzelm
parents:
diff changeset
     2
    ID:         $Id$
0f0d1cf4992d Generic print mode.
wenzelm
parents:
diff changeset
     3
    Author:     Makarius
0f0d1cf4992d Generic print mode.
wenzelm
parents:
diff changeset
     4
25734
b00b903ae8ae separated into global template vs. thread-local value;
wenzelm
parents: 25118
diff changeset
     5
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
     6
provides implicit configuration for various output mechanisms.
23827
0f0d1cf4992d Generic print mode.
wenzelm
parents:
diff changeset
     7
*)
0f0d1cf4992d Generic print mode.
wenzelm
parents:
diff changeset
     8
23934
79393cb9c0a6 added with_modes, with_default;
wenzelm
parents: 23827
diff changeset
     9
signature BASIC_PRINT_MODE =
23827
0f0d1cf4992d Generic print mode.
wenzelm
parents:
diff changeset
    10
sig
25734
b00b903ae8ae separated into global template vs. thread-local value;
wenzelm
parents: 25118
diff changeset
    11
  val print_mode: string list ref            (*global template*)
b00b903ae8ae separated into global template vs. thread-local value;
wenzelm
parents: 25118
diff changeset
    12
  val print_mode_value: unit -> string list  (*thread-local value*)
b00b903ae8ae separated into global template vs. thread-local value;
wenzelm
parents: 25118
diff changeset
    13
  val print_mode_active: string -> bool      (*thread-local value*)
23827
0f0d1cf4992d Generic print mode.
wenzelm
parents:
diff changeset
    14
end;
0f0d1cf4992d Generic print mode.
wenzelm
parents:
diff changeset
    15
23934
79393cb9c0a6 added with_modes, with_default;
wenzelm
parents: 23827
diff changeset
    16
signature PRINT_MODE =
79393cb9c0a6 added with_modes, with_default;
wenzelm
parents: 23827
diff changeset
    17
sig
79393cb9c0a6 added with_modes, with_default;
wenzelm
parents: 23827
diff changeset
    18
  include BASIC_PRINT_MODE
25118
158149a6e95b added input/internal, which are never active in print_mode_value;
wenzelm
parents: 24634
diff changeset
    19
  val input: string
158149a6e95b added input/internal, which are never active in print_mode_value;
wenzelm
parents: 24634
diff changeset
    20
  val internal: string
24634
38db11874724 simplified PrintMode interfaces;
wenzelm
parents: 24613
diff changeset
    21
  val setmp: string list -> ('a -> 'b) -> 'a -> 'b
23934
79393cb9c0a6 added with_modes, with_default;
wenzelm
parents: 23827
diff changeset
    22
  val with_modes: string list -> ('a -> 'b) -> 'a -> 'b
25734
b00b903ae8ae separated into global template vs. thread-local value;
wenzelm
parents: 25118
diff changeset
    23
  val closure: ('a -> 'b) -> 'a -> 'b
23934
79393cb9c0a6 added with_modes, with_default;
wenzelm
parents: 23827
diff changeset
    24
end;
79393cb9c0a6 added with_modes, with_default;
wenzelm
parents: 23827
diff changeset
    25
23827
0f0d1cf4992d Generic print mode.
wenzelm
parents:
diff changeset
    26
structure PrintMode: PRINT_MODE =
0f0d1cf4992d Generic print mode.
wenzelm
parents:
diff changeset
    27
struct
0f0d1cf4992d Generic print mode.
wenzelm
parents:
diff changeset
    28
25118
158149a6e95b added input/internal, which are never active in print_mode_value;
wenzelm
parents: 24634
diff changeset
    29
val input = "input";
158149a6e95b added input/internal, which are never active in print_mode_value;
wenzelm
parents: 24634
diff changeset
    30
val internal = "internal";
24613
bc889c3d55a3 added print_mode_value (CRITICAL);
wenzelm
parents: 24603
diff changeset
    31
25118
158149a6e95b added input/internal, which are never active in print_mode_value;
wenzelm
parents: 24634
diff changeset
    32
val print_mode = ref ([]: string list);
25734
b00b903ae8ae separated into global template vs. thread-local value;
wenzelm
parents: 25118
diff changeset
    33
val tag = Universal.tag () : string list option Universal.tag;
b00b903ae8ae separated into global template vs. thread-local value;
wenzelm
parents: 25118
diff changeset
    34
b00b903ae8ae separated into global template vs. thread-local value;
wenzelm
parents: 25118
diff changeset
    35
fun print_mode_value () =
b00b903ae8ae separated into global template vs. thread-local value;
wenzelm
parents: 25118
diff changeset
    36
  let val modes =
b00b903ae8ae separated into global template vs. thread-local value;
wenzelm
parents: 25118
diff changeset
    37
    (case Multithreading.get_data tag of
b00b903ae8ae separated into global template vs. thread-local value;
wenzelm
parents: 25118
diff changeset
    38
      SOME (SOME modes) => modes
b00b903ae8ae separated into global template vs. thread-local value;
wenzelm
parents: 25118
diff changeset
    39
    | _ => NAMED_CRITICAL "print_mode" (fn () => ! print_mode))
b00b903ae8ae separated into global template vs. thread-local value;
wenzelm
parents: 25118
diff changeset
    40
  in subtract (op =) [input, internal] modes end;
b00b903ae8ae separated into global template vs. thread-local value;
wenzelm
parents: 25118
diff changeset
    41
b00b903ae8ae separated into global template vs. thread-local value;
wenzelm
parents: 25118
diff changeset
    42
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
    43
25734
b00b903ae8ae separated into global template vs. thread-local value;
wenzelm
parents: 25118
diff changeset
    44
fun setmp modes f x =
25798
1e6eafbb466f setmp_thread_data;
wenzelm
parents: 25734
diff changeset
    45
  let val orig_modes = (case Multithreading.get_data tag of SOME (SOME ms) => SOME ms | _ => NONE)
1e6eafbb466f setmp_thread_data;
wenzelm
parents: 25734
diff changeset
    46
  in setmp_thread_data tag orig_modes (SOME modes) f x end;
23827
0f0d1cf4992d Generic print mode.
wenzelm
parents:
diff changeset
    47
25734
b00b903ae8ae separated into global template vs. thread-local value;
wenzelm
parents: 25118
diff changeset
    48
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
    49
fun closure f = with_modes [] f;
23934
79393cb9c0a6 added with_modes, with_default;
wenzelm
parents: 23827
diff changeset
    50
23827
0f0d1cf4992d Generic print mode.
wenzelm
parents:
diff changeset
    51
end;
0f0d1cf4992d Generic print mode.
wenzelm
parents:
diff changeset
    52
23934
79393cb9c0a6 added with_modes, with_default;
wenzelm
parents: 23827
diff changeset
    53
structure BasicPrintMode: BASIC_PRINT_MODE = PrintMode;
79393cb9c0a6 added with_modes, with_default;
wenzelm
parents: 23827
diff changeset
    54
open BasicPrintMode;