author | wenzelm |
Fri, 01 Dec 2000 19:43:57 +0100 | |
changeset 10571 | fdde440a9033 |
parent 9414 | 1463576f3968 |
child 10937 | 5651e0636e38 |
permissions | -rw-r--r-- |
6346 | 1 |
(* Title: Pure/Isar/session.ML |
2 |
ID: $Id$ |
|
3 |
Author: Markus Wenzel, TU Muenchen |
|
8807 | 4 |
License: GPL (GNU GENERAL PUBLIC LICENSE) |
6346 | 5 |
|
6 |
Session management -- maintain state of logic images. |
|
7 |
*) |
|
8 |
||
9 |
signature SESSION = |
|
10 |
sig |
|
11 |
val welcome: unit -> string |
|
10571 | 12 |
val use_dir: |
13 |
string list -> bool -> bool -> string -> string -> string -> string -> string -> unit |
|
6346 | 14 |
val finish: unit -> unit |
15 |
end; |
|
16 |
||
17 |
structure Session: SESSION = |
|
18 |
struct |
|
19 |
||
20 |
||
21 |
(* session state *) |
|
22 |
||
23 |
val pure = "Pure"; |
|
24 |
||
25 |
val session = ref ([pure]: string list); |
|
26 |
val session_path = ref ([]: string list); |
|
27 |
val session_finished = ref false; |
|
9414 | 28 |
val rpath = ref (None: Url.T option); |
29 |
||
30 |
||
31 |
(* access path *) |
|
6346 | 32 |
|
33 |
fun path () = ! session_path; |
|
34 |
||
35 |
fun str_of [] = "Pure" |
|
36 |
| str_of elems = space_implode "/" elems; |
|
37 |
||
38 |
fun welcome () = "Welcome to Isabelle/" ^ str_of (path ()) ^ " (" ^ version ^ ")"; |
|
39 |
||
40 |
||
9414 | 41 |
(* add_path *) |
42 |
||
43 |
fun add_path reset s = |
|
44 |
let val sess = ! session @ [s] in |
|
45 |
(case Library.duplicates sess of |
|
46 |
[] => (session := sess; session_path := ((if reset then [] else ! session_path) @ [s])) |
|
47 |
| dups => error ("Duplicate session identifiers " ^ commas_quote dups ^ " in " ^ str_of sess)) |
|
48 |
end; |
|
49 |
||
50 |
||
6346 | 51 |
(* init *) |
52 |
||
53 |
fun init reset parent name = |
|
54 |
if not (parent mem_string (! session)) orelse not (! session_finished) then |
|
55 |
error ("Unfinished parent session " ^ quote parent ^ " for " ^ quote name) |
|
56 |
else (add_path reset name; session_finished := false); |
|
57 |
||
58 |
||
59 |
(* finish *) |
|
60 |
||
61 |
fun finish () = |
|
6663 | 62 |
(ThyInfo.finish (); |
6346 | 63 |
Present.finish (); |
64 |
session_finished := true); |
|
65 |
||
66 |
||
67 |
(* use_dir *) |
|
68 |
||
69 |
val root_file = ThyLoad.ml_path "ROOT"; |
|
70 |
||
7236
e077484d50d8
Better handling of path for remote theory browsing information.
berghofe
parents:
7227
diff
changeset
|
71 |
fun get_rpath rpath_str = |
e077484d50d8
Better handling of path for remote theory browsing information.
berghofe
parents:
7227
diff
changeset
|
72 |
(if rpath_str = "" then () else |
7227
a8e86b8e6fd1
Path for remote theory browsing information is now stored in referece variable rpath.
berghofe
parents:
6663
diff
changeset
|
73 |
if is_some (!rpath) then |
a8e86b8e6fd1
Path for remote theory browsing information is now stored in referece variable rpath.
berghofe
parents:
6663
diff
changeset
|
74 |
error "Path for remote theory browsing information may only be set once" |
a8e86b8e6fd1
Path for remote theory browsing information is now stored in referece variable rpath.
berghofe
parents:
6663
diff
changeset
|
75 |
else |
a8e86b8e6fd1
Path for remote theory browsing information is now stored in referece variable rpath.
berghofe
parents:
6663
diff
changeset
|
76 |
rpath := Some (Url.unpack rpath_str); |
7236
e077484d50d8
Better handling of path for remote theory browsing information.
berghofe
parents:
7227
diff
changeset
|
77 |
(!rpath, rpath_str <> "")); |
e077484d50d8
Better handling of path for remote theory browsing information.
berghofe
parents:
7227
diff
changeset
|
78 |
|
10571 | 79 |
fun use_dir modes reset info doc parent name dump rpath_str = |
80 |
Library.setmp print_mode (modes @ ! print_mode) (fn () => |
|
81 |
(init reset parent name; |
|
82 |
Present.init info doc (path ()) name |
|
83 |
(if dump = "" then None else Some (Path.unpack dump)) (get_rpath rpath_str); |
|
84 |
File.symbol_use root_file; |
|
85 |
finish ())) () |
|
86 |
handle exn => (writeln (Toplevel.exn_message exn); exit 1); |
|
6346 | 87 |
|
88 |
||
89 |
end; |