| author | wenzelm | 
| Thu, 04 Oct 2007 14:42:47 +0200 | |
| changeset 24830 | a7b3ab44d993 | 
| parent 24612 | d1b315bdb8d7 | 
| child 25703 | 832073e402ae | 
| permissions | -rw-r--r-- | 
| 6346 | 1 | (* Title: Pure/Isar/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 | |
| 11509 | 10 | val name: unit -> string | 
| 6346 | 11 | val welcome: unit -> string | 
| 24061 | 12 | val use_dir: string -> bool -> string list -> bool -> bool -> string -> bool -> string list -> | 
| 24118 | 13 | string -> string -> bool * string -> string -> int -> bool -> int -> int -> unit | 
| 6346 | 14 | val finish: unit -> unit | 
| 15 | end; | |
| 16 | ||
| 17 | structure Session: SESSION = | |
| 18 | struct | |
| 19 | ||
| 20 | ||
| 21 | (* session state *) | |
| 22 | ||
| 16451 | 23 | val session = ref ([Context.PureN]: string list); | 
| 6346 | 24 | val session_path = ref ([]: string list); | 
| 25 | val session_finished = ref false; | |
| 15979 | 26 | val remote_path = ref (NONE: Url.T option); | 
| 9414 | 27 | |
| 28 | ||
| 29 | (* access path *) | |
| 6346 | 30 | |
| 31 | fun path () = ! session_path; | |
| 32 | ||
| 16451 | 33 | fun str_of [] = Context.PureN | 
| 6346 | 34 | | str_of elems = space_implode "/" elems; | 
| 35 | ||
| 11509 | 36 | fun name () = "Isabelle/" ^ str_of (path ()); | 
| 37 | fun welcome () = "Welcome to " ^ name () ^ " (" ^ version ^ ")";
 | |
| 6346 | 38 | |
| 39 | ||
| 9414 | 40 | (* add_path *) | 
| 41 | ||
| 42 | fun add_path reset s = | |
| 43 | let val sess = ! session @ [s] in | |
| 18964 | 44 | (case duplicates (op =) sess of | 
| 9414 | 45 | [] => (session := sess; session_path := ((if reset then [] else ! session_path) @ [s])) | 
| 46 |     | dups => error ("Duplicate session identifiers " ^ commas_quote dups ^ " in " ^ str_of sess))
 | |
| 47 | end; | |
| 48 | ||
| 49 | ||
| 6346 | 50 | (* init *) | 
| 51 | ||
| 52 | fun init reset parent name = | |
| 20664 | 53 | if not (member (op =) (! session) parent) orelse not (! session_finished) then | 
| 6346 | 54 |     error ("Unfinished parent session " ^ quote parent ^ " for " ^ quote name)
 | 
| 55 | else (add_path reset name; session_finished := false); | |
| 56 | ||
| 57 | ||
| 58 | (* finish *) | |
| 59 | ||
| 60 | fun finish () = | |
| 16728 | 61 | (Output.accumulated_time (); | 
| 62 | ThyInfo.finish (); | |
| 6346 | 63 | Present.finish (); | 
| 21957 | 64 | Toplevel.init_state (); | 
| 6346 | 65 | session_finished := true); | 
| 66 | ||
| 67 | ||
| 68 | (* use_dir *) | |
| 69 | ||
| 17207 | 70 | fun get_rpath rpath = | 
| 71 | (if rpath = "" then () else | |
| 15979 | 72 | if is_some (! remote_path) then | 
| 7227 
a8e86b8e6fd1
Path for remote theory browsing information is now stored in referece variable rpath.
 berghofe parents: 
6663diff
changeset | 73 | 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: 
6663diff
changeset | 74 | else | 
| 21858 
05f57309170c
avoid conflict with Alice keywords: renamed pack -> implode, unpack -> explode, any -> many, avoided assert;
 wenzelm parents: 
20664diff
changeset | 75 | remote_path := SOME (Url.explode rpath); | 
| 17207 | 76 | (! remote_path, rpath <> "")); | 
| 77 | ||
| 78 | fun dumping (_, "") = NONE | |
| 21858 
05f57309170c
avoid conflict with Alice keywords: renamed pack -> implode, unpack -> explode, any -> many, avoided assert;
 wenzelm parents: 
20664diff
changeset | 79 | | dumping (cp, path) = SOME (cp, Path.explode path); | 
| 7236 
e077484d50d8
Better handling of path for remote theory browsing information.
 berghofe parents: 
7227diff
changeset | 80 | |
| 17074 | 81 | fun use_dir root build modes reset info doc doc_graph doc_versions | 
| 24061 | 82 | parent name dump rpath level verbose max_threads trace_threads = | 
| 23972 | 83 | ((fn () => | 
| 84 | (init reset parent name; | |
| 85 | Present.init build info doc doc_graph doc_versions (path ()) name | |
| 86 | (dumping dump) (get_rpath rpath) verbose (map ThyInfo.theory (ThyInfo.names ())); | |
| 23979 | 87 | Secure.use_noncritical root; | 
| 23972 | 88 | finish ())) | 
| 89 | |> setmp_noncritical Proofterm.proofs level | |
| 24612 | 90 | |> setmp_noncritical print_mode (modes @ print_mode_value ()) | 
| 24061 | 91 | |> setmp_noncritical Multithreading.trace trace_threads | 
| 23979 | 92 | |> setmp_noncritical Multithreading.max_threads | 
| 93 | (if Multithreading.available then max_threads | |
| 94 | else (if max_threads = 1 then () else warning "Multithreading support unavailable"; 1))) () | |
| 18683 | 95 | handle exn => (Output.error_msg (Toplevel.exn_message exn); exit 1); | 
| 6346 | 96 | |
| 97 | end; |