src/Pure/General/output.ML
changeset 32738 15bb09ca0378
parent 31685 c124445a4b61
child 32966 5b21661fe618
equal deleted inserted replaced
32737:76fa673eee8b 32738:15bb09ca0378
     9   type output = string
     9   type output = string
    10   val writeln: string -> unit
    10   val writeln: string -> unit
    11   val priority: string -> unit
    11   val priority: string -> unit
    12   val tracing: string -> unit
    12   val tracing: string -> unit
    13   val warning: string -> unit
    13   val warning: string -> unit
    14   val tolerate_legacy_features: bool ref
    14   val tolerate_legacy_features: bool Unsynchronized.ref
    15   val legacy_feature: string -> unit
    15   val legacy_feature: string -> unit
    16   val cond_timeit: bool -> string -> (unit -> 'a) -> 'a
    16   val cond_timeit: bool -> string -> (unit -> 'a) -> 'a
    17   val timeit: (unit -> 'a) -> 'a
    17   val timeit: (unit -> 'a) -> 'a
    18   val timeap: ('a -> 'b) -> 'a -> 'b
    18   val timeap: ('a -> 'b) -> 'a -> 'b
    19   val timeap_msg: string -> ('a -> 'b) -> 'a -> 'b
    19   val timeap_msg: string -> ('a -> 'b) -> 'a -> 'b
    20   val timing: bool ref
    20   val timing: bool Unsynchronized.ref
    21 end;
    21 end;
    22 
    22 
    23 signature OUTPUT =
    23 signature OUTPUT =
    24 sig
    24 sig
    25   include BASIC_OUTPUT
    25   include BASIC_OUTPUT
    30   val output: string -> output
    30   val output: string -> output
    31   val escape: output -> string
    31   val escape: output -> string
    32   val std_output: output -> unit
    32   val std_output: output -> unit
    33   val std_error: output -> unit
    33   val std_error: output -> unit
    34   val writeln_default: output -> unit
    34   val writeln_default: output -> unit
    35   val writeln_fn: (output -> unit) ref
    35   val writeln_fn: (output -> unit) Unsynchronized.ref
    36   val priority_fn: (output -> unit) ref
    36   val priority_fn: (output -> unit) Unsynchronized.ref
    37   val tracing_fn: (output -> unit) ref
    37   val tracing_fn: (output -> unit) Unsynchronized.ref
    38   val warning_fn: (output -> unit) ref
    38   val warning_fn: (output -> unit) Unsynchronized.ref
    39   val error_fn: (output -> unit) ref
    39   val error_fn: (output -> unit) Unsynchronized.ref
    40   val debug_fn: (output -> unit) ref
    40   val debug_fn: (output -> unit) Unsynchronized.ref
    41   val prompt_fn: (output -> unit) ref
    41   val prompt_fn: (output -> unit) Unsynchronized.ref
    42   val status_fn: (output -> unit) ref
    42   val status_fn: (output -> unit) Unsynchronized.ref
    43   val error_msg: string -> unit
    43   val error_msg: string -> unit
    44   val prompt: string -> unit
    44   val prompt: string -> unit
    45   val status: string -> unit
    45   val status: string -> unit
    46   val debugging: bool ref
    46   val debugging: bool Unsynchronized.ref
    47   val no_warnings: ('a -> 'b) -> 'a -> 'b
    47   val no_warnings: ('a -> 'b) -> 'a -> 'b
    48   val debug: (unit -> string) -> unit
    48   val debug: (unit -> string) -> unit
    49 end;
    49 end;
    50 
    50 
    51 structure Output: OUTPUT =
    51 structure Output: OUTPUT =
    58 fun default_output s = (s, size s);
    58 fun default_output s = (s, size s);
    59 fun default_escape (s: output) = s;
    59 fun default_escape (s: output) = s;
    60 
    60 
    61 local
    61 local
    62   val default = {output = default_output, escape = default_escape};
    62   val default = {output = default_output, escape = default_escape};
    63   val modes = ref (Symtab.make [("", default)]);
    63   val modes = Unsynchronized.ref (Symtab.make [("", default)]);
    64 in
    64 in
    65   fun add_mode name output escape = CRITICAL (fn () =>
    65   fun add_mode name output escape = CRITICAL (fn () =>
    66     change modes (Symtab.update_new (name, {output = output, escape = escape})));
    66     Unsynchronized.change modes (Symtab.update_new (name, {output = output, escape = escape})));
    67   fun get_mode () =
    67   fun get_mode () =
    68     the_default default (Library.get_first (Symtab.lookup (! modes)) (print_mode_value ()));
    68     the_default default (Library.get_first (Symtab.lookup (! modes)) (print_mode_value ()));
    69 end;
    69 end;
    70 
    70 
    71 fun output_width x = #output (get_mode ()) x;
    71 fun output_width x = #output (get_mode ()) x;
    89   | writeln_default s = std_output (suffix "\n" s);
    89   | writeln_default s = std_output (suffix "\n" s);
    90 
    90 
    91 
    91 
    92 (* Isabelle output channels *)
    92 (* Isabelle output channels *)
    93 
    93 
    94 val writeln_fn = ref writeln_default;
    94 val writeln_fn = Unsynchronized.ref writeln_default;
    95 val priority_fn = ref (fn s => ! writeln_fn s);
    95 val priority_fn = Unsynchronized.ref (fn s => ! writeln_fn s);
    96 val tracing_fn = ref (fn s => ! writeln_fn s);
    96 val tracing_fn = Unsynchronized.ref (fn s => ! writeln_fn s);
    97 val warning_fn = ref (std_output o suffix "\n" o prefix_lines "### ");
    97 val warning_fn = Unsynchronized.ref (std_output o suffix "\n" o prefix_lines "### ");
    98 val error_fn = ref (std_output o suffix "\n" o prefix_lines "*** ");
    98 val error_fn = Unsynchronized.ref (std_output o suffix "\n" o prefix_lines "*** ");
    99 val debug_fn = ref (std_output o suffix "\n" o prefix_lines "::: ");
    99 val debug_fn = Unsynchronized.ref (std_output o suffix "\n" o prefix_lines "::: ");
   100 val prompt_fn = ref std_output;
   100 val prompt_fn = Unsynchronized.ref std_output;
   101 val status_fn = ref (fn _: string => ());
   101 val status_fn = Unsynchronized.ref (fn _: string => ());
   102 
   102 
   103 fun writeln s = ! writeln_fn (output s);
   103 fun writeln s = ! writeln_fn (output s);
   104 fun priority s = ! priority_fn (output s);
   104 fun priority s = ! priority_fn (output s);
   105 fun tracing s = ! tracing_fn (output s);
   105 fun tracing s = ! tracing_fn (output s);
   106 fun warning s = ! warning_fn (output s);
   106 fun warning s = ! warning_fn (output s);
   107 fun error_msg s = ! error_fn (output s);
   107 fun error_msg s = ! error_fn (output s);
   108 fun prompt s = ! prompt_fn (output s);
   108 fun prompt s = ! prompt_fn (output s);
   109 fun status s = ! status_fn (output s);
   109 fun status s = ! status_fn (output s);
   110 
   110 
   111 val tolerate_legacy_features = ref true;
   111 val tolerate_legacy_features = Unsynchronized.ref true;
   112 fun legacy_feature s =
   112 fun legacy_feature s =
   113   (if ! tolerate_legacy_features then warning else error) ("Legacy feature! " ^ s);
   113   (if ! tolerate_legacy_features then warning else error) ("Legacy feature! " ^ s);
   114 
   114 
   115 fun no_warnings f = setmp warning_fn (K ()) f;
   115 fun no_warnings f = setmp warning_fn (K ()) f;
   116 
   116 
   117 val debugging = ref false;
   117 val debugging = Unsynchronized.ref false;
   118 fun debug s = if ! debugging then ! debug_fn (output (s ())) else ()
   118 fun debug s = if ! debugging then ! debug_fn (output (s ())) else ()
   119 
   119 
   120 
   120 
   121 
   121 
   122 (** timing **)
   122 (** timing **)
   138 (*timed application function*)
   138 (*timed application function*)
   139 fun timeap f x = timeit (fn () => f x);
   139 fun timeap f x = timeit (fn () => f x);
   140 fun timeap_msg msg f x = cond_timeit true msg (fn () => f x);
   140 fun timeap_msg msg f x = cond_timeit true msg (fn () => f x);
   141 
   141 
   142 (*global timing mode*)
   142 (*global timing mode*)
   143 val timing = ref false;
   143 val timing = Unsynchronized.ref false;
   144 
   144 
   145 end;
   145 end;
   146 
   146 
   147 structure BasicOutput: BASIC_OUTPUT = Output;
   147 structure Basic_Output: BASIC_OUTPUT = Output;
   148 open BasicOutput;
   148 open Basic_Output;