src/Pure/Isar/session.ML
author kleing
Mon Jun 21 10:25:57 2004 +0200 (2004-06-21)
changeset 14981 e73f8140af78
parent 12120 a08c61932501
child 15269 f856f4f3258f
permissions -rw-r--r--
Merged in license change from Isabelle2004
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
wenzelm@11910
    12
  val use_dir: bool -> string list -> bool -> bool -> string -> bool -> string
wenzelm@11579
    13
    -> string -> string -> string -> int -> 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@6346
    23
val pure = "Pure";
wenzelm@6346
    24
wenzelm@6346
    25
val session = ref ([pure]: string list);
wenzelm@6346
    26
val session_path = ref ([]: string list);
wenzelm@6346
    27
val session_finished = ref false;
wenzelm@9414
    28
val rpath = ref (None: Url.T option);
wenzelm@9414
    29
wenzelm@9414
    30
wenzelm@9414
    31
(* access path *)
wenzelm@6346
    32
wenzelm@6346
    33
fun path () = ! session_path;
wenzelm@6346
    34
wenzelm@10937
    35
fun str_of [] = pure
wenzelm@6346
    36
  | str_of elems = space_implode "/" elems;
wenzelm@6346
    37
wenzelm@11509
    38
fun name () = "Isabelle/" ^ str_of (path ());
wenzelm@11509
    39
fun welcome () = "Welcome to " ^ name () ^ " (" ^ version ^ ")";
wenzelm@6346
    40
wenzelm@6346
    41
wenzelm@9414
    42
(* add_path *)
wenzelm@9414
    43
wenzelm@9414
    44
fun add_path reset s =
wenzelm@9414
    45
  let val sess = ! session @ [s] in
wenzelm@9414
    46
    (case Library.duplicates sess of
wenzelm@9414
    47
      [] => (session := sess; session_path := ((if reset then [] else ! session_path) @ [s]))
wenzelm@9414
    48
    | dups => error ("Duplicate session identifiers " ^ commas_quote dups ^ " in " ^ str_of sess))
wenzelm@9414
    49
  end;
wenzelm@9414
    50
wenzelm@9414
    51
wenzelm@6346
    52
(* init *)
wenzelm@6346
    53
wenzelm@6346
    54
fun init reset parent name =
wenzelm@6346
    55
  if not (parent mem_string (! session)) orelse not (! session_finished) then
wenzelm@6346
    56
    error ("Unfinished parent session " ^ quote parent ^ " for " ^ quote name)
wenzelm@6346
    57
  else (add_path reset name; session_finished := false);
wenzelm@6346
    58
wenzelm@6346
    59
wenzelm@6346
    60
(* finish *)
wenzelm@6346
    61
wenzelm@6346
    62
fun finish () =
wenzelm@6663
    63
  (ThyInfo.finish ();
wenzelm@6346
    64
    Present.finish ();
wenzelm@6346
    65
    session_finished := true);
wenzelm@6346
    66
wenzelm@6346
    67
wenzelm@6346
    68
(* use_dir *)
wenzelm@6346
    69
wenzelm@6346
    70
val root_file = ThyLoad.ml_path "ROOT";
wenzelm@6346
    71
berghofe@7236
    72
fun get_rpath rpath_str =
berghofe@7236
    73
  (if rpath_str = "" then () else
berghofe@7227
    74
     if is_some (!rpath) then
berghofe@7227
    75
       error "Path for remote theory browsing information may only be set once"
berghofe@7227
    76
     else
berghofe@7227
    77
       rpath := Some (Url.unpack rpath_str);
berghofe@7236
    78
   (!rpath, rpath_str <> ""));
berghofe@7236
    79
wenzelm@11910
    80
fun use_dir build modes reset info doc doc_graph parent name dump rpath_str level verbose =
wenzelm@11543
    81
  Library.setmp print_mode (modes @ ! print_mode)
wenzelm@11543
    82
    (Library.setmp Proofterm.proofs level (fn () =>
wenzelm@11543
    83
      (init reset parent name;
wenzelm@11910
    84
       Present.init build info doc doc_graph (path ()) name
wenzelm@11579
    85
         (if dump = "" then None else Some (Path.unpack dump)) (get_rpath rpath_str) verbose;
wenzelm@12120
    86
       File.use root_file;
wenzelm@11543
    87
       finish ()))) ()
wenzelm@10571
    88
  handle exn => (writeln (Toplevel.exn_message exn); exit 1);
wenzelm@6346
    89
wenzelm@6346
    90
wenzelm@6346
    91
end;