author | wenzelm |
Fri, 02 Aug 2013 14:26:09 +0200 | |
changeset 52849 | 199e9fa5a5c2 |
parent 52808 | 143f225e50f5 |
child 52862 | 930ce8eacb87 |
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 _ = |
52786 | 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); |
|
52585 | 24 |
|
25 |
val _ = |
|
46119
0d7172a7672c
tuned signature -- emphasize special nature of protocol commands;
wenzelm
parents:
45709
diff
changeset
|
26 |
Isabelle_Process.protocol_command "Document.define_command" |
44644
317e4962dd0f
clarified define_command: store name as structural information;
wenzelm
parents:
44612
diff
changeset
|
27 |
(fn [id, name, text] => |
52530
99dd8b4ef3fe
explicit module Document_ID as source of globally unique identifiers across ML/Scala;
wenzelm
parents:
52527
diff
changeset
|
28 |
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
|
29 |
|
38418
9a7af64d71bb
more explicit / functional ML version of document model;
wenzelm
parents:
38417
diff
changeset
|
30 |
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
|
31 |
Isabelle_Process.protocol_command "Document.discontinue_execution" |
52606 | 32 |
(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
|
33 |
|
b8aeab386414
less aggressive discontinue_execution before document update, to avoid unstable execs that need to be re-assigned;
wenzelm
parents:
46938
diff
changeset
|
34 |
val _ = |
46119
0d7172a7672c
tuned signature -- emphasize special nature of protocol commands;
wenzelm
parents:
45709
diff
changeset
|
35 |
Isabelle_Process.protocol_command "Document.update" |
44157
a21d3e1e64fd
uniform treatment of header edits as document edits;
wenzelm
parents:
44156
diff
changeset
|
36 |
(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
|
37 |
let |
52606 | 38 |
val _ = Execution.discontinue (); |
47404
e6e5750f1311
simplified Future.cancel/cancel_group (again) -- running threads only;
wenzelm
parents:
47388
diff
changeset
|
39 |
|
52530
99dd8b4ef3fe
explicit module Document_ID as source of globally unique identifiers across ML/Scala;
wenzelm
parents:
52527
diff
changeset
|
40 |
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
|
41 |
val new_id = Document_ID.parse new_id_string; |
44157
a21d3e1e64fd
uniform treatment of header edits as document edits;
wenzelm
parents:
44156
diff
changeset
|
42 |
val edits = |
a21d3e1e64fd
uniform treatment of header edits as document edits;
wenzelm
parents:
44156
diff
changeset
|
43 |
YXML.parse_body edits_yxml |> |
a21d3e1e64fd
uniform treatment of header edits as document edits;
wenzelm
parents:
44156
diff
changeset
|
44 |
let open XML.Decode in |
a21d3e1e64fd
uniform treatment of header edits as document edits;
wenzelm
parents:
44156
diff
changeset
|
45 |
list (pair string |
a21d3e1e64fd
uniform treatment of header edits as document edits;
wenzelm
parents:
44156
diff
changeset
|
46 |
(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
|
47 |
[fn ([], []) => Document.Clear, (* FIXME unused !? *) |
44157
a21d3e1e64fd
uniform treatment of header edits as document edits;
wenzelm
parents:
44156
diff
changeset
|
48 |
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
|
49 |
fn ([], a) => |
46938
cda018294515
some support for outer syntax keyword declarations within theory header;
wenzelm
parents:
46774
diff
changeset
|
50 |
let |
51294
0850d43cb355
discontinued obsolete header "files" -- these are loaded explicitly after exploring dependencies;
wenzelm
parents:
51293
diff
changeset
|
51 |
val (master, (name, (imports, (keywords, errors)))) = |
48707
ba531af91148
simplified Document.Node.Header -- internalized errors;
wenzelm
parents:
47420
diff
changeset
|
52 |
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
|
53 |
(pair (list (pair string |
3ee314ae1e0a
added keyword kind "thy_load" (with optional list of file extensions);
wenzelm
parents:
48755
diff
changeset
|
54 |
(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
|
55 |
(list string)))) a; |
48927
ef462b5558eb
theory def/ref position reports, which enable hyperlinks etc.;
wenzelm
parents:
48864
diff
changeset
|
56 |
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
|
57 |
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
|
58 |
in Document.Deps (master, header, errors) end, |
52849 | 59 |
fn (a :: b, c) => |
60 |
Document.Perspective (bool_atom a, map int_atom b, |
|
61 |
list (triple int string (list string)) c)])) |
|
44157
a21d3e1e64fd
uniform treatment of header edits as document edits;
wenzelm
parents:
44156
diff
changeset
|
62 |
end; |
38412
c23f3abbf42d
moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff
changeset
|
63 |
|
52655
3b2b1ef13979
more careful termination of removed execs, leaving running execs undisturbed;
wenzelm
parents:
52607
diff
changeset
|
64 |
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
|
65 |
val _ = List.app Execution.terminate removed; |
52765
260949bf6529
actually purge removed goal futures -- avoid memory leak;
wenzelm
parents:
52760
diff
changeset
|
66 |
val _ = Goal.purge_futures removed; |
52655
3b2b1ef13979
more careful termination of removed execs, leaving running execs undisturbed;
wenzelm
parents:
52607
diff
changeset
|
67 |
val _ = List.app Isabelle_Process.reset_tracing removed; |
52601 | 68 |
|
69 |
val _ = |
|
70 |
Output.protocol_message Markup.assign_update |
|
71 |
((new_id, assign_update) |> |
|
72 |
let open XML.Encode |
|
73 |
in pair int (list (pair int (list int))) end |
|
74 |
|> YXML.string_of_body); |
|
52774
627fb639a2d9
maintain explicit execution frontier: avoid conflict with former task via static dependency;
wenzelm
parents:
52765
diff
changeset
|
75 |
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
|
76 |
|
43748 | 77 |
val _ = |
46119
0d7172a7672c
tuned signature -- emphasize special nature of protocol commands;
wenzelm
parents:
45709
diff
changeset
|
78 |
Isabelle_Process.protocol_command "Document.remove_versions" |
44673 | 79 |
(fn [versions_yxml] => Document.change_state (fn state => |
80 |
let |
|
81 |
val versions = |
|
82 |
YXML.parse_body versions_yxml |> |
|
83 |
let open XML.Decode in list int end; |
|
44676 | 84 |
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
|
85 |
val _ = Output.protocol_message Markup.removed_versions versions_yxml; |
44676 | 86 |
in state1 end)); |
44673 | 87 |
|
88 |
val _ = |
|
50498 | 89 |
Isabelle_Process.protocol_command "Document.dialog_result" |
50500
c94bba7906d2
identify dialogs via official serial and maintain as result message;
wenzelm
parents:
50498
diff
changeset
|
90 |
(fn [serial, result] => |
c94bba7906d2
identify dialogs via official serial and maintain as result message;
wenzelm
parents:
50498
diff
changeset
|
91 |
Active.dialog_result (Markup.parse_int serial) result |
52775
e0169f13bd37
keep memo_exec execution running, which is important to cancel goal forks eventually;
wenzelm
parents:
52774
diff
changeset
|
92 |
handle exn => if Exn.is_interrupt exn then () (*sic!*) else reraise exn); |
50498 | 93 |
|
38412
c23f3abbf42d
moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff
changeset
|
94 |
end; |
c23f3abbf42d
moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff
changeset
|
95 |