X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=ghc%2Flib%2Fstd%2FPrelWord.lhs;h=0a8bc1dfa6fa36f9bff5c8f6b3d8b3d294b74ab3;hb=d9af408e5c512501cfa991f5e4a76c9154bca917;hp=0d720dd9cd0975b987a240971ebda3111f7bd5e6;hpb=871db587eda4fcba3fdc049b225a1d63a4ebe641;p=ghc-hetmet.git diff --git a/ghc/lib/std/PrelWord.lhs b/ghc/lib/std/PrelWord.lhs index 0d720dd..0a8bc1d 100644 --- a/ghc/lib/std/PrelWord.lhs +++ b/ghc/lib/std/PrelWord.lhs @@ -4,7 +4,7 @@ \section[PrelWord]{Module @PrelWord@} \begin{code} -{-# OPTIONS -monly-3-regs #-} +{-# OPTIONS -fno-implicit-prelude #-} #include "MachDeps.h" @@ -20,6 +20,7 @@ import PrelReal import PrelRead import PrelArr import PrelBits +import PrelShow ------------------------------------------------------------------------ -- Helper functions @@ -100,6 +101,8 @@ instance Enum Word where | otherwise = fromEnumError "Word" x enumFrom = integralEnumFrom enumFromThen = integralEnumFromThen + enumFromTo = integralEnumFromTo + enumFromThenTo = integralEnumFromThenTo instance Integral Word where quot x@(W# x#) y@(W# y#) @@ -168,7 +171,7 @@ instance Bits Word where "fromIntegral/Int->Word" fromIntegral = \(I# x#) -> W# (int2Word# x#) "fromIntegral/Word->Int" fromIntegral = \(W# x#) -> I# (word2Int# x#) "fromIntegral/Word->Word" fromIntegral = id :: Word -> Word - #-} + #-} ------------------------------------------------------------------------ -- type Word8 @@ -265,9 +268,11 @@ instance Bits Word8 where isSigned _ = False {-# RULES -"fromIntegral/a->Word8" fromIntegral = \x -> case fromIntegral x of W# x# -> W8# (wordToWord8# x#) -"fromIntegral/Word8->a" fromIntegral = \(W8# x#) -> fromIntegral (W# x#) - #-} +"fromIntegral/Word8->Word8" fromIntegral = id :: Word8 -> Word8 +"fromIntegral/Word8->Integer" fromIntegral = toInteger :: Word8 -> Integer +"fromIntegral/a->Word8" fromIntegral = \x -> case fromIntegral x of W# x# -> W8# (wordToWord8# x#) +"fromIntegral/Word8->a" fromIntegral = \(W8# x#) -> fromIntegral (W# x#) + #-} ------------------------------------------------------------------------ -- type Word16 @@ -364,9 +369,12 @@ instance Bits Word16 where isSigned _ = False {-# RULES -"fromIntegral/a->Word16" fromIntegral = \x -> case fromIntegral x of W# x# -> W16# (wordToWord16# x#) -"fromIntegral/Word16->a" fromIntegral = \(W16# x#) -> fromIntegral (W# x#) - #-} +"fromIntegral/Word8->Word16" fromIntegral = \(W8# x#) -> W16# x# +"fromIntegral/Word16->Word16" fromIntegral = id :: Word16 -> Word16 +"fromIntegral/Word16->Integer" fromIntegral = toInteger :: Word16 -> Integer +"fromIntegral/a->Word16" fromIntegral = \x -> case fromIntegral x of W# x# -> W16# (wordToWord16# x#) +"fromIntegral/Word16->a" fromIntegral = \(W16# x#) -> fromIntegral (W# x#) + #-} ------------------------------------------------------------------------ -- type Word32 @@ -380,10 +388,6 @@ instance Bits Word16 where data Word32 = W32# Word# deriving (Eq, Ord) -#if WORD_SIZE_IN_BYTES == 4 -{-# RULES "wordToWord32#" forall x#. wordToWord32# x# = x# #-} -#endif - instance CCallable Word32 instance CReturnable Word32 @@ -423,14 +427,16 @@ instance Enum Word32 where = W32# (int2Word# i#) | otherwise = toEnumError "Word32" i (minBound::Word32, maxBound::Word32) #if WORD_SIZE_IN_BYTES == 4 - fromEnum (W32# x#) = I# (word2Int# x#) - enumFrom = integralEnumFrom - enumFromThen = integralEnumFromThen -#else fromEnum x@(W32# x#) | x <= fromIntegral (maxBound::Int) = I# (word2Int# x#) | otherwise = fromEnumError "Word32" x + enumFrom = integralEnumFrom + enumFromThen = integralEnumFromThen + enumFromTo = integralEnumFromTo + enumFromThenTo = integralEnumFromThenTo +#else + fromEnum (W32# x#) = I# (word2Int# x#) enumFrom = boundedEnumFrom enumFromThen = boundedEnumFromThen #endif @@ -498,9 +504,13 @@ instance Bits Word32 where isSigned _ = False {-# RULES -"fromIntegral/a->Word32" fromIntegral = \x -> case fromIntegral x of W# x# -> W32# (wordToWord32# x#) -"fromIntegral/Word32->a" fromIntegral = \(W32# x#) -> fromIntegral (W# x#) - #-} +"fromIntegral/Word8->Word32" fromIntegral = \(W8# x#) -> W32# x# +"fromIntegral/Word16->Word32" fromIntegral = \(W16# x#) -> W32# x# +"fromIntegral/Word32->Word32" fromIntegral = id :: Word32 -> Word32 +"fromIntegral/Word32->Integer" fromIntegral = toInteger :: Word32 -> Integer +"fromIntegral/a->Word32" fromIntegral = \x -> case fromIntegral x of W# x# -> W32# (wordToWord32# x#) +"fromIntegral/Word32->a" fromIntegral = \(W32# x#) -> fromIntegral (W# x#) + #-} ------------------------------------------------------------------------ -- type Word64 @@ -547,6 +557,8 @@ instance Enum Word64 where | otherwise = fromEnumError "Word64" x enumFrom = integralEnumFrom enumFromThen = integralEnumFromThen + enumFromTo = integralEnumFromTo + enumFromThenTo = integralEnumFromThenTo instance Integral Word64 where quot x@(W64# x#) y@(W64# y#) @@ -616,11 +628,11 @@ foreign import "stg_shiftRL64" unsafe shiftRL64# :: Word64# -> Int# -> W "fromIntegral/Word64->Int" fromIntegral = \(W64# x#) -> I# (word2Int# (word64ToWord# x#)) "fromIntegral/Word64->Word" fromIntegral = \(W64# x#) -> W# (word64ToWord# x#) "fromIntegral/Word64->Word64" fromIntegral = id :: Word64 -> Word64 - #-} + #-} #else -data Word32 = W64# Word# deriving (Eq, Ord) +data Word64 = W64# Word# deriving (Eq, Ord) instance Num Word64 where (W64# x#) + (W64# y#) = W64# (x# `plusWord#` y#) @@ -649,6 +661,8 @@ instance Enum Word64 where | otherwise = fromEnumError "Word64" x enumFrom = integralEnumFrom enumFromThen = integralEnumFromThen + enumFromTo = integralEnumFromTo + enumFromThenTo = integralEnumFromThenTo instance Integral Word64 where quot x@(W64# x#) y@(W64# y#) @@ -693,7 +707,7 @@ instance Bits Word64 where {-# RULES "fromIntegral/a->Word64" fromIntegral = \x -> case fromIntegral x of W# x# -> W64# x# "fromIntegral/Word64->a" fromIntegral = \(W64# x#) -> fromIntegral (W# x#) - #-} + #-} #endif