src/Pure/PIDE/document.ML
author wenzelm
Mon Aug 15 14:54:36 2011 +0200 (2011-08-15)
changeset 44196 3588f71abb50
parent 44186 806f0ec1a43d
child 44197 458573968568
permissions -rw-r--r--
simplified exec: eliminated unused status flag;
wenzelm@38150
     1
(*  Title:      Pure/PIDE/document.ML
wenzelm@38150
     2
    Author:     Makarius
wenzelm@38150
     3
wenzelm@38150
     4
Document as collection of named nodes, each consisting of an editable
wenzelm@38418
     5
list of commands, associated with asynchronous execution process.
wenzelm@38150
     6
*)
wenzelm@38150
     7
wenzelm@38150
     8
signature DOCUMENT =
wenzelm@38150
     9
sig
wenzelm@38363
    10
  type id = int
wenzelm@38373
    11
  type version_id = id
wenzelm@38363
    12
  type command_id = id
wenzelm@38373
    13
  type exec_id = id
wenzelm@38363
    14
  val no_id: id
wenzelm@38419
    15
  val new_id: unit -> id
wenzelm@38363
    16
  val parse_id: string -> id
wenzelm@38363
    17
  val print_id: id -> string
wenzelm@44185
    18
  type node_header = (string * string list * (string * bool) list) Exn.result
wenzelm@44157
    19
  datatype node_edit =
wenzelm@44185
    20
    Clear |
wenzelm@44157
    21
    Edits of (command_id option * command_id option) list |
wenzelm@44182
    22
    Header of node_header
wenzelm@44156
    23
  type edit = string * node_edit
wenzelm@38418
    24
  type state
wenzelm@38418
    25
  val init_state: state
wenzelm@43668
    26
  val get_theory: state -> version_id -> Position.T -> string -> theory
wenzelm@43666
    27
  val cancel_execution: state -> unit -> unit
wenzelm@38418
    28
  val define_command: command_id -> string -> state -> state
wenzelm@44157
    29
  val edit: version_id -> version_id -> edit list -> state -> (command_id * exec_id) list * state
wenzelm@38418
    30
  val execute: version_id -> state -> state
wenzelm@43713
    31
  val state: unit -> state
wenzelm@43713
    32
  val change_state: (state -> state) -> unit
wenzelm@38150
    33
end;
wenzelm@38150
    34
wenzelm@38150
    35
structure Document: DOCUMENT =
wenzelm@38150
    36
struct
wenzelm@38150
    37
wenzelm@38150
    38
(* unique identifiers *)
wenzelm@38150
    39
wenzelm@38363
    40
type id = int;
wenzelm@38373
    41
type version_id = id;
wenzelm@38363
    42
type command_id = id;
wenzelm@38373
    43
type exec_id = id;
wenzelm@38355
    44
wenzelm@38355
    45
val no_id = 0;
wenzelm@40449
    46
val new_id = Synchronized.counter ();
wenzelm@38418
    47
wenzelm@38414
    48
val parse_id = Markup.parse_int;
wenzelm@38414
    49
val print_id = Markup.print_int;
wenzelm@38150
    50
wenzelm@38418
    51
fun err_dup kind id = error ("Duplicate " ^ kind ^ ": " ^ print_id id);
wenzelm@38418
    52
fun err_undef kind id = error ("Undefined " ^ kind ^ ": " ^ print_id id);
wenzelm@38150
    53
wenzelm@38418
    54
wenzelm@38418
    55
wenzelm@38418
    56
(** document structure **)
wenzelm@38418
    57
wenzelm@44185
    58
type node_header = (string * string list * (string * bool) list) Exn.result;
wenzelm@38448
    59
structure Entries = Linear_Set(type key = command_id val ord = int_ord);
wenzelm@38448
    60
wenzelm@43668
    61
abstype node = Node of
wenzelm@44182
    62
 {header: node_header,
wenzelm@44180
    63
  entries: exec_id option Entries.T,  (*command entries with excecutions*)
wenzelm@44180
    64
  last: exec_id}  (*last entry with main result*)
wenzelm@43668
    65
and version = Version of node Graph.T  (*development graph wrt. static imports*)
wenzelm@38418
    66
with
wenzelm@38418
    67
wenzelm@44180
    68
fun make_node (header, entries, last) =
wenzelm@44180
    69
  Node {header = header, entries = entries, last = last};
