src/Pure/Thy/thy_load.ML
author wenzelm
Sun, 20 Mar 2011 13:49:21 +0100
changeset 42002 ac7097bd8611
parent 41955 703ea96b13c6
child 42003 6e45dc518ebb
permissions -rw-r--r--
tuned;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6168
9d5b74068bf9 Theory loader primitives.
wenzelm
parents:
diff changeset
     1
(*  Title:      Pure/Thy/thy_load.ML
42002
wenzelm
parents: 41955
diff changeset
     2
    Author:     Makarius
6168
9d5b74068bf9 Theory loader primitives.
wenzelm
parents:
diff changeset
     3
42002
wenzelm
parents: 41955
diff changeset
     4
Loading files that contribute to a theory.  Global master path.
6168
9d5b74068bf9 Theory loader primitives.
wenzelm
parents:
diff changeset
     5
*)
9d5b74068bf9 Theory loader primitives.
wenzelm
parents:
diff changeset
     6
9d5b74068bf9 Theory loader primitives.
wenzelm
parents:
diff changeset
     7
signature THY_LOAD =
9d5b74068bf9 Theory loader primitives.
wenzelm
parents:
diff changeset
     8
sig
37949
48a874444164 moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
wenzelm
parents: 37943
diff changeset
     9
  val master_directory: theory -> Path.T
41548
bd0bebf93fa6 Thy_Load.begin_theory: maintain source specification of imports;
wenzelm
parents: 41414
diff changeset
    10
  val imports_of: theory -> string list
41955
703ea96b13c6 files are identified via SHA1 digests -- discontinued ISABELLE_FILE_IDENT;
wenzelm
parents: 41944
diff changeset
    11
  val provide: Path.T * (Path.T * SHA1.digest) -> theory -> theory
703ea96b13c6 files are identified via SHA1 digests -- discontinued ISABELLE_FILE_IDENT;
wenzelm
parents: 41944
diff changeset
    12
  val check_file: Path.T -> Path.T -> Path.T * SHA1.digest
703ea96b13c6 files are identified via SHA1 digests -- discontinued ISABELLE_FILE_IDENT;
wenzelm
parents: 41944
diff changeset
    13
  val check_thy: Path.T -> string -> Path.T * SHA1.digest
24189
1fa9852643a3 simplified ThyLoad.deps_thy etc.: discontinued attached ML files;
wenzelm
parents: 24065
diff changeset
    14
  val deps_thy: Path.T -> string ->
41955
703ea96b13c6 files are identified via SHA1 digests -- discontinued ISABELLE_FILE_IDENT;
wenzelm
parents: 41944
diff changeset
    15
   {master: Path.T * SHA1.digest, text: string, imports: string list, uses: Path.T list}
37949
48a874444164 moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
wenzelm
parents: 37943
diff changeset
    16
  val loaded_files: theory -> Path.T list
48a874444164 moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
wenzelm
parents: 37943
diff changeset
    17
  val all_current: theory -> bool
48a874444164 moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
wenzelm
parents: 37943
diff changeset
    18
  val provide_file: Path.T -> theory -> theory
48a874444164 moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
wenzelm
parents: 37943
diff changeset
    19
  val use_ml: Path.T -> unit
48a874444164 moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
wenzelm
parents: 37943
diff changeset
    20
  val exec_ml: Path.T -> generic_theory -> generic_theory
41548
bd0bebf93fa6 Thy_Load.begin_theory: maintain source specification of imports;
wenzelm
parents: 41414
diff changeset
    21
  val begin_theory: Path.T -> string -> string list -> theory list -> (Path.T * bool) list -> theory
42002
wenzelm
parents: 41955
diff changeset
    22
  val set_master_path: Path.T -> unit
wenzelm
parents: 41955
diff changeset
    23
  val get_master_path: unit -> Path.T
6168
9d5b74068bf9 Theory loader primitives.
wenzelm
parents:
diff changeset
    24
end;
9d5b74068bf9 Theory loader primitives.
wenzelm
parents:
diff changeset
    25
37216
3165bc303f66 modernized some structure names, keeping a few legacy aliases;
wenzelm
parents: 33221
diff changeset
    26
