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