src/Pure/PIDE/protocol.ML
author wenzelm
Mon, 04 Nov 2019 20:24:52 +0100
changeset 71024 38bed2483e6a
parent 70991 f9f7c34b7dd4
child 71875 aaa984499d36
permissions -rw-r--r--
proper message (amending 94442fce40a5);
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
45709
87017fcbad83 clarified modules (again) -- NB: both Document and Protocol are specific to this particular prover;
wenzelm
parents: 45672
diff changeset
     1
(*  Title:      Pure/PIDE/protocol.ML
38412
c23f3abbf42d moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff changeset
     2
    Author:     Makarius
c23f3abbf42d moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff changeset
     3
45709
87017fcbad83 clarified modules (again) -- NB: both Document and Protocol are specific to this particular prover;
wenzelm
parents: 45672
diff changeset
     4
Protocol message formats for interactive proof documents.
38412
c23f3abbf42d moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff changeset
     5
*)
c23f3abbf42d moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff changeset
     6
45709
87017fcbad83 clarified modules (again) -- NB: both Document and Protocol are specific to this particular prover;
wenzelm
parents: 45672
diff changeset
     7
structure Protocol: sig end =
38412
c23f3abbf42d moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff changeset
     8
struct
c23f3abbf42d moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff changeset
     9
38418
9a7af64d71bb more explicit / functional ML version of document model;
wenzelm
parents: 38417
diff changeset
    10
val _ =
56387
d92eb5c3960d more general prover operations;
wenzelm
parents: 56333
diff changeset
    11
  Isabelle_Process.protocol_command "Prover.echo"
52786
9795ea654905 tuned signature;
wenzelm
parents: 52775
diff changeset
    12
    (fn args => List.app writeln args);
9795ea654905 tuned signature;
wenzelm
parents: 52775
diff changeset
    13
9795ea654905 tuned signature;
wenzelm
parents: 52775
diff changeset
    14
val _ =
56387
d92eb5c3960d more general prover operations;
wenzelm
parents: 56333
diff changeset
    15
  Isabelle_Process.protocol_command "Prover.options"
52786
9795ea654905 tuned signature;
wenzelm
parents: 52775
diff changeset
    16
    (fn [options_yxml] =>
65300
c262653a3b88 clarified signature;
wenzelm
parents: 63806
diff changeset
    17
      (Options.set_default (Options.decode (YXML.parse_body options_yxml));
c262653a3b88 clarified signature;
wenzelm
parents: 63806
diff changeset
    18
       Isabelle_Process.init_options_interactive ()));
52585
ff525a38dba9 added "echo" command for demonstration purposes;
wenzelm
parents: 52579
diff changeset
    19
ff525a38dba9 added "echo" command for demonstration purposes;
wenzelm
parents: 52579
diff changeset
    20
val _ =
67219
81e9804b2014 added document antiquotation @{session name};
wenzelm
parents: 66712
diff changeset
    21
  Isabelle_Process.protocol_command "Prover.init_session_base"