structure Thy_Load: THY_LOAD =
6168
9d5b74068bf9 Theory loader primitives.
wenzelm
parents:
diff changeset
    27
struct
9d5b74068bf9 Theory loader primitives.
wenzelm
parents:
diff changeset
    28
37949
48a874444164 moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
wenzelm
parents: 37943
diff changeset
    29
(* manage source files *)
48a874444164 moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
wenzelm
parents: 37943
diff changeset
    30
48a874444164 moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
wenzelm
parents: 37943
diff changeset
    31
type files =
40741
17d6293a1e26 moved file identification to thy_load.ML (where it is actually used);
wenzelm
parents: 40625
diff changeset
    32
 {master_dir: Path.T,  (*master directory of theory source*)
41548
bd0bebf93fa6 Thy_Load.begin_theory: maintain source specification of imports;
wenzelm
parents: 41414
diff changeset
    33
  imports: string list,  (*source specification of imports*)
40741
17d6293a1e26 moved file identification to thy_load.ML (where it is actually used);
wenzelm
parents: 40625
diff changeset
    34
  required: Path.T list,  (*source path*)
41955
703ea96b13c6 files are identified via SHA1 digests -- discontinued ISABELLE_FILE_IDENT;
wenzelm
parents: 41944
diff changeset
    35
  provided: (Path.T * (Path.T * SHA1.digest)) list};  (*source path, physical path, digest*)
37949
48a874444164 moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
wenzelm
parents: 37943
diff changeset
    36
41548
bd0bebf93fa6 Thy_Load.begin_theory: maintain source specification of imports;
wenzelm
parents: 41414
diff changeset
    37
fun make_files (master_dir, imports, required, provided): files =
bd0bebf93fa6 Thy_Load.begin_theory: maintain source specification of imports;
wenzelm
parents: 41414
diff changeset
    38
 {master_dir = master_dir, imports = imports, required = required, provided = provided};
37949
48a874444164 moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
wenzelm
parents: 37943
diff changeset
    39
48a874444164 moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
wenzelm
parents: 37943
diff changeset
    40
structure Files = Theory_Data
48a874444164 moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
wenzelm
parents: 37943
diff changeset
    41
(
48a874444164 moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
wenzelm
parents: 37943
diff changeset
    42
  type T = files;
41548
bd0bebf93fa6 Thy_Load.begin_theory: maintain source specification of imports;
wenzelm
parents: 41414
diff changeset
    43
  val empty = make_files (Path.current, [], [], []);
37949
48a874444164 moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
wenzelm
parents: 37943
diff changeset
    44
  fun extend _ = empty;
48a874444164 moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
wenzelm
parents: 37943
diff changeset
    45
  fun merge _ = empty;
48a874444164 moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
wenzelm
parents: 37943
diff changeset
    46
);
48a874444164 moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
wenzelm
parents: 37943
diff changeset
    47
48a874444164 moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
wenzelm
parents: 37943
diff changeset
    48
fun map_files f =
41548
bd0bebf93fa6 Thy_Load.begin_theory: maintain source specification of imports;
wenzelm
parents: 41414
diff changeset
    49
  Files.map (fn {master_dir, imports, required, provided} =>
bd0bebf93fa6 Thy_Load.begin_theory: maintain source specification of imports;
wenzelm
parents: 41414
diff changeset
    50
    make_files (f (master_dir, imports, required, provided)));
37949
48a874444164 moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
wenzelm
parents: 37943
diff changeset
    51
48a874444164 moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
wenzelm
parents: 37943
diff changeset
    52
48a874444164 moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
wenzelm
parents: 37943
diff changeset
    53
val master_directory = #master_dir o Files.get;
41548
bd0bebf93fa6 Thy_Load.begin_theory: maintain source specification of imports;
wenzelm
parents: 41414
diff changeset
    54
val imports_of = #imports o Files.get;
37949
48a874444164 moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
wenzelm
parents: 37943
diff changeset
    55
41548
bd0bebf93fa6 Thy_Load.begin_theory: maintain source specification of imports;
wenzelm
parents: 41414
diff changeset
    56
