[project @ 1998-07-20 10:00:34 by sof]
authorsof <unknown>
Mon, 20 Jul 1998 10:00:36 +0000 (10:00 +0000)
committersof <unknown>
Mon, 20 Jul 1998 10:00:36 +0000 (10:00 +0000)
non-standard extensions: intToWord and wordToInt coercion functions

ghc/lib/exts/Int.lhs
ghc/lib/exts/Word.lhs

index 88d6b44..138d668 100644 (file)
@@ -31,7 +31,8 @@ module Int
        -- plus Eq, Ord, Num, Bounded, Real, Integral, Ix, Enum, Read,
        --  Show and Bits instances for each of Int8, Int16, Int32 and Int64
 
-       -- The "official" place to get these from is Addr.
+       -- The "official" place to get these from is Addr, importing
+       -- them from Int is a non-standard thing to do.
        , indexInt8OffAddr
        , indexInt16OffAddr
        , indexInt32OffAddr
@@ -51,6 +52,9 @@ module Int
        , sizeofInt16
        , sizeofInt32
        , sizeofInt64
+       
+       -- non-standard, GHC specific
+       , intToWord
 
        ) where
 
@@ -88,6 +92,10 @@ int16ToInt8  (I16# x) = I8#  x
 int16ToInt32 (I16# x) = I32# x
 int32ToInt8  (I32# x) = I8#  x
 int32ToInt16 (I32# x) = I16# x
+
+--GHC specific
+intToWord :: Int -> Word
+intToWord (I# i#) = W# (int2Word# i#)
 \end{code}
 
 \subsection[Int8]{The @Int8@ interface}
index 5a06a81..75a4749 100644 (file)
@@ -66,6 +66,9 @@ module Word
        , sizeofWord32
        , sizeofWord64
 
+       -- non-standard, GHC specific
+       , wordToInt
+
        ) where
 
 import GlaExts
@@ -97,6 +100,9 @@ intToWord32 (I# x)   = W32# ((int2Word# x) `and#` (case (maxBound::Word32) of W3
 --intToWord32 (I# x)   = W32# (int2Word# x)
 word32ToInt (W32# x) = I#   (word2Int# x)
 
+wordToInt :: Word -> Int
+wordToInt (W# w#) = I# (word2Int# w#)
+
 \end{code}
 
 \subsection[Word8]{The @Word8@ interface}