author | wenzelm |
Fri, 24 Oct 1997 17:18:25 +0200 | |
changeset 3997 | 42062f636bdf |
parent 3976 | 1030dd79720b |
child 4111 | 93baba60ece2 |
permissions | -rw-r--r-- |
3604
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
1 |
(* Title: Pure/Thy/thy_info.ML |
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
2 |
ID: $Id$ |
3976 | 3 |
Author: Stefan Berghofer and Markus Wenzel, TU Muenchen |
3604
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
4 |
|
3976 | 5 |
Theory loader info database. |
3604
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
6 |
*) |
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
7 |
|
3976 | 8 |
(* FIXME wipe out! *) |
3604
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
9 |
(*Functions to handle arbitrary data added by the user; type "exn" is used |
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
10 |
to store data*) |
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
11 |
datatype thy_methods = |
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
12 |
ThyMethods of {merge: exn list -> exn, put: exn -> unit, get: unit -> exn}; |
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
13 |
|
3976 | 14 |
|
15 |
type thy_info = |
|
16 |
{path: string, |
|
17 |
children: string list, parents: string list, |
|
18 |
thy_time: string option, ml_time: string option, |
|
19 |
theory: theory option, thms: thm Symtab.table, |
|
20 |
methods: thy_methods Symtab.table, |
|
21 |
data: exn Symtab.table * exn Symtab.table}; |
|
22 |
||
23 |
(* |
|
24 |
path: directory where theory's files are located |
|
25 |
||
26 |
thy_time, ml_time = None theory file has not been read yet |
|
3604
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
27 |
= Some "" theory was read but has either been marked |
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
28 |
as outdated or there is no such file for |
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
29 |
this theory (see e.g. 'virtual' theories |
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
30 |
like Pure or theories without a ML file) |
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
31 |
theory = None theory has not been read yet |
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
32 |
|
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
33 |
parents: While 'children' contains all theories the theory depends |
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
34 |
on (i.e. also ones quoted in the .thy file), |
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
35 |
'parents' only contains the theories which were used to form |
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
36 |
the base of this theory. |
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
37 |
|
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
38 |
methods: three methods for each user defined data; |
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
39 |
merge: merges data of ancestor theories |
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
40 |
put: retrieves data from loaded_thys and stores it somewhere |
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
41 |
get: retrieves data from somewhere and stores it |
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
42 |
in loaded_thys |
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
43 |
data: user defined data; exn is used to allow arbitrary types; |
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
44 |
first element of pairs contains result that get returned after |
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
45 |
thy file was read, second element after ML file was read; |
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
46 |
if ML files has not been read, second element is identical to |
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
47 |
first one because get_thydata, which is meant to return the |
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
48 |
latest data, always accesses the 2nd element |
3976 | 49 |
*) |
3604
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
50 |
|
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
51 |
signature THY_INFO = |
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
52 |
sig |
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
53 |
val loaded_thys : thy_info Symtab.table ref |
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
54 |
val store_theory : theory * string -> unit |
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
55 |
|
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
56 |
val theory_of : string -> theory |
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
57 |
val theory_of_sign : Sign.sg -> theory |
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
58 |
val theory_of_thm : thm -> theory |
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
59 |
val children_of : string -> string list |
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
60 |
val parents_of_name: string -> string list |
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
61 |
val thyinfo_of_sign: Sign.sg -> string * thy_info |
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
62 |
|
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
63 |
val add_thydata : string -> string * thy_methods -> unit |
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
64 |
val get_thydata : string -> string -> exn option |
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
65 |
val put_thydata : bool -> string -> unit |
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
66 |
val set_current_thy: string -> unit |
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
67 |
val get_thyinfo : string -> thy_info option |
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
68 |
|
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
69 |
val path_of : string -> string |
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
70 |
end; |
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
71 |
|
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
72 |
|
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
73 |
structure ThyInfo: THY_INFO = |
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
74 |
struct |
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
75 |
|
3976 | 76 |
(* loaded theories *) |
3604
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
77 |
|
3976 | 78 |
fun mk_info (name, children, parents, theory) = |
79 |
(name, |
|
80 |
{path = "", children = children, parents = parents, thy_time = Some "", |
|
81 |
ml_time = Some "", theory = Some theory, thms = Symtab.null, |
|
82 |
methods = Symtab.null, data = (Symtab.null, Symtab.null)}: thy_info); |
|
83 |
||
84 |
(*preloaded theories*) |
|
3604
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
85 |
val loaded_thys = |
3976 | 86 |
ref (Symtab.make (map mk_info |
3997 | 87 |
[("ProtoPure", ["Pure", "CPure"], [], ProtoPure.thy), |
88 |
("Pure", [], ["ProtoPure"], Pure.thy), |
|
89 |
("CPure", [], ["ProtoPure"], CPure.thy)])); |
|
3604
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
90 |
|
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
91 |
|
3976 | 92 |
(* retrieve info *) |
93 |
||
94 |
fun err_not_stored name = |
|
95 |
error ("Theory " ^ name ^ " not stored by loader"); |
|
96 |
||
97 |
fun get_thyinfo name = Symtab.lookup (! loaded_thys, name); |
|
3604
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
98 |
|
3976 | 99 |
fun the_thyinfo name = |
100 |
(case get_thyinfo name of |
|
101 |
Some info => info |
|
102 |
| None => err_not_stored name); |
|
103 |
||
104 |
fun thyinfo_of_sign sg = |
|
105 |
let val name = Sign.name_of sg |
|
106 |
in (name, the_thyinfo name) end; |
|
3604
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
107 |
|
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
108 |
|
3976 | 109 |
(*path where theory's files are located*) |
110 |
val path_of = #path o the_thyinfo; |
|
3604
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
111 |
|
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
112 |
|
3976 | 113 |
(*try to get the theory object corresponding to a given signature*) |
3604
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
114 |
fun theory_of_sign sg = |
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
115 |
(case thyinfo_of_sign sg of |
3976 | 116 |
(_, {theory = Some thy, ...}) => thy |
3604
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
117 |
| _ => sys_error "theory_of_sign"); |
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
118 |
|
3976 | 119 |
(*try to get the theory object corresponding to a given theorem*) |
120 |
val theory_of_thm = theory_of_sign o #sign o rep_thm; |
|
3604
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
121 |
|
3976 | 122 |
(*get all direct descendants of a theory*) |
123 |
fun children_of t = |
|
124 |
(case get_thyinfo t of |
|
125 |
Some ({children, ...}) => children |
|
126 |
| None => []); |
|
127 |
||
128 |
(*get all direct ancestors of a theory*) |
|
129 |
fun parents_of_name t = |
|
130 |
(case get_thyinfo t of |
|
131 |
Some ({parents, ...}) => parents |
|
132 |
| None => []); |
|
133 |
||
134 |
(*get theory object for a loaded theory*) |
|
135 |
fun theory_of name = |
|
136 |
(case get_thyinfo name of |
|
137 |
Some ({theory = Some t, ...}) => t |
|
138 |
| _ => err_not_stored name); |
|
3604
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
139 |
|
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
140 |
|
3976 | 141 |
(*invoke every put method stored in a theory's methods table to initialize |
3604
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
142 |
the state of user defined variables*) |
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
143 |
fun put_thydata first tname = |
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
144 |
let val (methods, data) = |
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
145 |
case get_thyinfo tname of |
3976 | 146 |
Some ({methods, data, ...}) => |
3604
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
147 |
(methods, Symtab.dest ((if first then fst else snd) data)) |
3976 | 148 |
| None => err_not_stored tname; |
3604
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
149 |
|
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
150 |
fun put_data (id, date) = |
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
151 |
case Symtab.lookup (methods, id) of |
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
152 |
Some (ThyMethods {put, ...}) => put date |
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
153 |
| None => error ("No method defined for theory data \"" ^ |
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
154 |
id ^ "\""); |
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
155 |
in seq put_data data end; |
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
156 |
|
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
157 |
|
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
158 |
val set_current_thy = put_thydata false; |
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
159 |
|
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
160 |
|
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
161 |
(*Change theory object for an existent item of loaded_thys*) |
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
162 |
fun store_theory (thy, tname) = |
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
163 |
let val tinfo = case Symtab.lookup (!loaded_thys, tname) of |
3976 | 164 |
Some ({path, children, parents, thy_time, ml_time, thms, |
3604
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
165 |
methods, data, ...}) => |
3976 | 166 |
{path = path, children = children, parents = parents, |
3604
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
167 |
thy_time = thy_time, ml_time = ml_time, |
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
168 |
theory = Some thy, thms = thms, |
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
169 |
methods = methods, data = data} |
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
170 |
| None => error ("store_theory: theory " ^ tname ^ " not found"); |
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
171 |
in loaded_thys := Symtab.update ((tname, tinfo), !loaded_thys) end; |
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
172 |
|
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
173 |
|
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
174 |
(*** Misc functions ***) |
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
175 |
|
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
176 |
(*Add data handling methods to theory*) |
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
177 |
fun add_thydata tname (new_methods as (id, ThyMethods {get, ...})) = |
3976 | 178 |
let val {path, children, parents, thy_time, ml_time, theory, |
179 |
thms, methods, data} = the_thyinfo tname; |
|
180 |
in loaded_thys := Symtab.update ((tname, {path = path, |
|
3604
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
181 |
children = children, parents = parents, thy_time = thy_time, |
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
182 |
ml_time = ml_time, theory = theory, thms = thms, |
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
183 |
methods = Symtab.update (new_methods, methods), data = data}), |
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
184 |
!loaded_thys) |
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
185 |
end; |
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
186 |
|
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
187 |
|
3976 | 188 |
(*retrieve data associated with theory*) |
189 |
fun get_thydata name id = |
|
190 |
Symtab.lookup (snd (#data (the_thyinfo name)), id); |
|
191 |
||
3604
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
192 |
|
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
193 |
end; |