src/Pure/Isar/session.ML
author wenzelm
Wed Sep 29 13:49:07 1999 +0200 (1999-09-29)
changeset 7632 25a0d2ba3a87
parent 7236 e077484d50d8
child 7730 ba9e55b92998
permissions -rw-r--r--
removed extra shyps error;
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
berghofe@6651
    11
  val use_dir: bool -> bool -> string -> 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;
berghofe@7236
    26
val rpath = ref (None : Url.T option);
wenzelm@6346
    27
wenzelm@6346
    28
fun path () = ! session_path;
wenzelm@6346
    29
wenzelm@6346
    30
fun add_path reset s =
wenzelm@6346
    31
  (session := ! session @ [s]; session_path := ((if reset then [] else ! session_path) @ [s]));
wenzelm@6346
    32
wenzelm@6346
    33
wenzelm@6346
    34
(* diagnostics *)
wenzelm@6346
    35
wenzelm@6346
    36
fun str_of [] = "Pure"
wenzelm@6346
    37
  | str_of elems = space_implode "/" elems;
wenzelm@6346
    38
wenzelm@6346
    39
fun welcome () = "Welcome to Isabelle/" ^ str_of (path ()) ^ " (" ^ version ^ ")";
wenzelm@6346
    40
wenzelm@6346
    41
wenzelm@6346
    42
(* init *)
wenzelm@6346
    43
wenzelm@6346
    44
fun init reset parent name =
wenzelm@6346
    45
  if not (parent mem_string (! session)) orelse not (! session_finished) then
wenzelm@6346
    46
    error ("Unfinished parent session " ^ quote parent ^ " for " ^ quote name)
wenzelm@6346
    47
  else (add_path reset name; session_finished := false);
wenzelm@6346
    48
wenzelm@6346
    49
wenzelm@6346
    50
(* finish *)
wenzelm@6346
    51
wenzelm@6346
    52
fun finish () =
wenzelm@6663
    53
  (ThyInfo.finish ();
wenzelm@6346
    54
    Present.finish ();
wenzelm@6346
    55
    session_finished := true);
wenzelm@6346
    56
wenzelm@6346
    57
wenzelm@6346
    58
(* use_dir *)
wenzelm@6346
    59
wenzelm@6346
    60
val root_file = ThyLoad.ml_path "ROOT";
wenzelm@6346
    61
berghofe@7236
    62
fun get_rpath rpath_str =
berghofe@7236
    63
  (if rpath_str = "" then () else
berghofe@7227
    64
     if is_some (!rpath) then
berghofe@7227
    65
       error "Path for remote theory browsing information may only be set once"
berghofe@7227
    66
     else
berghofe@7227
    67
       rpath := Some (Url.unpack rpath_str);
berghofe@7236
    68
   (!rpath, rpath_str <> ""));
berghofe@7236
    69
berghofe@7236
    70
fun use_dir reset info parent name rpath_str =
berghofe@7236
    71
  (init reset parent name;
berghofe@7236
    72
   Present.init info (path ()) name (get_rpath rpath_str);
berghofe@7227
    73
   File.symbol_use root_file;
berghofe@7227
    74
   finish ()) handle exn => (writeln (Toplevel.exn_message exn); exit 1);
wenzelm@6346
    75
wenzelm@6346
    76
wenzelm@6346
    77
end;