| author | wenzelm | 
| Thu, 12 May 2011 16:46:21 +0200 | |
| changeset 42720 | caa4f1279154 | 
| parent 42172 | e86b10c68f0b | 
| child 44389 | a3b5fdfb04a3 | 
| permissions | -rw-r--r-- | 
| 30173 
eabece26b89b
moved isabelle_process.ML, isabelle_process.scala, isar.ML, session.ML to Pure/System/ (together with associated Isar commands);
 wenzelm parents: 
29435diff
changeset | 1 | (* Title: Pure/System/session.ML | 
| 6346 | 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 | 
| 31688 | 12 | val use_dir: string -> string -> bool -> string list -> bool -> bool -> | 
| 13 | string -> bool -> string list -> string -> string -> bool * string -> | |
| 41703 
d27950860514
parallelization of nested Isar proofs is subject to Goal.parallel_proofs_threshold;
 wenzelm parents: 
39733diff
changeset | 14 | string -> int -> bool -> bool -> int -> int -> int -> int -> unit | 
| 6346 | 15 | val finish: unit -> unit | 
| 16 | end; | |
| 17 | ||
| 18 | structure Session: SESSION = | |
| 19 | struct | |
| 20 | ||
| 21 | ||
| 22 | (* session state *) | |
| 23 | ||
| 32738 | 24 | val session = Unsynchronized.ref ([Context.PureN]: string list); | 
| 25 | val session_path = Unsynchronized.ref ([]: string list); | |
| 26 | val session_finished = Unsynchronized.ref false; | |
| 27 | val remote_path = Unsynchronized.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 | |
| 30173 
eabece26b89b
moved isabelle_process.ML, isabelle_process.scala, isar.ML, session.ML to Pure/System/ (together with associated Isar commands);
 wenzelm parents: 
29435diff
changeset | 40 | |
| 
eabece26b89b
moved isabelle_process.ML, isabelle_process.scala, isar.ML, session.ML to Pure/System/ (together with associated Isar commands);
 wenzelm parents: 
29435diff
changeset | 41 | (* welcome *) | 
| 
eabece26b89b
moved isabelle_process.ML, isabelle_process.scala, isar.ML, session.ML to Pure/System/ (together with associated Isar commands);
 wenzelm parents: 
29435diff
changeset | 42 | |
| 26109 
c69c3559355b
more elaborate structure Distribution (filled-in by makedist);
 wenzelm parents: 
25840diff
changeset | 43 | fun welcome () = | 
| 26134 | 44 | if Distribution.is_official then | 
| 45 |     "Welcome to " ^ name () ^ " (" ^ Distribution.version ^ ")"
 | |
| 46 | else | |
| 47 |     "Unofficial version of " ^ name () ^ " (" ^ Distribution.version ^ ")" ^
 | |
| 27643 | 48 | (if Distribution.changelog <> "" then "\nSee also " ^ Distribution.changelog else ""); | 
| 6346 | 49 | |
| 30173 
eabece26b89b
moved isabelle_process.ML, isabelle_process.scala, isar.ML, session.ML to Pure/System/ (together with associated Isar commands);
 wenzelm parents: 
29435diff
changeset | 50 | val _ = | 
| 36953 
2af1ad9aa1a3
renamed structure OuterSyntax to Outer_Syntax, keeping the old name as alias for some time;
 wenzelm parents: 
36950diff
changeset | 51 | Outer_Syntax.improper_command "welcome" "print welcome message" Keyword.diag | 
| 30173 
eabece26b89b
moved isabelle_process.ML, isabelle_process.scala, isar.ML, session.ML to Pure/System/ (together with associated Isar commands);
 wenzelm parents: 
29435diff
changeset | 52 | (Scan.succeed (Toplevel.no_timing o Toplevel.imperative (writeln o welcome))); | 
| 
eabece26b89b
moved isabelle_process.ML, isabelle_process.scala, isar.ML, session.ML to Pure/System/ (together with associated Isar commands);
 wenzelm parents: 
29435diff
changeset | 53 | |
| 6346 | 54 | |
| 9414 | 55 | (* add_path *) | 
| 56 | ||
| 57 | fun add_path reset s = | |
| 58 | let val sess = ! session @ [s] in | |
| 18964 | 59 | (case duplicates (op =) sess of | 
| 9414 | 60 | [] => (session := sess; session_path := ((if reset then [] else ! session_path) @ [s])) | 
| 61 |     | dups => error ("Duplicate session identifiers " ^ commas_quote dups ^ " in " ^ str_of sess))
 | |
| 62 | end; | |
| 63 | ||
| 64 | ||
| 6346 | 65 | (* init *) | 
| 66 | ||
| 67 | fun init reset parent name = | |
| 20664 | 68 | if not (member (op =) (! session) parent) orelse not (! session_finished) then | 
| 6346 | 69 |     error ("Unfinished parent session " ^ quote parent ^ " for " ^ quote name)
 | 
| 70 | else (add_path reset name; session_finished := false); | |
| 71 | ||
| 72 | ||
| 73 | (* finish *) | |
| 74 | ||
| 75 | fun finish () = | |
| 37216 
3165bc303f66
modernized some structure names, keeping a few legacy aliases;
 wenzelm parents: 
36953diff
changeset | 76 | (Thy_Info.finish (); | 
| 28207 | 77 | Present.finish (); | 
| 28205 | 78 | Future.shutdown (); | 
| 6346 | 79 | session_finished := true); | 
| 80 | ||
| 81 | ||
| 82 | (* use_dir *) | |
| 83 | ||
| 17207 | 84 | fun get_rpath rpath = | 
| 85 | (if rpath = "" then () else | |
| 15979 | 86 | 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 | 87 | 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 | 88 | else | 
| 21858 
05f57309170c
avoid conflict with Alice keywords: renamed pack -> implode, unpack -> explode, any -> many, avoided assert;
 wenzelm parents: 
20664diff
changeset | 89 | remote_path := SOME (Url.explode rpath); | 
| 17207 | 90 | (! remote_path, rpath <> "")); | 
| 91 | ||
| 92 | fun dumping (_, "") = NONE | |
| 21858 
05f57309170c
avoid conflict with Alice keywords: renamed pack -> implode, unpack -> explode, any -> many, avoided assert;
 wenzelm parents: 
20664diff
changeset | 93 | | dumping (cp, path) = SOME (cp, Path.explode path); | 
| 7236 
e077484d50d8
Better handling of path for remote theory browsing information.
 berghofe parents: 
7227diff
changeset | 94 | |
| 42004 | 95 | fun use_dir item root build modes reset info doc doc_graph doc_variants parent | 
| 41703 
d27950860514
parallelization of nested Isar proofs is subject to Goal.parallel_proofs_threshold;
 wenzelm parents: 
39733diff
changeset | 96 | name dump rpath level timing verbose max_threads trace_threads | 
| 
d27950860514
parallelization of nested Isar proofs is subject to Goal.parallel_proofs_threshold;
 wenzelm parents: 
39733diff
changeset | 97 | parallel_proofs parallel_proofs_threshold = | 
| 23972 | 98 | ((fn () => | 
| 99 | (init reset parent name; | |
| 42004 | 100 | Present.init build info doc doc_graph doc_variants (path ()) name | 
| 37216 
3165bc303f66
modernized some structure names, keeping a few legacy aliases;
 wenzelm parents: 
36953diff
changeset | 101 | (dumping dump) (get_rpath rpath) verbose (map Thy_Info.get_theory (Thy_Info.get_names ())); | 
| 31688 | 102 | if timing then | 
| 103 | let | |
| 42012 
2c3fe3cbebae
structure Timing: covers former start_timing/end_timing and Output.timeit etc;
 wenzelm parents: 
42004diff
changeset | 104 | val start = Timing.start (); | 
| 31688 | 105 | val _ = use root; | 
| 42172 | 106 | val timing = Timing.result start; | 
| 107 | val factor = Time.toReal (#cpu timing) / Time.toReal (#elapsed timing) | |
| 108 | |> Real.fmt (StringCvt.FIX (SOME 2)); | |
| 31898 | 109 | val _ = | 
| 39733 
6d373e9dcb9d
renamed raw output primitives to emphasize their meaning -- not to be used in user-space;
 wenzelm parents: 
39616diff
changeset | 110 |             Output.raw_stderr ("Timing " ^ item ^ " (" ^
 | 
| 31898 | 111 | string_of_int (Multithreading.max_threads_value ()) ^ " threads, " ^ | 
| 42172 | 112 | Timing.message timing ^ ", factor " ^ factor ^ ")\n"); | 
| 31688 | 113 | in () end | 
| 114 | else use root; | |
| 23972 | 115 | finish ())) | 
| 39616 
8052101883c3
renamed setmp_noncritical to Unsynchronized.setmp to emphasize its meaning;
 wenzelm parents: 
37216diff
changeset | 116 | |> Unsynchronized.setmp Proofterm.proofs level | 
| 
8052101883c3
renamed setmp_noncritical to Unsynchronized.setmp to emphasize its meaning;
 wenzelm parents: 
37216diff
changeset | 117 | |> Unsynchronized.setmp print_mode (modes @ print_mode_value ()) | 
| 
8052101883c3
renamed setmp_noncritical to Unsynchronized.setmp to emphasize its meaning;
 wenzelm parents: 
37216diff
changeset | 118 | |> Unsynchronized.setmp Goal.parallel_proofs parallel_proofs | 
| 41703 
d27950860514
parallelization of nested Isar proofs is subject to Goal.parallel_proofs_threshold;
 wenzelm parents: 
39733diff
changeset | 119 | |> Unsynchronized.setmp Goal.parallel_proofs_threshold parallel_proofs_threshold | 
| 39616 
8052101883c3
renamed setmp_noncritical to Unsynchronized.setmp to emphasize its meaning;
 wenzelm parents: 
37216diff
changeset | 120 | |> Unsynchronized.setmp Multithreading.trace trace_threads | 
| 
8052101883c3
renamed setmp_noncritical to Unsynchronized.setmp to emphasize its meaning;
 wenzelm parents: 
37216diff
changeset | 121 | |> Unsynchronized.setmp Multithreading.max_threads | 
| 23979 | 122 | (if Multithreading.available then max_threads | 
| 123 | else (if max_threads = 1 then () else warning "Multithreading support unavailable"; 1))) () | |
| 31478 | 124 | handle exn => (Output.error_msg (ML_Compiler.exn_message exn); exit 1); | 
| 6346 | 125 | |
| 126 | end; |