[handle local function definitions in Grin
John Meacham <john@repetae.net>**20060814135035] hunk ./Grin/FromE.hs 31
+import Name.Id
hunk ./Grin/FromE.hs 44
+import Util.SetLike
hunk ./Grin/FromE.hs 76
+    localFuncMap :: IORef (IdMap (Atom,Int,Ty)),
hunk ./Grin/FromE.hs 142
+    lm <- newIORef mempty
hunk ./Grin/FromE.hs 149
+            localFuncMap = lm,
hunk ./Grin/FromE.hs 337
+        lfunc <- readIORef (localFuncMap cenv)
hunk ./Grin/FromE.hs 342
+            Nothing | Just (v,n,rt) <- mlookup (tvrIdent tvr) lfunc -> do
+                    let (x,y) = splitAt n as
+                    app fty (App v x rt) y
hunk ./Grin/FromE.hs 539
+        f (Left te@(_,ELam {}):ds) x = f (Right [te]:ds) x
hunk ./Grin/FromE.hs 549
+        f (Right bs:ds) x | any (isELam . snd) bs = do
+            let g (t,e@ELam {}) = do
+                    let (a,as) = fromLam e
+                        (nn,_,_) = toEntry (t,[],getType t)
+                    x <- ce a
+                    return $ [createFuncDef True nn (Tup (map toVal (filter (shouldKeep . getType) as)) :-> x)]
+                g' (t,e@ELam {}) = do
+                    let (a,as) = fromLam e
+                        (nn,_,_) = toEntry (t,[],getType t)
+                    modifyIORef (localFuncMap cenv) (minsert (tvrIdent t) (nn,length as,toType TyNode (getType a)))
+            mapM_ g' bs
+            v <- f ds x
+            defs <- mapM g bs
+            return $ Let { expDefs = concat defs , expBody = v, expInfo = mempty }
+
+
hunk ./Grin/Grin.hs 21
+    createFuncDef,
hunk ./Grin/Grin.hs 607
+    freeVars Let { expDefs = fdefs, expBody = body } = mconcat (map (funcFreeVars . funcDefProps) fdefs) `mappend` freeVars body
+    freeVars NewRegion { expLam = l } = freeVars l
+    freeVars Alloc { expValue = v, expCount = c, expRegion = r } = freeVars (v,c,r)
+    freeVars Call { expValue = v, expArgs = as } = freeVars (v:as)
+    freeVars MkClosure { expValue = v, expArgs = as, expRegion = r } = freeVars (v,as,r)
+    freeVars MkCont { expCont = v, expRest = as} = freeVars (v,as)
hunk ./Grin/Grin.hs 649
+    freeVars Let { expDefs = fdefs, expBody = body } = mconcat (map (funcTags . funcDefProps) fdefs) `mappend` freeVars body
+    freeVars NewRegion { expLam = l } = freeVars l
+    freeVars Alloc { expValue = v, expCount = c, expRegion = r } = freeVars (v,c,r)
+    freeVars Call { expValue = v, expArgs = as } = freeVars (v:as)
+    freeVars MkClosure { expValue = v, expArgs = as, expRegion = r } = freeVars (v,as,r)
+    freeVars MkCont { expCont = v, expRest = as} = freeVars (v,as)
hunk ./Grin/MangleE.hs 129
-        f e | (a,as) <- fromAp e = do
+        f (ELam t e) = f e
+        f e | (a,as@(_:_)) <- fromAp e = do
hunk ./Grin/Whiz.hs 85
+    g env lt@Let { expDefs = defs, expBody = body } = do
+        body <- f body [] env
+        let f def@FuncDef { funcDefName = n, funcDefBody = b } = do
+                b <- dc env b
+                return $ createFuncDef True n b
+        defs <- mapM f defs
+        return lt { expBody = body, expDefs = defs }
hunk ./Grin/Whiz.hs 153
+    g env lt@Let { expDefs = defs, expBody = body } = do
+        body <- f body [] env
+        let f def@FuncDef { funcDefName = n, funcDefBody = b } = do
+                b <- dc env b
+                return $ createFuncDef True n b
+        defs <- mapM f defs
+        return lt { expBody = body, expDefs = defs }