diff src/mono_shake.sml @ 178:eb3f9913bf31

First part of getting cases through monoize
author Adam Chlipala <adamc@hcoop.net>
date Sun, 03 Aug 2008 09:26:49 -0400
parents 25b169416ea8
children 8e9f97508f0d
line wrap: on
line diff
--- a/src/mono_shake.sml	Sat Aug 02 11:15:32 2008 -0400
+++ b/src/mono_shake.sml	Sun Aug 03 09:26:49 2008 -0400
@@ -47,8 +47,10 @@
                           (fn ((DExport (_, _, n, _), _), page_es) => n :: page_es
                             | (_, page_es) => page_es) [] file
 
-        val (cdef, edef) = foldl (fn ((DDatatype _, _), acc) => acc
-                                   | ((DVal (_, n, t, e, _), _), (cdef, edef)) => (cdef, IM.insert (edef, n, (t, e)))
+        val (cdef, edef) = foldl (fn ((DDatatype (_, n, xncs), _), (cdef, edef)) =>
+                                     (IM.insert (cdef, n, xncs), edef)
+                                   | ((DVal (_, n, t, e, _), _), (cdef, edef)) =>
+                                     (cdef, IM.insert (edef, n, (t, e)))
                                    | ((DValRec vis, _), (cdef, edef)) =>
                                      (cdef, foldl (fn ((_, n, t, e, _), edef) => IM.insert (edef, n, (t, e))) edef vis)
                                    | ((DExport _, _), acc) => acc)
@@ -60,10 +62,22 @@
                 if IS.member (#con s, n) then
                     s
                 else
-                    {exp = #exp s,
-                     con = IS.add (#con s, n)}
+                    let
+                        val s' = {exp = #exp s,
+                                  con = IS.add (#con s, n)}
+                    in
+                        case IM.find (cdef, n) of
+                            NONE => s'
+                          | SOME xncs => foldl (fn ((_, _, to), s) =>
+                                                   case to of
+                                                       NONE => s
+                                                     | SOME t => shakeTyp s t)
+                                         s' xncs
+                    end
               | _ => s
 
+        and shakeTyp s = U.Typ.fold typ s
+
         fun exp (e, s) =
             case e of
                 ENamed n =>