70683
8c7706b053c7 find theory files via session structure: much faster Prover IDE startup;
wenzelm
parents: 70665
diff changeset
    22
    (fn [session_positions_yxml, session_directories_yxml, doc_names_yxml, global_theories_yxml,
70712
a3cfe859d915 find theories via session directories only -- ignore known_theories;
wenzelm
parents: 70683
diff changeset
    23
          loaded_theories_yxml] =>
65470
a0f49174dbeb global session_base for PIDE interaction;
wenzelm
parents: 65300
diff changeset
    24
      let
a0f49174dbeb global session_base for PIDE interaction;
wenzelm
parents: 65300
diff changeset
    25
        val decode_table = YXML.parse_body #> let open XML.Decode in list (pair string string) end;
66712
4c98c929a12a session-qualified theory names are mandatory;
wenzelm
parents: 66379
diff changeset
    26
        val decode_list = YXML.parse_body #> let open XML.Decode in list string end;
67493
c4e9e0c50487 treat sessions as entities with defining position;
wenzelm
parents: 67471
diff changeset
    27
        val decode_sessions =
c4e9e0c50487 treat sessions as entities with defining position;
wenzelm
parents: 67471
diff changeset
    28
          YXML.parse_body #> let open XML.Decode in list (pair string properties) end;
65470
a0f49174dbeb global session_base for PIDE interaction;
wenzelm
parents: 65300
diff changeset
    29
      in
65478
7c40477e0a87 clarified init_session_base / finish_session_base: retain some information for plain "isabelle process", without rechecking dependencies as in "isabelle console";
wenzelm
parents: 65470
diff changeset
    30
        Resources.init_session_base
70683
8c7706b053c7 find theory files via session structure: much faster Prover IDE startup;
wenzelm
parents: 70665
diff changeset
    31
          {session_positions = decode_sessions session_positions_yxml,
8c7706b053c7 find theory files via session structure: much faster Prover IDE startup;
wenzelm
parents: 70665
diff changeset
    32
           session_directories = decode_table session_directories_yxml,
67493
c4e9e0c50487 treat sessions as entities with defining position;
wenzelm
parents: 67471
diff changeset
    33
           docs = decode_list doc_names_yxml,
67219
81e9804b2014 added document antiquotation @{session name};
wenzelm
parents: 66712
diff changeset
    34
           global_theories = decode_table global_theories_yxml,
70712
a3cfe859d915 find theories via session directories only -- ignore known_theories;
wenzelm
parents: 70683
diff changeset
    35
           loaded_theories = decode_list loaded_theories_yxml}
65470
a0f49174dbeb global session_base for PIDE interaction;
wenzelm
parents: 65300
diff changeset
    36
      end);
a0f49174dbeb global session_base for PIDE interaction;
wenzelm
parents: 65300
diff changeset
    37
a0f49174dbeb global session_base for PIDE interaction;
wenzelm
parents: 65300
diff changeset
    38
val _ =
54519
5fed81762406 maintain blobs within document state: digest + text in ML, digest-only in Scala;
wenzelm
parents: 53192
diff changeset
    39
  Isabelle_Process.protocol_command "Document.define_blob"
5fed81762406 maintain blobs within document state: digest + text in ML, digest-only in Scala;
wenzelm
parents: 53192
diff changeset
    40
    (fn [digest, content] => Document.change_state (Document.define_blob digest content));
5fed81762406 maintain blobs within document state: digest + text in ML, digest-only in Scala;
wenzelm
parents: 53192
diff changeset
    41
70664
2bd9e30183b1 prefer define_commands_bulk: fewer protocol messages;
wenzelm
parents: 70663
diff changeset
    42
fun decode_command id name blobs_xml toks_xml sources : Document.command =
70663
4a358f8c7cb7 clarified signature;
wenzelm
parents: 70284
diff changeset
    43
  let
4a358f8c7cb7 clarified signature;
wenzelm
parents: 70284
diff changeset
    44
    open XML.Decode;
4a358f8c7cb7 clarified signature;
wenzelm
parents: 70284
diff changeset
    45
    val (blobs_digests, blobs_index) =
70664
2bd9e30183b1 prefer define_commands_bulk: fewer protocol messages;
wenzelm
parents: 70663
diff changeset
    46
      blobs_xml |>
70663
4a358f8c7cb7 clarified signature;
wenzelm
parents: 70284
diff changeset
    47
        let
4a358f8c7cb7 clarified signature;
wenzelm
parents: 70284
diff changeset
    48
          val message = YXML.string_of_body o Protocol_Message.command_positions id;
4a358f8c7cb7 clarified signature;
wenzelm
parents: 70284
diff changeset
    49
        in
4a358f8c7cb7 clarified signature;
wenzelm
parents: 70284
diff changeset
    50
          pair
4a358f8c7cb7 clarified signature;
wenzelm
parents: 70284
diff changeset
    51
            (list (variant
4a358f8c7cb7 clarified signature;
wenzelm
parents: 70284
diff changeset
    52
             [fn ([], a) => Exn.Res (pair string (option string) a),
4a358f8c7cb7 clarified signature;
wenzelm
parents: 70284
diff changeset
    53
              fn ([], a) => Exn.Exn (ERROR (message a))]))
4a358f8c7cb7 clarified signature;
wenzelm
parents: 70284
diff changeset
    54
            int
4a358f8c7cb7 clarified signature;
wenzelm
parents: 70284
diff changeset
    55
        end;
