X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=compiler%2FdeSugar%2FDsUtils.lhs;h=ef16317f9532e5ff87d7624dd86f51afda3abb8a;hb=dafaa80f1f849ba18bb2852914b74f86c0331bba;hp=f63b8842d69f5b5de5836e48f15c7fe7abb8cd0c;hpb=591c501950c7d6f884bb4531f66b666bab5b4928;p=ghc-hetmet.git diff --git a/compiler/deSugar/DsUtils.lhs b/compiler/deSugar/DsUtils.lhs index f63b884..ef16317f 100644 --- a/compiler/deSugar/DsUtils.lhs +++ b/compiler/deSugar/DsUtils.lhs @@ -27,6 +27,7 @@ module DsUtils ( mkErrorAppDs, mkNilExpr, mkConsExpr, mkListExpr, mkIntExpr, mkCharExpr, mkStringExpr, mkStringExprFS, mkIntegerExpr, + mkBuildExpr, mkFoldrExpr, seqVar, @@ -116,7 +117,7 @@ lookupEvidence :: [(Name, Id)] -> Name -> Id lookupEvidence prs std_name = assocDefault (mk_panic std_name) prs std_name where - mk_panic std_name = pprPanic "dsSyntaxTable" (ptext SLIT("Not found:") <+> ppr std_name) + mk_panic std_name = pprPanic "dsSyntaxTable" (ptext (sLit "Not found:") <+> ppr std_name) \end{code} @@ -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) @@ -871,7 +872,7 @@ mkTupleCase uniqs vars body scrut_var scrut one_tuple_case chunk_vars (us, vs, body) = let (us1, us2) = splitUniqSupply us - scrut_var = mkSysLocal FSLIT("ds") (uniqFromSupply us1) + scrut_var = mkSysLocal (fsLit "ds") (uniqFromSupply us1) (mkCoreTupTy (map idType chunk_vars)) body' = mkSmallTupleCase chunk_vars body scrut_var (Var scrut_var) in (us2, scrut_var:vs, body') @@ -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 @@ -1037,7 +1059,7 @@ mkTickBox ix vars e = do mkBinaryTickBox :: Int -> Int -> CoreExpr -> DsM CoreExpr mkBinaryTickBox ixT ixF e = do uq <- newUnique - let bndr1 = mkSysLocal FSLIT("t1") uq boolTy + let bndr1 = mkSysLocal (fsLit "t1") uq boolTy falseBox <- mkTickBox ixF [] $ Var falseDataConId trueBox <- mkTickBox ixT [] $ Var trueDataConId return $ Case e bndr1 boolTy