107 val add_trrules: (string * string) Syntax.trrule list -> sg -> sg |
107 val add_trrules: (string * string) Syntax.trrule list -> sg -> sg |
108 val add_trrules_i: ast Syntax.trrule list -> sg -> sg |
108 val add_trrules_i: ast Syntax.trrule list -> sg -> sg |
109 val add_path: string -> sg -> sg |
109 val add_path: string -> sg -> sg |
110 val add_space: string * string list -> sg -> sg |
110 val add_space: string * string list -> sg -> sg |
111 val add_name: string -> sg -> sg |
111 val add_name: string -> sg -> sg |
112 val init_data: string * exn * (exn -> exn) * (exn * exn -> exn) * |
112 val init_data: string * (exn * (exn -> exn) * (exn * exn -> exn) * (exn -> unit)) |
113 (string -> exn -> unit) -> sg -> sg |
113 -> sg -> sg |
114 val get_data: sg -> string -> exn |
114 val get_data: sg -> string -> exn |
115 val put_data: string * exn -> sg -> sg |
115 val put_data: string * exn -> sg -> sg |
116 val print_data: sg -> string -> unit |
116 val print_data: sg -> string -> unit |
117 val merge_refs: sg_ref * sg_ref -> sg_ref |
117 val merge_refs: sg_ref * sg_ref -> sg_ref |
118 val prep_ext: sg -> sg |
118 val prep_ext: sg -> sg |
119 val merge: sg * sg -> sg |
119 val merge: sg * sg -> sg |
120 val proto_pure: sg |
120 val pre_pure: sg |
121 val pure: sg |
|
122 val cpure: sg |
|
123 val const_of_class: class -> string |
121 val const_of_class: class -> string |
124 val class_of_const: string -> class |
122 val class_of_const: string -> class |
125 end; |
123 end; |
126 |
124 |
127 structure Sign : SIGN = |
125 structure Sign : SIGN = |
158 fun stamp_names_of (Sg ({stamps, ...}, _)) = rev (map ! stamps); |
156 fun stamp_names_of (Sg ({stamps, ...}, _)) = rev (map ! stamps); |
159 fun pretty_sg sg = Pretty.str_list "{" "}" (stamp_names_of sg); |
157 fun pretty_sg sg = Pretty.str_list "{" "}" (stamp_names_of sg); |
160 val str_of_sg = Pretty.str_of o pretty_sg; |
158 val str_of_sg = Pretty.str_of o pretty_sg; |
161 val pprint_sg = Pretty.pprint o pretty_sg; |
159 val pprint_sg = Pretty.pprint o pretty_sg; |
162 |
160 |
163 |
|
164 val tsig_of = #tsig o rep_sg; |
161 val tsig_of = #tsig o rep_sg; |
165 val self_ref = #self o rep_sg; |
|
166 val get_data = Data.get o #data o rep_sg; |
162 val get_data = Data.get o #data o rep_sg; |
167 val print_data = Data.print o #data o rep_sg; |
163 val print_data = Data.print o #data o rep_sg; |
168 |
164 |
169 fun const_type (Sg (_, {const_tab, ...})) c = Symtab.lookup (const_tab, c); |
165 fun const_type (Sg (_, {const_tab, ...})) c = Symtab.lookup (const_tab, c); |
170 val classes = #classes o Type.rep_tsig o tsig_of; |
166 val classes = #classes o Type.rep_tsig o tsig_of; |
172 val subsort = Type.subsort o tsig_of; |
168 val subsort = Type.subsort o tsig_of; |
173 val norm_sort = Type.norm_sort o tsig_of; |
169 val norm_sort = Type.norm_sort o tsig_of; |
174 val nonempty_sort = Type.nonempty_sort o tsig_of; |
170 val nonempty_sort = Type.nonempty_sort o tsig_of; |
175 |
171 |
176 |
172 |
177 (* signature id *) |
173 (* id and self *) |
178 |
|
179 fun deref (SgRef (Some (ref sg))) = sg |
|
180 | deref (SgRef None) = sys_error "Sign.deref"; |
|
181 |
174 |
182 fun check_stale (sg as Sg ({id, ...}, |
175 fun check_stale (sg as Sg ({id, ...}, |
183 {self = SgRef (Some (ref (Sg ({id = id', ...}, _)))), ...})) = |
176 {self = SgRef (Some (ref (Sg ({id = id', ...}, _)))), ...})) = |
184 if id = id' then sg |
177 if id = id' then sg |
185 else raise TERM ("Stale signature: " ^ str_of_sg sg, []) |
178 else raise TERM ("Stale signature: " ^ str_of_sg sg, []) |
186 | check_stale _ = sys_error "Sign.check_stale"; |
179 | check_stale _ = sys_error "Sign.check_stale"; |
|
180 |
|
181 fun self_ref (sg as Sg (_, {self, ...})) = (check_stale sg; self); |
|
182 |
|
183 fun deref (SgRef (Some (ref sg))) = sg |
|
184 | deref (SgRef None) = sys_error "Sign.deref"; |
187 |
185 |
188 fun name_of (sg as Sg ({id = ref name, ...}, _)) = |
186 fun name_of (sg as Sg ({id = ref name, ...}, _)) = |
189 if name = "" orelse name = "#" then |
187 if name = "" orelse name = "#" then |
190 raise TERM ("Nameless signature " ^ str_of_sg sg, []) |
188 raise TERM ("Nameless signature " ^ str_of_sg sg, []) |
191 else name; |
189 else name; |
283 |
281 |
284 fun space_of spaces kind = |
282 fun space_of spaces kind = |
285 if_none (assoc (spaces, kind)) NameSpace.empty; |
283 if_none (assoc (spaces, kind)) NameSpace.empty; |
286 |
284 |
287 (*input and output of qualified names*) |
285 (*input and output of qualified names*) |
288 fun intrn spaces kind = NameSpace.lookup (space_of spaces kind); |
286 fun intrn spaces kind = NameSpace.intern (space_of spaces kind); |
289 fun extrn spaces kind = NameSpace.prune (space_of spaces kind); |
287 fun extrn spaces kind = NameSpace.extern (space_of spaces kind); |
290 |
288 |
291 (*add names*) |
289 (*add names*) |
292 fun add_names spaces kind names = |
290 fun add_names spaces kind names = |
293 let val space' = NameSpace.extend (names, space_of spaces kind) in |
291 let val space' = NameSpace.extend (names, space_of spaces kind) in |
294 overwrite (spaces, (kind, space')) |
292 overwrite (spaces, (kind, space')) |
829 (syn, tsig, ctab, (path, add_names spaces kind names), data); |
827 (syn, tsig, ctab, (path, add_names spaces kind names), data); |
830 |
828 |
831 |
829 |
832 (* signature data *) |
830 (* signature data *) |
833 |
831 |
834 fun ext_init_data (syn, tsig, ctab, names, data) (kind, e, ext, mrg, prt) = |
832 fun ext_init_data (syn, tsig, ctab, names, data) (kind, (e, ext, mrg, prt)) = |
835 (syn, tsig, ctab, names, Data.init data kind e ext mrg prt); |
833 (syn, tsig, ctab, names, Data.init data kind e ext mrg prt); |
836 |
834 |
837 fun ext_put_data (syn, tsig, ctab, names, data) (kind, e) = |
835 fun ext_put_data (syn, tsig, ctab, names, data) (kind, e) = |
838 (syn, tsig, ctab, names, Data.put data kind e); |
836 (syn, tsig, ctab, names, Data.put data kind e); |
839 |
837 |
936 OK sg => sg |
934 OK sg => sg |
937 | Error msg => raise TERM (msg, [])); |
935 | Error msg => raise TERM (msg, [])); |
938 |
936 |
939 |
937 |
940 |
938 |
941 (** the Pure signature **) |
939 (** partial Pure signature **) |
942 |
940 |
943 val dummy_sg = make_sign (ref "", SgRef None, Type.tsig0, |
941 val dummy_sg = make_sign (ref "", SgRef None, Type.tsig0, |
944 Symtab.null, Syntax.pure_syn, [], [], Data.empty, []); |
942 Symtab.null, Syntax.pure_syn, [], [], Data.empty, []); |
945 |
943 |
946 val proto_pure = |
944 val pre_pure = |
947 create_sign (SgRef (Some (ref dummy_sg))) [] "#" |
945 create_sign (SgRef (Some (ref dummy_sg))) [] "#" |
948 (Syntax.pure_syn, Type.tsig0, Symtab.null, ([], []), Data.empty) |
946 (Syntax.pure_syn, Type.tsig0, Symtab.null, ([], []), Data.empty); |
949 |> add_types |
|
950 (("fun", 2, NoSyn) :: |
|
951 ("prop", 0, NoSyn) :: |
|
952 ("itself", 1, NoSyn) :: |
|
953 Syntax.pure_types) |
|
954 |> add_classes_i [(logicC, [])] |
|
955 |> add_defsort_i logicS |
|
956 |> add_arities_i |
|
957 [("fun", [logicS, logicS], logicS), |
|
958 ("prop", [], logicS), |
|
959 ("itself", [logicS], logicS)] |
|
960 |> add_syntax Syntax.pure_syntax |
|
961 |> add_modesyntax (("symbols", true), Syntax.pure_sym_syntax) |
|
962 |> add_trfuns Syntax.pure_trfuns |
|
963 |> add_trfunsT Syntax.pure_trfunsT |
|
964 |> add_syntax |
|
965 [("==>", "[prop, prop] => prop", Delimfix "op ==>")] |
|
966 |> add_consts |
|
967 [("==", "['a::{}, 'a] => prop", InfixrName ("==", 2)), |
|
968 ("=?=", "['a::{}, 'a] => prop", InfixrName ("=?=", 2)), |
|
969 ("==>", "[prop, prop] => prop", Mixfix ("(_/ ==> _)", [2, 1], 1)), |
|
970 ("all", "('a => prop) => prop", Binder ("!!", 0, 0)), |
|
971 ("TYPE", "'a itself", NoSyn)] |
|
972 |> add_name "ProtoPure"; |
|
973 |
|
974 val pure = proto_pure |
|
975 |> add_syntax Syntax.pure_appl_syntax |
|
976 |> add_name "Pure"; |
|
977 |
|
978 val cpure = proto_pure |
|
979 |> add_syntax Syntax.pure_applC_syntax |
|
980 |> add_name "CPure"; |
|
981 |
947 |
982 |
948 |
983 end; |
949 end; |
984 |
950 |
985 |
951 |