| author | paulson | 
| Tue, 10 Feb 2004 12:17:04 +0100 | |
| changeset 14379 | ea10a8c3e9cf | 
| parent 12120 | a08c61932501 | 
| child 14981 | e73f8140af78 | 
| 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 | |
| 11509 | 11 | val name: unit -> string | 
| 6346 | 12 | val welcome: unit -> string | 
| 11910 | 13 | val use_dir: bool -> string list -> bool -> bool -> string -> bool -> string | 
| 11579 | 14 | -> string -> string -> string -> int -> bool -> unit | 
| 6346 | 15 | val finish: unit -> unit | 
| 16 | end; | |
| 17 | ||
| 18 | structure Session: SESSION = | |
| 19 | struct | |
| 20 | ||
| 21 | ||
| 22 | (* session state *) | |
| 23 | ||
| 24 | val pure = "Pure"; | |
| 25 | ||
| 26 | val session = ref ([pure]: string list); | |
| 27 | val session_path = ref ([]: string list); | |
| 28 | val session_finished = ref false; | |
| 9414 | 29 | val rpath = ref (None: Url.T option); | 
| 30 | ||
| 31 | ||
| 32 | (* access path *) | |
| 6346 | 33 | |
| 34 | fun path () = ! session_path; | |
| 35 | ||
| 10937 | 36 | fun str_of [] = pure | 
| 6346 | 37 | | str_of elems = space_implode "/" elems; | 
| 38 | ||
| 11509 | 39 | fun name () = "Isabelle/" ^ str_of (path ()); | 
| 40 | fun welcome () = "Welcome to " ^ name () ^ " (" ^ version ^ ")";
 | |
| 6346 | 41 | |
| 42 | ||
| 9414 | 43 | (* add_path *) | 
| 44 | ||
| 45 | fun add_path reset s = | |
| 46 | let val sess = ! session @ [s] in | |
| 47 | (case Library.duplicates sess of | |
| 48 | [] => (session := sess; session_path := ((if reset then [] else ! session_path) @ [s])) | |
| 49 |     | dups => error ("Duplicate session identifiers " ^ commas_quote dups ^ " in " ^ str_of sess))
 | |
| 50 | end; | |
| 51 | ||
| 52 | ||
| 6346 | 53 | (* init *) | 
| 54 | ||
| 55 | fun init reset parent name = | |
| 56 | if not (parent mem_string (! session)) orelse not (! session_finished) then | |
| 57 |     error ("Unfinished parent session " ^ quote parent ^ " for " ^ quote name)
 | |
| 58 | else (add_path reset name; session_finished := false); | |
| 59 | ||
| 60 | ||
| 61 | (* finish *) | |
| 62 | ||
| 63 | fun finish () = | |
| 6663 | 64 | (ThyInfo.finish (); | 
| 6346 | 65 | Present.finish (); | 
| 66 | session_finished := true); | |
| 67 | ||
| 68 | ||
| 69 | (* use_dir *) | |
| 70 | ||
| 71 | val root_file = ThyLoad.ml_path "ROOT"; | |
| 72 | ||
| 7236 
e077484d50d8
Better handling of path for remote theory browsing information.
 berghofe parents: 
7227diff
changeset | 73 | fun get_rpath rpath_str = | 
| 
e077484d50d8
Better handling of path for remote theory browsing information.
 berghofe parents: 
7227diff
changeset | 74 | (if rpath_str = "" then () else | 
| 7227 
a8e86b8e6fd1
Path for remote theory browsing information is now stored in referece variable rpath.
 berghofe parents: 
6663diff
changeset | 75 | if is_some (!rpath) then | 
| 
a8e86b8e6fd1
Path for remote theory browsing information is now stored in referece variable rpath.
 berghofe parents: 
6663diff
changeset | 76 | 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 | 77 | else | 
| 
a8e86b8e6fd1
Path for remote theory browsing information is now stored in referece variable rpath.
 berghofe parents: 
6663diff
changeset | 78 | rpath := Some (Url.unpack rpath_str); | 
| 7236 
e077484d50d8
Better handling of path for remote theory browsing information.
 berghofe parents: 
7227diff
changeset | 79 | (!rpath, rpath_str <> "")); | 
| 
e077484d50d8
Better handling of path for remote theory browsing information.
 berghofe parents: 
7227diff
changeset | 80 | |
| 11910 | 81 | fun use_dir build modes reset info doc doc_graph parent name dump rpath_str level verbose = | 
| 11543 
d61b913431c5
renamed `keep_derivs' to `proofs', and made an integer;
 wenzelm parents: 
11527diff
changeset | 82 | Library.setmp print_mode (modes @ ! print_mode) | 
| 
d61b913431c5
renamed `keep_derivs' to `proofs', and made an integer;
 wenzelm parents: 
11527diff
changeset | 83 | (Library.setmp Proofterm.proofs level (fn () => | 
| 
d61b913431c5
renamed `keep_derivs' to `proofs', and made an integer;
 wenzelm parents: 
11527diff
changeset | 84 | (init reset parent name; | 
| 11910 | 85 | Present.init build info doc doc_graph (path ()) name | 
| 11579 | 86 | (if dump = "" then None else Some (Path.unpack dump)) (get_rpath rpath_str) verbose; | 
| 12120 | 87 | File.use root_file; | 
| 11543 
d61b913431c5
renamed `keep_derivs' to `proofs', and made an integer;
 wenzelm parents: 
11527diff
changeset | 88 | finish ()))) () | 
| 10571 | 89 | handle exn => (writeln (Toplevel.exn_message exn); exit 1); | 
| 6346 | 90 | |
| 91 | ||
| 92 | end; |