src/Pure/Isar/session.ML
author wenzelm
Tue May 17 18:10:31 2005 +0200 (2005-05-17)
changeset 15979 c81578ac2d31
parent 15973 5fd94d84470f
child 16451 c9f1fc144132
permissions -rw-r--r--
tuned;
wenzelm@6346
     1
(*  Title:      Pure/Isar/session.ML
wenzelm@6346
     2
    ID:         $Id$
wenzelm@6346
     3
    Author:     Markus Wenzel, TU Muenchen
wenzelm@6346
     4
wenzelm@6346
     5
Session management -- maintain state of logic images.
wenzelm@6346
     6
*)
wenzelm@6346
     7
wenzelm@6346
     8
signature SESSION =
wenzelm@6346
     9
sig
wenzelm@11509
    10
  val name: unit -> string
wenzelm@6346
    11
  val welcome: unit -> string
webertj@15269
    12
  val use_dir: string -> bool -> string list -> bool -> bool -> string -> bool -> string
berghofe@15433
    13
    -> string -> string -> string -> int -> bool -> bool -> unit
wenzelm@6346
    14
  val finish: unit -> unit
wenzelm@6346
    15
end;
wenzelm@6346
    16
wenzelm@6346
    17
structure Session: SESSION =
wenzelm@6346
    18
struct
wenzelm@6346
    19
wenzelm@6346
    20
wenzelm@6346
    21
(* session state *)
wenzelm@6346
    22
wenzelm@15979
    23
val session = ref ([Sign.PureN]: string list);
wenzelm@6346
    24
val session_path = ref ([]: string list);
wenzelm@6346
    25
val session_finished = ref false;
wenzelm@15979
    26
val remote_path = ref (NONE: Url.T option);
wenzelm@9414
    27
wenzelm@9414
    28
wenzelm@9414
    29
(* access path *)
wenzelm@6346
    30
wenzelm@6346
    31
fun path () = ! session_path;
wenzelm@6346
    32
wenzelm@15979
    33
fun str_of [] = Sign.PureN
wenzelm@6346
    34
  | str_of elems = space_implode "/" elems;
wenzelm@6346
    35
wenzelm@11509
    36
fun name () = "Isabelle/" ^ str_of (path ());
wenzelm@11509
    37
fun welcome () = "Welcome to " ^ name () ^ " (" ^ version ^ ")";
wenzelm@6346
    38
wenzelm@6346
    39
wenzelm@9414
    40
(* add_path *)
wenzelm@9414
    41
wenzelm@9414
    42
fun add_path reset s =
wenzelm@9414
    43
  let val sess = ! session @ [s] in
wenzelm@9414
    44
    (case Library.duplicates sess of
wenzelm@9414
    45
      [] => (session := sess; session_path := ((if reset then [] else ! session_path) @ [s]))
wenzelm@9414
    46
    | dups => error ("Duplicate session identifiers " ^ commas_quote dups ^ " in " ^ str_of sess))
wenzelm@9414
    47
  end;
wenzelm@9414
    48
wenzelm@9414
    49
wenzelm@6346
    50
(* init *)
wenzelm@6346
    51
wenzelm@6346
    52
fun init reset parent name =
wenzelm@6346
    53
  if not (parent mem_string (! session)) orelse not (! session_finished) then
wenzelm@6346
    54
    error ("Unfinished parent session " ^ quote parent ^ " for " ^ quote name)
wenzelm@6346
    55
  else (add_path reset name; session_finished := false);
wenzelm@6346
    56
wenzelm@6346
    57
wenzelm@6346
    58
(* finish *)
wenzelm@6346
    59
wenzelm@6346
    60
fun finish () =
wenzelm@6663
    61
  (ThyInfo.finish ();
wenzelm@6346
    62
    Present.finish ();
wenzelm@6346
    63
    session_finished := true);
wenzelm@6346
    64
wenzelm@6346
    65
wenzelm@6346
    66
(* use_dir *)
wenzelm@6346
    67
berghofe@7236
    68
fun get_rpath rpath_str =
berghofe@7236
    69
  (if rpath_str = "" then () else
wenzelm@15979
    70
     if is_some (! remote_path) then
berghofe@7227
    71
       error "Path for remote theory browsing information may only be set once"
berghofe@7227
    72
     else
wenzelm@15979
    73
       remote_path := SOME (Url.unpack rpath_str);
wenzelm@15979
    74
   (! remote_path, rpath_str <> ""));
berghofe@7236
    75
wenzelm@15979
    76
fun use_dir root build modes reset info doc doc_graph parent name dump rpath_str level verbose hide =
wenzelm@11543
    77
  Library.setmp print_mode (modes @ ! print_mode)
berghofe@15433
    78
    (Library.setmp Proofterm.proofs level (Library.setmp IsarOutput.hide_commands hide (fn () =>
wenzelm@11543
    79
      (init reset parent name;
wenzelm@11910
    80
       Present.init build info doc doc_graph (path ()) name
skalberg@15531
    81
         (if dump = "" then NONE else SOME (Path.unpack dump)) (get_rpath rpath_str) verbose;
wenzelm@15979
    82
       File.use (Path.basic root);
berghofe@15433
    83
       finish ())))) ()
wenzelm@10571
    84
  handle exn => (writeln (Toplevel.exn_message exn); exit 1);
wenzelm@6346
    85
wenzelm@6346
    86
wenzelm@6346
    87
end;