| author | wenzelm | 
| Tue, 06 Sep 2011 20:37:07 +0200 | |
| changeset 44736 | c2a3f1c84179 | 
| parent 44478 | 4fdb1009a370 | 
| child 46737 | 09ab89658a5d | 
| permissions | -rw-r--r-- | 
| 6168 | 1 | (* Title: Pure/Thy/thy_load.ML | 
| 42002 | 2 | Author: Makarius | 
| 6168 | 3 | |
| 42002 | 4 | Loading files that contribute to a theory. Global master path. | 
| 6168 | 5 | *) | 
| 6 | ||
| 7 | signature THY_LOAD = | |
| 8 | sig | |
| 37949 
48a874444164
moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
 wenzelm parents: 
37943diff
changeset | 9 | val master_directory: theory -> Path.T | 
| 41548 
bd0bebf93fa6
Thy_Load.begin_theory: maintain source specification of imports;
 wenzelm parents: 
41414diff
changeset | 10 | val imports_of: theory -> string list | 
| 41955 
703ea96b13c6
files are identified via SHA1 digests -- discontinued ISABELLE_FILE_IDENT;
 wenzelm parents: 
41944diff
changeset | 11 | val provide: Path.T * (Path.T * SHA1.digest) -> theory -> theory | 
| 42003 
6e45dc518ebb
replaced File.check by specific File.check_file, File.check_dir;
 wenzelm parents: 
42002diff
changeset | 12 | val check_file: Path.T -> Path.T -> Path.T | 
| 
6e45dc518ebb
replaced File.check by specific File.check_file, File.check_dir;
 wenzelm parents: 
42002diff
changeset | 13 | val check_thy: Path.T -> string -> | 
| 
6e45dc518ebb
replaced File.check by specific File.check_file, File.check_dir;
 wenzelm parents: 
42002diff
changeset | 14 |     {master: Path.T * SHA1.digest, text: string, imports: string list, uses: (Path.T * bool) list}
 | 
| 43702 
24fb44c1086a
more abstract Thy_Load.load_file/use_file for external theory resources;
 wenzelm parents: 
43700diff
changeset | 15 | val load_file: theory -> Path.T -> (Path.T * SHA1.digest) * string | 
| 
24fb44c1086a
more abstract Thy_Load.load_file/use_file for external theory resources;
 wenzelm parents: 
43700diff
changeset | 16 | val use_file: Path.T -> theory -> string * theory | 
| 37949 
48a874444164
moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
 wenzelm parents: 
37943diff
changeset | 17 | 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: 
37943diff
changeset | 18 | 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: 
37943diff
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: 
37943diff
changeset | 20 | val exec_ml: Path.T -> generic_theory -> generic_theory | 
| 43712 
3c2c912af2ef
moved Outer_Syntax.load_thy to Thy_Load.load_thy;
 wenzelm parents: 
43702diff
changeset | 21 | val begin_theory: Path.T -> string -> string list -> (Path.T * bool) list -> | 
| 
3c2c912af2ef
moved Outer_Syntax.load_thy to Thy_Load.load_thy;
 wenzelm parents: 
43702diff
changeset | 22 | theory list -> theory | 
| 
3c2c912af2ef
moved Outer_Syntax.load_thy to Thy_Load.load_thy;
 wenzelm parents: 
43702diff
changeset | 23 | val load_thy: int -> Path.T -> string -> string list -> (Path.T * bool) list -> | 
| 
3c2c912af2ef
moved Outer_Syntax.load_thy to Thy_Load.load_thy;
 wenzelm parents: 
43702diff
changeset | 24 | Position.T -> string -> theory list -> theory * unit future | 
| 42002 | 25 | val set_master_path: Path.T -> unit | 
| 26 | val get_master_path: unit -> Path.T | |
| 6168 | 27 | end; | 
| 28 | ||
| 37216 
3165bc303f66
modernized some structure names, keeping a few legacy aliases;
 wenzelm parents: 
33221diff
changeset | 29 | structure Thy_Load: THY_LOAD = | 
| 6168 | 30 | struct | 
| 31 | ||
| 37949 
48a874444164
moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
 wenzelm parents: 
