src/Pure/PIDE/protocol.ML
author wenzelm
Sun Aug 25 20:32:26 2013 +0200 (2013-08-25 ago)
changeset 53192 04df1d236e1c
parent 52931 ac6648c0c0fb
child 54519 5fed81762406
permissions -rw-r--r--
maintain goal forks as part of global execution;
tuned;
     1 (*  Title:      Pure/PIDE/protocol.ML
     2     Author:     Makarius
     3 
     4 Protocol message formats for interactive proof documents.
     5 *)
     6 
     7 structure Protocol: sig end =
     8 struct
     9 
    10 val _ =
    11   Isabelle_Process.protocol_command "Isabelle_Process.echo"
    12     (fn args => List.app writeln args);
    13 
    14 val _ =
    15   Isabelle_Process.protocol_command "Isabelle_Process.options"
    16     (fn [options_yxml] =>
    17       let val options = Options.decode (YXML.parse_body options_yxml) in
    18         Options.set_default options;
    19         Future.ML_statistics := true;
    20         Multithreading.trace := Options.int options "threads_trace";
    21         Multithreading.max_threads := Options.int options "threads";
    22         Goal.parallel_proofs := (if Options.int options "parallel_proofs" > 0 then 3 else 0)
    23       end);
    24 
    25 val _ =
    26   Isabelle_Process.protocol_command "Document.define_command"
    27     (fn [id, name, text] =>
    28       Document.change_state (Document.define_command (Document_ID.parse id) name text));
    29 
    30 val _ =
    31   Isabelle_Process.protocol_command "Document.discontinue_execution"
    32     (fn [] => Execution.discontinue ());
    33 
    34 val _ =
    35   Isabelle_Process.protocol_command "Document.cancel_exec"
    36     (fn [exec_id] => Execution.cancel (Document_ID.parse exec_id));
    37 
    38 val _ =
    39   Isabelle_Process.protocol_command "Document.update"
    40     (fn [old_id_string, new_id_string, edits_yxml] => Document.change_state (fn state =>
    41       let
    42         val _ = Execution.discontinue ();
    43 
    44         val old_id = Document_ID.parse old_id_string;
    45         val new_id = Document_ID.parse new_id_string;
    46         val edits =
    47           YXML.parse_body edits_yxml |>
    48             let open XML.Decode in
    49               list (pair string
    50                 (variant
    51                  [fn ([], []) => Document.Clear,  (* FIXME unused !? *)
    52                   fn ([], a) => Document.Edits (list (pair (option int) (option int)) a),
    53                   fn ([], a) =>
    54                     let
    55                       val (master, (name, (imports, (keywords, errors)))) =
    56                         pair string (pair string (pair (list string)
    57                           (pair (list (pair string
    58                             (option (pair (pair string (list string)) (list string)))))
    59                             (list string)))) a;
    60                       val imports' = map (rpair Position.none) imports;
    61                       val header = Thy_Header.make (name, Position.none) imports' keywords;
    62                     in Document.Deps (master, header, errors) end,
    63                   fn (a :: b, c) =>
    64                     Document.Perspective (bool_atom a, map int_atom b,
    65                       list (pair int (pair string (list string))) c)]))
    66             end;
    67 
    68         val (removed, assign_update, state') = Document.update old_id new_id edits state;
    69         val _ = List.app Execution.terminate removed;
    70         val _ = Execution.purge removed;
    71         val _ = List.app Isabelle_Process.reset_tracing removed;
    72 
    73         val _ =
    74           Output.protocol_message Markup.assign_update
    75             ((new_id, assign_update) |>
    76               let open XML.Encode
    77               in pair int (list (pair int (list int))) end
    78               |> YXML.string_of_body);
    79       in Document.start_execution state' end));
    80 
    81 val _ =
    82   Isabelle_Process.protocol_command "Document.remove_versions"
    83     (fn [versions_yxml] => Document.change_state (fn state =>
    84       let
    85         val versions =
    86           YXML.parse_body versions_yxml |>
    87             let open XML.Decode in list int end;
    88         val state1 = Document.remove_versions versions state;
    89         val _ = Output.protocol_message Markup.removed_versions versions_yxml;
    90       in state1 end));
    91 
    92 val _ =
    93   Isabelle_Process.protocol_command "Document.dialog_result"
    94     (fn [serial, result] =>
    95       Active.dialog_result (Markup.parse_int serial) result
    96         handle exn => if Exn.is_interrupt exn then () (*sic!*) else reraise exn);
    97 
    98 end;
    99