src/Pure/PIDE/protocol.ML
changeset 73225 3ab0cedaccad
parent 72946 9329abcdd651
child 73559 22b5ecb53dd9
equal deleted inserted replaced
73224:49686e3b1909 73225:3ab0cedaccad
     6 
     6 
     7 structure Protocol: sig end =
     7 structure Protocol: sig end =
     8 struct
     8 struct
     9 
     9 
    10 val _ =
    10 val _ =
    11   Isabelle_Process.protocol_command "Prover.echo"
    11   Protocol_Command.define "Prover.echo"
    12     (fn args => List.app writeln args);
    12     (fn args => List.app writeln args);
    13 
    13 
    14 val _ =
    14 val _ =
    15   Isabelle_Process.protocol_command "Prover.stop"
    15   Protocol_Command.define "Prover.stop"
    16     (fn rc :: msgs =>
    16     (fn rc :: msgs =>
    17       (List.app Output.system_message msgs;
    17       (List.app Output.system_message msgs;
    18        raise Isabelle_Process.STOP (Value.parse_int rc)));
    18        raise Protocol_Command.STOP (Value.parse_int rc)));
    19 
    19 
    20 val _ =
    20 val _ =
    21   Isabelle_Process.protocol_command "Prover.options"
    21   Protocol_Command.define "Prover.options"
    22     (fn [options_yxml] =>
    22     (fn [options_yxml] =>
    23       (Options.set_default (Options.decode (YXML.parse_body options_yxml));
    23       (Options.set_default (Options.decode (YXML.parse_body options_yxml));
    24        Isabelle_Process.init_options_interactive ()));
    24        Isabelle_Process.init_options_interactive ()));
    25 
    25 
    26 val _ =
    26 val _ =
    27   Isabelle_Process.protocol_command "Prover.init_session"
    27   Protocol_Command.define "Prover.init_session"
    28     (fn [yxml] => Resources.init_session_yxml yxml);
    28     (fn [yxml] => Resources.init_session_yxml yxml);
    29 
    29 
    30 val _ =
    30 val _ =
    31   Isabelle_Process.protocol_command "Document.define_blob"
    31   Protocol_Command.define "Document.define_blob"
    32     (fn [digest, content] => Document.change_state (Document.define_blob digest content));
    32     (fn [digest, content] => Document.change_state (Document.define_blob digest content));
    33 
    33 
    34 fun decode_command id name parents_xml blobs_xml toks_xml sources : Document.command =
    34 fun decode_command id name parents_xml blobs_xml toks_xml sources : Document.command =
    35   let
    35   let
    36     open XML.Decode;
    36     open XML.Decode;
    61 
    61 
    62 fun commands_accepted ids =
    62 fun commands_accepted ids =
    63   Output.protocol_message Markup.commands_accepted [XML.Text (space_implode "," ids)];
    63   Output.protocol_message Markup.commands_accepted [XML.Text (space_implode "," ids)];
    64 
    64 
    65 val _ =
    65 val _ =
    66   Isabelle_Process.protocol_command "Document.define_command"
    66   Protocol_Command.define "Document.define_command"
    67     (fn id :: name :: parents :: blobs :: toks :: sources =>
    67     (fn id :: name :: parents :: blobs :: toks :: sources =>
    68       let
    68       let
    69         val command =
    69         val command =
    70           decode_command id name (YXML.parse_body parents) (YXML.parse_body blobs)
    70           decode_command id name (YXML.parse_body parents) (YXML.parse_body blobs)
    71             (YXML.parse_body toks) sources;
    71             (YXML.parse_body toks) sources;
    72         val _ = Document.change_state (Document.define_command command);
    72         val _ = Document.change_state (Document.define_command command);
    73       in commands_accepted [id] end);
    73       in commands_accepted [id] end);
    74 
    74 
    75 val _ =
    75 val _ =
    76   Isabelle_Process.protocol_command "Document.define_commands"
    76   Protocol_Command.define "Document.define_commands"
    77     (fn args =>
    77     (fn args =>
    78       let
    78       let
    79         fun decode arg =
    79         fun decode arg =
    80           let
    80           let
    81             open XML.Decode;
    81             open XML.Decode;
    87         val commands = map decode args;
    87         val commands = map decode args;
    88         val _ = Document.change_state (fold Document.define_command commands);
    88         val _ = Document.change_state (fold Document.define_command commands);
    89       in commands_accepted (map (Value.print_int o #command_id) commands) end);
    89       in commands_accepted (map (Value.print_int o #command_id) commands) end);
    90 
    90 
    91 val _ =
    91 val _ =
    92   Isabelle_Process.protocol_command "Document.discontinue_execution"
    92   Protocol_Command.define "Document.discontinue_execution"
    93     (fn [] => Execution.discontinue ());
    93     (fn [] => Execution.discontinue ());
    94 
    94 
    95 val _ =
    95 val _ =
    96   Isabelle_Process.protocol_command "Document.cancel_exec"
    96   Protocol_Command.define "Document.cancel_exec"
    97     (fn [exec_id] => Execution.cancel (Document_ID.parse exec_id));
    97     (fn [exec_id] => Execution.cancel (Document_ID.parse exec_id));
    98 
    98 
    99 val _ =
    99 val _ =
   100   Isabelle_Process.protocol_command "Document.update"
   100   Protocol_Command.define "Document.update"
   101     (Future.task_context "Document.update" (Future.new_group NONE)
   101     (Future.task_context "Document.update" (Future.new_group NONE)
   102       (fn old_id_string :: new_id_string :: consolidate_yxml :: edits_yxml =>
   102       (fn old_id_string :: new_id_string :: consolidate_yxml :: edits_yxml =>
   103         Document.change_state (fn state =>
   103         Document.change_state (fn state =>
   104           let
   104           let
   105             val old_id = Document_ID.parse old_id_string;
   105             val old_id = Document_ID.parse old_id_string;
   148                       string (space_implode "," (map Value.print_int (a :: bs)));
   148                       string (space_implode "," (map Value.print_int (a :: bs)));
   149                   in triple int (list string) (list encode_upd) end);
   149                   in triple int (list string) (list encode_upd) end);
   150           in Document.start_execution state' end)));
   150           in Document.start_execution state' end)));
   151 
   151 
   152 val _ =
   152 val _ =
   153   Isabelle_Process.protocol_command "Document.remove_versions"
   153   Protocol_Command.define "Document.remove_versions"
   154     (fn [versions_yxml] => Document.change_state (fn state =>
   154     (fn [versions_yxml] => Document.change_state (fn state =>
   155       let
   155       let
   156         val versions =
   156         val versions =
   157           YXML.parse_body versions_yxml |>
   157           YXML.parse_body versions_yxml |>
   158             let open XML.Decode in list int end;
   158             let open XML.Decode in list int end;
   159         val state1 = Document.remove_versions versions state;
   159         val state1 = Document.remove_versions versions state;
   160         val _ = Output.protocol_message Markup.removed_versions [XML.Text (versions_yxml)];
   160         val _ = Output.protocol_message Markup.removed_versions [XML.Text (versions_yxml)];
   161       in state1 end));
   161       in state1 end));
   162 
   162 
   163 val _ =
   163 val _ =
   164   Isabelle_Process.protocol_command "Document.dialog_result"
   164   Protocol_Command.define "Document.dialog_result"
   165     (fn [serial, result] =>
   165     (fn [serial, result] =>
   166       Active.dialog_result (Value.parse_int serial) result
   166       Active.dialog_result (Value.parse_int serial) result
   167         handle exn => if Exn.is_interrupt exn then () (*sic!*) else Exn.reraise exn);
   167         handle exn => if Exn.is_interrupt exn then () (*sic!*) else Exn.reraise exn);
   168 
   168 
   169 val _ =
   169 val _ =
   170   Isabelle_Process.protocol_command "ML_Heap.full_gc"
   170   Protocol_Command.define "ML_Heap.full_gc"
   171     (fn [] => ML_Heap.full_gc ());
   171     (fn [] => ML_Heap.full_gc ());
   172 
   172 
   173 val _ =
   173 val _ =
   174   Isabelle_Process.protocol_command "ML_Heap.share_common_data"
   174   Protocol_Command.define "ML_Heap.share_common_data"
   175     (fn [] => ML_Heap.share_common_data ());
   175     (fn [] => ML_Heap.share_common_data ());
   176 
   176 
   177 end;
   177 end;