src/Pure/Isar/session.ML
author wenzelm
Thu Mar 11 12:32:40 1999 +0100 (1999-03-11)
changeset 6346 643a1bd31a91
child 6641 254ab03bd082
permissions -rw-r--r--
moved Thy/session.ML to Isar/session.ML;
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@6346
    10
  val welcome: unit -> string
wenzelm@6346
    11
  val use_dir: bool -> bool -> string -> string -> unit
wenzelm@6346
    12
  val finish: unit -> unit
wenzelm@6346
    13
end;
wenzelm@6346
    14
wenzelm@6346
    15
structure Session: SESSION =
wenzelm@6346
    16
struct
wenzelm@6346
    17
wenzelm@6346
    18
wenzelm@6346
    19
(* session state *)
wenzelm@6346
    20
wenzelm@6346
    21
val pure = "Pure";
wenzelm@6346
    22
wenzelm@6346
    23
val session = ref ([pure]: string list);
wenzelm@6346
    24
val session_path = ref ([]: string list);
wenzelm@6346
    25
val session_finished = ref false;
wenzelm@6346
    26
wenzelm@6346
    27
fun path () = ! session_path;
wenzelm@6346
    28
wenzelm@6346
    29
fun add_path reset s =
wenzelm@6346
    30
  (session := ! session @ [s]; session_path := ((if reset then [] else ! session_path) @ [s]));
wenzelm@6346
    31
wenzelm@6346
    32
wenzelm@6346
    33
(* diagnostics *)
wenzelm@6346
    34
wenzelm@6346
    35
fun str_of [] = "Pure"
wenzelm@6346
    36
  | str_of elems = space_implode "/" elems;
wenzelm@6346
    37
wenzelm@6346
    38
fun welcome () = "Welcome to Isabelle/" ^ str_of (path ()) ^ " (" ^ version ^ ")";
wenzelm@6346
    39
wenzelm@6346
    40
wenzelm@6346
    41
(* init *)
wenzelm@6346
    42
wenzelm@6346
    43
fun init reset parent name =
wenzelm@6346
    44
  if not (parent mem_string (! session)) orelse not (! session_finished) then
wenzelm@6346
    45
    error ("Unfinished parent session " ^ quote parent ^ " for " ^ quote name)
wenzelm@6346
    46
  else (add_path reset name; session_finished := false);
wenzelm@6346
    47
wenzelm@6346
    48
wenzelm@6346
    49
(* finish *)
wenzelm@6346
    50
wenzelm@6346
    51
fun finish () =
wenzelm@6346
    52
  (ThyInfo.finalize_all ();
wenzelm@6346
    53
    Present.finish ();
wenzelm@6346
    54
    session_finished := true);
wenzelm@6346
    55
wenzelm@6346
    56
wenzelm@6346
    57
(* use_dir *)
wenzelm@6346
    58
wenzelm@6346
    59
val root_file = ThyLoad.ml_path "ROOT";
wenzelm@6346
    60
wenzelm@6346
    61
fun use_dir reset info parent name =
wenzelm@6346
    62
  (init reset parent name;
wenzelm@6346
    63
    Present.init info (path ()) name;
wenzelm@6346
    64
    Symbol.use root_file;
wenzelm@6346
    65
    finish ()) handle exn => (writeln (Toplevel.exn_message exn); exit 1);
wenzelm@6346
    66
wenzelm@6346
    67
wenzelm@6346
    68
end;