wenzelm@43668
    70
wenzelm@44180
    71
fun map_node f (Node {header, entries, last}) =
wenzelm@44180
    72
  make_node (f (header, entries, last));
wenzelm@38418
    73
wenzelm@44180
    74
fun get_header (Node {header, ...}) = header;
wenzelm@44180
    75
fun set_header header = map_node (fn (_, entries, last) => (header, entries, last));
wenzelm@44180
    76
wenzelm@44180
    77
fun map_entries f (Node {header, entries, last}) = make_node (header, f entries, last);
wenzelm@43668
    78
fun fold_entries start f (Node {entries, ...}) = Entries.fold start f entries;
wenzelm@43668
    79
fun first_entry start P (Node {entries, ...}) = Entries.get_first start P entries;
wenzelm@43668
    80
wenzelm@44180
    81
fun get_last (Node {last, ...}) = last;
wenzelm@44180
    82
fun set_last last = map_node (fn (header, entries, _) => (header, entries, last));
wenzelm@44180
    83
wenzelm@44180
    84
val empty_node = make_node (Exn.Exn (ERROR "Bad theory header"), Entries.empty, no_id);
wenzelm@44185
    85
val clear_node = map_node (fn (header, _, _) => (header, Entries.empty, no_id));
wenzelm@44185
    86
wenzelm@44185
    87
fun get_node nodes name = Graph.get_node nodes name handle Graph.UNDEF _ => empty_node;
wenzelm@44185
    88
fun remove_node name nodes = Graph.del_node name nodes handle Graph.UNDEF _ => nodes;
wenzelm@44185
    89
fun update_node name f = Graph.default_node (name, empty_node) #> Graph.map_node name f;
wenzelm@38418
    90
wenzelm@38418
    91
wenzelm@38448
    92
(* node edits and associated executions *)
wenzelm@38150
    93
wenzelm@44157
    94
datatype node_edit =
wenzelm@44185
    95
  Clear |
wenzelm@44157
    96
  Edits of (command_id option * command_id option) list |
wenzelm@44182
    97
  Header of node_header;
wenzelm@44157
    98
wenzelm@44156
    99
type edit = string * node_edit;
wenzelm@38448
   100
wenzelm@43668
   101
fun the_entry (Node {entries, ...}) id =
wenzelm@38448
   102
  (case Entries.lookup entries id of
wenzelm@38448
   103
    NONE => err_undef "command entry" id
wenzelm@38448
   104
  | SOME entry => entry);
wenzelm@38150
   105
wenzelm@43668
   106
fun update_entry (id, exec_id) =
wenzelm@43668
   107
  map_entries (Entries.update (id, SOME exec_id));
wenzelm@38418
   108
wenzelm@38448
   109
fun reset_after id entries =
wenzelm@38448
   110
  (case Entries.get_after entries id of
wenzelm@38448
   111
    NONE => entries
wenzelm@38448
   112
  | SOME next => Entries.update (next, NONE) entries);
wenzelm@38448
   113
wenzelm@43668
   114
