diff src/explify.sml @ 176:33d4a8eea484

Case through explify
author Adam Chlipala <adamc@hcoop.net>
date Thu, 31 Jul 2008 16:28:55 -0400
parents c7a6e6dbc318
children d11754ffe252
line wrap: on
line diff
--- a/src/explify.sml	Thu Jul 31 13:08:57 2008 -0400
+++ b/src/explify.sml	Thu Jul 31 16:28:55 2008 -0400
@@ -71,6 +71,19 @@
       | L.CUnif (_, _, _, ref (SOME c)) => explifyCon c
       | L.CUnif _ => raise Fail ("explifyCon: CUnif at " ^ EM.spanToString loc)
 
+fun explifyPatCon pc =
+    case pc of
+        L.PConVar n => L'.PConVar n
+      | L.PConProj x => L'.PConProj x
+
+fun explifyPat (p, loc) =
+    case p of
+        L.PWild => (L'.PWild, loc)
+      | L.PVar x => (L'.PVar x, loc)
+      | L.PPrim p => (L'.PPrim p, loc)
+      | L.PCon (pc, po) => (L'.PCon (explifyPatCon pc, Option.map explifyPat po), loc)
+      | L.PRecord xps => (L'.PRecord (map (fn (x, p) => (x, explifyPat p)) xps), loc)
+
 fun explifyExp (e, loc) =
     case e of
         L.EPrim p => (L'.EPrim p, loc)
@@ -89,7 +102,9 @@
                                                      {field = explifyCon field, rest = explifyCon rest}), loc)
       | L.EFold k => (L'.EFold (explifyKind k), loc)
 
-      | L.ECase _ => raise Fail "Explify ECase"
+      | L.ECase (e, pes, t) => (L'.ECase (explifyExp e,
+                                          map (fn (p, e) => (explifyPat p, explifyExp e)) pes,
+                                          explifyCon t), loc)
 
       | L.EError => raise Fail ("explifyExp: EError at " ^ EM.spanToString loc)