207 |
207 |
208 (*errors are indicated by exception ERROR (with messages already printed)*) |
208 (*errors are indicated by exception ERROR (with messages already printed)*) |
209 |
209 |
210 fun extend sg name (classes, default, types, abbrs, arities, consts, opt_sext) = |
210 fun extend sg name (classes, default, types, abbrs, arities, consts, opt_sext) = |
211 let |
211 let |
|
212 fun read_abbr syn (c, vs, rhs_src) = |
|
213 (c, (map (rpair 0) vs, varifyT (Syntax.read_typ syn (K []) rhs_src))) |
|
214 handle ERROR => error ("The error(s) above occurred in the rhs " ^ |
|
215 quote rhs_src ^ "\nof type abbreviation " ^ quote c); |
|
216 |
212 (*reset TVar indices to 0, renaming to preserve distinctness*) |
217 (*reset TVar indices to 0, renaming to preserve distinctness*) |
213 fun zero_tvar_idxs T = |
218 fun zero_tvar_idxs T = |
214 let |
219 let |
215 val inxSs = typ_tvars T; |
220 val inxSs = typ_tvars T; |
216 val nms' = variantlist (map (#1 o #1) inxSs, []); |
221 val nms' = variantlist (map (#1 o #1) inxSs, []); |
223 indices because type inference requires it*) |
228 indices because type inference requires it*) |
224 fun read_const tsig syn (c, s) = |
229 fun read_const tsig syn (c, s) = |
225 (c, zero_tvar_idxs (varifyT (rd_typ tsig syn (K None) s))) |
230 (c, zero_tvar_idxs (varifyT (rd_typ tsig syn (K None) s))) |
226 handle ERROR => error ("in declaration of constant " ^ quote c); |
231 handle ERROR => error ("in declaration of constant " ^ quote c); |
227 |
232 |
228 fun read_abbr tsig syn (c, vs, rhs_src) = |
|
229 (c, (map (rpair 0) vs, varifyT (rd_typ tsig syn (K None) rhs_src) |
|
230 handle ERROR => error ("in type abbreviation " ^ quote c))); |
|
231 |
|
232 |
233 |
233 val Sg {tsig, const_tab, syn, stamps} = sg; |
234 val Sg {tsig, const_tab, syn, stamps} = sg; |
234 val xconsts = map #1 classes @ flat (map #1 types) @ map #1 abbrs @ |
235 val xconsts = map #1 classes @ flat (map #1 types) @ map #1 abbrs @ |
235 flat (map #1 consts); |
236 flat (map #1 consts); |
236 val sext = if_none opt_sext Syntax.empty_sext; |
237 val sext = if_none opt_sext Syntax.empty_sext; |
237 |
238 |
238 val tsig' = extend_tsig tsig (classes, default, types, arities); |
239 val tsig' = extend_tsig tsig (classes, default, types, arities); |
239 val tsig1 = ext_tsig_abbrs tsig' (map (read_abbr tsig' syn) abbrs); |
240 val tsig1 = ext_tsig_abbrs tsig' (map (read_abbr syn) abbrs); |
240 |
241 |
241 val syn1 = Syntax.extend syn (rd_typ tsig1 syn (K None)) |
242 val syn1 = Syntax.extend syn (rd_typ tsig1 syn (K None)) |
242 (logical_types tsig1, xconsts, sext); |
243 (logical_types tsig1, xconsts, sext); |
243 |
244 |
244 val all_consts = flat (map (fn (cs, s) => map (rpair s) cs) |
245 val all_consts = flat (map (fn (cs, s) => map (rpair s) cs) |