src/Pure/Thy/thy_load.ML
changeset 48896 bb1f461a7815
parent 48888 74ad16f79425
child 48897 873fdafc5b09
equal deleted inserted replaced
48895:4cd4ef1ef4a4 48896:bb1f461a7815
     6 
     6 
     7 signature THY_LOAD =
     7 signature THY_LOAD =
     8 sig
     8 sig
     9   val master_directory: theory -> Path.T
     9   val master_directory: theory -> Path.T
    10   val imports_of: theory -> string list
    10   val imports_of: theory -> string list
    11   val provide: Path.T * (Path.T * SHA1.digest) -> theory -> theory
    11   val provide: Path.T * SHA1.digest -> theory -> theory
    12   val check_file: Path.T -> Path.T -> Path.T
    12   val check_file: Path.T -> Path.T -> Path.T
    13   val thy_path: Path.T -> Path.T
    13   val thy_path: Path.T -> Path.T
    14   val check_thy: Thy_Header.keywords -> Path.T -> string ->
    14   val check_thy: Thy_Header.keywords -> Path.T -> string ->
    15    {master: Path.T * SHA1.digest, text: string, imports: string list,
    15    {master: Path.T * SHA1.digest, text: string, imports: string list,
    16     uses: (Path.T * bool) list, keywords: Thy_Header.keywords}
    16     uses: (Path.T * bool) list, keywords: Thy_Header.keywords}
    34 (* manage source files *)
    34 (* manage source files *)
    35 
    35 
    36 type files =
    36 type files =
    37  {master_dir: Path.T,  (*master directory of theory source*)
    37  {master_dir: Path.T,  (*master directory of theory source*)
    38   imports: string list,  (*source specification of imports*)
    38   imports: string list,  (*source specification of imports*)
    39   provided: (Path.T * (Path.T * SHA1.digest)) list};  (*source path, physical path, digest*)
    39   provided: (Path.T * SHA1.digest) list};  (*source path, digest*)
    40 
    40 
    41 fun make_files (master_dir, imports, provided): files =
    41 fun make_files (master_dir, imports, provided): files =
    42  {master_dir = master_dir, imports = imports, provided = provided};
    42  {master_dir = master_dir, imports = imports, provided = provided};
    43 
    43 
    44 structure Files = Theory_Data
    44 structure Files = Theory_Data
    57 val master_directory = #master_dir o Files.get;
    57 val master_directory = #master_dir o Files.get;
    58 val imports_of = #imports o Files.get;
    58 val imports_of = #imports o Files.get;
    59 
    59 
    60 fun put_deps master_dir imports = map_files (fn _ => (master_dir, imports, []));
    60 fun put_deps master_dir imports = map_files (fn _ => (master_dir, imports, []));
    61 
    61 
    62 fun provide (src_path, path_id) =
    62 fun provide (src_path, id) =
    63   map_files (fn (master_dir, imports, provided) =>
    63   map_files (fn (master_dir, imports, provided) =>
    64     if AList.defined (op =) provided src_path then
    64     if AList.defined (op =) provided src_path then
    65       error ("Duplicate use of source file: " ^ Path.print src_path)
    65       error ("Duplicate use of source file: " ^ Path.print src_path)
    66     else (master_dir, imports, (src_path, path_id) :: provided));
    66     else (master_dir, imports, (src_path, id) :: provided));
    67 
    67 
    68 
    68 
    69 (* inlined files *)
    69 (* inlined files *)
    70 
    70 
    71 fun check_file dir file = File.check_file (File.full_path dir file);
    71 fun check_file dir file = File.check_file (File.full_path dir file);
   176     val id = SHA1.digest text;
   176     val id = SHA1.digest text;
   177   in ((full_path, id), text) end;
   177   in ((full_path, id), text) end;
   178 
   178 
   179 fun use_file src_path thy =
   179 fun use_file src_path thy =
   180   let
   180   let
   181     val (path_id, text) = load_file thy src_path;
   181     val ((_, id), text) = load_file thy src_path;
   182     val thy' = provide (src_path, path_id) thy;
   182     val thy' = provide (src_path, id) thy;
   183   in (text, thy') end;
   183   in (text, thy') end;
   184 
   184 
   185 val loaded_files = map (#1 o #2) o #provided o Files.get;
   185 fun loaded_files thy =
       
   186   let val {master_dir, provided, ...} = Files.get thy
       
   187   in map (File.full_path master_dir o #1) provided end;
   186 
   188 
   187 fun load_current thy =
   189 fun load_current thy =
   188   #provided (Files.get thy) |>
   190   #provided (Files.get thy) |>
   189     forall (fn (src_path, (_, id)) =>
   191     forall (fn (src_path, id) =>
   190       (case try (load_file thy) src_path of
   192       (case try (load_file thy) src_path of
   191         NONE => false
   193         NONE => false
   192       | SOME ((_, id'), _) => id = id'));
   194       | SOME ((_, id'), _) => id = id'));
   193 
   195 
   194 
   196 
   206 
   208 
   207       val ((path, id), text) = load_file thy src_path;
   209       val ((path, id), text) = load_file thy src_path;
   208       val _ = eval_file path text;
   210       val _ = eval_file path text;
   209       val _ = Context.>> Local_Theory.propagate_ml_env;
   211       val _ = Context.>> Local_Theory.propagate_ml_env;
   210 
   212 
   211       val provide = provide (src_path, (path, id));
   213       val provide = provide (src_path, id);
   212       val _ = Context.>> (Context.mapping provide (Local_Theory.background_theory provide));
   214       val _ = Context.>> (Context.mapping provide (Local_Theory.background_theory provide));
   213     in () end;
   215     in () end;
   214 
   216 
   215 fun exec_ml src_path = ML_Context.exec (fn () => use_ml src_path);
   217 fun exec_ml src_path = ML_Context.exec (fn () => use_ml src_path);
   216 
   218