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 |
|
6326
|
18 |
|
6209
|
19 |
(* session state *)
|
|
20 |
|
6240
|
21 |
val pure = "Pure";
|
|
22 |
|
|
23 |
val session = ref ([pure]: string list);
|
6209
|
24 |
val session_path = ref ([]: string list);
|
6240
|
25 |
val session_finished = ref false;
|
6209
|
26 |
|
|
27 |
fun path () = ! session_path;
|
|
28 |
|
|
29 |
fun add_path reset s =
|
6326
|
30 |
(session := ! session @ [s]; session_path := ((if reset then [] else ! session_path) @ [s]));
|
6209
|
31 |
|
|
32 |
|
|
33 |
(* diagnostics *)
|
|
34 |
|
6341
|
35 |
fun str_of [] = "Pure"
|
|
36 |
| str_of elems = space_implode "/" elems;
|
6209
|
37 |
|
6341
|
38 |
fun welcome () = "Welcome to Isabelle/" ^ str_of (path ()) ^ " (" ^ version ^ ")";
|
6209
|
39 |
|
|
40 |
|
|
41 |
(* init *)
|
|
42 |
|
6240
|
43 |
fun init reset parent name =
|
|
44 |
if not (parent mem_string (! session)) orelse not (! session_finished) then
|
6262
|
45 |
error ("Unfinished parent session " ^ quote parent ^ " for " ^ quote name)
|
6209
|
46 |
else (add_path reset name; session_finished := false);
|
|
47 |
|
|
48 |
|
|
49 |
(* finish *)
|
|
50 |
|
6326
|
51 |
fun finish () =
|
|
52 |
(ThyInfo.finalize_all ();
|
|
53 |
Present.finish ();
|
|
54 |
session_finished := true);
|
6209
|
55 |
|
|
56 |
|
6230
|
57 |
(* use_dir *)
|
|
58 |
|
|
59 |
val root_file = ThyLoad.ml_path "ROOT";
|
6209
|
60 |
|
6240
|
61 |
fun use_dir reset info parent name =
|
6341
|
62 |
(init reset parent name;
|
|
63 |
Present.init info (path ()) name;
|
6275
|
64 |
Symbol.use root_file;
|
6341
|
65 |
finish ()) handle _ => exit 1;
|
6209
|
66 |
|
|
67 |
|
|
68 |
end;
|