author | wenzelm |
Mon, 12 Jul 1999 22:23:59 +0200 | |
changeset 6978 | a5b67157b94d |
parent 6641 | 254ab03bd082 |
child 7190 | ba6f09cd7769 |
permissions | -rw-r--r-- |
6168 | 1 |
(* Title: Pure/Thy/thy_load.ML |
2 |
ID: $Id$ |
|
3 |
Author: Markus Wenzel, TU Muenchen |
|
4 |
||
5 |
Theory loader primitives. |
|
6 |
*) |
|
7 |
||
8 |
signature BASIC_THY_LOAD = |
|
9 |
sig |
|
10 |
val show_path: unit -> string list |
|
11 |
val add_path: string -> unit |
|
12 |
val del_path: string -> unit |
|
6205 | 13 |
val reset_path: unit -> unit |
6168 | 14 |
end; |
15 |
||
16 |
signature THY_LOAD = |
|
17 |
sig |
|
18 |
include BASIC_THY_LOAD |
|
6205 | 19 |
val ml_path: string -> Path.T |
6232 | 20 |
val check_file: Path.T -> (Path.T * File.info) option |
21 |
val load_file: Path.T -> (Path.T * File.info) |
|
6487 | 22 |
val check_thy: Path.T -> string -> bool -> (Path.T * File.info) list |
23 |
val deps_thy: Path.T -> string -> bool -> |
|
6484
3f098b0ec683
use_thy etc.: may specify path prefix, which is temporarily used as load path;
wenzelm
parents:
6363
diff
changeset
|
24 |
(Path.T * File.info) list * (string list * Path.T list) |
6487 | 25 |
val load_thy: Path.T -> string -> bool -> bool -> (Path.T * File.info) list |
6168 | 26 |
end; |
27 |
||
6363 | 28 |
(*backdoor sealed later*) |
6168 | 29 |
signature PRIVATE_THY_LOAD = |
30 |
sig |
|
31 |
include THY_LOAD |
|
6205 | 32 |
val deps_thy_fn: (string -> bool -> Path.T -> string list * Path.T list) ref |
33 |
val load_thy_fn: (string -> bool -> bool -> Path.T -> unit) ref |
|
6168 | 34 |
end; |
35 |
||
36 |
structure ThyLoad: PRIVATE_THY_LOAD = |
|
37 |
struct |
|
38 |
||
39 |
||
6232 | 40 |
(* maintain load path *) |
6168 | 41 |
|
42 |
val load_path = ref [Path.current]; |
|
43 |
fun change_path f = load_path := f (! load_path); |
|
44 |
||
45 |
fun show_path () = map Path.pack (! load_path); |
|
6484
3f098b0ec683
use_thy etc.: may specify path prefix, which is temporarily used as load path;
wenzelm
parents:
6363
diff
changeset
|
46 |
fun add_path s = change_path (cons (Path.unpack s)); |
6168 | 47 |
fun del_path s = change_path (filter_out (equal (Path.unpack s))); |
6205 | 48 |
fun reset_path () = load_path := [Path.current]; |
6168 | 49 |
|
50 |
||
6232 | 51 |
(* file formats *) |
6168 | 52 |
|
6232 | 53 |
val ml_exts = ["", "ML", "sml"]; |
54 |
val ml_path = Path.ext "ML" o Path.basic; |
|
55 |
val thy_path = Path.ext "thy" o Path.basic; |
|
6168 | 56 |
|
57 |
||
6232 | 58 |
(* check_file *) |
59 |
||
60 |
fun check_file src_path = |
|
61 |
let |
|
62 |
val path = Path.expand src_path; |
|
6168 | 63 |
|
6232 | 64 |
fun find_ext rel_path ext = |
65 |
let val ext_path = Path.ext ext rel_path |
|
66 |
in apsome (fn info => (File.full_path ext_path, info)) (File.info ext_path) end; |
|
67 |
||
68 |
fun find_dir dir = |
|
69 |
get_first (find_ext (Path.append dir path)) ml_exts; |
|
70 |
in get_first find_dir (if Path.is_basic path then ! load_path else [Path.current]) end; |
|
71 |
||
72 |
||
73 |
(* load_file *) |
|
6168 | 74 |
|
75 |
fun load_file raw_path = |
|
6232 | 76 |
(case check_file raw_path of |
77 |
None => error ("Could not find ML file " ^ quote (Path.pack raw_path)) |
|
6641 | 78 |
| Some (path, info) => (File.symbol_use path; (path, info))); |
6232 | 79 |
|
80 |
||
81 |
(* check_thy *) |
|
6168 | 82 |
|
6487 | 83 |
fun tmp_path path f x = |
6978 | 84 |
if Path.is_current path then f x else Library.setmp load_path (path :: ! load_path) f x; |
6484
3f098b0ec683
use_thy etc.: may specify path prefix, which is temporarily used as load path;
wenzelm
parents:
6363
diff
changeset
|
85 |
|
3f098b0ec683
use_thy etc.: may specify path prefix, which is temporarily used as load path;
wenzelm
parents:
6363
diff
changeset
|
86 |
fun check_thy_aux name ml = |
6232 | 87 |
(case check_file (thy_path name) of |
6484
3f098b0ec683
use_thy etc.: may specify path prefix, which is temporarily used as load path;
wenzelm
parents:
6363
diff
changeset
|
88 |
None => error ("Could not find theory file for " ^ quote name ^ " in dir(s) " ^ |
3f098b0ec683
use_thy etc.: may specify path prefix, which is temporarily used as load path;
wenzelm
parents:
6363
diff
changeset
|
89 |
commas_quote (show_path ())) |
6232 | 90 |
| Some thy_info => thy_info :: |
91 |
(case if ml then check_file (ml_path name) else None of |
|
92 |
None => [] |
|
93 |
| Some info => [info])); |
|
6205 | 94 |
|
6484
3f098b0ec683
use_thy etc.: may specify path prefix, which is temporarily used as load path;
wenzelm
parents:
6363
diff
changeset
|
95 |
fun check_thy dir name ml = tmp_path dir (check_thy_aux name) ml; |
3f098b0ec683
use_thy etc.: may specify path prefix, which is temporarily used as load path;
wenzelm
parents:
6363
diff
changeset
|
96 |
|
6168 | 97 |
|
98 |
(* process theory files *) |
|
99 |
||
100 |
(*hooks for theory syntax dependent operations*) |
|
101 |
fun undefined _ = raise Match; |
|
6205 | 102 |
val deps_thy_fn = ref (undefined: string -> bool -> Path.T -> string list * Path.T list); |
103 |
val load_thy_fn = ref (undefined: string -> bool -> bool -> Path.T -> unit); |
|
6168 | 104 |
|
6484
3f098b0ec683
use_thy etc.: may specify path prefix, which is temporarily used as load path;
wenzelm
parents:
6363
diff
changeset
|
105 |
fun process_thy dir f name ml = |
3f098b0ec683
use_thy etc.: may specify path prefix, which is temporarily used as load path;
wenzelm
parents:
6363
diff
changeset
|
106 |
let val master = check_thy dir name ml |
6487 | 107 |
in (master, tmp_path dir f (#1 (hd master))) end; |
6219 | 108 |
|
6484
3f098b0ec683
use_thy etc.: may specify path prefix, which is temporarily used as load path;
wenzelm
parents:
6363
diff
changeset
|
109 |
fun deps_thy dir name ml = process_thy dir (! deps_thy_fn name ml) name ml; |
3f098b0ec683
use_thy etc.: may specify path prefix, which is temporarily used as load path;
wenzelm
parents:
6363
diff
changeset
|
110 |
fun load_thy dir name ml time = #1 (process_thy dir (! load_thy_fn name ml time) name ml); |
6168 | 111 |
|
112 |
||
113 |
end; |
|
114 |
||
115 |
structure BasicThyLoad: BASIC_THY_LOAD = ThyLoad; |
|
116 |
open BasicThyLoad; |