comparison src/mono_shake.sml @ 164:6847741e1f5f

Datatypes through monoize
author Adam Chlipala <adamc@hcoop.net>
date Tue, 29 Jul 2008 13:32:07 -0400
parents f0d3402184d1
children 25b169416ea8
comparison
equal deleted inserted replaced
163:80192edca30d 164:6847741e1f5f
45 let 45 let
46 val page_es = List.foldl 46 val page_es = List.foldl
47 (fn ((DExport (_, _, n, _), _), page_es) => n :: page_es 47 (fn ((DExport (_, _, n, _), _), page_es) => n :: page_es
48 | (_, page_es) => page_es) [] file 48 | (_, page_es) => page_es) [] file
49 49
50 val (cdef, edef) = foldl (fn ((DVal (_, n, t, e, _), _), (cdef, edef)) => (cdef, IM.insert (edef, n, (t, e))) 50 val (cdef, edef) = foldl (fn ((DDatatype _, _), acc) => acc
51 | ((DVal (_, n, t, e, _), _), (cdef, edef)) => (cdef, IM.insert (edef, n, (t, e)))
51 | ((DValRec vis, _), (cdef, edef)) => 52 | ((DValRec vis, _), (cdef, edef)) =>
52 (cdef, foldl (fn ((_, n, t, e, _), edef) => IM.insert (edef, n, (t, e))) edef vis) 53 (cdef, foldl (fn ((_, n, t, e, _), edef) => IM.insert (edef, n, (t, e))) edef vis)
53 | ((DExport _, _), acc) => acc) 54 | ((DExport _, _), acc) => acc)
54 (IM.empty, IM.empty) file 55 (IM.empty, IM.empty) file
55 56
56 fun typ (_, s) = s 57 fun typ (c, s) =
58 case c of
59 TNamed n =>
60 if IS.member (#con s, n) then
61 s
62 else
63 {exp = #exp s,
64 con = IS.add (#con s, n)}
65 | _ => s
57 66
58 fun exp (e, s) = 67 fun exp (e, s) =
59 case e of 68 case e of
60 ENamed n => 69 ENamed n =>
61 if IS.member (#exp s, n) then 70 if IS.member (#exp s, n) then
78 val s = foldl (fn (n, s) => 87 val s = foldl (fn (n, s) =>
79 case IM.find (edef, n) of 88 case IM.find (edef, n) of
80 NONE => raise Fail "Shake: Couldn't find 'val'" 89 NONE => raise Fail "Shake: Couldn't find 'val'"
81 | SOME (t, e) => shakeExp s e) s page_es 90 | SOME (t, e) => shakeExp s e) s page_es
82 in 91 in
83 List.filter (fn (DVal (_, n, _, _, _), _) => IS.member (#exp s, n) 92 List.filter (fn (DDatatype (_, n, _), _) => IS.member (#con s, n)
93 | (DVal (_, n, _, _, _), _) => IS.member (#exp s, n)
84 | (DValRec vis, _) => List.exists (fn (_, n, _, _, _) => IS.member (#exp s, n)) vis 94 | (DValRec vis, _) => List.exists (fn (_, n, _, _, _) => IS.member (#exp s, n)) vis
85 | (DExport _, _) => true) file 95 | (DExport _, _) => true) file
86 end 96 end
87 97
88 end 98 end