src/Pure/PIDE/document.ML
author wenzelm
Tue Aug 16 21:50:53 2011 +0200 (2011-08-16)
changeset 44223 cac52579f2c2
parent 44222 9d5ef6cd4ee1
child 44226 1ea760da0f2d
permissions -rw-r--r--
more robust treatment of node dependencies in incremental edits;
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@44197
    26
  val join_commands: state -> unit
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@44197
    64
  result: Toplevel.state lazy}
wenzelm@43668
    65
and version = Version of node Graph.T  (*development graph wrt. static imports*)
wenzelm@38418
    66
with
wenzelm@38418
    67
wenzelm@44197
    68
fun make_node (header, entries, result) =
wenzelm@44197
    69
  Node {header = header, entries = entries, result = result};
wenzelm@43668
    70
wenzelm@44197
    71
fun map_node f (Node {header, entries, result}) =
wenzelm@44197
    72
  make_node (f (header, entries, result));
wenzelm@38418
    73
wenzelm@44180
    74
fun get_header (Node {header, ...}) = header;
wenzelm@44197
    75
fun set_header header = map_node (fn (_, entries, result) => (header, entries, result));
wenzelm@44180
    76
wenzelm@44197
    77
fun map_entries f (Node {header, entries, result}) = make_node (header, f entries, result);
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@44200
    81
fun get_theory pos (Node {result, ...}) = Toplevel.end_theory pos (Lazy.get_finished result);
wenzelm@44197
    82
fun set_result result = map_node (fn (header, entries, _) => (header, entries, result));
wenzelm@44180
    83
wenzelm@44197
    84
val empty_exec = Lazy.value Toplevel.toplevel;
wenzelm@44197
    85
val empty_node = make_node (Exn.Exn (ERROR "Bad theory header"), Entries.empty, empty_exec);
wenzelm@44197
    86
val clear_node = map_node (fn (header, _, _) => (header, Entries.empty, empty_exec));
wenzelm@44185
    87
wenzelm@44185
    88
fun get_node nodes name = Graph.get_node nodes name handle Graph.UNDEF _ => empty_node;
wenzelm@44202
    89
fun default_node name = Graph.default_node (name, empty_node);
wenzelm@44202
    90
fun update_node name f = default_node name #> Graph.map_node name f;
wenzelm@38418
    91
wenzelm@38418
    92
wenzelm@38448
    93
(* node edits and associated executions *)
wenzelm@38150
    94
wenzelm@44157
    95
datatype node_edit =
wenzelm@44185
    96
  Clear |
wenzelm@44157
    97
  Edits of (command_id option * command_id option) list |
wenzelm@44182
    98
  Header of node_header;
wenzelm@44157
    99
wenzelm@44156
   100
type edit = string * node_edit;
wenzelm@38448
   101
wenzelm@43668
   102
fun the_entry (Node {entries, ...}) id =
wenzelm@38448
   103
  (case Entries.lookup entries id of
wenzelm@38448
   104
    NONE => err_undef "command entry" id
wenzelm@38448
   105
  | SOME entry => entry);
wenzelm@38150
   106
wenzelm@43668
   107
fun update_entry (id, exec_id) =
wenzelm@43668
   108
  map_entries (Entries.update (id, SOME exec_id));
wenzelm@38418
   109
wenzelm@38448
   110
fun reset_after id entries =
wenzelm@38448
   111
  (case Entries.get_after entries id of
wenzelm@38448
   112
    NONE => entries
wenzelm@38448
   113
  | SOME next => Entries.update (next, NONE) entries);
wenzelm@38448
   114
wenzelm@43668
   115
