diff src/cjrize.sml @ 129:78d59cf0a0cc

Compiled (non-mutual) 'val rec'
author Adam Chlipala <adamc@hcoop.net>
date Thu, 17 Jul 2008 11:02:10 -0400
parents 76a4d69719d8
children f0d3402184d1
line wrap: on
line diff
--- a/src/cjrize.sml	Thu Jul 17 10:48:25 2008 -0400
+++ b/src/cjrize.sml	Thu Jul 17 11:02:10 2008 -0400
@@ -195,7 +195,36 @@
         in
             (SOME (d, loc), NONE, sm)
         end
-      | L.DValRec _ => raise Fail "Cjrize DValRec"
+      | L.DValRec vis =>
+        let
+            val (vis, sm) = ListUtil.foldlMap
+                            (fn ((x, n, t, e, _), sm) =>
+                                let                                    
+                                    val (t, sm) = cifyTyp (t, sm)
+
+                                    fun unravel (tAll as (t, _), eAll as (e, _)) =
+                                        case (t, e) of
+                                            (L'.TFun (dom, ran), L.EAbs (ax, _, _, e)) =>
+                                            let
+                                                val (args, t, e) = unravel (ran, e)
+                                            in
+                                                ((ax, dom) :: args, t, e)
+                                            end
+                                          | (L'.TFun _, _) =>
+                                            (ErrorMsg.errorAt loc "Function isn't explicit at code generation";
+                                             ([], tAll, eAll))
+                                          | _ => ([], tAll, eAll)
+                                                 
+                                    val (args, ran, e) = unravel (t, e)
+                                    val (e, sm) = cifyExp (e, sm)
+                              in
+                                  ((x, n, args, ran, e), sm)
+                              end)
+                            sm vis
+        in
+            (SOME (L'.DFunRec vis, loc), NONE, sm)
+        end        
+
       | L.DExport (s, n, ts) =>
         let
             val (ts, sm) = ListUtil.foldlMap cifyTyp sm ts