| author | blanchet | 
| Tue, 10 Dec 2013 15:24:17 +0800 | |
| changeset 54712 | cbebe2cf77f1 | 
| parent 53192 | 04df1d236e1c | 
| child 55386 | 0c15ac6edcf7 | 
| permissions | -rw-r--r-- | 
| 30173 
eabece26b89b
moved isabelle_process.ML, isabelle_process.scala, isar.ML, session.ML to Pure/System/ (together with associated Isar commands);
 wenzelm parents: 
29435diff
changeset | 1 | (* Title: Pure/System/session.ML | 
| 52052 
892061142ba6
discontinued obsolete isabelle usedir, mkdir, make;
 wenzelm parents: 
52050diff
changeset | 2 | Author: Makarius | 
| 6346 | 3 | |
| 52111 
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
 wenzelm parents: 
52083diff
changeset | 4 | Session management -- internal state of logic images. | 
| 6346 | 5 | *) | 
| 6 | ||
| 7 | signature SESSION = | |
| 8 | sig | |
| 11509 | 9 | val name: unit -> string | 
| 6346 | 10 | val welcome: unit -> string | 
| 51399 
6ac3c29a300e
discontinued "isabelle usedir" option -r (reset session path);
 wenzelm parents: 
51398diff
changeset | 11 | val init: bool -> bool -> Path.T -> string -> bool -> string -> (string * string) list -> | 
| 
6ac3c29a300e
discontinued "isabelle usedir" option -r (reset session path);
 wenzelm parents: 
51398diff
changeset | 12 | string -> string * string -> bool * string -> bool -> unit | 
| 48457 | 13 | val finish: unit -> unit | 
| 52111 
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
 wenzelm parents: 
52083diff
changeset | 14 | val protocol_handler: string -> unit | 
| 
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
 wenzelm parents: 
52083diff
changeset | 15 | val init_protocol_handlers: unit -> unit | 
| 6346 | 16 | end; | 
| 17 | ||
| 18 | structure Session: SESSION = | |
| 19 | struct | |
| 20 | ||
| 52111 
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
 wenzelm parents: 
52083diff
changeset | 21 | (** session identification -- not thread-safe **) | 
| 6346 | 22 | |
| 51399 
6ac3c29a300e
discontinued "isabelle usedir" option -r (reset session path);
 wenzelm parents: 
51398diff
changeset | 23 | val session = Unsynchronized.ref {chapter = "Pure", name = "Pure"};
 | 
| 32738 | 24 | val session_finished = Unsynchronized.ref false; | 
| 48542 | 25 | |
| 51399 
6ac3c29a300e
discontinued "isabelle usedir" option -r (reset session path);
 wenzelm parents: 
51398diff
changeset | 26 | fun name () = "Isabelle/" ^ #name (! session); | 
| 30173 
eabece26b89b
moved isabelle_process.ML, isabelle_process.scala, isar.ML, session.ML to Pure/System/ (together with associated Isar commands);
 wenzelm parents: 
29435diff
changeset | 27 | |
| 26109 
c69c3559355b
more elaborate structure Distribution (filled-in by makedist);
 wenzelm parents: 
25840diff
changeset | 28 | fun welcome () = | 
| 26134 | 29 | if Distribution.is_official then | 
| 30 |     "Welcome to " ^ name () ^ " (" ^ Distribution.version ^ ")"
 | |
| 48990 | 31 |   else "Unofficial version of " ^ name () ^ " (" ^ Distribution.version ^ ")";
 | 
| 6346 | 32 | |
| 33 | ||
| 51399 
6ac3c29a300e
discontinued "isabelle usedir" option -r (reset session path);
 wenzelm parents: 
51398diff
changeset | 34 | (* init *) | 
| 9414 | 35 | |
| 51399 
6ac3c29a300e
discontinued "isabelle usedir" option -r (reset session path);
 wenzelm parents: 
51398diff
changeset | 36 | fun init build info info_path doc doc_graph doc_output doc_variants | 
| 
6ac3c29a300e
discontinued "isabelle usedir" option -r (reset session path);
 wenzelm parents: 
51398diff
changeset | 37 | parent (chapter, name) doc_dump verbose = | 
| 
6ac3c29a300e
discontinued "isabelle usedir" option -r (reset session path);
 wenzelm parents: 
51398diff
changeset | 38 | if #name (! session) <> parent orelse not (! session_finished) then | 
| 6346 | 39 |     error ("Unfinished parent session " ^ quote parent ^ " for " ^ quote name)
 | 
