[document Grin generation process. remove code dealing with boxed literals. remove some irrelevant code paths that are never executed.
John Meacham <john@repetae.net>**20060124015123] hunk ./Grin/FromE.hs 192
--- constant CAF analysis
+-- | constant CAF analysis
hunk ./Grin/FromE.hs 197
---type ConstantCafMap = Map.Map Int -> Val
---constantCaf :: DataTable -> SC -> [(TVr,Val)]
+constantCaf :: DataTable -> SC -> ([(TVr,Var,Val)],[Var])
hunk ./Grin/FromE.hs 210
-    conv (ELit (LitInt i (ELit (LitCons n [] (ESort EStar))))) | Just pt <- Map.lookup n ctypeMap = ( Const (NodeC (toAtom $ 'C':show n) [(Lit i (Ty (toAtom pt)))]))
+    --conv (ELit (LitInt i (ELit (LitCons n [] (ESort EStar))))) | Just pt <- Map.lookup n ctypeMap = ( Const (NodeC (toAtom $ 'C':show n) [(Lit i (Ty (toAtom pt)))]))
hunk ./Grin/FromE.hs 264
+
+    -- | ce evaluates something in strict context returning the evaluated result of its argument.
hunk ./Grin/FromE.hs 278
-                    Nothing -> do
-                        var@Var {} <- caforconst (EVar v)
-                        app fty (gEval var) as   -- CAFs are looked up in global env
hunk ./Grin/FromE.hs 351
-
-    ce (ECase e b as d) | any isJust  ls = ans where
-        ans = do
-            v <- newPrimVar ty
-            nv <- newNodeVar
-            e <- ce e
-            as' <- mapM (cp' v cons) as
-            def <- createDef d (newPrimVar ty)
-            return $
-                e :>>= nv :->
-                Store nv :>>= toVal b :->
-                Return nv :>>= NodeC cons [v] :->
-                Case v (as' ++ def)
-        ls = map isBasic [ a | Alt a _ <- as]
-        Just (cons,ty) = msum ls
hunk ./Grin/FromE.hs 365
-    cpa :: E -> IO (Val,Val,Exp)
-    cpa e = do
-        v <- newVar
-        (c,t) <- case lookupCType dataTable (getType e) of
-            Right x -> return x
-            Left m -> fail (m <+> show e)
-        let var = Var v (Ty $ toAtom t)
-        w <- ce e
-        return (var,NodeC (toAtom $ 'C':show c) [var],w)
hunk ./Grin/FromE.hs 366
-    isBasic ( (LitInt _ t)) | Just (c,pt) <- lookupCType dataTable t = return (toAtom $ 'C':show c, Ty $ toAtom pt)
-    --isBasic ( (LitInt _ (ELit (LitCons c [] _)))) | Just pt <- Prelude.lookup (show c) allCTypes = return (toAtom $ 'C':show c, Ty $ toAtom pt)
-    --isBasic (PatLit (LitChar {})) = return tCharzh
-    isBasic e = fail $ "Not Basic: " ++ show e
hunk ./Grin/FromE.hs 384
-    cp' nv cons p = f p where
-        f (Alt l@(LitInt i _) e) = do
-            x <- ce e
-            (_,tp) <- isBasic l
-            z <- return $ Lit i tp
-            return (z :-> x)
-
hunk ./Grin/FromE.hs 425
+    -- | cc evaluates something in lazy context, returning a pointer to a node which when evaluated will produce the strict result.
+    -- it is an invarient that evaling (cc e) produces the same value as (ce e)
hunk ./Grin/FromE.hs 497
-        --f x | Just z <- caforconst x =  z
hunk ./Grin/FromE.hs 509
-    -- | Takes an E and returns something constant which is either a pointer to a constant heap location or a CAF which may be evaluated or a literal
-    -- constant is sort of a misnomer here, it means a compile time constant, the CAFs may be updated at runtime when evaluated.
+    -- | Takes an E and returns something constant which is either a pointer to
+    -- a constant heap location only pointing to global values or constants.
+    -- this includes a CAF which may be evaluated, a literal, a saturated
+    -- application of constant values to a supercombinator, or a constructor
+    -- containing constant values. constant is sort of a misnomer here when
+    -- runtime behavior is considered, it means a compile time constant, the
+    -- CAFs may be updated with evaluated values.
+
hunk ./Grin/FromE.hs 526
---    constant (ELit (LitInt i (ELit (LitCons n [] (ESort EStar))))) | Just pt <- Map.lookup n ctypeMap = (return $ Const (NodeC (toAtom $ 'C':show n) [(Lit i (Ty (toAtom pt)))]))
---    constant (ELit lc@(LitCons n es _)) | Just es <- mapM constant es, Just _ <- fromUnboxedNameTuple n, DataConstructor <- nameType n = (return $ Const (Tup es))
hunk ./Grin/FromE.hs 532
-    caforconst e = constant e
-
-    -- | convert a constructor into a Val
+    -- | convert a constructor into a Val, arguments may depend on local vars.
hunk ./Grin/FromE.hs 534
-    --con e | Just z <- const e = return z
-    --con e | Just (Const z) <- constant e = return z
hunk ./Grin/FromE.hs 541
-            return ((NodeC cn (args es)))
+            return (NodeC cn (args es))