| author | wenzelm | 
| Fri, 16 Jan 2009 21:24:33 +0100 | |
| changeset 29520 | 7402322256b0 | 
| parent 29435 | a5f84ac14609 | 
| permissions | -rw-r--r-- | 
| 6346 | 1 | (* Title: Pure/Isar/session.ML | 
| 2 | Author: Markus Wenzel, TU Muenchen | |
| 3 | ||
| 4 | Session management -- maintain state of logic images. | |
| 5 | *) | |
| 6 | ||
| 7 | signature SESSION = | |
| 8 | sig | |
| 25840 | 9 | val id: unit -> string list | 
| 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 -> | 
| 29435 
a5f84ac14609
added parallel_proofs flag (default true, cf. usedir option -Q), which can be disabled in low-memory situations;
 wenzelm parents: 
28207diff
changeset | 13 | string -> string -> bool * string -> string -> int -> bool -> int -> int -> bool -> 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 | |
| 25840 | 31 | fun id () = ! session; | 
| 6346 | 32 | fun path () = ! session_path; | 
| 33 | ||
| 16451 | 34 | fun str_of [] = Context.PureN | 
| 6346 | 35 | | str_of elems = space_implode "/" elems; | 
| 36 | ||
| 11509 | 37 | fun name () = "Isabelle/" ^ str_of (path ()); | 
| 26109 
c69c3559355b
more elaborate structure Distribution (filled-in by makedist);
 wenzelm parents: 
25840diff
changeset | 38 | |
| 
c69c3559355b
more elaborate structure Distribution (filled-in by makedist);
 wenzelm parents: 
25840diff
changeset | 39 | fun welcome () = | 
| 26134 | 40 | if Distribution.is_official then | 
| 41 |     "Welcome to " ^ name () ^ " (" ^ Distribution.version ^ ")"
 | |
| 42 | else | |
| 43 |     "Unofficial version of " ^ name () ^ " (" ^ Distribution.version ^ ")" ^
 | |
| 27643 | 44 | (if Distribution.changelog <> "" then "\nSee also " ^ Distribution.changelog else ""); | 
| 6346 | 45 | |
| 46 | ||
| 9414 | 47 | (* add_path *) | 
| 48 | ||
| 49 | fun add_path reset s = | |
| 50 | let val sess = ! session @ [s] in | |
| 18964 | 51 | (case duplicates (op =) sess of | 
| 9414 | 52 | [] => (session := sess; session_path := ((if reset then [] else ! session_path) @ [s])) | 
| 53 |     | dups => error ("Duplicate session identifiers " ^ commas_quote dups ^ " in " ^ str_of sess))
 | |
| 54 | end; | |
| 55 | ||
| 56 | ||
| 6346 | 57 | (* init *) | 
| 58 | ||
| 59 | fun init reset parent name = | |
| 20664 | 60 | if not (member (op =) (! session) parent) orelse not (! session_finished) then | 
| 6346 | 61 |     error ("Unfinished parent session " ^ quote parent ^ " for " ^ quote name)
 | 
| 62 | else (add_path reset name; session_finished := false); | |
| 63 | ||
| 64 | ||
| 65 | (* finish *) | |
| 66 | ||
| 67 | fun finish () = | |
| 16728 | 68 | (Output.accumulated_time (); | 
| 69 | ThyInfo.finish (); | |
| 28207 | 70 | Present.finish (); | 
| 28205 | 71 | Future.shutdown (); | 
| 6346 | 72 | session_finished := true); | 
| 73 | ||
| 74 | ||
| 75 | (* use_dir *) | |
| 76 | ||
| 17207 | 77 | fun get_rpath rpath = | 
| 78 | (if rpath = "" then () else | |
| 15979 | 79 | 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 | 80 | 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 | 81 | else | 
| 21858 
05f57309170c
avoid conflict with Alice keywords: renamed pack -> implode, unpack -> explode, any -> many, avoided assert;
 wenzelm parents: 
20664diff
changeset | 82 | remote_path := SOME (Url.explode rpath); | 
| 17207 | 83 | (! remote_path, rpath <> "")); | 
| 84 | ||
| 85 | fun dumping (_, "") = NONE | |
| 21858 
05f57309170c
avoid conflict with Alice keywords: renamed pack -> implode, unpack -> explode, any -> many, avoided assert;
 wenzelm parents: 
20664diff
changeset | 86 | | dumping (cp, path) = SOME (cp, Path.explode path); | 
| 7236 
e077484d50d8
Better handling of path for remote theory browsing information.
 berghofe parents: 
7227diff
changeset | 87 | |
| 17074 | 88 | fun use_dir root build modes reset info doc doc_graph doc_versions | 
| 29435 
a5f84ac14609
added parallel_proofs flag (default true, cf. usedir option -Q), which can be disabled in low-memory situations;
 wenzelm parents: 
28207diff
changeset | 89 | parent name dump rpath level verbose max_threads trace_threads parallel_proofs = | 
| 23972 | 90 | ((fn () => | 
| 91 | (init reset parent name; | |
| 92 | Present.init build info doc doc_graph doc_versions (path ()) name | |
| 26612 | 93 | (dumping dump) (get_rpath rpath) verbose (map ThyInfo.get_theory (ThyInfo.get_names ())); | 
| 25703 
832073e402ae
removed obsolete use_noncritical (plain use is already non-critical);
 wenzelm parents: 
24612diff
changeset | 94 | use root; | 
| 23972 | 95 | finish ())) | 
| 96 | |> setmp_noncritical Proofterm.proofs level | |
| 24612 | 97 | |> setmp_noncritical print_mode (modes @ print_mode_value ()) | 
| 29435 
a5f84ac14609
added parallel_proofs flag (default true, cf. usedir option -Q), which can be disabled in low-memory situations;
 wenzelm parents: 
28207diff
changeset | 98 | |> setmp_noncritical Goal.parallel_proofs parallel_proofs | 
| 24061 | 99 | |> setmp_noncritical Multithreading.trace trace_threads | 
| 23979 | 100 | |> setmp_noncritical Multithreading.max_threads | 
| 101 | (if Multithreading.available then max_threads | |
| 102 | else (if max_threads = 1 then () else warning "Multithreading support unavailable"; 1))) () | |
| 18683 | 103 | handle exn => (Output.error_msg (Toplevel.exn_message exn); exit 1); | 
| 6346 | 104 | |
| 105 | end; |