val edit_node = map_entries o fold
wenzelm@43668
   115
  (fn (id, SOME id2) => Entries.insert_after id (id2, NONE)
wenzelm@43668
   116
    | (id, NONE) => Entries.delete_after id #> reset_after id);
wenzelm@38418
   117
wenzelm@38418
   118
wenzelm@38418
   119
(* version operations *)
wenzelm@38418
   120
wenzelm@44185
   121
val empty_version = Version Graph.empty;
wenzelm@44185
   122
wenzelm@38418
   123
fun nodes_of (Version nodes) = nodes;
wenzelm@44185
   124
val node_of = get_node o nodes_of;
wenzelm@38418
   125
val node_names_of = Graph.keys o nodes_of;
wenzelm@38418
   126
wenzelm@44185
   127
fun cycle_msg names = "Cyclic dependency of " ^ space_implode " via " (map quote names);
wenzelm@44180
   128
wenzelm@44157
   129
fun edit_nodes (name, node_edit) (Version nodes) =
wenzelm@44157
   130
  Version
wenzelm@44157
   131
    (case node_edit of
wenzelm@44185
   132
      Clear => update_node name clear_node nodes
wenzelm@44180
   133
    | Edits edits => update_node name (edit_node edits) nodes
wenzelm@44185
   134
    | Header header =>
wenzelm@44185
   135
        let
wenzelm@44185
   136
          val node = get_node nodes name;
wenzelm@44185
   137
          val nodes' = Graph.new_node (name, node) (remove_node name nodes);
wenzelm@44185
   138
          val parents =
wenzelm@44185
   139
            (case header of Exn.Res (_, parents, _) => parents | _ => [])
wenzelm@44185
   140
            |> filter (can (Graph.get_node nodes'));
wenzelm@44185
   141
          val (header', nodes'') =
wenzelm@44185
   142
            (header, Graph.add_deps_acyclic (name, parents) nodes')
wenzelm@44185
   143
              handle Graph.CYCLES cs => (Exn.Exn (ERROR (cat_lines (map cycle_msg cs))), nodes');
wenzelm@44185
   144
        in Graph.map_node name (set_header header') nodes'' end);
wenzelm@38418
   145
wenzelm@38418
   146
fun put_node name node (Version nodes) =
wenzelm@40481
   147
  Version (nodes
wenzelm@40481
   148
    |> Graph.default_node (name, empty_node)
wenzelm@40481
   149
    |> Graph.map_node name (K node));
wenzelm@38418
   150
wenzelm@38150
   151
end;
wenzelm@38150
   152
wenzelm@38418
   153
wenzelm@38418
   154
wenzelm@38418
   155
(** global state -- document structure and execution process **)
wenzelm@38418
   156
wenzelm@38418
   157
abstype state = State of
wenzelm@40398
   158
 {versions: version Inttab.table,  (*version_id -> document content*)
wenzelm@38421
   159
  commands: Toplevel.transition future Inttab.table,  (*command_id -> transition (future parsing)*)
wenzelm@44196
   160
  execs: Toplevel.state lazy Inttab.table,  (*exec_id -> execution process*)
wenzelm@40398
   161
  execution: unit future list}  (*global execution process*)
wenzelm@38418
   162
with
wenzelm@38418
   163
wenzelm@38418
   164
fun make_state (versions, commands, execs, execution) =
wenzelm@38418
   165
  State {versions = versions, commands = commands, execs = execs, execution = execution};
wenzelm@38418
   166
wenzelm@38418
   167
fun map_state f (State {versions, commands, execs, execution}) =
wenzelm@38418
   168
  make_state (f (versions, commands, execs, execution));
wenzelm@38418
   169
wenzelm@38418
   170
val init_state =
wenzelm@38418
   171
  make_state (Inttab.make [(no_id, empty_version)],
wenzelm@38449
   172
    Inttab.make [(no_id, Future.value Toplevel.empty)],
wenzelm@44196
   173
    Inttab.make [(no_id, Lazy.value Toplevel.toplevel)],
wenzelm@38418
   174
    []);
wenzelm@38418
   175
wenzelm@38418
   176
wenzelm@38418
   177
(* document versions *)
wenzelm@38418
   178
wenzelm@38418
   179
fun define_version (id: version_id) version =
wenzelm@38418
   180
  map_state (fn (versions, commands, execs, execution) =>
wenzelm@38418
   181
    let val versions' = Inttab.update_new (id, version) versions
wenzelm@38418
   182
      handle Inttab.DUP dup => err_dup "document version" dup
wenzelm@38418
   183
    in (versions', commands, execs, execution) end);
wenzelm@38418
   184
wenzelm@38418
   185
fun the_version (State {versions, ...}) (id: version_id) =
wenzelm@38418
   186
  (case Inttab.lookup versions id of
wenzelm@38418
   187
    NONE => err_undef "document version" id
wenzelm@38418
   188
  | SOME version => version);
wenzelm@38418
   189
wenzelm@38418
   190
wenzelm@38418
   191
(* commands *)
wenzelm@38418
   192
wenzelm@38418
   193
fun define_command (id: command_id) text =
wenzelm@38418
   194
  map_state (fn (versions, commands, execs, execution) =>
wenzelm@38418
   195
    let
wenzelm@38418
   196
      val id_string = print_id id;
wenzelm@38421
   197
      val tr = Future.fork_pri 2 (fn () =>
wenzelm@38418
   198
        Position.setmp_thread_data (Position.id_only id_string)
wenzelm@38421
   199
          (fn () => Outer_Syntax.prepare_command (Position.id id_string) text) ());
wenzelm@38418
   200
      val commands' =
wenzelm@38421
   201
        Inttab.update_new (id, tr) commands
wenzelm@38418
   202
          handle Inttab.DUP dup => err_dup "command" dup;
wenzelm@38418
   203
    in (versions, commands', execs, execution) end);
wenzelm@38418
   204
wenzelm@38418
   205
fun the_command (State {commands, ...}) (id: command_id) =
wenzelm@38418
   206
  (case Inttab.lookup commands id of
wenzelm@38418
   207
    NONE => err_undef "command" id
wenzelm@38418
   208
  | SOME tr => tr);
wenzelm@38418
   209
wenzelm@38421
   210
fun join_commands (State {commands, ...}) =
wenzelm@38421
   211
  Inttab.fold (fn (_, tr) => fn () => ignore (Future.join_result tr)) commands ();
wenzelm@38421
   212
wenzelm@38418
   213
wenzelm@38418
   214
(* command executions *)
wenzelm@38418
   215
wenzelm@38418
   216
fun define_exec (id: exec_id) exec =
wenzelm@38418
   217
  map_state (fn (versions, commands, execs, execution) =>
wenzelm@38418
   218
    let val execs' = Inttab.update_new (id, exec) execs
wenzelm@38418
   219
      handle Inttab.DUP dup => err_dup "command execution" dup
wenzelm@38418
   220
    in (versions, commands, execs', execution) end);
wenzelm@38418
   221
wenzelm@38418
   222
fun the_exec (State {execs, ...}) (id: exec_id) =
wenzelm@38418
   223
  (case Inttab.lookup execs id of
wenzelm@38418
   224
    NONE => err_undef "command execution" id
wenzelm@38418
   225
  | SOME exec => exec);
wenzelm@38418
   226
wenzelm@43668
   227
fun get_theory state version_id pos name =
wenzelm@43668
   228
  let
wenzelm@44185
   229
    val last = get_last (node_of (the_version state version_id) name);
wenzelm@44180
   230
    val st =
wenzelm@44180
   231
      (case Lazy.peek (the_exec state last) of
wenzelm@44196
   232
        SOME result => Exn.release result
wenzelm@44185
   233
      | NONE => error ("Unfinished execution for theory " ^ quote name ^ Position.str_of pos));
wenzelm@43668
   234
  in Toplevel.end_theory pos st end;
wenzelm@43668
   235
wenzelm@41634
   236
wenzelm@41634
   237
(* document execution *)
wenzelm@41634
   238
wenzelm@43666
   239
fun cancel_execution (State {execution, ...}) =
wenzelm@43666
   240
  (List.app Future.cancel execution;
wenzelm@43666
   241
    fn () => ignore (Future.join_results execution));
wenzelm@41634
   242
wenzelm@38418
   243
end;
wenzelm@38418
   244
wenzelm@38418
   245
wenzelm@38418
   246
wenzelm@38888
   247
(* toplevel transactions *)
wenzelm@38888
   248
wenzelm@38888
   249
local
wenzelm@38888
   250
wenzelm@40391
   251
fun timing tr t = Toplevel.status tr (Markup.timing t);
wenzelm@40391
   252
wenzelm@38888
   253
fun proof_status tr st =
wenzelm@38888
   254
  (case try Toplevel.proof_of st of
wenzelm@38888
   255
    SOME prf => Toplevel.status tr (Proof.status_markup prf)
wenzelm@38888
   256
  | NONE => ());
wenzelm@38888
   257
wenzelm@38888
   258
fun async_state tr st =
wenzelm@40534
   259
  ignore
wenzelm@41673
   260
    (singleton
wenzelm@41674
   261
      (Future.forks {name = "Document.async_state",
wenzelm@44113
   262
        group = SOME (Task_Queue.new_group NONE), deps = [], pri = 0, interrupts = true})
wenzelm@40534
   263
      (fn () =>
wenzelm@40534
   264
        Toplevel.setmp_thread_position tr
wenzelm@40534
   265
          (fn () => Toplevel.print_state false st) ()));
wenzelm@38888
   266
wenzelm@40390
   267
fun run int tr st =
wenzelm@40390
   268
  (case Toplevel.transition int tr st of
wenzelm@40390
   269
    SOME (st', NONE) => ([], SOME st')
wenzelm@40390
   270
  | SOME (_, SOME exn_info) =>
wenzelm@40390
   271
      (case ML_Compiler.exn_messages (Runtime.EXCURSION_FAIL exn_info) of
wenzelm@40390
   272
        [] => Exn.interrupt ()
wenzelm@40390
   273
      | errs => (errs, NONE))
wenzelm@40390
   274
  | NONE => ([ML_Compiler.exn_message Runtime.TERMINATE], NONE));
wenzelm@40390
   275
wenzelm@38888
   276
in
wenzelm@38888
   277
wenzelm@44185
   278
fun run_command (node_name, node_header) raw_tr st =
wenzelm@44185
   279
  let
wenzelm@44185
   280
    val is_init = Toplevel.is_init raw_tr;
wenzelm@44185
   281
    val tr =
wenzelm@44185
   282
      if is_init then
wenzelm@44186
   283
        raw_tr |> Toplevel.modify_init (fn () =>
wenzelm@44185
   284
          let
wenzelm@44185
   285
            (* FIXME get theories from document state *)
wenzelm@44185
   286
            (* FIXME provide files via Scala layer *)
wenzelm@44185
   287
            val (name, imports, uses) = Exn.release node_header;
wenzelm@44186
   288
            val master = Path.dir (Path.explode node_name);
wenzelm@44185
   289
          in Thy_Info.toplevel_begin_theory master name imports (map (apfst Path.explode) uses) end)
wenzelm@44185
   290
      else raw_tr;
wenzelm@40534
   291
wenzelm@44185
   292
    val is_proof = Keyword.is_proof (Toplevel.name_of tr);
wenzelm@44185
   293
    val do_print = not is_init andalso (Toplevel.print_of tr orelse is_proof);
wenzelm@44185
   294
wenzelm@44185
   295
    val start = Timing.start ();
wenzelm@44185
   296
    val (errs, result) =
wenzelm@44185
   297
      if Toplevel.is_toplevel st andalso not is_init then ([], SOME st)
wenzelm@44185
   298
      else run (is_init orelse is_proof) (Toplevel.set_print false tr) st;
wenzelm@44185
   299
    val _ = timing tr (Timing.result start);
wenzelm@44185
   300
    val _ = List.app (Toplevel.error_msg tr) errs;
wenzelm@44185
   301
  in
wenzelm@44185
   302
    (case result of
wenzelm@44196
   303
      NONE => (Toplevel.status tr Markup.failed; st)
wenzelm@44185
   304
    | SOME st' =>
wenzelm@44185
   305
       (Toplevel.status tr Markup.finished;
wenzelm@44185
   306
        proof_status tr st';
wenzelm@44185
   307
        if do_print then async_state tr st' else ();
wenzelm@44196
   308
        st'))
wenzelm@44185
   309
  end;
wenzelm@38888
   310
wenzelm@38888
   311
end;
wenzelm@38888
   312
wenzelm@38888
   313
wenzelm@38888
   314
wenzelm@38888
   315
wenzelm@38418
   316
(** editing **)
wenzelm@38418
   317
wenzelm@38418
   318
(* edit *)
wenzelm@38418
   319
wenzelm@38418
   320
local
wenzelm@38418
   321
wenzelm@38448
   322
fun is_changed node' ((_, id), exec) =
wenzelm@38418
   323
  (case try (the_entry node') id of
wenzelm@38418
   324
    NONE => true
wenzelm@38448
   325
  | SOME exec' => exec' <> exec);
wenzelm@38418
   326
wenzelm@44185
   327
fun new_exec node_info (id: command_id) (exec_id, updates, state) =
wenzelm@38418
   328
  let
wenzelm@38418
   329
    val exec = the_exec state exec_id;
wenzelm@38419
   330
    val exec_id' = new_id ();
wenzelm@38449
   331
    val future_tr = the_command state id;
wenzelm@38418
   332
    val exec' =
wenzelm@38418
   333
      Lazy.lazy (fn () =>
wenzelm@40398
   334
        let
wenzelm@44196
   335
          val st = Lazy.force exec;
wenzelm@40398
   336
          val exec_tr = Toplevel.put_id (print_id exec_id') (Future.join future_tr);
wenzelm@44185
   337
        in run_command node_info exec_tr st end);
wenzelm@38418
   338
    val state' = define_exec exec_id' exec' state;
wenzelm@38418
   339
  in (exec_id', (id, exec_id') :: updates, state') end;
wenzelm@38418
   340
wenzelm@38418
   341
in
wenzelm@38418
   342
wenzelm@44157
   343
fun edit (old_id: version_id) (new_id: version_id) edits state =
wenzelm@38418
   344
  let
wenzelm@38418
   345
    val old_version = the_version state old_id;
wenzelm@44180
   346
    val _ = Time.now ();  (* FIXME odd workaround for polyml-5.4.0/x86_64 *)
wenzelm@38418
   347
    val new_version = fold edit_nodes edits old_version;
wenzelm@38418
   348
wenzelm@38418
   349
    fun update_node name (rev_updates, version, st) =
wenzelm@44185
   350
      let
wenzelm@44185
   351
        val node = node_of version name;
wenzelm@44185
   352
        val header = get_header node;
wenzelm@44185
   353
      in
wenzelm@44185
   354
        (case first_entry NONE (is_changed (node_of old_version name)) node of
wenzelm@38418
   355
          NONE => (rev_updates, version, st)
wenzelm@38448
   356
        | SOME ((prev, id), _) =>
wenzelm@38418
   357
            let
wenzelm@38448
   358
              val prev_exec =
wenzelm@38448
   359
                (case prev of
wenzelm@38448
   360
                  NONE => no_id
wenzelm@38448
   361
                | SOME prev_id => the_default no_id (the_entry node prev_id));
wenzelm@43668
   362
              val (last, rev_upds, st') =
wenzelm@44185
   363
                fold_entries (SOME id) (new_exec (name, header) o #2 o #1) node (prev_exec, [], st);
wenzelm@43668
   364
              val node' = node |> fold update_entry rev_upds |> set_last last;
wenzelm@38418
   365
            in (rev_upds @ rev_updates, put_node name node' version, st') end)
wenzelm@38418
   366
      end;
wenzelm@38418
   367
wenzelm@44185
   368
    (* FIXME Graph.schedule *)
wenzelm@38418
   369
    val (rev_updates, new_version', state') =
wenzelm@38418
   370
      fold update_node (node_names_of new_version) ([], new_version, state);
wenzelm@38418
   371
    val state'' = define_version new_id new_version' state';
wenzelm@38421
   372
wenzelm@38421
   373
    val _ = join_commands state'';  (* FIXME async!? *)
wenzelm@38418
   374
  in (rev rev_updates, state'') end;
wenzelm@38418
   375
wenzelm@38418
   376
end;
wenzelm@38418
   377
wenzelm@38418
   378
wenzelm@38418
   379
(* execute *)
wenzelm@38418
   380
wenzelm@38418
   381
fun execute version_id state =
wenzelm@41673
   382
  state |> map_state (fn (versions, commands, execs, _) =>
wenzelm@38418
   383
    let
wenzelm@38418
   384
      val version = the_version state version_id;
wenzelm@38418
   385
wenzelm@38418
   386
      fun force_exec NONE = ()
wenzelm@38418
   387
        | force_exec (SOME exec_id) = ignore (Lazy.force (the_exec state exec_id));
wenzelm@38418
   388
wenzelm@44180
   389
      val execution' = (* FIXME Graph.schedule *)
wenzelm@44113
   390
        Future.forks
wenzelm@44113
   391
          {name = "Document.execute", group = NONE, deps = [], pri = 1, interrupts = true}
wenzelm@41673
   392
          [fn () =>
wenzelm@43666
   393
            node_names_of version |> List.app (fn name =>
wenzelm@43666
   394
              fold_entries NONE (fn (_, exec) => fn () => force_exec exec)
wenzelm@44185
   395
                  (node_of version name) ())];
wenzelm@40520
   396
wenzelm@38418
   397
    in (versions, commands, execs, execution') end);
wenzelm@38418
   398
wenzelm@43713
   399
wenzelm@43713
   400
wenzelm@43713
   401
(** global state **)
wenzelm@43713
   402
wenzelm@43713
   403
val global_state = Synchronized.var "Document" init_state;
wenzelm@43713
   404
wenzelm@43713
   405
fun state () = Synchronized.value global_state;
wenzelm@43713
   406
val change_state = Synchronized.change global_state;
wenzelm@43713
   407
wenzelm@38418
   408
end;
wenzelm@38418
   409