Follow library changes
[ghc-hetmet.git] / compiler / deSugar / DsUtils.lhs
index f63b884..cf670cd 100644 (file)
@@ -27,6 +27,7 @@ module DsUtils (
        mkErrorAppDs, mkNilExpr, mkConsExpr, mkListExpr,
        mkIntExpr, mkCharExpr,
        mkStringExpr, mkStringExprFS, mkIntegerExpr, 
+       mkBuildExpr, mkFoldrExpr,
 
     seqVar,
        
@@ -514,8 +515,8 @@ mkCharExpr c = mkConApp charDataCon [mkLit (MachChar c)]
 
 mkIntegerExpr i
   | inIntRange i        -- Small enough, so start from an Int
-    = do integer_dc <- dsLookupDataCon  smallIntegerDataConName
-         return (mkSmallIntegerLit integer_dc i)
+    = do integer_id <- dsLookupGlobalId smallIntegerName
+         return (mkSmallIntegerLit integer_id i)
 
 -- Special case for integral literals with a large magnitude:
 -- They are transformed into an expression involving only smaller
@@ -524,9 +525,9 @@ mkIntegerExpr i
   | otherwise = do       -- Big, so start from a string
       plus_id <- dsLookupGlobalId plusIntegerName
       times_id <- dsLookupGlobalId timesIntegerName
-      integer_dc <- dsLookupDataCon  smallIntegerDataConName
+      integer_id <- dsLookupGlobalId smallIntegerName
       let
-           lit i = mkSmallIntegerLit integer_dc i
+           lit i = mkSmallIntegerLit integer_id i
            plus a b  = Var plus_id  `App` a `App` b
            times a b = Var times_id `App` a `App` b
 
@@ -542,8 +543,8 @@ mkIntegerExpr i
 
       return (horner tARGET_MAX_INT i)
 
-mkSmallIntegerLit :: DataCon -> Integer -> CoreExpr
-mkSmallIntegerLit small_integer_data_con i = mkConApp small_integer_data_con [mkIntLit i]
+mkSmallIntegerLit :: Id -> Integer -> CoreExpr
+mkSmallIntegerLit small_integer i = mkApps (Var small_integer) [mkIntLit i]
 
 mkStringExpr str = mkStringExprFS (mkFastString str)
 
@@ -913,6 +914,27 @@ mkConsExpr ty hd tl = mkConApp consDataCon [Type ty, hd, tl]
 mkListExpr :: Type -> [CoreExpr] -> CoreExpr
 mkListExpr ty xs = foldr (mkConsExpr ty) (mkNilExpr ty) xs
 
+mkFoldrExpr :: PostTcType -> PostTcType -> CoreExpr -> CoreExpr -> CoreExpr -> DsM CoreExpr
+mkFoldrExpr elt_ty result_ty c n list = do
+    foldr_id <- dsLookupGlobalId foldrName
+    return (Var foldr_id `App` Type elt_ty 
+           `App` Type result_ty
+           `App` c
+           `App` n
+           `App` list)
+
+mkBuildExpr :: Type -> ((Id, Type) -> (Id, Type) -> DsM CoreExpr) -> DsM CoreExpr
+mkBuildExpr elt_ty mk_build_inside = do
+    [n_tyvar] <- newTyVarsDs [alphaTyVar]
+    let n_ty = mkTyVarTy n_tyvar
+        c_ty = mkFunTys [elt_ty, n_ty] n_ty
+    [c, n] <- newSysLocalsDs [c_ty, n_ty]
+    
+    build_inside <- mk_build_inside (c, c_ty) (n, n_ty)
+    
+    build_id <- dsLookupGlobalId buildName
+    return $ Var build_id `App` Type elt_ty `App` mkLams [n_tyvar, c, n] build_inside
+
 mkCoreSel :: [Id]      -- The tuple args
          -> Id         -- The selected one
          -> Id         -- A variable of the same type as the scrutinee