fun put_deps dir imports = map_files (fn _ => (dir, imports, [], []));
37949
48a874444164 moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
wenzelm
parents: 37943
diff changeset
    57
48a874444164 moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
wenzelm
parents: 37943
diff changeset
    58
fun require src_path =
41548
bd0bebf93fa6 Thy_Load.begin_theory: maintain source specification of imports;
wenzelm
parents: 41414
diff changeset
    59
  map_files (fn (master_dir, imports, required, provided) =>
37949
48a874444164 moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
wenzelm
parents: 37943
diff changeset
    60
    if member (op =) required src_path then
41944
b97091ae583a Path.print is the official way to show file-system paths to users -- note that Path.implode often indicates violation of the abstract datatype;
wenzelm
parents: 41886
diff changeset
    61
      error ("Duplicate source file dependency: " ^ Path.print src_path)
41548
bd0bebf93fa6 Thy_Load.begin_theory: maintain source specification of imports;
wenzelm
parents: 41414
diff changeset
    62
    else (master_dir, imports, src_path :: required, provided));
37949
48a874444164 moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
wenzelm
parents: 37943
diff changeset
    63
37978
548f3f165d05 simplified Thy_Header.read -- include Source.of_string_limited here;
wenzelm
parents: 37977
diff changeset
    64
fun provide (src_path, path_id) =
41548
bd0bebf93fa6 Thy_Load.begin_theory: maintain source specification of imports;
wenzelm
parents: 41414
diff changeset
    65
  map_files (fn (master_dir, imports, required, provided) =>
37949
48a874444164 moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
wenzelm
parents: 37943
diff changeset
    66
    if AList.defined (op =) provided src_path then
41944
b97091ae583a Path.print is the official way to show file-system paths to users -- note that Path.implode often indicates violation of the abstract datatype;
wenzelm
parents: 41886
diff changeset
    67
      error ("Duplicate resolution of source file dependency: " ^ Path.print src_path)
41548
bd0bebf93fa6 Thy_Load.begin_theory: maintain source specification of imports;
wenzelm
parents: 41414
diff changeset
    68
    else (master_dir, imports, required, (src_path, path_id) :: provided));
37949
48a874444164 moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
wenzelm
parents: 37943
diff changeset
    69
48a874444164 moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
wenzelm
parents: 37943
diff changeset
    70
23872
f449381e2caa tuned signature;
wenzelm
parents: 22145
diff changeset
    71
(* check files *)
6232
4336add1c251 include full paths in file info;
wenzelm
parents: 6219
diff changeset
    72
41886
aa8dce9ab8a9 discontinued legacy load path;
wenzelm
parents: 41548
diff changeset
    73
fun get_file dir src_path =
6232
4336add1c251 include full paths in file info;
wenzelm
parents: 6219
diff changeset
    74
  let
4336add1c251 include full paths in file info;
wenzelm
parents: 6219
diff changeset
    75
    val path = Path.expand src_path;
23872
f449381e2caa tuned signature;
wenzelm
parents: 22145
diff changeset
    76
    val _ = Path.is_current path andalso error "Bad file specification";
41886
aa8dce9ab8a9 discontinued legacy load path;
wenzelm
parents: 41548
diff changeset
    77
    val full_path = File.full_path (Path.append dir path);
37939
965537d86fcc discontinued special treatment of ML files -- no longer complete extensions on demand;
wenzelm
parents: 37938
diff changeset
    78
  in
41955
703ea96b13c6 files are identified via SHA1 digests -- discontinued ISABELLE_FILE_IDENT;
wenzelm
parents: 41944
diff changeset
    79
    if File.exists full_path
703ea96b13c6 files are identified via SHA1 digests -- discontinued ISABELLE_FILE_IDENT;
wenzelm
parents: 41944
diff changeset
    80
    then SOME (full_path, SHA1.digest (File.read full_path))
703ea96b13c6 files are identified via SHA1 digests -- discontinued ISABELLE_FILE_IDENT;
wenzelm
parents: 41944
diff changeset
    81
    else NONE
37939
965537d86fcc discontinued special treatment of ML files -- no longer complete extensions on demand;
wenzelm
parents: 37938
diff changeset
    82
  end;
