author | wenzelm |
Sat, 21 Nov 2015 20:13:52 +0100 | |
changeset 61728 | 5f5ff1eab407 |
parent 61381 | ddca85598c65 |
child 62467 | c1b88e647e2f |
permissions | -rw-r--r-- |
56210 | 1 |
(* Title: Pure/PIDE/session.ML |
52052
892061142ba6
discontinued obsolete isabelle usedir, mkdir, make;
wenzelm
parents:
52050
diff
changeset
|
2 |
Author: Makarius |
6346 | 3 |
|
56210 | 4 |
Prover session: persistent state of logic image. |
6346 | 5 |
*) |
6 |
||
7 |
signature SESSION = |
|
8 |
sig |
|
60081 | 9 |
val get_name: unit -> string |
6346 | 10 |
val welcome: unit -> string |
59086
94b2690ad494
node-specific keywords, with session base syntax as default;
wenzelm
parents:
58928
diff
changeset
|
11 |
val get_keywords: unit -> Keyword.keywords |
61381 | 12 |
val init: HTML.symbols -> bool -> bool -> Path.T -> string -> string -> (string * string) list -> |
59445 | 13 |
(Path.T * Path.T) list -> Path.T -> string -> string * string -> bool -> unit |
59369
7090199d3f78
more informative build_theories_result: cumulative Runtime.exn_message;
wenzelm
parents:
59345
diff
changeset
|
14 |
val shutdown: unit -> unit |
48457 | 15 |
val finish: unit -> unit |
59344
e0ce214303c1
proper Session.save with shutdown, which is relevant to avoid persistent threads;
wenzelm
parents:
59086
diff
changeset
|
16 |
val save: string -> unit |
52111
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents:
52083
diff
changeset
|
17 |
val protocol_handler: string -> unit |
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents:
52083
diff
changeset
|
18 |
val init_protocol_handlers: unit -> unit |
6346 | 19 |
end; |
20 |
||
21 |
structure Session: SESSION = |
|
22 |
struct |
|
23 |
||
52111
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents:
52083
diff
changeset
|
24 |
(** session identification -- not thread-safe **) |
6346 | 25 |
|
51399
6ac3c29a300e
discontinued "isabelle usedir" option -r (reset session path);
wenzelm
parents:
51398
diff
changeset
|
26 |
val session = Unsynchronized.ref {chapter = "Pure", name = "Pure"}; |
32738 | 27 |
val session_finished = Unsynchronized.ref false; |
48542 | 28 |
|
60081 | 29 |
fun get_name () = #name (! session); |
30 |
||
31 |
fun description () = "Isabelle/" ^ get_name (); |
|
30173
eabece26b89b
moved isabelle_process.ML, isabelle_process.scala, isar.ML, session.ML to Pure/System/ (together with associated Isar commands);
wenzelm
parents:
29435
diff
changeset
|
32 |
|
26109
c69c3559355b
more elaborate structure Distribution (filled-in by makedist);
wenzelm
parents:
25840
diff
changeset
|
33 |
fun welcome () = |
57649
a43898f76ae9
further distinction of Isabelle distribution: alert for identified release candidates;
wenzelm
parents:
56533
diff
changeset
|
34 |
if Distribution.is_identified then |
60081 | 35 |
"Welcome to " ^ description () ^ " (" ^ Distribution.version ^ ")" |
36 |
else "Unofficial version of " ^ description () ^ " (" ^ Distribution.version ^ ")"; |
|
6346 | 37 |
|
38 |
||
59086
94b2690ad494
node-specific keywords, with session base syntax as default;
wenzelm
parents:
58928
diff
changeset
|
39 |
(* base syntax *) |
94b2690ad494
node-specific keywords, with session base syntax as default;
wenzelm
parents:
58928
diff
changeset
|
40 |
|
94b2690ad494
node-specific keywords, with session base syntax as default;
wenzelm
parents:
58928
diff
changeset
|
41 |
val keywords = Unsynchronized.ref Keyword.empty_keywords; |
94b2690ad494
node-specific keywords, with session base syntax as default;
wenzelm
parents:
58928
diff
changeset
|
42 |
fun get_keywords () = ! keywords; |
94b2690ad494
node-specific keywords, with session base syntax as default;
wenzelm
parents:
58928
diff
changeset
|
43 |
|
94b2690ad494
node-specific keywords, with session base syntax as default;
wenzelm
parents:
58928
diff
changeset
|
44 |
|
51399
6ac3c29a300e
discontinued "isabelle usedir" option -r (reset session path);
wenzelm
parents:
51398
diff
changeset
|
45 |
(* init *) |
9414 | 46 |
|
61381 | 47 |
fun init symbols build info info_path doc doc_output doc_variants doc_files graph_file |
56530
5c178501cf78
removed obsolete doc_dump option (see also 892061142ba6);
wenzelm
parents:
56333
diff
changeset
|
48 |
parent (chapter, name) verbose = |
60081 | 49 |
if get_name () <> parent orelse not (! session_finished) then |
6346 | 50 |
error ("Unfinished parent session " ^ quote parent ^ " for " ^ quote name) |
51399
6ac3c29a300e
discontinued "isabelle usedir" option -r (reset session path);
wenzelm
parents:
51398
diff
changeset
|
51 |
else |
6ac3c29a300e
discontinued "isabelle usedir" option -r (reset session path);
wenzelm
parents:
51398
diff
changeset
|
52 |
let |
6ac3c29a300e
discontinued "isabelle usedir" option -r (reset session path);
wenzelm
parents:
51398
diff
changeset
|
53 |
val _ = session := {chapter = chapter, name = name}; |
6ac3c29a300e
discontinued "isabelle usedir" option -r (reset session path);
wenzelm
parents:
51398
diff
changeset
|
54 |
val _ = session_finished := false; |
6ac3c29a300e
discontinued "isabelle usedir" option -r (reset session path);
wenzelm
parents:
51398
diff
changeset
|
55 |
in |
61381 | 56 |
Present.init symbols build info info_path (if doc = "false" then "" else doc) |
59448
149d2bc5ddb6
prefer plain session_graph.pdf over GraphBrowser applet;
wenzelm
parents:
59446
diff
changeset
|
57 |
doc_output doc_variants doc_files graph_file (chapter, name) verbose |
51399
6ac3c29a300e
discontinued "isabelle usedir" option -r (reset session path);
wenzelm
parents:
51398
diff
changeset
|
58 |
end; |
6346 | 59 |
|
60 |
||
61 |
(* finish *) |
|
62 |
||
59369
7090199d3f78
more informative build_theories_result: cumulative Runtime.exn_message;
wenzelm
parents:
59345
diff
changeset
|
63 |
fun shutdown () = |
7090199d3f78
more informative build_theories_result: cumulative Runtime.exn_message;
wenzelm
parents:
59345
diff
changeset
|
64 |
(Execution.shutdown (); |
7090199d3f78
more informative build_theories_result: cumulative Runtime.exn_message;
wenzelm
parents:
59345
diff
changeset
|
65 |
Event_Timer.shutdown (); |
7090199d3f78
more informative build_theories_result: cumulative Runtime.exn_message;
wenzelm
parents:
59345
diff
changeset
|
66 |
Future.shutdown ()); |
7090199d3f78
more informative build_theories_result: cumulative Runtime.exn_message;
wenzelm
parents:
59345
diff
changeset
|
67 |
|
6346 | 68 |
fun finish () = |
59369
7090199d3f78
more informative build_theories_result: cumulative Runtime.exn_message;
wenzelm
parents:
59345
diff
changeset
|
69 |
(shutdown (); |
49911
262c36fd5f26
collective errors from use_thys and Session.finish/Goal.finish_futures -- avoid uninformative interrupts stemming from failure of goal forks that are not registered in the theory (e.g. unnamed theorems);
wenzelm
parents:
49895
diff
changeset
|
70 |
Thy_Info.finish (); |
262c36fd5f26
collective errors from use_thys and Session.finish/Goal.finish_futures -- avoid uninformative interrupts stemming from failure of goal forks that are not registered in the theory (e.g. unnamed theorems);
wenzelm
parents:
49895
diff
changeset
|
71 |
Present.finish (); |
59369
7090199d3f78
more informative build_theories_result: cumulative Runtime.exn_message;
wenzelm
parents:
59345
diff
changeset
|
72 |
shutdown (); |
59086
94b2690ad494
node-specific keywords, with session base syntax as default;
wenzelm
parents:
58928
diff
changeset
|
73 |
keywords := |
94b2690ad494
node-specific keywords, with session base syntax as default;
wenzelm
parents:
58928
diff
changeset
|
74 |
fold (curry Keyword.merge_keywords o Thy_Header.get_keywords o Thy_Info.get_theory) |
94b2690ad494
node-specific keywords, with session base syntax as default;
wenzelm
parents:
58928
diff
changeset
|
75 |
(Thy_Info.get_names ()) Keyword.empty_keywords; |
49911
262c36fd5f26
collective errors from use_thys and Session.finish/Goal.finish_futures -- avoid uninformative interrupts stemming from failure of goal forks that are not registered in the theory (e.g. unnamed theorems);
wenzelm
parents:
49895
diff
changeset
|
76 |
session_finished := true); |
6346 | 77 |
|
59344
e0ce214303c1
proper Session.save with shutdown, which is relevant to avoid persistent threads;
wenzelm
parents:
59086
diff
changeset
|
78 |
fun save heap = |
59369
7090199d3f78
more informative build_theories_result: cumulative Runtime.exn_message;
wenzelm
parents:
59345
diff
changeset
|
79 |
(shutdown (); |
59344
e0ce214303c1
proper Session.save with shutdown, which is relevant to avoid persistent threads;
wenzelm
parents:
59086
diff
changeset
|
80 |
ML_System.share_common_data (); |
e0ce214303c1
proper Session.save with shutdown, which is relevant to avoid persistent threads;
wenzelm
parents:
59086
diff
changeset
|
81 |
ML_System.save_state heap); |
e0ce214303c1
proper Session.save with shutdown, which is relevant to avoid persistent threads;
wenzelm
parents:
59086
diff
changeset
|
82 |
|
52111
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents:
52083
diff
changeset
|
83 |
|
56210 | 84 |
|
52111
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents:
52083
diff
changeset
|
85 |
(** protocol handlers **) |
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents:
52083
diff
changeset
|
86 |
|
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents:
52083
diff
changeset
|
87 |
val protocol_handlers = Synchronized.var "protocol_handlers" ([]: string list); |
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents:
52083
diff
changeset
|
88 |
|
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents:
52083
diff
changeset
|
89 |
fun protocol_handler name = |
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents:
52083
diff
changeset
|
90 |
Synchronized.change protocol_handlers (fn handlers => |
56333
38f1422ef473
support bulk messages consisting of small string segments, which are more healthy to the Poly/ML RTS and might prevent spurious GC crashes such as MTGCProcessMarkPointers::ScanAddressesInObject;
wenzelm
parents:
56210
diff
changeset
|
91 |
(Output.try_protocol_message (Markup.protocol_handler name) []; |
52111
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents:
52083
diff
changeset
|
92 |
if not (member (op =) handlers name) then () |
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents:
52083
diff
changeset
|
93 |
else warning ("Redefining protocol handler: " ^ quote name); |
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents:
52083
diff
changeset
|
94 |
update (op =) name handlers)); |
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents:
52083
diff
changeset
|
95 |
|
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents:
52083
diff
changeset
|
96 |
fun init_protocol_handlers () = |
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents:
52083
diff
changeset
|
97 |
Synchronized.value protocol_handlers |
56333
38f1422ef473
support bulk messages consisting of small string segments, which are more healthy to the Poly/ML RTS and might prevent spurious GC crashes such as MTGCProcessMarkPointers::ScanAddressesInObject;
wenzelm
parents:
56210
diff
changeset
|
98 |
|> List.app (fn name => Output.try_protocol_message (Markup.protocol_handler name) []); |
52111
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents:
52083
diff
changeset
|
99 |
|
6346 | 100 |
end; |