6209
|
1 |
(* Title: Pure/Thy/session.ML
|
|
2 |
ID: $Id$
|
|
3 |
Author: Markus Wenzel, TU Muenchen
|
|
4 |
|
|
5 |
Session management -- maintain state of logic images.
|
|
6 |
*)
|
|
7 |
|
|
8 |
signature SESSION =
|
|
9 |
sig
|
|
10 |
val welcome: unit -> string
|
6240
|
11 |
val use_dir: bool -> bool -> string -> string -> unit
|
|
12 |
val finish: unit -> unit
|
6209
|
13 |
end;
|
|
14 |
|
|
15 |
structure Session: SESSION =
|
|
16 |
struct
|
|
17 |
|
|
18 |
(* session state *)
|
|
19 |
|
6240
|
20 |
val pure = "Pure";
|
|
21 |
|
|
22 |
val session = ref ([pure]: string list);
|
6209
|
23 |
val session_path = ref ([]: string list);
|
6240
|
24 |
val session_finished = ref false;
|
6209
|
25 |
|
|
26 |
fun path () = ! session_path;
|
|
27 |
|
|
28 |
fun add_path reset s =
|
|
29 |
(session := ! session @ [s]; session_path := (if reset then [] else ! session));
|
|
30 |
|
|
31 |
|
|
32 |
(* diagnostics *)
|
|
33 |
|
6240
|
34 |
fun str_of [id] = id
|
|
35 |
| str_of ids = space_implode "/" (tl ids);
|
6209
|
36 |
|
|
37 |
fun welcome () = "Welcome to Isabelle/" ^ str_of (! session) ^ " (" ^ version ^ ")";
|
|
38 |
|
|
39 |
|
|
40 |
(* init *)
|
|
41 |
|
6240
|
42 |
fun init reset parent name =
|
|
43 |
if not (parent mem_string (! session)) orelse not (! session_finished) then
|
6262
|
44 |
error ("Unfinished parent session " ^ quote parent ^ " for " ^ quote name)
|
6209
|
45 |
else (add_path reset name; session_finished := false);
|
|
46 |
|
|
47 |
|
|
48 |
(* finish *)
|
|
49 |
|
6240
|
50 |
fun finish () = (ThyInfo.finalize_all (); session_finished := true);
|
6209
|
51 |
|
|
52 |
|
6230
|
53 |
(* use_dir *)
|
|
54 |
|
|
55 |
val root_file = ThyLoad.ml_path "ROOT";
|
6209
|
56 |
|
6240
|
57 |
fun use_dir reset info parent name =
|
6275
|
58 |
(init reset parent name;
|
|
59 |
Present.init info (! session) (path ()) parent name;
|
|
60 |
Symbol.use root_file;
|
|
61 |
finish ())
|
|
62 |
handle _ => exit 1;
|
6209
|
63 |
|
|
64 |
|
|
65 |
end;
|