src/Pure/Isar/session.ML
author wenzelm
Wed Dec 05 03:18:03 2001 +0100 (2001-12-05 ago)
changeset 12385 389d11fb62c8
parent 12120 a08c61932501
child 14981 e73f8140af78
permissions -rw-r--r--
removed unused functionality (weight etc.);
wenzelm@6346
     1
(*  Title:      Pure/Isar/session.ML
wenzelm@6346
     2
    ID:         $Id$
wenzelm@6346
     3
    Author:     Markus Wenzel, TU Muenchen
wenzelm@8807
     4
    License:    GPL (GNU GENERAL PUBLIC LICENSE)
wenzelm@6346
     5
wenzelm@6346
     6
Session management -- maintain state of logic images.
wenzelm@6346
     7
*)
wenzelm@6346
     8
wenzelm@6346
     9
signature SESSION =
wenzelm@6346
    10
sig
wenzelm@11509
    11
  val name: unit -> string
wenzelm@6346
    12
  val welcome: unit -> string
wenzelm@11910
    13
  val use_dir: bool -> string list -> bool -> bool -> string -> bool -> string
wenzelm@11579
    14
    -> string -> string -> string -> int -> bool -> unit
wenzelm@6346
    15
  val finish: unit -> unit
wenzelm@6346
    16
end;
wenzelm@6346
    17
wenzelm@6346
    18
structure Session: SESSION =
wenzelm@6346
    19
struct
wenzelm@6346
    20
wenzelm@6346
    21
wenzelm@6346
    22
(* session state *)
wenzelm@6346
    23
wenzelm@6346
    24
val pure = "Pure";
wenzelm@6346
    25
wenzelm@6346
    26
val session = ref ([pure]: string list);
wenzelm@6346
    27
val session_path = ref ([]: string list);
wenzelm@6346
    28
val session_finished = ref false;
wenzelm@9414
    29
val rpath = ref (None: Url.T option);
wenzelm@9414
    30
wenzelm@9414
    31
wenzelm@9414
    32
(* access path *)
wenzelm@6346
    33
wenzelm@6346
    34
fun path () = ! session_path;
wenzelm@6346
    35
wenzelm@10937
    36
fun str_of [] = pure
wenzelm@6346
    37
  | str_of elems = space_implode "/" elems;
wenzelm@6346
    38
wenzelm@11509
    39
fun name () = "Isabelle/" ^ str_of (path ());
wenzelm@11509
    40
fun welcome () = "Welcome to " ^ name () ^ " (" ^ version ^ ")";
wenzelm@6346
    41
wenzelm@6346
    42
wenzelm@9414
    43
(* add_path *)
wenzelm@9414
    44
wenzelm@9414
    45
fun add_path reset s =
wenzelm@9414
    46
  let val sess = ! session @ [s] in
wenzelm@9414
    47
    (case Library.duplicates sess of
wenzelm@9414
    48
      [] => (session := sess; session_path := ((if reset then [] else ! session_path) @ [s]))
wenzelm@9414
    49
    | dups => error ("Duplicate session identifiers " ^ commas_quote dups ^ " in " ^ str_of sess))
wenzelm@9414
    50
  end;
wenzelm@9414
    51
wenzelm@9414
    52
wenzelm@6346
    53
(* init *)
wenzelm@6346
    54
wenzelm@6346
    55
fun init reset parent name =
wenzelm@6346
    56
  if not (parent mem_string (! session)) orelse not (! session_finished) then
wenzelm@6346
    57
    error ("Unfinished parent session " ^ quote parent ^ " for " ^ quote name)
wenzelm@6346
    58
  else (add_path reset name; session_finished := false);
wenzelm@6346
    59
wenzelm@6346
    60
wenzelm@6346
    61
(* finish *)
wenzelm@6346
    62
wenzelm@6346
    63
fun finish () =
wenzelm@6663
    64
  (ThyInfo.finish ();
wenzelm@6346
    65
    Present.finish ();
wenzelm@6346
    66
    session_finished := true);
wenzelm@6346
    67
wenzelm@6346
    68
wenzelm@6346
    69
(* use_dir *)
wenzelm@6346
    70
wenzelm@6346
    71
val root_file = ThyLoad.ml_path "ROOT";
wenzelm@6346
    72
berghofe@7236
    73
fun get_rpath rpath_str =
berghofe@7236
    74
  (if rpath_str = "" then () else
berghofe@7227
    75
     if is_some (!rpath) then
berghofe@7227
    76
       error "Path for remote theory browsing information may only be set once"
berghofe@7227
    77
     else
berghofe@7227
    78
       rpath := Some (Url.unpack rpath_str);
berghofe@7236
    79
   (!rpath, rpath_str <> ""));
berghofe@7236
    80
wenzelm@11910
    81
fun use_dir build modes reset info doc doc_graph parent name dump rpath_str level verbose =
wenzelm@11543
    82
  Library.setmp print_mode (modes @ ! print_mode)
wenzelm@11543
    83
    (Library.setmp Proofterm.proofs level (fn () =>
wenzelm@11543
    84
      (init reset parent name;
wenzelm@11910
    85
       Present.init build info doc doc_graph (path ()) name
wenzelm@11579
    86
         (if dump = "" then None else Some (Path.unpack dump)) (get_rpath rpath_str) verbose;
wenzelm@12120
    87
       File.use root_file;
wenzelm@11543
    88
       finish ()))) ()
wenzelm@10571
    89
  handle exn => (writeln (Toplevel.exn_message exn); exit 1);
wenzelm@6346
    90
wenzelm@6346
    91
wenzelm@6346
    92
end;