X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=ghc%2Fcompiler%2Futils%2FUtil.lhs;h=c6e92c0740d97d4cc3e861f7c4b404e5d222cd8c;hb=ca5a4a480d10d61e5b7a52eb4d556e8b8c33e69d;hp=68fdb493fb0e7b9e1878c7fe135b693ad2c0f073;hpb=7d61cb61daa5e433a0cb85b34b7f0c58b2f961ff;p=ghc-hetmet.git diff --git a/ghc/compiler/utils/Util.lhs b/ghc/compiler/utils/Util.lhs index 68fdb49..c6e92c0 100644 --- a/ghc/compiler/utils/Util.lhs +++ b/ghc/compiler/utils/Util.lhs @@ -39,7 +39,9 @@ module Util ( IF_NOT_GHC(forall COMMA exists COMMA) zipEqual, zipWithEqual, zipWith3Equal, zipWith4Equal, zipLazy, + mapAndUnzip, nOfThem, lengthExceeds, isSingleton, + startsWith, endsWith, #if defined(COMPILING_GHC) isIn, isn'tIn, #endif @@ -78,9 +80,7 @@ module Util ( -- error handling #if defined(COMPILING_GHC) , panic, panic#, pprPanic, pprPanic#, pprError, pprTrace -# ifdef DEBUG , assertPanic -# endif #endif {- COMPILING_GHC -} -- and to make the interface self-sufficient... @@ -184,6 +184,18 @@ zipLazy (x:xs) ~(y:ys) = (x,y) : zipLazy xs ys \end{code} \begin{code} +mapAndUnzip :: (a -> (b, c)) -> [a] -> ([b], [c]) + +mapAndUnzip f [] = ([],[]) +mapAndUnzip f (x:xs) + = let + (r1, r2) = f x + (rs1, rs2) = mapAndUnzip f xs + in + (r1:rs1, r2:rs2) +\end{code} + +\begin{code} nOfThem :: Int -> a -> [a] nOfThem n thing = take n (repeat thing) @@ -196,6 +208,17 @@ isSingleton :: [a] -> Bool isSingleton [x] = True isSingleton _ = False + +startsWith, endsWith :: String -> String -> Maybe String + +startsWith [] str = Just str +startsWith (c:cs) (s:ss) + = if c /= s then Nothing else startsWith cs ss + +endsWith cs ss + = case (startsWith (reverse cs) (reverse ss)) of + Nothing -> Nothing + Just rs -> Just (reverse rs) \end{code} Debugging/specialising versions of \tr{elem} and \tr{notElem} @@ -233,27 +256,6 @@ isn'tIn msg x ys # endif {- DEBUG -} -# ifdef USE_ATTACK_PRAGMAS -{-# SPECIALIZE isIn :: String -> Literal -> [Literal] -> Bool #-} -{-# SPECIALIZE isIn :: String -> Class -> [Class] -> Bool #-} -{-# SPECIALIZE isIn :: String -> Id -> [Id] -> Bool #-} -{-# SPECIALIZE isIn :: String -> Int -> [Int] -> Bool #-} -{-# SPECIALIZE isIn :: String -> MagicId -> [MagicId] -> Bool #-} -{-# SPECIALIZE isIn :: String -> Name -> [Name] -> Bool #-} -{-# SPECIALIZE isIn :: String -> TyCon -> [TyCon] -> Bool #-} -{-# SPECIALIZE isIn :: String -> TyVar -> [TyVar] -> Bool #-} -{-# SPECIALIZE isIn :: String -> TyVarTemplate -> [TyVarTemplate] -> Bool #-} -{-# SPECIALIZE isIn :: String -> Unique -> [Unique] -> Bool #-} -{-# SPECIALIZE isIn :: String -> _PackedString -> [_PackedString] -> Bool #-} -{-# SPECIALIZE isn'tIn :: String -> (Id, Id) -> [(Id, Id)] -> Bool #-} -{-# SPECIALIZE isn'tIn :: String -> Int -> [Int] -> Bool #-} -{-# SPECIALIZE isn'tIn :: String -> Id -> [Id] -> Bool #-} -{-# SPECIALIZE isn'tIn :: String -> MagicId -> [MagicId] -> Bool #-} -{-# SPECIALIZE isn'tIn :: String -> TyCon -> [TyCon] -> Bool #-} -{-# SPECIALIZE isn'tIn :: String -> TyVar -> [TyVar] -> Bool #-} -{-# SPECIALIZE isn'tIn :: String -> TyVarTemplate -> [TyVarTemplate] -> Bool #-} -# endif - #endif {- COMPILING_GHC -} \end{code} @@ -273,21 +275,6 @@ assoc crash_msg lst key then panic ("Failed in assoc: " ++ crash_msg) else head res where res = [ val | (key', val) <- lst, key == key'] - -#if defined(COMPILING_GHC) -# ifdef USE_ATTACK_PRAGMAS -{-# SPECIALIZE assoc :: String -> [(Id, a)] -> Id -> a #-} -{-# SPECIALIZE assoc :: String -> [(Class, a)] -> Class -> a #-} -{-# SPECIALIZE assoc :: String -> [(Name, a)] -> Name -> a #-} -{-# SPECIALIZE assoc :: String -> [(PrimRep, a)] -> PrimRep -> a #-} -{-# SPECIALIZE assoc :: String -> [(String, a)] -> String -> a #-} -{-# SPECIALIZE assoc :: String -> [(TyCon, a)] -> TyCon -> a #-} -{-# SPECIALIZE assoc :: String -> [(TyVar, a)] -> TyVar -> a #-} -{-# SPECIALIZE assoc :: String -> [(TyVarTemplate, a)] -> TyVarTemplate -> a #-} -{-# SPECIALIZE assoc :: String -> [(Type, a)] -> Type -> a #-} -{-# SPECIALIZE assoc :: String -> [(_PackedString, a)] -> _PackedString -> a #-} -# endif -#endif \end{code} %************************************************************************ @@ -312,11 +299,6 @@ hasNoDups xs = f [] xs #else is_elem = elem #endif -#if defined(COMPILING_GHC) -# ifdef USE_ATTACK_PRAGMAS -{-# SPECIALIZE hasNoDups :: [TyVar] -> Bool #-} -# endif -#endif \end{code} \begin{code} @@ -819,9 +801,8 @@ panic# s = case (panic s) of () -> EQ_ pprPanic# heading pretty_msg = panic# (heading++(ppShow 80 pretty_msg)) -# ifdef DEBUG assertPanic :: String -> Int -> a assertPanic file line = panic ("ASSERT failed! file "++file++", line "++show line) -# endif + #endif {- COMPILING_GHC -} \end{code}