val edit_node = map_entries o fold
wenzelm@43668
   116
  (fn (id, SOME id2) => Entries.insert_after id (id2, NONE)
wenzelm@43668
   117
    | (id, NONE) => Entries.delete_after id #> reset_after id);
wenzelm@38418
   118
wenzelm@38418
   119
wenzelm@38418
   120
(* version operations *)
wenzelm@38418
   121
wenzelm@44185
   122
val empty_version = Version Graph.empty;
wenzelm@44185
   123
wenzelm@38418
   124
fun nodes_of (Version nodes) = nodes;
wenzelm@44185
   125
val node_of = get_node 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@44202
   129
fun touch_descendants name nodes =
wenzelm@44202
   130
  fold (fn desc => desc <> name ? update_node desc (map_entries (reset_after NONE)))
wenzelm@44202
   131
    (Graph.all_succs nodes [name]) nodes;
wenzelm@44202
   132
wenzelm@44157
   133
fun edit_nodes (name, node_edit) (Version nodes) =
wenzelm@44157
   134
  Version
wenzelm@44202
   135
    (touch_descendants name
wenzelm@44202
   136
      (case node_edit of
wenzelm@44202
   137
        Clear => update_node name clear_node nodes
wenzelm@44202
   138
      | Edits edits =>
wenzelm@44202
   139
          nodes
wenzelm@44202
   140
          |> update_node name (edit_node edits)
wenzelm@44202
   141
      | Header header =>
wenzelm@44202
   142
          let
wenzelm@44222
   143
            val parents = (case header of Exn.Res (_, parents, _) => parents | _ => []);
wenzelm@44223
   144
            val nodes1 = nodes
wenzelm@44223
   145
              |> default_node name
wenzelm@44223
   146
              |> fold default_node parents;
wenzelm@44223
   147
            val nodes2 = nodes1
wenzelm@44223
   148
              |> fold (fn dep => Graph.del_edge (dep, name)) (Graph.imm_preds nodes1 name);
wenzelm@44222
   149
            val (header', nodes3) =
wenzelm@44222
   150
              (header, Graph.add_deps_acyclic (name, parents) nodes2)
wenzelm@44222
   151
                handle Graph.CYCLES cs => (Exn.Exn (ERROR (cat_lines (map cycle_msg cs))), nodes2);
wenzelm@44222
   152
          in Graph.map_node name (set_header header') nodes3 end));
wenzelm@38418
   153
wenzelm@44222
   154
fun put_node (name, node) (Version nodes) =
wenzelm@44222
   155
  Version (update_node name (K node) nodes);
wenzelm@38418
   156
wenzelm@38150
   157
end;
wenzelm@38150
   158
wenzelm@38418
   159
wenzelm@38418
   160
wenzelm@38418
   161
(** global state -- document structure and execution process **)
wenzelm@38418
   162
wenzelm@38418
   163
abstype state = State of
wenzelm@40398
   164
 {versions: version Inttab.table,  (*version_id -> document content*)
wenzelm@38421
   165
  commands: Toplevel.transition future Inttab.table,  (*command_id -> transition (future parsing)*)
wenzelm@44196
   166
  execs: Toplevel.state lazy Inttab.table,  (*exec_id -> execution process*)
wenzelm@40398
   167
  execution: unit future list}  (*global execution process*)
wenzelm@38418
   168
with
wenzelm@38418
   169
wenzelm@38418
   170
fun make_state (versions, commands, execs, execution) =
wenzelm@38418
   171
  State {versions = versions, commands = commands, execs = execs, execution = execution};
wenzelm@38418
   172
wenzelm@38418
   173
fun map_state f (State {versions, commands, execs, execution}) =
wenzelm@38418
   174
  make_state (f (versions, commands, execs, execution));
wenzelm@38418
   175
wenzelm@38418
   176
val init_state =
wenzelm@38418
   177
  make_state (Inttab.make [(no_id, empty_version)],
wenzelm@38449
   178
    Inttab.make [(no_id, Future.value Toplevel.empty)],
wenzelm@44197
   179
    Inttab.make [(no_id, empty_exec)],
wenzelm@38418
   180
    []);
wenzelm@38418
   181
wenzelm@38418
   182
wenzelm@38418
   183
(* document versions *)
wenzelm@38418
   184
wenzelm@38418
   185
fun define_version (id: version_id) version =
wenzelm@38418
   186
  map_state (fn (versions, commands, execs, execution) =>
wenzelm@38418
   187
    let val versions' = Inttab.update_new (id, version) versions
wenzelm@38418
   188
      handle Inttab.DUP dup => err_dup "document version" dup
wenzelm@38418
   189
    in (versions', commands, execs, execution) end);
wenzelm@38418
   190
wenzelm@38418
   191
fun the_version (State {versions, ...}) (id: version_id) =
wenzelm@38418
   192
  (case Inttab.lookup versions id of
wenzelm@38418
   193
    NONE => err_undef "document version" id
wenzelm@38418
   194
  | SOME version => version);
wenzelm@38418
   195
wenzelm@38418
   196
wenzelm@38418
   197
(* commands *)
wenzelm@38418
   198
wenzelm@38418
   199
fun define_command (id: command_id) text =
wenzelm@38418
   200
  map_state (fn (versions, commands, execs, execution) =>
wenzelm@38418
   201
    let
wenzelm@38418
   202
      val id_string = print_id id;
wenzelm@38421
   203
      val tr = Future.fork_pri 2 (fn () =>
wenzelm@38418
   204
        Position.setmp_thread_data (Position.id_only id_string)
wenzelm@38421
   205
          (fn () => Outer_Syntax.prepare_command (Position.id id_string) text) ());
wenzelm@38418
   206
      val commands' =
wenzelm@38421
   207
        Inttab.update_new (id, tr) commands
wenzelm@38418
   208
          handle Inttab.DUP dup => err_dup "command" dup;
wenzelm@38418
   209
    in (versions, commands', execs, execution) end);
wenzelm@38418
   210
wenzelm@38418
   211
fun the_command (State {commands, ...}) (id: command_id) =
wenzelm@38418
   212
  (case Inttab.lookup commands id of
wenzelm@38418
   213
    NONE => err_undef "command" id
wenzelm@38418
   214
  | SOME tr => tr);
wenzelm@38418
   215
wenzelm@38421
   216
fun join_commands (State {commands, ...}) =
wenzelm@38421
   217
  Inttab.fold (fn (_, tr) => fn () => ignore (Future.join_result tr)) commands ();
wenzelm@38421
   218
wenzelm@38418
   219
wenzelm@38418
   220
(* command executions *)
wenzelm@38418
   221
wenzelm@44197
   222
fun define_exec (exec_id, exec) =
wenzelm@38418
   223
  map_state (fn (versions, commands, execs, execution) =>
wenzelm@44197
   224
    let val execs' = Inttab.update_new (exec_id, exec) execs
wenzelm@38418
   225
      handle Inttab.DUP dup => err_dup "command execution" dup
wenzelm@38418
   226
    in (versions, commands, execs', execution) end);
wenzelm@38418
   227
wenzelm@44197
   228
fun the_exec (State {execs, ...}) exec_id =
wenzelm@44197
   229
  (case Inttab.lookup execs exec_id of
wenzelm@44197
   230
    NONE => err_undef "command execution" exec_id
wenzelm@38418
   231
  | SOME exec => exec);
wenzelm@38418
   232
wenzelm@41634
   233
wenzelm@41634
   234
(* document execution *)
wenzelm@41634
   235
wenzelm@43666
   236
fun cancel_execution (State {execution, ...}) =
wenzelm@43666
   237
  (List.app Future.cancel execution;
wenzelm@43666
   238
    fn () => ignore (Future.join_results execution));
wenzelm@41634
   239
wenzelm@38418
   240
end;
wenzelm@38418
   241
wenzelm@38418
   242
wenzelm@38418
   243
wenzelm@38888
   244
(* toplevel transactions *)
wenzelm@38888
   245
wenzelm@38888
   246
local
wenzelm@38888
   247
wenzelm@40391
   248
fun timing tr t = Toplevel.status tr (Markup.timing t);
wenzelm@40391
   249
wenzelm@38888
   250
fun proof_status tr st =
wenzelm@38888
   251
  (case try Toplevel.proof_of st of
wenzelm@38888
   252
    SOME prf => Toplevel.status tr (Proof.status_markup prf)
wenzelm@38888
   253
  | NONE => ());
wenzelm@38888
   254
wenzelm@38888
   255
fun async_state tr st =
wenzelm@40534
   256
  ignore
wenzelm@41673
   257
    (singleton
wenzelm@41674
   258
      (Future.forks {name = "Document.async_state",
wenzelm@44113
   259
        group = SOME (Task_Queue.new_group NONE), deps = [], pri = 0, interrupts = true})
wenzelm@40534
   260
      (fn () =>
wenzelm@40534
   261
        Toplevel.setmp_thread_position tr
wenzelm@40534
   262
          (fn () => Toplevel.print_state false st) ()));
wenzelm@38888
   263
wenzelm@40390
   264
fun run int tr st =
wenzelm@40390
   265
  (case Toplevel.transition int tr st of
wenzelm@40390
   266
    SOME (st', NONE) => ([], SOME st')
wenzelm@40390
   267
  | SOME (_, SOME exn_info) =>
wenzelm@40390
   268
      (case ML_Compiler.exn_messages (Runtime.EXCURSION_FAIL exn_info) of
wenzelm@40390
   269
        [] => Exn.interrupt ()
wenzelm@40390
   270
      | errs => (errs, NONE))
wenzelm@40390
   271
  | NONE => ([ML_Compiler.exn_message Runtime.TERMINATE], NONE));
wenzelm@40390
   272
wenzelm@38888
   273
in
wenzelm@38888
   274
wenzelm@44199
   275
fun run_command tr st =
wenzelm@44185
   276
  let
wenzelm@44199
   277
    val is_init = Toplevel.is_init tr;
wenzelm@44185
   278
    val is_proof = Keyword.is_proof (Toplevel.name_of tr);
wenzelm@44185
   279
    val do_print = not is_init andalso (Toplevel.print_of tr orelse is_proof);
wenzelm@44185
   280
wenzelm@44185
   281
    val start = Timing.start ();
wenzelm@44185
   282
    val (errs, result) =
wenzelm@44185
   283
      if Toplevel.is_toplevel st andalso not is_init then ([], SOME st)
wenzelm@44185
   284
      else run (is_init orelse is_proof) (Toplevel.set_print false tr) st;
wenzelm@44185
   285
    val _ = timing tr (Timing.result start);
wenzelm@44185
   286
    val _ = List.app (Toplevel.error_msg tr) errs;
wenzelm@44185
   287
  in
wenzelm@44185
   288
    (case result of
wenzelm@44196
   289
      NONE => (Toplevel.status tr Markup.failed; st)
wenzelm@44185
   290
    | SOME st' =>
wenzelm@44185
   291
       (Toplevel.status tr Markup.finished;
wenzelm@44185
   292
        proof_status tr st';
wenzelm@44185
   293
        if do_print then async_state tr st' else ();
wenzelm@44196
   294
        st'))
wenzelm@44185
   295
  end;
wenzelm@38888
   296
wenzelm@38888
   297
end;
wenzelm@38888
   298
wenzelm@38888
   299
wenzelm@38888
   300
wenzelm@38888
   301
wenzelm@38418
   302
(** editing **)
wenzelm@38418
   303
wenzelm@38418
   304
(* edit *)
wenzelm@38418
   305
wenzelm@38418
   306
local
wenzelm@38418
   307
wenzelm@38448
   308
fun is_changed node' ((_, id), exec) =
wenzelm@38418
   309
  (case try (the_entry node') id of
wenzelm@38418
   310
    NONE => true
wenzelm@38448
   311
  | SOME exec' => exec' <> exec);
wenzelm@38418
   312
wenzelm@44199
   313
fun new_exec (command_id, command) (assigns, execs, exec) =
wenzelm@38418
   314
  let
wenzelm@38419
   315
    val exec_id' = new_id ();
wenzelm@38418
   316
    val exec' =
wenzelm@38418
   317
      Lazy.lazy (fn () =>
wenzelm@40398
   318
        let
wenzelm@44198
   319
          val tr = Toplevel.put_id (print_id exec_id') (Future.get_finished command);
wenzelm@44198
   320
          val st = Lazy.get_finished exec;
wenzelm@44199
   321
        in run_command tr st end);
wenzelm@44197
   322
  in ((command_id, exec_id') :: assigns, (exec_id', exec') :: execs, exec') end;
wenzelm@38418
   323
wenzelm@38418
   324
in
wenzelm@38418
   325
wenzelm@44157
   326
fun edit (old_id: version_id) (new_id: version_id) edits state =
wenzelm@38418
   327
  let
wenzelm@38418
   328
    val old_version = the_version state old_id;
wenzelm@44180
   329
    val _ = Time.now ();  (* FIXME odd workaround for polyml-5.4.0/x86_64 *)
wenzelm@44222
   330
    val new_version = fold edit_nodes edits old_version;
wenzelm@38418
   331
wenzelm@44197
   332
    val updates =
wenzelm@44197
   333
      nodes_of new_version |> Graph.schedule
wenzelm@44199
   334
        (fn deps => fn (name, node) =>
wenzelm@44197
   335
          (case first_entry NONE (is_changed (node_of old_version name)) node of
wenzelm@44201
   336
            NONE => Future.value (([], [], []), node)
wenzelm@44197
   337
          | SOME ((prev, id), _) =>
wenzelm@44197
   338
              let
wenzelm@44199
   339
                fun init () =
wenzelm@44199
   340
                  let
wenzelm@44199
   341
                    val (thy_name, imports, uses) = Exn.release (get_header node);
wenzelm@44199
   342
                    (* FIXME provide files via Scala layer *)
wenzelm@44199
   343
                    val dir = Path.dir (Path.explode name);
wenzelm@44199
   344
                    val files = map (apfst Path.explode) uses;
wenzelm@44199
   345
wenzelm@44199
   346
                    val parents =
wenzelm@44199
   347
                      imports |> map (fn import =>
wenzelm@44222
   348
                        (case Thy_Info.lookup_theory import of
wenzelm@44222
   349
                          SOME thy => thy
wenzelm@44222
   350
                        | NONE =>
wenzelm@44222
   351
                            get_theory (Position.file_only import)
wenzelm@44222
   352
                              (#2 (Future.join (the (AList.lookup (op =) deps import))))));
wenzelm@44199
   353
                  in Thy_Load.begin_theory dir thy_name imports files parents end
wenzelm@44199
   354
                fun get_command id =
wenzelm@44199
   355
                  (id, the_command state id |> Future.map (Toplevel.modify_init init));
wenzelm@44201
   356
              in
wenzelm@44201
   357
                singleton
wenzelm@44201
   358
                  (Future.forks {name = "Document.edit", group = NONE,
wenzelm@44201
   359
                    deps = map (Future.task_of o #2) deps, pri = 2, interrupts = false})
wenzelm@44201
   360
                  (fn () =>
wenzelm@44201
   361
                    let
wenzelm@44201
   362
                      val prev_exec =
wenzelm@44201
   363
                        (case prev of
wenzelm@44201
   364
                          NONE => no_id
wenzelm@44201
   365
                        | SOME prev_id => the_default no_id (the_entry node prev_id));
wenzelm@44201
   366
                      val (assigns, execs, result) =
wenzelm@44201
   367
                        fold_entries (SOME id) (new_exec o get_command o #2 o #1)
wenzelm@44201
   368
                          node ([], [], the_exec state prev_exec);
wenzelm@44201
   369
                      val node' = node
wenzelm@44201
   370
                        |> fold update_entry assigns
wenzelm@44201
   371
                        |> set_result result;
wenzelm@44201
   372
                    in ((assigns, execs, [(name, node')]), node') end)
wenzelm@44201
   373
              end))
wenzelm@44201
   374
      |> Future.join_results |> Exn.release_all |> map #1;
wenzelm@38418
   375
wenzelm@44197
   376
    val state' = state
wenzelm@44197
   377
      |> fold (fold define_exec o #2) updates
wenzelm@44197
   378
      |> define_version new_id (fold (fold put_node o #3) updates new_version);
wenzelm@38421
   379
wenzelm@44197
   380
  in (maps #1 (rev updates), state') end;
wenzelm@38418
   381
wenzelm@38418
   382
end;
wenzelm@38418
   383
wenzelm@38418
   384
wenzelm@38418
   385
(* execute *)
wenzelm@38418
   386
wenzelm@38418
   387
fun execute version_id state =
wenzelm@41673
   388
  state |> map_state (fn (versions, commands, execs, _) =>
wenzelm@38418
   389
    let
wenzelm@38418
   390
      val version = the_version state version_id;
wenzelm@38418
   391
wenzelm@38418
   392
      fun force_exec NONE = ()
wenzelm@38418
   393
        | force_exec (SOME exec_id) = ignore (Lazy.force (the_exec state exec_id));
wenzelm@38418
   394
wenzelm@44201
   395
      val execution' =
wenzelm@44201
   396
        nodes_of version |> Graph.schedule
wenzelm@44201
   397
          (fn deps => fn (name, node) =>
wenzelm@44201
   398
            singleton
wenzelm@44201
   399
              (Future.forks
wenzelm@44201
   400
                {name = "theory:" ^ name, group = NONE,
wenzelm@44201
   401
                  deps = map (Future.task_of o #2) deps,
wenzelm@44201
   402
                  pri = 1, interrupts = true})
wenzelm@44201
   403
              (fold_entries NONE (fn (_, exec) => fn () => force_exec exec) node));
wenzelm@40520
   404
wenzelm@38418
   405
    in (versions, commands, execs, execution') end);
wenzelm@38418
   406
wenzelm@43713
   407
wenzelm@43713
   408
wenzelm@43713
   409
(** global state **)
wenzelm@43713
   410
wenzelm@43713
   411
val global_state = Synchronized.var "Document" init_state;
wenzelm@43713
   412
wenzelm@43713
   413
fun state () = Synchronized.value global_state;
wenzelm@43713
   414
val change_state = Synchronized.change global_state;
wenzelm@43713
   415
wenzelm@38418
   416
end;
wenzelm@38418
   417