src/Pure/PIDE/protocol.ML
author wenzelm
Mon Jul 29 16:52:04 2013 +0200 (2013-07-29 ago)
changeset 52774 627fb639a2d9
parent 52765 260949bf6529
child 52775 e0169f13bd37
permissions -rw-r--r--
maintain explicit execution frontier: avoid conflict with former task via static dependency;
start execution immediate after assignment, to keep frontier simple;
wenzelm@45709
     1
(*  Title:      Pure/PIDE/protocol.ML
wenzelm@38412
     2
    Author:     Makarius
wenzelm@38412
     3
wenzelm@45709
     4
Protocol message formats for interactive proof documents.
wenzelm@38412
     5
*)
wenzelm@38412
     6
wenzelm@45709
     7
structure Protocol: sig end =
wenzelm@38412
     8
struct
wenzelm@38412
     9
wenzelm@38418
    10
val _ =
wenzelm@52585
    11
  Isabelle_Process.protocol_command "echo" (fn args => List.app writeln args);
wenzelm@52585
    12
wenzelm@52585
    13
val _ =
wenzelm@46119
    14
  Isabelle_Process.protocol_command "Document.define_command"
wenzelm@44644
    15
    (fn [id, name, text] =>
wenzelm@52530
    16
      Document.change_state (Document.define_command (Document_ID.parse id) name text));
wenzelm@38412
    17
wenzelm@38418
    18
val _ =
wenzelm@47343
    19
  Isabelle_Process.protocol_command "Document.discontinue_execution"
wenzelm@52606
    20
    (fn [] => Execution.discontinue ());
wenzelm@47343
    21
wenzelm@47343
    22
val _ =
wenzelm@46119
    23
  Isabelle_Process.protocol_command "Document.update"
wenzelm@44157
    24
    (fn [old_id_string, new_id_string, edits_yxml] => Document.change_state (fn state =>
wenzelm@38418
    25
      let
wenzelm@52606
    26
        val _ = Execution.discontinue ();
wenzelm@47404
    27
wenzelm@52530
    28
        val old_id = Document_ID.parse old_id_string;
wenzelm@52530
    29
        val new_id = Document_ID.parse new_id_string;
wenzelm@44157
    30
        val edits =
wenzelm@44157
    31
          YXML.parse_body edits_yxml |>
wenzelm@44157
    32
            let open XML.Decode in
wenzelm@44157
    33
              list (pair string
wenzelm@44157
    34
                (variant
wenzelm@48755
    35
                 [fn ([], []) => Document.Clear,  (* FIXME unused !? *)
wenzelm@44157
    36
                  fn ([], a) => Document.Edits (list (pair (option int) (option int)) a),
wenzelm@44157
    37
                  fn ([], a) =>
wenzelm@46938
    38
                    let
wenzelm@51294
    39
                      val (master, (name, (imports, (keywords, errors)))) =
wenzelm@48707
    40
                        pair string (pair string (pair (list string)
wenzelm@48864
    41
                          (pair (list (pair string
wenzelm@48864
    42
                            (option (pair (pair string (list string)) (list string)))))
wenzelm@51294
    43
                            (list string)))) a;
wenzelm@48927
    44
                      val imports' = map (rpair Position.none) imports;
wenzelm@51294
    45
                      val header = Thy_Header.make (name, Position.none) imports' keywords;
wenzelm@51294
    46
                    in Document.Deps (master, header, errors) end,
wenzelm@44384
    47
                  fn (a, []) => Document.Perspective (map int_atom a)]))
wenzelm@44157
    48
            end;
wenzelm@38412
    49
wenzelm@52655
    50
        val (removed, assign_update, state') = Document.update old_id new_id edits state;
wenzelm@52655
    51
        val _ = List.app Execution.terminate removed;
wenzelm@52765
    52
        val _ = Goal.purge_futures removed;
wenzelm@52655
    53
        val _ = List.app Isabelle_Process.reset_tracing removed;
wenzelm@52601
    54
wenzelm@52601
    55
        val _ =
wenzelm@52601
    56
          Output.protocol_message Markup.assign_update
wenzelm@52601
    57
            ((new_id, assign_update) |>
wenzelm@52601
    58
              let open XML.Encode
wenzelm@52601
    59
              in pair int (list (pair int (list int))) end
wenzelm@52601
    60
              |> YXML.string_of_body);
wenzelm@52774
    61
      in Document.start_execution state' end));
wenzelm@38412
    62
wenzelm@43748
    63
val _ =
wenzelm@46119
    64
  Isabelle_Process.protocol_command "Document.remove_versions"
wenzelm@44673
    65
    (fn [versions_yxml] => Document.change_state (fn state =>
wenzelm@44673
    66
      let
wenzelm@44673
    67
        val versions =
wenzelm@44673
    68
          YXML.parse_body versions_yxml |>
wenzelm@44673
    69
            let open XML.Decode in list int end;
wenzelm@44676
    70
        val state1 = Document.remove_versions versions state;
wenzelm@50201
    71
        val _ = Output.protocol_message Markup.removed_versions versions_yxml;
wenzelm@44676
    72
      in state1 end));
wenzelm@44673
    73
wenzelm@44673
    74
val _ =
wenzelm@50498
    75
  Isabelle_Process.protocol_command "Document.dialog_result"
wenzelm@50500
    76
    (fn [serial, result] =>
wenzelm@50500
    77
      Active.dialog_result (Markup.parse_int serial) result
wenzelm@50498
    78
        handle exn => if Exn.is_interrupt exn then () else reraise exn);
wenzelm@50498
    79
wenzelm@38412
    80
end;
wenzelm@38412
    81