[clean up some code, fix handling of ffi exports interacting with the main function
John Meacham <john@repetae.net>**20060815051212] hunk ./E/FromHs.hs 201
-  nameToEntryPoint dataTable (fst mt) (toName Name.Val "theMain") (FfiExport "_amain" Safe CCall) funcs
+  nameToEntryPoint dataTable (fst mt) (toName Name.Val "theMain") Nothing funcs
hunk ./E/FromHs.hs 203
-nameToEntryPoint :: Monad m => DataTable -> TVr -> Name -> FfiExport -> FuncNames TVr -> m (Name,TVr,E)
+nameToEntryPoint :: Monad m => DataTable -> TVr -> Name -> Maybe FfiExport -> FuncNames TVr -> m (Name,TVr,E)
hunk ./E/FromHs.hs 219
-        return (cname, tvrInfo_u (Info.insert ffi) $ setProperty prop_EXPORTED theMainTvr,ne)
+        return (cname, tvrInfo_u (case ffi of Just ffi -> Info.insert ffi; Nothing -> id) $ setProperty prop_EXPORTED theMainTvr,ne)
hunk ./E/FromHs.hs 443
-        return . (:[]) =<< nameToEntryPoint dataTable (tv n) (toName Name.FfiExportName ecn) ffi =<< fmapM (return . toTVr assumps) sFuncNames
+        return . (:[]) =<< nameToEntryPoint dataTable (tv n) (toName Name.FfiExportName ecn) (Just ffi) =<< fmapM (return . toTVr assumps) sFuncNames
hunk ./Grin/FromE.hs 4
+import Control.Monad
hunk ./Grin/FromE.hs 16
+import C.FFI hiding(Primitive)
hunk ./Grin/FromE.hs 117
-    | Just nm <- intToAtom (tvrIdent n)  = f (toAtom ('f':show (fromAtom nm :: Name)))
+    | Just nm <- fromId (tvrIdent n)  = f (toAtom ('f':show nm))
hunk ./Grin/FromE.hs 166
-    let tvrAtom (TVr i _ _)  = intToAtom i
+    let tvrAtom t  = liftM convertName (fromId $ tvrIdent t)
hunk ./Grin/FromE.hs 171
-                  l <- Info.lookup (tvrInfo x)
-                  return (n, l)
-    efv <- mapM ef $ tail entries -- FIXME
-    epv <- mapM ep entries
+                  case Info.lookup (tvrInfo x) of
+                    Just l -> return [(n, l)]
+                    Nothing -> return []
+    -- efv <- mapM ef entries -- FIXME
+    efv <- return []
+    epv <- liftM concat $ mapM ep entries
hunk ./Grin/FromE.hs 182
-    let newTyEnv = TyEnv $ Map.fromList (concatMap makePartials (Map.toList endTyEnv) ++ [(en, ([],tyUnit)) | en <- enames])
+    let newTyEnv = TyEnv $ Map.fromList (concatMap makePartials (Map.toList endTyEnv) ++ [(funcMain, ([],tyUnit))] ++ [(en, ([],tyUnit)) | en <- enames])
hunk ./Grin/FromE.hs 198
-            grinEntryPoints = Map.fromList epv,
+            grinEntryPoints = Map.insert funcMain (FfiExport "_amain" Safe CCall) $ Map.fromList epv,
hunk ./Grin/FromE.hs 201
-            grinFunctions = (head enames ,(Tup [] :-> App funcInitCafs [] tyUnit :>>= unit :->  discardResult theMain)) : efv ++ ds',
+            grinFunctions = (funcMain ,(Tup [] :-> App funcInitCafs [] tyUnit :>>= unit :->  discardResult theMain)) : efv ++ ds',
hunk ./Grin/FromE.hs 326
-    funcName = maybe (show $ tvrIdent tvr) show (fmap fromAtom ( intToAtom $ tvrIdent tvr) :: Maybe Name)
+    funcName = maybe (show $ tvrIdent tvr) show (fromId (tvrIdent tvr))
hunk ./Grin/Grin.hs 156
-                  expJump :: Bool,
+                  expJump :: Bool,                                        -- ^ Jump is equivalent to a call except it deallocates the region it resides in before transfering control
hunk ./Grin/Grin.hs 173
-                  expRest :: Lam,                          -- ^ the computation that is passed the newly created computation
-                  expInfo :: Info.Info }                   -- ^ Make a continuation, always allocated on region encompasing expRest
+                  expLam :: Lam,                           -- ^ the computation that is passed the newly created computation
+                  expInfo :: Info.Info }                   -- ^ Make a continuation, always allocated on region encompasing expLam
hunk ./Grin/Grin.hs 530
+    typecheck te (Let { expDefs = defs, expBody = body }) = do
+        mapM_ (typecheck te) [ b | FuncDef { funcDefBody = _ :-> b } <- defs ]
+        typecheck te body
hunk ./Grin/Grin.hs 569
-    getType MkCont { expRest = _ :-> rbody } = getType rbody
+    getType MkCont { expLam = _ :-> rbody } = getType rbody
hunk ./Grin/Grin.hs 623
-    freeVars MkCont { expCont = v, expRest = as} = freeVars (v,as)
+    freeVars MkCont { expCont = v, expLam = as} = freeVars (v,as)
hunk ./Grin/Grin.hs 665
-    freeVars MkCont { expCont = v, expRest = as} = freeVars (v,as)
+    freeVars MkCont { expCont = v, expLam = as} = freeVars (v,as)