6168
9d5b74068bf9 Theory loader primitives.
wenzelm
parents:
diff changeset
    83
41886
aa8dce9ab8a9 discontinued legacy load path;
wenzelm
parents: 41548
diff changeset
    84
fun check_file dir file =
aa8dce9ab8a9 discontinued legacy load path;
wenzelm
parents: 41548
diff changeset
    85
  (case get_file dir file of
aa8dce9ab8a9 discontinued legacy load path;
wenzelm
parents: 41548
diff changeset
    86
    SOME path_id => path_id
41944
b97091ae583a Path.print is the official way to show file-system paths to users -- note that Path.implode often indicates violation of the abstract datatype;
wenzelm
parents: 41886
diff changeset
    87
  | NONE => error ("Could not find file " ^ Path.print file ^ "\nin " ^ Path.print dir));
37939
965537d86fcc discontinued special treatment of ML files -- no longer complete extensions on demand;
wenzelm
parents: 37938
diff changeset
    88
41886
aa8dce9ab8a9 discontinued legacy load path;
wenzelm
parents: 41548
diff changeset
    89
fun check_thy dir name =
aa8dce9ab8a9 discontinued legacy load path;
wenzelm
parents: 41548
diff changeset
    90
  check_file dir (Thy_Header.thy_path name);
6232
4336add1c251 include full paths in file info;
wenzelm
parents: 6219
diff changeset
    91
4336add1c251 include full paths in file info;
wenzelm
parents: 6219
diff changeset
    92
23872
f449381e2caa tuned signature;
wenzelm
parents: 22145
diff changeset
    93
(* theory deps *)
7940
def6db239934 improved ml handling;
wenzelm
parents: 7901
diff changeset
    94
38133
987680d2e77d simplified/clarified Thy_Load path: search for master only, lookup other files relative to that;
wenzelm
parents: 37978
diff changeset
    95
fun deps_thy master_dir name =
23872
f449381e2caa tuned signature;
wenzelm
parents: 22145
diff changeset
    96
  let
38133
987680d2e77d simplified/clarified Thy_Load path: search for master only, lookup other files relative to that;
wenzelm
parents: 37978
diff changeset
    97
    val master as (thy_path, _) = check_thy master_dir name;
37978
548f3f165d05 simplified Thy_Header.read -- include Source.of_string_limited here;
wenzelm
parents: 37977
diff changeset
    98
    val text = File.read thy_path;