| 51399 
6ac3c29a300e
discontinued "isabelle usedir" option -r (reset session path);
 wenzelm parents: 
51398diff
changeset | 40 | else | 
| 
6ac3c29a300e
discontinued "isabelle usedir" option -r (reset session path);
 wenzelm parents: 
51398diff
changeset | 41 | let | 
| 
6ac3c29a300e
discontinued "isabelle usedir" option -r (reset session path);
 wenzelm parents: 
51398diff
changeset | 42 |       val _ = session := {chapter = chapter, name = name};
 | 
| 
6ac3c29a300e
discontinued "isabelle usedir" option -r (reset session path);
 wenzelm parents: 
51398diff
changeset | 43 | val _ = session_finished := false; | 
| 
6ac3c29a300e
discontinued "isabelle usedir" option -r (reset session path);
 wenzelm parents: 
51398diff
changeset | 44 | in | 
| 
6ac3c29a300e
discontinued "isabelle usedir" option -r (reset session path);
 wenzelm parents: 
51398diff
changeset | 45 | Present.init build info info_path (if doc = "false" then "" else doc) | 
| 
6ac3c29a300e
discontinued "isabelle usedir" option -r (reset session path);
 wenzelm parents: 
51398diff
changeset | 46 | doc_graph doc_output doc_variants (chapter, name) | 
| 
6ac3c29a300e
discontinued "isabelle usedir" option -r (reset session path);
 wenzelm parents: 
51398diff
changeset | 47 | doc_dump verbose (map Thy_Info.get_theory (Thy_Info.get_names ())) | 
| 
6ac3c29a300e
discontinued "isabelle usedir" option -r (reset session path);
 wenzelm parents: 
51398diff
changeset | 48 | end; | 
| 6346 | 49 | |
| 50 | ||
| 51 | (* finish *) | |
| 52 | ||
| 53 | fun finish () = | |
| 53192 | 54 | (Execution.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: 
49895diff
changeset | 55 | 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: 
49895diff
changeset | 56 | Present.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: 
49895diff
changeset | 57 | Outer_Syntax.check_syntax (); | 
| 50430 
702278df3b57
make double-sure that the future scheduler is properly shutdown, otherwise its threads are made persistent and will deadlock with the fresh instance after reloading the image (NB: Present.finish involves another Par_List.map over document_variants and thus might fork again);
 wenzelm parents: 
50121diff
changeset | 58 | Future.shutdown (); | 
| 52050 | 59 | Event_Timer.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: 
49895diff
changeset | 60 | session_finished := true); | 
| 6346 | 61 | |
| 52111 
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
 wenzelm parents: 
52083diff
changeset | 62 | |
| 
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
 wenzelm parents: 
52083diff
changeset | 63 | (** protocol handlers **) | 
| 
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
 wenzelm parents: 
52083diff
changeset | 64 | |
| 
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
 wenzelm parents: 
52083diff
changeset | 65 | val protocol_handlers = Synchronized.var "protocol_handlers" ([]: string list); | 
| 
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
 wenzelm parents: 
52083diff
changeset | 66 | |
| 
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
 wenzelm parents: 
52083diff
changeset | 67 | fun protocol_handler name = | 
| 
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
 wenzelm parents: 
52083diff
changeset | 68 | Synchronized.change protocol_handlers (fn handlers => | 
| 
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
 wenzelm parents: 
52083diff
changeset | 69 | (Output.try_protocol_message (Markup.protocol_handler name) ""; | 
| 
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
 wenzelm parents: 
52083diff
changeset | 70 | if not (member (op =) handlers name) then () | 
| 
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
 wenzelm parents: 
52083diff
changeset | 71 |     else warning ("Redefining protocol handler: " ^ quote name);
 | 
| 
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
 wenzelm parents: 
52083diff
changeset | 72 | update (op =) name handlers)); | 
| 
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
 wenzelm parents: 
52083diff
changeset | 73 | |
| 
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
 wenzelm parents: 
52083diff
changeset | 74 | fun init_protocol_handlers () = | 
| 
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
 wenzelm parents: 
52083diff
changeset | 75 | Synchronized.value protocol_handlers | 
| 
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
 wenzelm parents: 
52083diff
changeset | 76 | |> List.app (fn name => Output.try_protocol_message (Markup.protocol_handler name) ""); | 
| 
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
 wenzelm parents: 
52083diff
changeset | 77 | |
| 6346 | 78 | end; |