src/Pure/Thy/thy_load.ML
changeset 46938 cda018294515
parent 46811 03a2dc9e0624
child 46958 0ec8f04e753a
equal deleted inserted replaced
46937:efb98d27dc1a 46938:cda018294515
    17   val use_file: Path.T -> theory -> string * theory
    17   val use_file: Path.T -> theory -> string * theory
    18   val loaded_files: theory -> Path.T list
    18   val loaded_files: theory -> Path.T list
    19   val all_current: theory -> bool
    19   val all_current: theory -> bool
    20   val use_ml: Path.T -> unit
    20   val use_ml: Path.T -> unit
    21   val exec_ml: Path.T -> generic_theory -> generic_theory
    21   val exec_ml: Path.T -> generic_theory -> generic_theory
    22   val begin_theory: Path.T -> string -> string list -> (Path.T * bool) list ->
    22   val begin_theory: Path.T -> Thy_Header.header -> theory list -> theory
    23     theory list -> theory
    23   val load_thy: int -> Path.T -> Thy_Header.header -> Position.T -> string ->
    24   val load_thy: int -> Path.T -> string -> string list -> (Path.T * bool) list ->
    24     theory list -> theory * unit future
    25     Position.T -> string -> theory list -> theory * unit future
       
    26   val set_master_path: Path.T -> unit
    25   val set_master_path: Path.T -> unit
    27   val get_master_path: unit -> Path.T
    26   val get_master_path: unit -> Path.T
    28 end;
    27 end;
    29 
    28 
    30 structure Thy_Load: THY_LOAD =
    29 structure Thy_Load: THY_LOAD =
    83     val path = thy_path (Path.basic name);
    82     val path = thy_path (Path.basic name);
    84     val master_file = check_file dir path;
    83     val master_file = check_file dir path;
    85     val text = File.read master_file;
    84     val text = File.read master_file;
    86     val (name', imports, uses) =
    85     val (name', imports, uses) =
    87       if name = Context.PureN then (Context.PureN, [], [])
    86       if name = Context.PureN then (Context.PureN, [], [])
    88       else Thy_Header.read (Path.position master_file) text;
    87       else
       
    88         let val {name, imports, uses, ...} = Thy_Header.read (Path.position master_file) text
       
    89         in (name, imports, uses) end;
    89     val _ = name <> name' andalso
    90     val _ = name <> name' andalso
    90       error ("Bad file name " ^ Path.print path ^ " for theory " ^ quote name');
    91       error ("Bad file name " ^ Path.print path ^ " for theory " ^ quote name');
    91   in {master = (master_file, SHA1.digest text), text = text, imports = imports, uses = uses} end;
    92   in {master = (master_file, SHA1.digest text), text = text, imports = imports, uses = uses} end;
    92 
    93 
    93 
    94 
   157 fun exec_ml src_path = ML_Context.exec (fn () => use_ml src_path);
   158 fun exec_ml src_path = ML_Context.exec (fn () => use_ml src_path);
   158 
   159 
   159 
   160 
   160 (* load_thy *)
   161 (* load_thy *)
   161 
   162 
   162 fun begin_theory dir name imports uses parents =
   163 fun begin_theory dir {name, imports, keywords, uses} parents =
   163   Theory.begin_theory name parents
   164   Theory.begin_theory name parents
   164   |> put_deps dir imports
   165   |> put_deps dir imports
       
   166   |> fold Thy_Header.declare_keyword keywords
   165   |> fold (require o fst) uses
   167   |> fold (require o fst) uses
   166   |> fold (fn (path, true) => Context.theory_map (exec_ml path) o Theory.checkpoint | _ => I) uses
   168   |> fold (fn (path, true) => Context.theory_map (exec_ml path) o Theory.checkpoint | _ => I) uses
   167   |> Theory.checkpoint;
   169   |> Theory.checkpoint;
   168 
   170 
   169 fun load_thy update_time dir name imports uses pos text parents =
   171 fun load_thy update_time dir header pos text parents =
   170   let
   172   let
   171     val (lexs, outer_syntax) = Outer_Syntax.get_syntax ();
   173     val (lexs, outer_syntax) = Outer_Syntax.get_syntax ();
   172     val time = ! Toplevel.timing;
   174     val time = ! Toplevel.timing;
   173 
   175 
       
   176     val {name, imports, uses, ...} = header;
   174     val _ = Present.init_theory name;
   177     val _ = Present.init_theory name;
   175     fun init () =
   178     fun init () =
   176       begin_theory dir name imports uses parents
   179       begin_theory dir header parents
   177       |> Present.begin_theory update_time dir uses;
   180       |> Present.begin_theory update_time dir uses;
   178 
   181 
   179     val toks = Thy_Syntax.parse_tokens lexs pos text;
   182     val toks = Thy_Syntax.parse_tokens lexs pos text;
   180     val spans = Thy_Syntax.parse_spans toks;
   183     val spans = Thy_Syntax.parse_spans toks;
   181     val elements =
   184     val elements =