548f3f165d05 simplified Thy_Header.read -- include Source.of_string_limited here;
wenzelm
parents: 37977
diff changeset
    99
    val (name', imports, uses) = Thy_Header.read (Path.position thy_path) text;
37950
bc285d91041e moved basic thy file name operations from Thy_Load to Thy_Header;
wenzelm
parents: 37949
diff changeset
   100
    val _ = Thy_Header.consistent_name name name';
24189
1fa9852643a3 simplified ThyLoad.deps_thy etc.: discontinued attached ML files;
wenzelm
parents: 24065
diff changeset
   101
    val uses = map (Path.explode o #1) uses;
24065
21483400c2ca load_thy: avoid reloading of text;
wenzelm
parents: 23944
diff changeset
   102
  in {master = master, text = text, imports = imports, uses = uses} end;
6484
3f098b0ec683 use_thy etc.: may specify path prefix, which is temporarily used as load path;
wenzelm
parents: 6363
diff changeset
   103
6168
9d5b74068bf9 Theory loader primitives.
wenzelm
parents:
diff changeset
   104
37949
48a874444164 moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
wenzelm
parents: 37943
diff changeset
   105
48a874444164 moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
wenzelm
parents: 37943
diff changeset
   106
(* loaded files *)
48a874444164 moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
wenzelm
parents: 37943
diff changeset
   107
48a874444164 moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
wenzelm
parents: 37943
diff changeset
   108
val loaded_files = map (#1 o #2) o #provided o Files.get;
6168
9d5b74068bf9 Theory loader primitives.
wenzelm
parents:
diff changeset
   109
37949
48a874444164 moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
wenzelm
parents: 37943
diff changeset
   110
fun check_loaded thy =
48a874444164 moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
wenzelm
parents: 37943
diff changeset
   111
  let
48a874444164 moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
wenzelm
parents: 37943
diff changeset
   112
    val {required, provided, ...} = Files.get thy;
48a874444164 moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
wenzelm
parents: 37943
diff changeset
   113
    val provided_paths = map #1 provided;
48a874444164 moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
wenzelm
parents: 37943
diff changeset
   114
    val _ =
48a874444164 moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
wenzelm
parents: 37943
diff changeset
   115
      (case subtract (op =) provided_paths required of
48a874444164 moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
wenzelm
parents: 37943
diff changeset
   116
        [] => NONE
41944
b97091ae583a Path.print is the official way to show file-system paths to users -- note that Path.implode often indicates violation of the abstract datatype;
wenzelm
parents: 41886
diff changeset
   117
      | bad => error ("Pending source file dependencies: " ^ commas (map Path.print (rev bad))));
37949
48a874444164 moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
wenzelm
parents: 37943
diff changeset
   118
    val _ =
48a874444164 moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
wenzelm
parents: 37943
diff changeset
   119
      (case subtract (op =) required provided_paths of
48a874444164 moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
wenzelm
parents: 37943
diff changeset
   120
        [] => NONE
41944
b97091ae583a Path.print is the official way to show file-system paths to users -- note that Path.implode often indicates violation of the abstract datatype;
wenzelm
parents: 41886
diff changeset
   121
      | bad => error ("Undeclared source file dependencies: " ^ commas (map Path.print (rev bad))));
37949
48a874444164 moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
wenzelm
parents: 37943
diff changeset
   122
  in () end;
48a874444164 moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
wenzelm
parents: 37943
diff changeset
   123
48a874444164 moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
wenzelm
parents: 37943
diff changeset
   124
fun all_current thy =
37939
965537d86fcc discontinued special treatment of ML files -- no longer complete extensions on demand;
wenzelm
parents: 37938
diff changeset
   125
  let
37949
48a874444164 moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
wenzelm
parents: 37943
diff changeset
   126
    val {master_dir, provided, ...} = Files.get thy;
37978
548f3f165d05 simplified Thy_Header.read -- include Source.of_string_limited here;
wenzelm
parents: 37977
diff changeset
   127
    fun current (src_path, (_, id)) =
41886
aa8dce9ab8a9 discontinued legacy load path;
wenzelm
parents: 41548
diff changeset
   128
      (case get_file master_dir src_path of
37949
48a874444164 moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
wenzelm
parents: 37943
diff changeset
   129
        NONE => false
41886
aa8dce9ab8a9 discontinued legacy load path;
wenzelm
parents: 41548
diff changeset
   130
      | SOME (_, id') => id = id');
37949
48a874444164 moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
wenzelm
parents: 37943
diff changeset
   131
  in can check_loaded thy andalso forall current provided end;
48a874444164 moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
wenzelm
parents: 37943
diff changeset
   132
37952
f6c40213675b Thy_Load.check_loaded via Theory.at_end;
wenzelm
parents: 37950
diff changeset
   133
val _ = Context.>> (Context.map_theory (Theory.at_end (fn thy => (check_loaded thy; NONE))));
f6c40213675b Thy_Load.check_loaded via Theory.at_end;
wenzelm
parents: 37950
diff changeset
   134
37949
48a874444164 moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
wenzelm
parents: 37943
diff changeset
   135
48a874444164 moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
wenzelm
parents: 37943
diff changeset
   136
(* provide files *)
48a874444164 moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
wenzelm
parents: 37943
diff changeset
   137
48a874444164 moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
wenzelm
parents: 37943
diff changeset
   138
fun provide_file src_path thy =
41886
aa8dce9ab8a9 discontinued legacy load path;
wenzelm
parents: 41548
diff changeset
   139
  provide (src_path, check_file (master_directory thy) src_path) thy;
37949
48a874444164 moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
wenzelm
parents: 37943
diff changeset
   140
48a874444164 moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
wenzelm
parents: 37943
diff changeset
   141
fun use_ml src_path =
48a874444164 moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
wenzelm
parents: 37943
diff changeset
   142
  if is_none (Context.thread_data ()) then
41886
aa8dce9ab8a9 discontinued legacy load path;
wenzelm
parents: 41548
diff changeset
   143
    ML_Context.eval_file (#1 (check_file Path.current src_path))
37949
48a874444164 moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
wenzelm
parents: 37943
diff changeset
   144
  else
48a874444164 moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
wenzelm
parents: 37943
diff changeset
   145
    let
48a874444164 moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
wenzelm
parents: 37943
diff changeset
   146
      val thy = ML_Context.the_global_context ();
41886
aa8dce9ab8a9 discontinued legacy load path;
wenzelm
parents: 41548
diff changeset
   147
      val (path, id) = check_file (master_directory thy) src_path;
37949
48a874444164 moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
wenzelm
parents: 37943
diff changeset
   148
48a874444164 moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
wenzelm
parents: 37943
diff changeset
   149
      val _ = ML_Context.eval_file path;
48a874444164 moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
wenzelm
parents: 37943
diff changeset
   150
      val _ = Context.>> Local_Theory.propagate_ml_env;
48a874444164 moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
wenzelm
parents: 37943
diff changeset
   151
37978
548f3f165d05 simplified Thy_Header.read -- include Source.of_string_limited here;
wenzelm
parents: 37977
diff changeset
   152
      val provide = provide (src_path, (path, id));
38757
2b3e054ae6fc renamed Local_Theory.theory(_result) to Local_Theory.background_theory(_result) to emphasize that this belongs to the infrastructure and is rarely appropriate in user-space tools;
wenzelm
parents: 38133
diff changeset
   153
      val _ = Context.>> (Context.mapping provide (Local_Theory.background_theory provide));
37978
548f3f165d05 simplified Thy_Header.read -- include Source.of_string_limited here;
wenzelm
parents: 37977
diff changeset
   154
    in () end;
37949
48a874444164 moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
wenzelm
parents: 37943
diff changeset
   155
48a874444164 moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
wenzelm
parents: 37943
diff changeset
   156
fun exec_ml src_path = ML_Context.exec (fn () => use_ml src_path);
6168
9d5b74068bf9 Theory loader primitives.
wenzelm
parents:
diff changeset
   157
37977
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37952
diff changeset
   158
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37952
diff changeset
   159
(* begin theory *)
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37952
diff changeset
   160
41548
bd0bebf93fa6 Thy_Load.begin_theory: maintain source specification of imports;
wenzelm
parents: 41414
diff changeset
   161
fun begin_theory dir name imports parents uses =
37977
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37952
diff changeset
   162
  Theory.begin_theory name parents
41548
bd0bebf93fa6 Thy_Load.begin_theory: maintain source specification of imports;
wenzelm
parents: 41414
diff changeset
   163
  |> put_deps dir imports
37977
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37952
diff changeset
   164
  |> fold (require o fst) uses
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37952
diff changeset
   165
  |> fold (fn (path, true) => Context.theory_map (exec_ml path) o Theory.checkpoint | _ => I) uses
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37952
diff changeset
   166
  |> Theory.checkpoint;
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37952
diff changeset
   167
42002
wenzelm
parents: 41955
diff changeset
   168
wenzelm
parents: 41955
diff changeset
   169
(* global master path *)
wenzelm
parents: 41955
diff changeset
   170
wenzelm
parents: 41955
diff changeset
   171
local
wenzelm
parents: 41955
diff changeset
   172
  val master_path = Unsynchronized.ref Path.current;
wenzelm
parents: 41955
diff changeset
   173
in
wenzelm
parents: 41955
diff changeset
   174
wenzelm
parents: 41955
diff changeset
   175
fun set_master_path path = master_path := path;
wenzelm
parents: 41955
diff changeset
   176
fun get_master_path () = ! master_path;
wenzelm
parents: 41955
diff changeset
   177
6168
9d5b74068bf9 Theory loader primitives.
wenzelm
parents:
diff changeset
   178
end;
9d5b74068bf9 Theory loader primitives.
wenzelm
parents:
diff changeset
   179
42002
wenzelm
parents: 41955
diff changeset
   180
end;