comparison src/shake.sml @ 453:787d4931fb07

Almost have that nested save function compiling
author Adam Chlipala <adamc@hcoop.net>
date Sat, 01 Nov 2008 21:19:43 -0400
parents e976b187d73a
children 5c9606deacb6
comparison
equal deleted inserted replaced
452:222cbc1da232 453:787d4931fb07
53 | (_, acc) => acc) ([], []) file 53 | (_, acc) => acc) ([], []) file
54 54
55 val (cdef, edef) = foldl (fn ((DCon (_, n, _, c), _), (cdef, edef)) => (IM.insert (cdef, n, [c]), edef) 55 val (cdef, edef) = foldl (fn ((DCon (_, n, _, c), _), (cdef, edef)) => (IM.insert (cdef, n, [c]), edef)
56 | ((DDatatype (_, n, _, xncs), _), (cdef, edef)) => 56 | ((DDatatype (_, n, _, xncs), _), (cdef, edef)) =>
57 (IM.insert (cdef, n, List.mapPartial #3 xncs), edef) 57 (IM.insert (cdef, n, List.mapPartial #3 xncs), edef)
58 | ((DVal (_, n, t, e, _), _), (cdef, edef)) => (cdef, IM.insert (edef, n, (t, e))) 58 | ((DVal (_, n, t, e, _), _), (cdef, edef)) => (cdef, IM.insert (edef, n, ([], t, e)))
59 | ((DValRec vis, _), (cdef, edef)) => 59 | ((DValRec vis, _), (cdef, edef)) =>
60 (cdef, foldl (fn ((_, n, t, e, _), edef) => IM.insert (edef, n, (t, e))) edef vis) 60 let
61 val all_ns = map (fn (_, n, _, _, _) => n) vis
62 in
63 (cdef, foldl (fn ((_, n, t, e, _), edef) =>
64 IM.insert (edef, n, (all_ns, t, e))) edef vis)
65 end
61 | ((DExport _, _), acc) => acc 66 | ((DExport _, _), acc) => acc
62 | ((DTable (_, n, c, _), _), (cdef, edef)) => 67 | ((DTable (_, n, c, _), _), (cdef, edef)) =>
63 (cdef, IM.insert (edef, n, (c, dummye))) 68 (cdef, IM.insert (edef, n, ([], c, dummye)))
64 | ((DSequence (_, n, _), _), (cdef, edef)) => 69 | ((DSequence (_, n, _), _), (cdef, edef)) =>
65 (cdef, IM.insert (edef, n, (dummyt, dummye))) 70 (cdef, IM.insert (edef, n, ([], dummyt, dummye)))
66 | ((DDatabase _, _), acc) => acc) 71 | ((DDatabase _, _), acc) => acc)
67 (IM.empty, IM.empty) file 72 (IM.empty, IM.empty) file
68 73
69 fun kind (_, s) = s 74 fun kind (_, s) = s
70 75
94 else 99 else
95 let 100 let
96 val s' = {exp = IS.add (#exp s, n), 101 val s' = {exp = IS.add (#exp s, n),
97 con = #con s} 102 con = #con s}
98 in 103 in
104 (*print ("Need " ^ Int.toString n ^ "\n");*)
99 case IM.find (edef, n) of 105 case IM.find (edef, n) of
100 NONE => s' 106 NONE => s'
101 | SOME (t, e) => shakeExp (shakeCon s' t) e 107 | SOME (ns, t, e) =>
108 let
109 val s' = shakeExp (shakeCon s' t) e
110 in
111 foldl (fn (n, s') => exp (ENamed n, s')) s' ns
112 end
102 end 113 end
103 | _ => s 114 | _ => s
104 115
105 and shakeExp s = U.Exp.fold {kind = kind, con = con, exp = exp} s 116 and shakeExp s = U.Exp.fold {kind = kind, con = con, exp = exp} s
106 117
107 val s = {con = IS.empty, exp = IS.addList (IS.empty, page_es)} 118 val s = {con = IS.empty, exp = IS.addList (IS.empty, page_es)}
108 119
109 val s = foldl (fn (n, s) => 120 val s = foldl (fn (n, s) =>
110 case IM.find (edef, n) of 121 case IM.find (edef, n) of
111 NONE => raise Fail "Shake: Couldn't find 'val'" 122 NONE => raise Fail "Shake: Couldn't find 'val'"
112 | SOME (t, e) => shakeExp (shakeCon s t) e) s page_es 123 | SOME (ns, t, e) =>
124 let
125 val s = shakeExp (shakeCon s t) e
126 in
127 foldl (fn (n, s) => exp (ENamed n, s)) s ns
128 end) s page_es
113 129
114 val s = foldl (fn (c, s) => shakeCon s c) s table_cs 130 val s = foldl (fn (c, s) => shakeCon s c) s table_cs
115 in 131 in
116 List.filter (fn (DCon (_, n, _, _), _) => IS.member (#con s, n) 132 List.filter (fn (DCon (_, n, _, _), _) => IS.member (#con s, n)
117 | (DDatatype (_, n, _, _), _) => IS.member (#con s, n) 133 | (DDatatype (_, n, _, _), _) => IS.member (#con s, n)