| author | wenzelm | 
| Thu, 28 Feb 2008 15:54:37 +0100 | |
| changeset 26179 | bc5d582d6cfe | 
| parent 26137 | 9b47c8a2d869 | 
| child 26601 | d5ae46a8a716 | 
| 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 | |
| 25840 | 10 | val id: unit -> string list | 
| 11509 | 11 | val name: unit -> string | 
| 6346 | 12 | val welcome: unit -> string | 
| 24061 | 13 | val use_dir: string -> bool -> string list -> bool -> bool -> string -> bool -> string list -> | 
| 24118 | 14 | string -> string -> bool * string -> string -> int -> bool -> int -> int -> unit | 
| 6346 | 15 | val finish: unit -> unit | 
| 16 | end; | |
| 17 | ||
| 18 | structure Session: SESSION = | |
| 19 | struct | |
| 20 | ||
| 21 | ||
| 22 | (* session state *) | |
| 23 | ||
| 16451 | 24 | val session = ref ([Context.PureN]: string list); | 
| 6346 | 25 | val session_path = ref ([]: string list); | 
| 26 | val session_finished = ref false; | |
| 15979 | 27 | val remote_path = ref (NONE: Url.T option); | 
| 9414 | 28 | |
| 29 | ||
| 30 | (* access path *) | |
| 6346 | 31 | |
| 25840 | 32 | fun id () = ! session; | 
| 6346 | 33 | fun path () = ! session_path; | 
| 34 | ||
| 16451 | 35 | fun str_of [] = Context.PureN | 
| 6346 | 36 | | str_of elems = space_implode "/" elems; | 
| 37 | ||
| 11509 | 38 | fun name () = "Isabelle/" ^ str_of (path ()); | 
| 26109 
c69c3559355b
more elaborate structure Distribution (filled-in by makedist);
 wenzelm parents: 
25840diff
changeset | 39 | |
| 26137 | 40 | val changelog = Path.explode "$ISABELLE_HOME/ChangeLog.gz"; | 
| 26134 | 41 | |
| 26109 
c69c3559355b
more elaborate structure Distribution (filled-in by makedist);
 wenzelm parents: 
25840diff
changeset | 42 | fun welcome () = | 
| 26134 | 43 | if Distribution.is_official then | 
| 44 |     "Welcome to " ^ name () ^ " (" ^ Distribution.version ^ ")"
 | |
| 45 | else | |
| 46 |     "Unofficial version of " ^ name () ^ " (" ^ Distribution.version ^ ")" ^
 | |
| 26137 | 47 | (if File.exists changelog then "\nSee also " ^ Path.implode (Path.expand changelog) else ""); | 
| 6346 | 48 | |
| 49 | ||
| 9414 | 50 | (* add_path *) | 
| 51 | ||
| 52 | fun add_path reset s = | |
| 53 | let val sess = ! session @ [s] in | |
| 18964 | 54 | (case duplicates (op =) sess of | 
| 9414 | 55 | [] => (session := sess; session_path := ((if reset then [] else ! session_path) @ [s])) | 
| 56 |     | dups => error ("Duplicate session identifiers " ^ commas_quote dups ^ " in " ^ str_of sess))
 | |
| 57 | end; | |
| 58 | ||
| 59 | ||
| 6346 | 60 | (* init *) | 
| 61 | ||
| 62 | fun init reset parent name = | |
| 20664 | 63 | if not (member (op =) (! session) parent) orelse not (! session_finished) then | 
| 6346 | 64 |     error ("Unfinished parent session " ^ quote parent ^ " for " ^ quote name)
 | 
| 65 | else (add_path reset name; session_finished := false); | |
| 66 | ||
| 67 | ||
| 68 | (* finish *) | |
| 69 | ||
| 70 | fun finish () = | |
| 16728 | 71 | (Output.accumulated_time (); | 
| 72 | ThyInfo.finish (); | |
| 6346 | 73 | Present.finish (); | 
| 21957 | 74 | Toplevel.init_state (); | 
| 6346 | 75 | session_finished := true); | 
| 76 | ||
| 77 | ||
| 78 | (* use_dir *) | |
| 79 | ||
| 17207 | 80 | fun get_rpath rpath = | 
| 81 | (if rpath = "" then () else | |
| 15979 | 82 | 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 | 83 | 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 | 84 | else | 
| 21858 
05f57309170c
avoid conflict with Alice keywords: renamed pack -> implode, unpack -> explode, any -> many, avoided assert;
 wenzelm parents: 
20664diff
changeset | 85 | remote_path := SOME (Url.explode rpath); | 
| 17207 | 86 | (! remote_path, rpath <> "")); | 
| 87 | ||
| 88 | fun dumping (_, "") = NONE | |
| 21858 
05f57309170c
avoid conflict with Alice keywords: renamed pack -> implode, unpack -> explode, any -> many, avoided assert;
 wenzelm parents: 
20664diff
changeset | 89 | | dumping (cp, path) = SOME (cp, Path.explode path); | 
| 7236 
e077484d50d8
Better handling of path for remote theory browsing information.
 berghofe parents: 
7227diff
changeset | 90 | |
| 17074 | 91 | fun use_dir root build modes reset info doc doc_graph doc_versions | 
| 24061 | 92 | parent name dump rpath level verbose max_threads trace_threads = | 
| 23972 | 93 | ((fn () => | 
| 94 | (init reset parent name; | |
| 95 | Present.init build info doc doc_graph doc_versions (path ()) name | |
| 96 | (dumping dump) (get_rpath rpath) verbose (map ThyInfo.theory (ThyInfo.names ())); | |
| 25703 
832073e402ae
removed obsolete use_noncritical (plain use is already non-critical);
 wenzelm parents: 
24612diff
changeset | 97 | use root; | 
| 23972 | 98 | finish ())) | 
| 99 | |> setmp_noncritical Proofterm.proofs level | |
| 24612 | 100 | |> setmp_noncritical print_mode (modes @ print_mode_value ()) | 
| 24061 | 101 | |> setmp_noncritical Multithreading.trace trace_threads | 
| 23979 | 102 | |> setmp_noncritical Multithreading.max_threads | 
| 103 | (if Multithreading.available then max_threads | |
| 104 | else (if max_threads = 1 then () else warning "Multithreading support unavailable"; 1))) () | |
| 18683 | 105 | handle exn => (Output.error_msg (Toplevel.exn_message exn); exit 1); | 
| 6346 | 106 | |
| 107 | end; |