37943diff
changeset | 32 | (* manage source files *) | 
| 
48a874444164
moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
 wenzelm parents: 
37943diff
changeset | 33 | |
| 
48a874444164
moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
 wenzelm parents: 
37943diff
changeset | 34 | type files = | 
| 40741 
17d6293a1e26
moved file identification to thy_load.ML (where it is actually used);
 wenzelm parents: 
40625diff
changeset | 35 |  {master_dir: Path.T,  (*master directory of theory source*)
 | 
| 41548 
bd0bebf93fa6
Thy_Load.begin_theory: maintain source specification of imports;
 wenzelm parents: 
41414diff
changeset | 36 | imports: string list, (*source specification of imports*) | 
| 40741 
17d6293a1e26
moved file identification to thy_load.ML (where it is actually used);
 wenzelm parents: 
40625diff
changeset | 37 | required: Path.T list, (*source path*) | 
| 41955 
703ea96b13c6
files are identified via SHA1 digests -- discontinued ISABELLE_FILE_IDENT;
 wenzelm parents: 
41944diff
changeset | 38 | 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: 
37943diff
changeset | 39 | |
| 41548 
bd0bebf93fa6
Thy_Load.begin_theory: maintain source specification of imports;
 wenzelm parents: 
41414diff
changeset | 40 | fun make_files (master_dir, imports, required, provided): files = | 
| 
bd0bebf93fa6
Thy_Load.begin_theory: maintain source specification of imports;
 wenzelm parents: 
41414diff
changeset | 41 |  {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: 
37943diff
changeset | 42 | |
| 
48a874444164
moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
 wenzelm parents: 
37943diff
changeset | 43 | 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: 
37943diff
changeset | 44 | ( | 
| 
48a874444164
moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
 wenzelm parents: 
37943diff
changeset | 45 | type T = files; | 
| 41548 
bd0bebf93fa6
Thy_Load.begin_theory: maintain source specification of imports;
 wenzelm parents: 
41414diff
changeset | 46 | 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: 
37943diff
changeset | 47 | fun extend _ = empty; | 
| 
48a874444164
moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
 wenzelm parents: 
37943diff
changeset | 48 | fun merge _ = empty; | 
| 
48a874444164
moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
 wenzelm parents: 
37943diff
changeset | 49 | ); | 
| 
48a874444164
moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
 wenzelm parents: 
37943diff
changeset | 50 | |
| 
48a874444164
moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
 wenzelm parents: 
37943diff
changeset | 51 | fun map_files f = | 
| 41548 
bd0bebf93fa6
Thy_Load.begin_theory: maintain source specification of imports;
 wenzelm parents: 
41414diff
changeset | 52 |   Files.map (fn {master_dir, imports, required, provided} =>
 | 
| 
bd0bebf93fa6
Thy_Load.begin_theory: maintain source specification of imports;
 wenzelm parents: 
41414diff
changeset | 53 | 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: 
37943diff
changeset | 54 | |
| 
48a874444164
moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
 wenzelm parents: 
37943diff
changeset | 55 | |
| 
48a874444164
moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
 wenzelm parents: 
37943diff
changeset | 56 | val master_directory = #master_dir o Files.get; | 
| 41548 
bd0bebf93fa6
Thy_Load.begin_theory: maintain source specification of imports;
 wenzelm parents: 
41414diff
changeset | 57 | 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: 
37943diff
changeset | 58 | |
| 41548 
bd0bebf93fa6
Thy_Load.begin_theory: maintain source specification of imports;
 wenzelm parents: 
41414diff
changeset | 59 | 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: 
37943diff
changeset | 60 | |
| 
48a874444164
moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
 wenzelm parents: 
37943diff
changeset | 61 | fun require src_path = | 
| 41548 
bd0bebf93fa6
Thy_Load.begin_theory: maintain source specification of imports;
 wenzelm parents: 
41414diff
changeset | 62 | 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: 
37943diff
changeset | 63 | 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: 
41886diff
changeset | 64 |       error ("Duplicate source file dependency: " ^ Path.print src_path)
 | 
| 41548 
bd0bebf93fa6
Thy_Load.begin_theory: maintain source specification of imports;
 wenzelm parents: 
41414diff
changeset | 65 | 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: 
37943diff
changeset | 66 | |
| 37978 
548f3f165d05
simplified Thy_Header.read -- include Source.of_string_limited here;
 wenzelm parents: 
37977diff
changeset | 67 | fun provide (src_path, path_id) = | 
| 41548 
bd0bebf93fa6
Thy_Load.begin_theory: maintain source specification of imports;
 wenzelm parents: 
41414diff
changeset | 68 | 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: 
37943diff
changeset | 69 | 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: 
41886diff
changeset | 70 |       error ("Duplicate resolution of source file dependency: " ^ Path.print src_path)
 | 
| 41548 
bd0bebf93fa6
Thy_Load.begin_theory: maintain source specification of imports;
 wenzelm parents: 
41414diff
changeset | 71 | 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: 
37943diff
changeset | 72 | |
| 
48a874444164
moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
 wenzelm parents: 
37943diff
changeset | 73 | |
| 23872 | 74 | (* check files *) | 
| 6232 | 75 | |
| 42003 
6e45dc518ebb
replaced File.check by specific File.check_file, File.check_dir;
 wenzelm parents: 
42002diff
changeset | 76 | fun check_file dir file = File.check_file (File.full_path dir file); | 
| 
6e45dc518ebb
replaced File.check by specific File.check_file, File.check_dir;
 wenzelm parents: 
42002diff
changeset | 77 | |
| 41886 | 78 | fun check_thy dir name = | 
| 23872 | 79 | let | 
| 42003 
6e45dc518ebb
replaced File.check by specific File.check_file, File.check_dir;
 wenzelm parents: 
42002diff
changeset | 80 | val master_file = check_file dir (Thy_Header.thy_path name); | 
| 
6e45dc518ebb
replaced File.check by specific File.check_file, File.check_dir;
 wenzelm parents: 
42002diff
changeset | 81 | val text = File.read master_file; | 
| 
6e45dc518ebb
replaced File.check by specific File.check_file, File.check_dir;
 wenzelm parents: 
42002diff
changeset | 82 | val (name', imports, uses) = | 
| 
6e45dc518ebb
replaced File.check by specific File.check_file, File.check_dir;
 wenzelm parents: 
42002diff
changeset | 83 | if name = Context.PureN then (Context.PureN, [], []) | 
| 
6e45dc518ebb
replaced File.check by specific File.check_file, File.check_dir;
 wenzelm parents: 
42002diff
changeset | 84 | else Thy_Header.read (Path.position master_file) text; | 
| 37950 
bc285d91041e
moved basic thy file name operations from Thy_Load to Thy_Header;
 wenzelm parents: 
37949diff
changeset | 85 | val _ = Thy_Header.consistent_name name name'; | 
| 42003 
6e45dc518ebb
replaced File.check by specific File.check_file, File.check_dir;
 wenzelm parents: 
42002diff
changeset | 86 |   in {master = (master_file, SHA1.digest text), text = text, imports = imports, uses = uses} end;
 | 
| 6168 | 87 | |
| 37949 
48a874444164
moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
 wenzelm parents: 
37943diff
changeset | 88 | |
| 43702 
24fb44c1086a
more abstract Thy_Load.load_file/use_file for external theory resources;
 wenzelm parents: 
43700diff
changeset | 89 | (* load files *) | 
| 
24fb44c1086a
more abstract Thy_Load.load_file/use_file for external theory resources;
 wenzelm parents: 
43700diff
changeset | 90 | |
| 
24fb44c1086a
more abstract Thy_Load.load_file/use_file for external theory resources;
 wenzelm parents: 
43700diff
changeset | 91 | fun load_file thy src_path = | 
| 
24fb44c1086a
more abstract Thy_Load.load_file/use_file for external theory resources;
 wenzelm parents: 
43700diff
changeset | 92 | let | 
| 
24fb44c1086a
more abstract Thy_Load.load_file/use_file for external theory resources;
 wenzelm parents: 
43700diff
changeset | 93 | val full_path = check_file (master_directory thy) src_path; | 
| 
24fb44c1086a
more abstract Thy_Load.load_file/use_file for external theory resources;
 wenzelm parents: 
43700diff
changeset | 94 | val text = File.read full_path; | 
| 
24fb44c1086a
more abstract Thy_Load.load_file/use_file for external theory resources;
 wenzelm parents: 
43700diff
changeset | 95 | val id = SHA1.digest text; | 
| 
24fb44c1086a
more abstract Thy_Load.load_file/use_file for external theory resources;
 wenzelm parents: 
43700diff
changeset | 96 | in ((full_path, id), text) end; | 
| 
24fb44c1086a
more abstract Thy_Load.load_file/use_file for external theory resources;
 wenzelm parents: 
43700diff
changeset | 97 | |
| 
24fb44c1086a
more abstract Thy_Load.load_file/use_file for external theory resources;
 wenzelm parents: 
43700diff
changeset | 98 | fun use_file src_path thy = | 
| 
24fb44c1086a
more abstract Thy_Load.load_file/use_file for external theory resources;
 wenzelm parents: 
43700diff
changeset | 99 | let | 
| 
24fb44c1086a
more abstract Thy_Load.load_file/use_file for external theory resources;
 wenzelm parents: 
43700diff
changeset | 100 | val (path_id, text) = load_file thy src_path; | 
| 
24fb44c1086a
more abstract Thy_Load.load_file/use_file for external theory resources;
 wenzelm parents: 
43700diff
changeset | 101 | val thy' = provide (src_path, path_id) thy; | 
| 
24fb44c1086a
more abstract Thy_Load.load_file/use_file for external theory resources;
 wenzelm parents: 
43700diff
changeset | 102 | in (text, thy') end; | 
| 37949 
48a874444164
moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
 wenzelm parents: 
37943diff
changeset | 103 | |
| 
48a874444164
moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
 wenzelm parents: 
37943diff
changeset | 104 | val loaded_files = map (#1 o #2) o #provided o Files.get; | 
| 6168 | 105 | |
| 37949 
48a874444164
moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
 wenzelm parents: 
37943diff
changeset | 106 | 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: 
37943diff
changeset | 107 | let | 
| 
48a874444164
moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
 wenzelm parents: 
37943diff
changeset | 108 |     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: 
37943diff
changeset | 109 | 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: 
37943diff
changeset | 110 | val _ = | 
| 
48a874444164
moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
 wenzelm parents: 
37943diff
changeset | 111 | (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: 
37943diff
changeset | 112 | [] => 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: 
41886diff
changeset | 113 |       | 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: 
37943diff
changeset | 114 | val _ = | 
| 
48a874444164
moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
 wenzelm parents: 
37943diff
changeset | 115 | (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: 
37943diff
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: 
41886diff
changeset | 117 |       | 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: 
37943diff
changeset | 118 | in () end; | 
| 
48a874444164
moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
 wenzelm parents: 
37943diff
changeset | 119 | |
| 
48a874444164
moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
 wenzelm parents: 
37943diff
changeset | 120 | fun all_current thy = | 
| 37939 
965537d86fcc
discontinued special treatment of ML files -- no longer complete extensions on demand;
 wenzelm parents: 
37938diff
changeset | 121 | let | 
| 43702 
24fb44c1086a
more abstract Thy_Load.load_file/use_file for external theory resources;
 wenzelm parents: 
43700diff
changeset | 122 |     val {provided, ...} = Files.get thy;
 | 
| 37978 
548f3f165d05
simplified Thy_Header.read -- include Source.of_string_limited here;
 wenzelm parents: 
37977diff
changeset | 123 | fun current (src_path, (_, id)) = | 
| 43702 
24fb44c1086a
more abstract Thy_Load.load_file/use_file for external theory resources;
 wenzelm parents: 
43700diff
changeset | 124 | (case try (load_file thy) 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: 
37943diff
changeset | 125 | NONE => false | 
| 43702 
24fb44c1086a
more abstract Thy_Load.load_file/use_file for external theory resources;
 wenzelm parents: 
43700diff
changeset | 126 | | 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: 
37943diff
changeset | 127 | 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: 
37943diff
changeset | 128 | |
| 37952 | 129 | val _ = Context.>> (Context.map_theory (Theory.at_end (fn thy => (check_loaded thy; NONE)))); | 
| 130 | ||
| 37949 
48a874444164
moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
 wenzelm parents: 
37943diff
changeset | 131 | |
| 
48a874444164
moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
 wenzelm parents: 
37943diff
changeset | 132 | (* provide files *) | 
| 
48a874444164
moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
 wenzelm parents: 
37943diff
changeset | 133 | |
| 43700 
e4ece46a9ca7
clarified Thy_Load.digest_file -- read ML files only once;
 wenzelm parents: 
42003diff
changeset | 134 | fun eval_file path text = ML_Context.eval_text true (Path.position path) text; | 
| 37949 
48a874444164
moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
 wenzelm parents: 
37943diff
changeset | 135 | |
| 
48a874444164
moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
 wenzelm parents: 
37943diff
changeset | 136 | 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: 
37943diff
changeset | 137 | if is_none (Context.thread_data ()) then | 
| 43700 
e4ece46a9ca7
clarified Thy_Load.digest_file -- read ML files only once;
 wenzelm parents: 
42003diff
changeset | 138 | let val path = check_file Path.current src_path | 
| 
e4ece46a9ca7
clarified Thy_Load.digest_file -- read ML files only once;
 wenzelm parents: 
42003diff
changeset | 139 | in eval_file path (File.read path) end | 
| 37949 
48a874444164
moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
 wenzelm parents: 
37943diff
changeset | 140 | else | 
| 
48a874444164
moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
 wenzelm parents: 
37943diff
changeset | 141 | let | 
| 
48a874444164
moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
 wenzelm parents: 
37943diff
changeset | 142 | val thy = ML_Context.the_global_context (); | 
| 
48a874444164
moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
 wenzelm parents: 
37943diff
changeset | 143 | |
| 43702 
24fb44c1086a
more abstract Thy_Load.load_file/use_file for external theory resources;
 wenzelm parents: 
43700diff
changeset | 144 | val ((path, id), text) = load_file thy src_path; | 
| 43700 
e4ece46a9ca7
clarified Thy_Load.digest_file -- read ML files only once;
 wenzelm parents: 
42003diff
changeset | 145 | val _ = eval_file path text; | 
| 37949 
48a874444164
moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
 wenzelm parents: 
37943diff
changeset | 146 | 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: 
37943diff
changeset | 147 | |
| 37978 
548f3f165d05
simplified Thy_Header.read -- include Source.of_string_limited here;
 wenzelm parents: 
37977diff
changeset | 148 | 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: 
38133diff
changeset | 149 | val _ = Context.>> (Context.mapping provide (Local_Theory.background_theory provide)); | 
| 37978 
548f3f165d05
simplified Thy_Header.read -- include Source.of_string_limited here;
 wenzelm parents: 
37977diff
changeset | 150 | in () end; | 
| 37949 
48a874444164
moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
 wenzelm parents: 
37943diff
changeset | 151 | |
| 
48a874444164
moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
 wenzelm parents: 
37943diff
changeset | 152 | fun exec_ml src_path = ML_Context.exec (fn () => use_ml src_path); | 
| 6168 | 153 | |
| 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: 
37952diff
changeset | 154 | |
| 43712 
3c2c912af2ef
moved Outer_Syntax.load_thy to Thy_Load.load_thy;
 wenzelm parents: 
43702diff
changeset | 155 | (* load_thy *) | 
| 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: 
37952diff
changeset | 156 | |
| 43712 
3c2c912af2ef
moved Outer_Syntax.load_thy to Thy_Load.load_thy;
 wenzelm parents: 
43702diff
changeset | 157 | fun begin_theory dir name imports uses parents = | 
| 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: 
37952diff
changeset | 158 | Theory.begin_theory name parents | 
| 41548 
bd0bebf93fa6
Thy_Load.begin_theory: maintain source specification of imports;
 wenzelm parents: 
41414diff
changeset | 159 | |> 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: 
37952diff
changeset | 160 | |> 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: 
37952diff
changeset | 161 | |> 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: 
37952diff
changeset | 162 | |> 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: 
37952diff
changeset | 163 | |
| 43712 
3c2c912af2ef
moved Outer_Syntax.load_thy to Thy_Load.load_thy;
 wenzelm parents: 
43702diff
changeset | 164 | fun load_thy update_time dir name imports uses pos text parents = | 
| 
3c2c912af2ef
moved Outer_Syntax.load_thy to Thy_Load.load_thy;
 wenzelm parents: 
43702diff
changeset | 165 | let | 
| 
3c2c912af2ef
moved Outer_Syntax.load_thy to Thy_Load.load_thy;
 wenzelm parents: 
43702diff
changeset | 166 | val (lexs, outer_syntax) = Outer_Syntax.get_syntax (); | 
| 
3c2c912af2ef
moved Outer_Syntax.load_thy to Thy_Load.load_thy;
 wenzelm parents: 
43702diff
changeset | 167 | val time = ! Toplevel.timing; | 
| 
3c2c912af2ef
moved Outer_Syntax.load_thy to Thy_Load.load_thy;
 wenzelm parents: 
43702diff
changeset | 168 | |
| 
3c2c912af2ef
moved Outer_Syntax.load_thy to Thy_Load.load_thy;
 wenzelm parents: 
43702diff
changeset | 169 | val _ = Present.init_theory name; | 
| 44186 
806f0ec1a43d
simplified Toplevel.init_theory: discontinued special master argument;
 wenzelm parents: 
44113diff
changeset | 170 | fun init () = | 
| 43712 
3c2c912af2ef
moved Outer_Syntax.load_thy to Thy_Load.load_thy;
 wenzelm parents: 
43702diff
changeset | 171 | begin_theory dir name imports uses parents | 
| 
3c2c912af2ef
moved Outer_Syntax.load_thy to Thy_Load.load_thy;
 wenzelm parents: 
43702diff
changeset | 172 | |> Present.begin_theory update_time dir uses; | 
| 
3c2c912af2ef
moved Outer_Syntax.load_thy to Thy_Load.load_thy;
 wenzelm parents: 
43702diff
changeset | 173 | |
| 
3c2c912af2ef
moved Outer_Syntax.load_thy to Thy_Load.load_thy;
 wenzelm parents: 
43702diff
changeset | 174 | val toks = Source.exhausted (Thy_Syntax.token_source lexs pos (Source.of_string text)); | 
| 
3c2c912af2ef
moved Outer_Syntax.load_thy to Thy_Load.load_thy;
 wenzelm parents: 
43702diff
changeset | 175 | val spans = Source.exhaust (Thy_Syntax.span_source toks); | 
| 
3c2c912af2ef
moved Outer_Syntax.load_thy to Thy_Load.load_thy;
 wenzelm parents: 
43702diff
changeset | 176 | val elements = | 
| 
3c2c912af2ef
moved Outer_Syntax.load_thy to Thy_Load.load_thy;
 wenzelm parents: 
43702diff
changeset | 177 | Source.exhaust (Thy_Syntax.element_source (Source.of_list spans)) | 
| 44478 
4fdb1009a370
tuned signature -- emphasize traditional read/eval/print terminology, which is still relevant here;
 wenzelm parents: 
44353diff
changeset | 178 | |> maps (Outer_Syntax.read_element outer_syntax init); | 
| 43712 
3c2c912af2ef
moved Outer_Syntax.load_thy to Thy_Load.load_thy;
 wenzelm parents: 
43702diff
changeset | 179 | |
| 
3c2c912af2ef
moved Outer_Syntax.load_thy to Thy_Load.load_thy;
 wenzelm parents: 
43702diff
changeset | 180 | val _ = Present.theory_source name | 
| 
3c2c912af2ef
moved Outer_Syntax.load_thy to Thy_Load.load_thy;
 wenzelm parents: 
43702diff
changeset | 181 | (fn () => HTML.html_mode (implode o map Thy_Syntax.present_span) spans); | 
| 
3c2c912af2ef
moved Outer_Syntax.load_thy to Thy_Load.load_thy;
 wenzelm parents: 
43702diff
changeset | 182 | |
| 
3c2c912af2ef
moved Outer_Syntax.load_thy to Thy_Load.load_thy;
 wenzelm parents: 
43702diff
changeset | 183 |     val _ = if time then writeln ("\n**** Starting theory " ^ quote name ^ " ****") else ();
 | 
| 
3c2c912af2ef
moved Outer_Syntax.load_thy to Thy_Load.load_thy;
 wenzelm parents: 
43702diff
changeset | 184 | val (results, thy) = cond_timeit time "" (fn () => Toplevel.excursion elements); | 
| 
3c2c912af2ef
moved Outer_Syntax.load_thy to Thy_Load.load_thy;
 wenzelm parents: 
43702diff
changeset | 185 |     val _ = if time then writeln ("**** Finished theory " ^ quote name ^ " ****\n") else ();
 | 
| 
3c2c912af2ef
moved Outer_Syntax.load_thy to Thy_Load.load_thy;
 wenzelm parents: 
43702diff
changeset | 186 | |
| 
3c2c912af2ef
moved Outer_Syntax.load_thy to Thy_Load.load_thy;
 wenzelm parents: 
43702diff
changeset | 187 | val present = | 
| 
3c2c912af2ef
moved Outer_Syntax.load_thy to Thy_Load.load_thy;
 wenzelm parents: 
43702diff
changeset | 188 |       singleton (Future.cond_forks {name = "Outer_Syntax.present:" ^ name, group = NONE,
 | 
| 44113 | 189 | deps = map Future.task_of results, pri = 0, interrupts = true}) | 
| 43712 
3c2c912af2ef
moved Outer_Syntax.load_thy to Thy_Load.load_thy;
 wenzelm parents: 
43702diff
changeset | 190 | (fn () => | 
| 
3c2c912af2ef
moved Outer_Syntax.load_thy to Thy_Load.load_thy;
 wenzelm parents: 
43702diff
changeset | 191 | Thy_Output.present_thy (#1 lexs) Keyword.command_tags | 
| 
3c2c912af2ef
moved Outer_Syntax.load_thy to Thy_Load.load_thy;
 wenzelm parents: 
43702diff
changeset | 192 | (Outer_Syntax.is_markup outer_syntax) | 
| 
3c2c912af2ef
moved Outer_Syntax.load_thy to Thy_Load.load_thy;
 wenzelm parents: 
43702diff
changeset | 193 | (maps Future.join results) toks | 
| 
3c2c912af2ef
moved Outer_Syntax.load_thy to Thy_Load.load_thy;
 wenzelm parents: 
43702diff
changeset | 194 | |> Buffer.content | 
| 
3c2c912af2ef
moved Outer_Syntax.load_thy to Thy_Load.load_thy;
 wenzelm parents: 
43702diff
changeset | 195 | |> Present.theory_output name); | 
| 
3c2c912af2ef
moved Outer_Syntax.load_thy to Thy_Load.load_thy;
 wenzelm parents: 
43702diff
changeset | 196 | |
| 
3c2c912af2ef
moved Outer_Syntax.load_thy to Thy_Load.load_thy;
 wenzelm parents: 
43702diff
changeset | 197 | in (thy, present) end; | 
| 
3c2c912af2ef
moved Outer_Syntax.load_thy to Thy_Load.load_thy;
 wenzelm parents: 
43702diff
changeset | 198 | |
| 42002 | 199 | |
| 200 | (* global master path *) | |
| 201 | ||
| 202 | local | |
| 203 | val master_path = Unsynchronized.ref Path.current; | |
| 204 | in | |
| 205 | ||
| 206 | fun set_master_path path = master_path := path; | |
| 207 | fun get_master_path () = ! master_path; | |
| 208 | ||
| 6168 | 209 | end; | 
| 210 | ||
| 42002 | 211 | end; |