70664
2bd9e30183b1 prefer define_commands_bulk: fewer protocol messages;
wenzelm
parents: 70663
diff changeset
    56
    val toks = list (pair int int) toks_xml;
70663
4a358f8c7cb7 clarified signature;
wenzelm
parents: 70284
diff changeset
    57
  in
4a358f8c7cb7 clarified signature;
wenzelm
parents: 70284
diff changeset
    58
   {command_id = Document_ID.parse id,
4a358f8c7cb7 clarified signature;
wenzelm
parents: 70284
diff changeset
    59
    name = name,
4a358f8c7cb7 clarified signature;
wenzelm
parents: 70284
diff changeset
    60
    blobs_digests = blobs_digests,
4a358f8c7cb7 clarified signature;
wenzelm
parents: 70284
diff changeset
    61
    blobs_index = blobs_index,
4a358f8c7cb7 clarified signature;
wenzelm
parents: 70284
diff changeset
    62
    tokens = toks ~~ sources}
4a358f8c7cb7 clarified signature;
wenzelm
parents: 70284
diff changeset
    63
  end;
4a358f8c7cb7 clarified signature;
wenzelm
parents: 70284
diff changeset
    64
71024
38bed2483e6a proper message (amending 94442fce40a5);
wenzelm
parents: 70991
diff changeset
    65
fun commands_accepted ids =
38bed2483e6a proper message (amending 94442fce40a5);
wenzelm
parents: 70991
diff changeset
    66
  Output.protocol_message Markup.commands_accepted [XML.Text (space_implode "," ids)];
70665
94442fce40a5 prefer commands_accepted: fewer protocol messages;
wenzelm
parents: 70664
diff changeset
    67
54519
5fed81762406 maintain blobs within document state: digest + text in ML, digest-only in Scala;
wenzelm
parents: 53192
diff changeset
    68
val _ =
46119
0d7172a7672c tuned signature -- emphasize special nature of protocol commands;
wenzelm
parents: 45709
diff changeset
    69
  Isabelle_Process.protocol_command "Document.define_command"
70664
2bd9e30183b1 prefer define_commands_bulk: fewer protocol messages;
wenzelm
parents: 70663
diff changeset
    70
    (fn id :: name :: blobs :: toks :: sources =>
2bd9e30183b1 prefer define_commands_bulk: fewer protocol messages;
wenzelm
parents: 70663
diff changeset
    71
      let
2bd9e30183b1 prefer define_commands_bulk: fewer protocol messages;
wenzelm
parents: 70663
diff changeset
    72
        val command = decode_command id name (YXML.parse_body blobs) (YXML.parse_body toks) sources;
70665
94442fce40a5 prefer commands_accepted: fewer protocol messages;
wenzelm
parents: 70664
diff changeset
    73
        val _ = Document.change_state (Document.define_command command);
94442fce40a5 prefer commands_accepted: fewer protocol messages;
wenzelm
parents: 70664
diff changeset
    74
      in commands_accepted [id] end);
70664
2bd9e30183b1 prefer define_commands_bulk: fewer protocol messages;
wenzelm
parents: 70663
diff changeset
    75
2bd9e30183b1 prefer define_commands_bulk: fewer protocol messages;
wenzelm
parents: 70663
diff changeset
    76
val _ =
2bd9e30183b1 prefer define_commands_bulk: fewer protocol messages;
wenzelm
parents: 70663
diff changeset
    77
  Isabelle_Process.protocol_command "Document.define_commands"
