comparison src/shake.sml @ 109:813e5a52063d

Remove closure conversion in favor of zany fun with modules, which also replaces 'page'
author Adam Chlipala <adamc@hcoop.net>
date Sun, 13 Jul 2008 10:17:06 -0400
parents f0f59e918cac
children fd98dd10dce7
comparison
equal deleted inserted replaced
108:f59553dc1b6a 109:813e5a52063d
41 exp : IS.set 41 exp : IS.set
42 } 42 }
43 43
44 fun shake file = 44 fun shake file =
45 let 45 let
46 val (page_cs, page_es) = List.foldl 46 val page_es = List.foldl
47 (fn ((DPage (c, e), _), (cs, es)) => (c :: cs, e :: es) 47 (fn ((DExport n, _), page_es) => n :: page_es
48 | (_, acc) => acc) ([], []) file 48 | (_, page_es) => page_es) [] file
49 49
50 val (cdef, edef) = foldl (fn ((DCon (_, n, _, c), _), (cdef, edef)) => (IM.insert (cdef, n, c), edef) 50 val (cdef, edef) = foldl (fn ((DCon (_, n, _, c), _), (cdef, edef)) => (IM.insert (cdef, n, c), edef)
51 | ((DVal (_, n, t, e), _), (cdef, edef)) => (cdef, IM.insert (edef, n, (t, e))) 51 | ((DVal (_, n, t, e, _), _), (cdef, edef)) => (cdef, IM.insert (edef, n, (t, e)))
52 | ((DPage _, _), acc) => acc) 52 | ((DExport _, _), acc) => acc)
53 (IM.empty, IM.empty) file 53 (IM.empty, IM.empty) file
54 54
55 fun kind (_, s) = s 55 fun kind (_, s) = s
56 56
57 fun con (c, s) = 57 fun con (c, s) =
88 end 88 end
89 | _ => s 89 | _ => s
90 90
91 and shakeExp s = U.Exp.fold {kind = kind, con = con, exp = exp} s 91 and shakeExp s = U.Exp.fold {kind = kind, con = con, exp = exp} s
92 92
93 val s = {con = IS.empty, exp = IS.empty} 93 val s = {con = IS.empty, exp = IS.addList (IS.empty, page_es)}
94 94
95 val s = foldl (fn (c, s) => U.Con.fold {kind = kind, con = con} s c) s page_cs 95 val s = foldl (fn (n, s) =>
96 val s = foldl (fn (e, s) => U.Exp.fold {kind = kind, con = con, exp = exp} s e) s page_es 96 case IM.find (edef, n) of
97 NONE => raise Fail "Shake: Couldn't find 'val'"
98 | SOME (t, e) => shakeExp (shakeCon s t) e) s page_es
97 in 99 in
98 List.filter (fn (DCon (_, n, _, _), _) => IS.member (#con s, n) 100 List.filter (fn (DCon (_, n, _, _), _) => IS.member (#con s, n)
99 | (DVal (_, n, _, _), _) => IS.member (#exp s, n) 101 | (DVal (_, n, _, _, _), _) => IS.member (#exp s, n)
100 | (DPage _, _) => true) file 102 | (DExport _, _) => true) file
101 end 103 end
102 104
103 end 105 end