| author | traytel |
| Thu, 25 Jul 2013 16:46:53 +0200 | |
| changeset 52731 | dacd47a0633f |
| parent 52655 | 3b2b1ef13979 |
| child 52760 | 8517172b9626 |
| permissions | -rw-r--r-- |
|
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 _ = |
| 52585 | 11 |
Isabelle_Process.protocol_command "echo" (fn args => List.app writeln args); |
12 |
||
13 |
val _ = |
|
|
46119
0d7172a7672c
tuned signature -- emphasize special nature of protocol commands;
wenzelm
parents:
45709
diff
changeset
|
14 |
Isabelle_Process.protocol_command "Document.define_command" |
|
44644
317e4962dd0f
clarified define_command: store name as structural information;
wenzelm
parents:
44612
diff
changeset
|
15 |
(fn [id, name, text] => |
|
52530
99dd8b4ef3fe
explicit module Document_ID as source of globally unique identifiers across ML/Scala;
wenzelm
parents:
52527
diff
changeset
|
16 |
Document.change_state (Document.define_command (Document_ID.parse id) name text)); |
|
38412
c23f3abbf42d
moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff
changeset
|
17 |
|
|
38418
9a7af64d71bb
more explicit / functional ML version of document model;
wenzelm
parents:
38417
diff
changeset
|
18 |
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
|
19 |
Isabelle_Process.protocol_command "Document.discontinue_execution" |
| 52606 | 20 |
(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
|
21 |
|
|
b8aeab386414
less aggressive discontinue_execution before document update, to avoid unstable execs that need to be re-assigned;
wenzelm
parents:
46938
diff
changeset
|
22 |
val _ = |
|
46119
0d7172a7672c
tuned signature -- emphasize special nature of protocol commands;
wenzelm
parents:
45709
diff
changeset
|
23 |
Isabelle_Process.protocol_command "Document.cancel_execution" |
|
52607
33a133d50616
clarified execution: maintain running execs only, check "stable" separately via memo (again);
wenzelm
parents:
52606
diff
changeset
|
24 |
(fn [] => |
|
33a133d50616
clarified execution: maintain running execs only, check "stable" separately via memo (again);
wenzelm
parents:
52606
diff
changeset
|
25 |
let |
|
33a133d50616
clarified execution: maintain running execs only, check "stable" separately via memo (again);
wenzelm
parents:
52606
diff
changeset
|
26 |
val _ = Execution.discontinue (); |
|
33a133d50616
clarified execution: maintain running execs only, check "stable" separately via memo (again);
wenzelm
parents:
52606
diff
changeset
|
27 |
val groups = Execution.snapshot (); |
|
33a133d50616
clarified execution: maintain running execs only, check "stable" separately via memo (again);
wenzelm
parents:
52606
diff
changeset
|
28 |
val _ = List.app Future.cancel_group groups; |
|
33a133d50616
clarified execution: maintain running execs only, check "stable" separately via memo (again);
wenzelm
parents:
52606
diff
changeset
|
29 |
val _ = List.app Future.terminate groups; |
|
33a133d50616
clarified execution: maintain running execs only, check "stable" separately via memo (again);
wenzelm
parents:
52606
diff
changeset
|
30 |
in () end); |
|
44612
990ac978854c
explicit cancel_execution before queueing new edits -- potential performance improvement for machines with few cores;
wenzelm
parents:
44610
diff
changeset
|
31 |
|
|
990ac978854c
explicit cancel_execution before queueing new edits -- potential performance improvement for machines with few cores;
wenzelm
parents:
44610
diff
changeset
|
32 |
val _ = |
|
46119
0d7172a7672c
tuned signature -- emphasize special nature of protocol commands;
wenzelm
parents:
45709
diff
changeset
|
33 |
Isabelle_Process.protocol_command "Document.update" |
|
44157
a21d3e1e64fd
uniform treatment of header edits as document edits;
wenzelm
parents:
44156
diff
changeset
|
34 |
(fn [old_id_string, new_id_string, edits_yxml] => Document.change_state (fn state => |
|
38418
9a7af64d71bb
more explicit / functional ML version of document model;
wenzelm
parents:
38417
diff
changeset
|
35 |
let |
| 52606 | 36 |
val _ = Execution.discontinue (); |
|
47404
e6e5750f1311
simplified Future.cancel/cancel_group (again) -- running threads only;
wenzelm
parents:
47388
diff
changeset
|
37 |
|
|
52530
99dd8b4ef3fe
explicit module Document_ID as source of globally unique identifiers across ML/Scala;
wenzelm
parents:
52527
diff
changeset
|
38 |
val old_id = Document_ID.parse old_id_string; |
|
99dd8b4ef3fe
explicit module Document_ID as source of globally unique identifiers across ML/Scala;
wenzelm
parents:
52527
diff
changeset
|
39 |
val new_id = Document_ID.parse new_id_string; |
|
44157
a21d3e1e64fd
uniform treatment of header edits as document edits;
wenzelm
parents:
44156
diff
changeset
|
40 |
val edits = |
|
a21d3e1e64fd
uniform treatment of header edits as document edits;
wenzelm
parents:
44156
diff
changeset
|
41 |
YXML.parse_body edits_yxml |> |
|
a21d3e1e64fd
uniform treatment of header edits as document edits;
wenzelm
parents:
44156
diff
changeset
|
42 |
let open XML.Decode in |
|
a21d3e1e64fd
uniform treatment of header edits as document edits;
wenzelm
parents:
44156
diff
changeset
|
43 |
list (pair string |
|
a21d3e1e64fd
uniform treatment of header edits as document edits;
wenzelm
parents:
44156
diff
changeset
|
44 |
(variant |
|
48755
393a37003851
apply all text edits to each node, before determining the resulting doc_edits -- allow several iterations to consolidate spans etc.;
wenzelm
parents:
48707
diff
changeset
|
45 |
[fn ([], []) => Document.Clear, (* FIXME unused !? *) |
|
44157
a21d3e1e64fd
uniform treatment of header edits as document edits;
wenzelm
parents:
44156
diff
changeset
|
46 |
fn ([], a) => Document.Edits (list (pair (option int) (option int)) a), |
|
a21d3e1e64fd
uniform treatment of header edits as document edits;
wenzelm
parents:
44156
diff
changeset
|
47 |
fn ([], a) => |
|
46938
cda018294515
some support for outer syntax keyword declarations within theory header;
wenzelm
parents:
46774
diff
changeset
|
48 |
let |
|
51294
0850d43cb355
discontinued obsolete header "files" -- these are loaded explicitly after exploring dependencies;
wenzelm
parents:
51293
diff
changeset
|
49 |
val (master, (name, (imports, (keywords, errors)))) = |
|
48707
ba531af91148
simplified Document.Node.Header -- internalized errors;
wenzelm
parents:
47420
diff
changeset
|
50 |
pair string (pair string (pair (list string) |
|
48864
3ee314ae1e0a
added keyword kind "thy_load" (with optional list of file extensions);
wenzelm
parents:
48755
diff
changeset
|
51 |
(pair (list (pair string |
|
3ee314ae1e0a
added keyword kind "thy_load" (with optional list of file extensions);
wenzelm
parents:
48755
diff
changeset
|
52 |
(option (pair (pair string (list string)) (list string))))) |
|
51294
0850d43cb355
discontinued obsolete header "files" -- these are loaded explicitly after exploring dependencies;
wenzelm
parents:
51293
diff
changeset
|
53 |
(list string)))) a; |
|
48927
ef462b5558eb
theory def/ref position reports, which enable hyperlinks etc.;
wenzelm
parents:
48864
diff
changeset
|
54 |
val imports' = map (rpair Position.none) imports; |
|
51294
0850d43cb355
discontinued obsolete header "files" -- these are loaded explicitly after exploring dependencies;
wenzelm
parents:
51293
diff
changeset
|
55 |
val header = Thy_Header.make (name, Position.none) imports' keywords; |
|
0850d43cb355
discontinued obsolete header "files" -- these are loaded explicitly after exploring dependencies;
wenzelm
parents:
51293
diff
changeset
|
56 |
in Document.Deps (master, header, errors) end, |
| 44384 | 57 |
fn (a, []) => Document.Perspective (map int_atom a)])) |
|
44157
a21d3e1e64fd
uniform treatment of header edits as document edits;
wenzelm
parents:
44156
diff
changeset
|
58 |
end; |
|
38412
c23f3abbf42d
moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff
changeset
|
59 |
|
|
52655
3b2b1ef13979
more careful termination of removed execs, leaving running execs undisturbed;
wenzelm
parents:
52607
diff
changeset
|
60 |
val (removed, assign_update, state') = Document.update old_id new_id edits state; |
|
3b2b1ef13979
more careful termination of removed execs, leaving running execs undisturbed;
wenzelm
parents:
52607
diff
changeset
|
61 |
val _ = List.app Execution.terminate removed; |
|
3b2b1ef13979
more careful termination of removed execs, leaving running execs undisturbed;
wenzelm
parents:
52607
diff
changeset
|
62 |
val _ = List.app Isabelle_Process.reset_tracing removed; |
| 52601 | 63 |
|
64 |
val _ = |
|
65 |
Output.protocol_message Markup.assign_update |
|
66 |
((new_id, assign_update) |> |
|
67 |
let open XML.Encode |
|
68 |
in pair int (list (pair int (list int))) end |
|
69 |
|> YXML.string_of_body); |
|
|
52573
815461c835b9
tuned start_execution: avoid sleep on worker thread;
wenzelm
parents:
52563
diff
changeset
|
70 |
val _ = |
| 52579 | 71 |
Event_Timer.request (Time.+ (Time.now (), seconds 0.02)) |
|
52573
815461c835b9
tuned start_execution: avoid sleep on worker thread;
wenzelm
parents:
52563
diff
changeset
|
72 |
(fn () => Document.start_execution state'); |
|
47420
0dbe6c69eda2
just one dedicated execution per document version -- NB: non-monotonicity of cancel always requires fresh update;
wenzelm
parents:
47404
diff
changeset
|
73 |
in state' end)); |
|
38412
c23f3abbf42d
moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff
changeset
|
74 |
|
| 43748 | 75 |
val _ = |
|
46119
0d7172a7672c
tuned signature -- emphasize special nature of protocol commands;
wenzelm
parents:
45709
diff
changeset
|
76 |
Isabelle_Process.protocol_command "Document.remove_versions" |
| 44673 | 77 |
(fn [versions_yxml] => Document.change_state (fn state => |
78 |
let |
|
79 |
val versions = |
|
80 |
YXML.parse_body versions_yxml |> |
|
81 |
let open XML.Decode in list int end; |
|
| 44676 | 82 |
val state1 = Document.remove_versions versions state; |
|
50201
c26369c9eda6
Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
wenzelm
parents:
49931
diff
changeset
|
83 |
val _ = Output.protocol_message Markup.removed_versions versions_yxml; |
| 44676 | 84 |
in state1 end)); |
| 44673 | 85 |
|
86 |
val _ = |
|
| 50498 | 87 |
Isabelle_Process.protocol_command "Document.dialog_result" |
|
50500
c94bba7906d2
identify dialogs via official serial and maintain as result message;
wenzelm
parents:
50498
diff
changeset
|
88 |
(fn [serial, result] => |
|
c94bba7906d2
identify dialogs via official serial and maintain as result message;
wenzelm
parents:
50498
diff
changeset
|
89 |
Active.dialog_result (Markup.parse_int serial) result |
| 50498 | 90 |
handle exn => if Exn.is_interrupt exn then () else reraise exn); |
91 |
||
|
38412
c23f3abbf42d
moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff
changeset
|
92 |
end; |
|
c23f3abbf42d
moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff
changeset
|
93 |