2bd9e30183b1 prefer define_commands_bulk: fewer protocol messages;
wenzelm
parents: 70663
diff changeset
    78
    (fn args =>
2bd9e30183b1 prefer define_commands_bulk: fewer protocol messages;
wenzelm
parents: 70663
diff changeset
    79
      let
2bd9e30183b1 prefer define_commands_bulk: fewer protocol messages;
wenzelm
parents: 70663
diff changeset
    80
        fun decode arg =
2bd9e30183b1 prefer define_commands_bulk: fewer protocol messages;
wenzelm
parents: 70663
diff changeset
    81
          let
2bd9e30183b1 prefer define_commands_bulk: fewer protocol messages;
wenzelm
parents: 70663
diff changeset
    82
            open XML.Decode;
2bd9e30183b1 prefer define_commands_bulk: fewer protocol messages;
wenzelm
parents: 70663
diff changeset
    83
            val (id, (name, (blobs_xml, (toks_xml, sources)))) =
2bd9e30183b1 prefer define_commands_bulk: fewer protocol messages;
wenzelm
parents: 70663
diff changeset
    84
              pair string (pair string (pair I (pair I (list string)))) (YXML.parse_body arg);
2bd9e30183b1 prefer define_commands_bulk: fewer protocol messages;
wenzelm
parents: 70663
diff changeset
    85
          in decode_command id name blobs_xml toks_xml sources end;
70665
94442fce40a5 prefer commands_accepted: fewer protocol messages;
wenzelm
parents: 70664
diff changeset
    86
94442fce40a5 prefer commands_accepted: fewer protocol messages;
wenzelm
parents: 70664
diff changeset
    87
        val commands = map decode args;
94442fce40a5 prefer commands_accepted: fewer protocol messages;
wenzelm
parents: 70664
diff changeset
    88
        val _ = Document.change_state (fold Document.define_command commands);
94442fce40a5 prefer commands_accepted: fewer protocol messages;
wenzelm
parents: 70664
diff changeset
    89
      in commands_accepted (map (Value.print_int o #command_id) commands) end);
38412
c23f3abbf42d moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff changeset
    90
38418
9a7af64d71bb more explicit / functional ML version of document model;
wenzelm
parents: 38417
diff changeset
    91
val _ =
47343
b8aeab386414 less aggressive discontinue_execution before document update, to avoid unstable execs that need to be re-assigned;
wenzelm
parents: 46938
diff changeset
    92
  Isabelle_Process.protocol_command "Document.discontinue_execution"
52606
0d68d108d7e0 tuned signature;
wenzelm
parents: 52605
diff changeset
    93
    (fn [] => Execution.discontinue ());
47343
b8aeab386414 less aggressive discontinue_execution before document update, to avoid unstable execs that need to be re-assigned;
wenzelm
parents: 46938
diff changeset
    94
b8aeab386414 less aggressive discontinue_execution before document update, to avoid unstable execs that need to be re-assigned;
wenzelm
parents: 46938
diff changeset
    95
val _ =
52931
ac6648c0c0fb cancel_query via direct access to the exec_id of the running query process;
wenzelm
parents: 52862
diff changeset
    96
  Isabelle_Process.protocol_command "Document.cancel_exec"
ac6648c0c0fb cancel_query via direct access to the exec_id of the running query process;
wenzelm
parents: 52862
diff changeset
    97
    (fn [exec_id] => Execution.cancel (Document_ID.parse exec_id));
ac6648c0c0fb cancel_query via direct access to the exec_id of the running query process;
wenzelm
parents: 52862
diff changeset
    98
ac6648c0c0fb cancel_query via direct access to the exec_id of the running query process;
wenzelm
parents: 52862
diff changeset
    99
val _ =
46119
0d7172a7672c tuned signature -- emphasize special nature of protocol commands;
wenzelm
parents: 45709
diff changeset
   100
  Isabelle_Process.protocol_command "Document.update"
59370
b13ff987c559 refrain from default task_context for all protocol commands, e.g. relevant for "build_theories" to admit Session.shutdown;
wenzelm
parents: 59366
diff changeset
   101
    (Future.task_context "Document.update" (Future.new_group NONE)
69849
09f200c658ed more scalable on 32-bit Poly/ML;
wenzelm
parents: 69846
diff changeset
   102
      (fn old_id_string :: new_id_string :: consolidate_yxml :: edits_yxml =>
68336
09ac56914b29 Document.update includes node consolidation / presentation as regular print operation: avoid user operations on protocol thread;
wenzelm
parents: 67493
diff changeset
   103
        Document.change_state (fn state =>
09ac56914b29 Document.update includes node consolidation / presentation as regular print operation: avoid user operations on protocol thread;
wenzelm
parents: 67493
diff changeset
   104
          let
09ac56914b29 Document.update includes node consolidation / presentation as regular print operation: avoid user operations on protocol thread;
wenzelm
parents: 67493
diff changeset
   105
            val old_id = Document_ID.parse old_id_string;
09ac56914b29 Document.update includes node consolidation / presentation as regular print operation: avoid user operations on protocol thread;
wenzelm
parents: 67493
diff changeset
   106
            val new_id = Document_ID.parse new_id_string;
69849
09f200c658ed more scalable on 32-bit Poly/ML;
wenzelm
parents: 69846
diff changeset
   107
            val consolidate =
09f200c658ed more scalable on 32-bit Poly/ML;
wenzelm
parents: 69846
diff changeset
   108
              YXML.parse_body consolidate_yxml |>
09f200c658ed more scalable on 32-bit Poly/ML;
wenzelm
parents: 69846
diff changeset
   109
                let open XML.Decode in list string end;
68336
09ac56914b29 Document.update includes node consolidation / presentation as regular print operation: avoid user operations on protocol thread;
wenzelm
parents: 67493
diff changeset
   110
            val edits =
69849
09f200c658ed more scalable on 32-bit Poly/ML;
wenzelm
parents: 69846
diff changeset
   111
              edits_yxml |> map (YXML.parse_body #>
68336
09ac56914b29 Document.update includes node consolidation / presentation as regular print operation: avoid user operations on protocol thread;
wenzelm
parents: 67493
diff changeset
   112
                let open XML.Decode in
69849
09f200c658ed more scalable on 32-bit Poly/ML;
wenzelm
parents: 69846
diff changeset
   113
                  pair string
68336
09ac56914b29 Document.update includes node consolidation / presentation as regular print operation: avoid user operations on protocol thread;
wenzelm
parents: 67493
diff changeset
   114
                    (variant
09ac56914b29 Document.update includes node consolidation / presentation as regular print operation: avoid user operations on protocol thread;
wenzelm
parents: 67493
diff changeset
   115
                     [fn ([], a) => Document.Edits (list (pair (option int) (option int)) a),
09ac56914b29 Document.update includes node consolidation / presentation as regular print operation: avoid user operations on protocol thread;
wenzelm
parents: 67493
diff changeset
   116
                      fn ([], a) =>
09ac56914b29 Document.update includes node consolidation / presentation as regular print operation: avoid user operations on protocol thread;
wenzelm
parents: 67493
diff changeset
   117
                        let
09ac56914b29 Document.update includes node consolidation / presentation as regular print operation: avoid user operations on protocol thread;
wenzelm
parents: 67493
diff changeset
   118
                          val (master, (name, (imports, (keywords, errors)))) =
09ac56914b29 Document.update includes node consolidation / presentation as regular print operation: avoid user operations on protocol thread;
wenzelm
parents: 67493
diff changeset
   119
                            pair string (pair string (pair (list string)
09ac56914b29 Document.update includes node consolidation / presentation as regular print operation: avoid user operations on protocol thread;
wenzelm
parents: 67493
diff changeset
   120
                              (pair (list (pair string
09ac56914b29 Document.update includes node consolidation / presentation as regular print operation: avoid user operations on protocol thread;
wenzelm
parents: 67493
diff changeset
   121
                                (pair (pair string (list string)) (list string))))
09ac56914b29 Document.update includes node consolidation / presentation as regular print operation: avoid user operations on protocol thread;
wenzelm
parents: 67493
diff changeset
   122
                                (list YXML.string_of_body)))) a;
09ac56914b29 Document.update includes node consolidation / presentation as regular print operation: avoid user operations on protocol thread;
wenzelm
parents: 67493
diff changeset
   123
                          val imports' = map (rpair Position.none) imports;
09ac56914b29 Document.update includes node consolidation / presentation as regular print operation: avoid user operations on protocol thread;
wenzelm
parents: 67493
diff changeset
   124
                          val keywords' = map (fn (x, y) => ((x, Position.none), y)) keywords;
09ac56914b29 Document.update includes node consolidation / presentation as regular print operation: avoid user operations on protocol thread;
wenzelm
parents: 67493
diff changeset
   125
                          val header = Thy_Header.make (name, Position.none) imports' keywords';
09ac56914b29 Document.update includes node consolidation / presentation as regular print operation: avoid user operations on protocol thread;
wenzelm
parents: 67493
diff changeset
   126
                        in Document.Deps {master = master, header = header, errors = errors} end,
09ac56914b29 Document.update includes node consolidation / presentation as regular print operation: avoid user operations on protocol thread;
wenzelm
parents: 67493
diff changeset
   127
                      fn (a :: b, c) =>
09ac56914b29 Document.update includes node consolidation / presentation as regular print operation: avoid user operations on protocol thread;
wenzelm
parents: 67493
diff changeset
   128
                        Document.Perspective (bool_atom a, map int_atom b,
69849
09f200c658ed more scalable on 32-bit Poly/ML;
wenzelm
parents: 69846
diff changeset
   129
                          list (pair int (pair string (list string))) c)])
09f200c658ed more scalable on 32-bit Poly/ML;
wenzelm
parents: 69846
diff changeset
   130
                end);
47404
e6e5750f1311 simplified Future.cancel/cancel_group (again) -- running threads only;
wenzelm
parents: 47388
diff changeset
   131
68336
09ac56914b29 Document.update includes node consolidation / presentation as regular print operation: avoid user operations on protocol thread;
wenzelm
parents: 67493
diff changeset
   132
            val _ = Execution.discontinue ();
38412
c23f3abbf42d moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff changeset
   133
70284
3e17c3a5fd39 more thorough assignment, e.g. when "purge" removes commands that were not assigned;
wenzelm
parents: 69849
diff changeset
   134
            val (edited, removed, assign_update, state') =
68336
09ac56914b29 Document.update includes node consolidation / presentation as regular print operation: avoid user operations on protocol thread;
wenzelm
parents: 67493
diff changeset
   135
              Document.update old_id new_id edits consolidate state;
09ac56914b29 Document.update includes node consolidation / presentation as regular print operation: avoid user operations on protocol thread;
wenzelm
parents: 67493
diff changeset
   136
            val _ =
09ac56914b29 Document.update includes node consolidation / presentation as regular print operation: avoid user operations on protocol thread;
wenzelm
parents: 67493
diff changeset
   137
              (singleton o Future.forks)
09ac56914b29 Document.update includes node consolidation / presentation as regular print operation: avoid user operations on protocol thread;
wenzelm
parents: 67493
diff changeset
   138
               {name = "Document.update/remove", group = NONE,
09ac56914b29 Document.update includes node consolidation / presentation as regular print operation: avoid user operations on protocol thread;
wenzelm
parents: 67493
diff changeset
   139
                deps = Execution.snapshot removed,
09ac56914b29 Document.update includes node consolidation / presentation as regular print operation: avoid user operations on protocol thread;
wenzelm
parents: 67493
diff changeset
   140
                pri = Task_Queue.urgent_pri + 2, interrupts = false}
09ac56914b29 Document.update includes node consolidation / presentation as regular print operation: avoid user operations on protocol thread;
wenzelm
parents: 67493
diff changeset
   141
               (fn () => (Execution.purge removed; List.app Isabelle_Process.reset_tracing removed));
52601
55e62a25a7ce tuned -- cleanup before publishing assignment;
wenzelm
parents: 52596
diff changeset
   142
68336
09ac56914b29 Document.update includes node consolidation / presentation as regular print operation: avoid user operations on protocol thread;
wenzelm
parents: 67493
diff changeset
   143
            val _ =
09ac56914b29 Document.update includes node consolidation / presentation as regular print operation: avoid user operations on protocol thread;
wenzelm
parents: 67493
diff changeset
   144
              Output.protocol_message Markup.assign_update
70284
3e17c3a5fd39 more thorough assignment, e.g. when "purge" removes commands that were not assigned;
wenzelm
parents: 69849
diff changeset
   145
                ((new_id, edited, assign_update) |>
69846
e02e3763e7a4 more compact representation: approx. factor 2;
wenzelm
parents: 69845
diff changeset
   146
                  let
e02e3763e7a4 more compact representation: approx. factor 2;
wenzelm
parents: 69845
diff changeset
   147
                    open XML.Encode;
e02e3763e7a4 more compact representation: approx. factor 2;
wenzelm
parents: 69845
diff changeset
   148
                    fun encode_upd (a, bs) =
e02e3763e7a4 more compact representation: approx. factor 2;
wenzelm
parents: 69845
diff changeset
   149
                      string (space_implode "," (map Value.print_int (a :: bs)));
70991
f9f7c34b7dd4 more scalable protocol_message: use XML.body directly (Output.output hook is not required);
wenzelm
parents: 70712
diff changeset
   150
                  in triple int (list string) (list encode_upd) end);
68336
09ac56914b29 Document.update includes node consolidation / presentation as regular print operation: avoid user operations on protocol thread;
wenzelm
parents: 67493
diff changeset
   151
          in Document.start_execution state' end)));
38412
c23f3abbf42d moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff changeset
   152
43748
c70bd78ec83c JVM method invocation service via Scala layer;
wenzelm
parents: 43731
diff changeset
   153
val _ =
46119
0d7172a7672c tuned signature -- emphasize special nature of protocol commands;
wenzelm
parents: 45709
diff changeset
   154
  Isabelle_Process.protocol_command "Document.remove_versions"
44673
2fa51ac191bc Document.remove_versions on ML side;
wenzelm
parents: 44661
diff changeset
   155
    (fn [versions_yxml] => Document.change_state (fn state =>
2fa51ac191bc Document.remove_versions on ML side;
wenzelm
parents: 44661
diff changeset
   156
      let
2fa51ac191bc Document.remove_versions on ML side;
wenzelm
parents: 44661
diff changeset
   157
        val versions =
2fa51ac191bc Document.remove_versions on ML side;
wenzelm
parents: 44661
diff changeset
   158
          YXML.parse_body versions_yxml |>
2fa51ac191bc Document.remove_versions on ML side;
wenzelm
parents: 44661
diff changeset
   159
            let open XML.Decode in list int end;
44676
7de87f1ae965 Document.removed_versions on Scala side;
wenzelm
parents: 44673
diff changeset
   160
        val state1 = Document.remove_versions versions state;
70991
f9f7c34b7dd4 more scalable protocol_message: use XML.body directly (Output.output hook is not required);
wenzelm
parents: 70712
diff changeset
   161
        val _ = Output.protocol_message Markup.removed_versions [XML.Text (versions_yxml)];
44676
7de87f1ae965 Document.removed_versions on Scala side;
wenzelm
parents: 44673
diff changeset
   162
      in state1 end));
44673
2fa51ac191bc Document.remove_versions on ML side;
wenzelm
parents: 44661
diff changeset
   163
2fa51ac191bc Document.remove_versions on ML side;
wenzelm
parents: 44661
diff changeset
   164
val _ =
50498
6647ba2775c1 support dialog via document content;
wenzelm
parents: 50201
diff changeset
   165
  Isabelle_Process.protocol_command "Document.dialog_result"
50500
c94bba7906d2 identify dialogs via official serial and maintain as result message;
wenzelm
parents: 50498
diff changeset
   166
    (fn [serial, result] =>
63806
c54a53ef1873 clarified modules;
wenzelm
parents: 63429
diff changeset
   167
      Active.dialog_result (Value.parse_int serial) result
62505
9e2a65912111 clarified modules;
wenzelm
parents: 62467
diff changeset
   168
        handle exn => if Exn.is_interrupt exn then () (*sic!*) else Exn.reraise exn);
50498
6647ba2775c1 support dialog via document content;
wenzelm
parents: 50201
diff changeset
   169
56616
abc2da18d08d added protocol command "use_theories", with core functionality of batch build;
wenzelm
parents: 56458
diff changeset
   170
val _ =
62467
c1b88e647e2f clarified ML heap operations;
wenzelm
parents: 61381
diff changeset
   171
  Isabelle_Process.protocol_command "ML_Heap.share_common_data"
c1b88e647e2f clarified ML heap operations;
wenzelm
parents: 61381
diff changeset
   172
    (fn [] => ML_Heap.share_common_data ());
57868
0b954ac94827 protocol command for heap management, e.g. in Isabelle/jEdit/Scala console: PIDE.session.protocol_command("ML_System.share_common_data");
wenzelm
parents: 56616
diff changeset
   173
38412
c23f3abbf42d moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff changeset
   174
end;
c23f3abbf42d moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff changeset
   175