comparison src/specialize.sml @ 792:d20d6afc1206

Improvements while working on Graftid
author Adam Chlipala <adamc@hcoop.net>
date Tue, 12 May 2009 18:02:25 -0400
parents e21d0dddda09
children 61a1f5c5ae2c
comparison
equal deleted inserted replaced
791:5368deb3764b 792:d20d6afc1206
240 240
241 val specDecl = U.Decl.foldMap {kind = kind, con = con, exp = exp, decl = decl} 241 val specDecl = U.Decl.foldMap {kind = kind, con = con, exp = exp, decl = decl}
242 242
243 fun specialize file = 243 fun specialize file =
244 let 244 let
245 fun doDecl (all as (d, _), st : state) = 245 fun doDecl (d, st) =
246 let 246 let
247 (*val () = Print.preface ("decl:", CorePrint.p_decl CoreEnv.empty all)*) 247 (*val () = Print.preface ("decl:", CorePrint.p_decl CoreEnv.empty all)*)
248 val (d, st) = specDecl st d
248 in 249 in
249 case d of 250 case #1 d of
250 DDatatype (x, n, xs, xnts) => 251 DDatatype (x, n, xs, xnts) =>
251 ([all], {count = #count st, 252 (rev (d :: #decls st),
252 datatypes = IM.insert (#datatypes st, n, 253 {count = #count st,
253 {name = x, 254 datatypes = IM.insert (#datatypes st, n,
254 params = length xs, 255 {name = x,
255 constructors = xnts, 256 params = length xs,
256 specializations = CM.empty}), 257 constructors = xnts,
257 constructors = foldl (fn ((_, n', _), constructors) => 258 specializations = CM.empty}),
258 IM.insert (constructors, n', n)) 259 constructors = foldl (fn ((_, n', _), constructors) =>
259 (#constructors st) xnts, 260 IM.insert (constructors, n', n))
260 decls = []}) 261 (#constructors st) xnts,
262 decls = []})
261 | _ => 263 | _ =>
262 let 264 (rev (d :: #decls st),
263 val (d, st) = specDecl st all 265 {count = #count st,
264 in 266 datatypes = #datatypes st,
265 (rev (d :: #decls st), 267 constructors = #constructors st,
266 {count = #count st, 268 decls = []})
267 datatypes = #datatypes st,
268 constructors = #constructors st,
269 decls = []})
270 end
271 end 269 end
272 270
273 val (ds, _) = ListUtil.foldlMapConcat doDecl 271 val (ds, _) = ListUtil.foldlMapConcat doDecl
274 {count = U.File.maxName file + 1, 272 {count = U.File.maxName file + 1,
275 datatypes = IM.empty, 273 datatypes = IM.empty,