From 9a492e410e18f9ca4ea1222ee960345332771d4d Mon Sep 17 00:00:00 2001 From: sof Date: Mon, 25 Jan 1999 13:58:56 +0000 Subject: [PATCH] [project @ 1999-01-25 13:58:55 by sof] Added --> {Int,Word}# coercion functions to export list. For internal use only --- ghc/lib/exts/Int.lhs | 74 ++++++++++++++++++++++++++++--------------------- ghc/lib/exts/Word.lhs | 28 +++++++++++++++---- 2 files changed, 65 insertions(+), 37 deletions(-) diff --git a/ghc/lib/exts/Int.lhs b/ghc/lib/exts/Int.lhs index 41a366f..55b5145 100644 --- a/ghc/lib/exts/Int.lhs +++ b/ghc/lib/exts/Int.lhs @@ -98,16 +98,21 @@ module Int -- non-standard, GHC specific , intToWord + -- Internal, do not use. + , int8ToInt# + , int16ToInt# + , int32ToInt# + ) where #ifdef __HUGS__ import PreludeBuiltin #else -import GlaExts -import PrelGHC +import PrelBase import CCall import PrelForeign -import PrelAddr ( Int64(..), Word64(..) ) +import PrelIOBase +import PrelAddr ( Int64(..), Word64(..), Addr(..), Word(..) ) #endif import Ix import Bits @@ -123,6 +128,10 @@ int8ToInt :: Int8 -> Int int16ToInt :: Int16 -> Int int32ToInt :: Int32 -> Int +int8ToInt# :: Int8 -> Int# +int16ToInt# :: Int16 -> Int# +int32ToInt# :: Int32 -> Int# + intToInt8 :: Int -> Int8 intToInt16 :: Int -> Int16 intToInt32 :: Int -> Int32 @@ -159,10 +168,11 @@ data Int8 = I8# Int# instance CCallable Int8 instance CReturnable Int8 -int8ToInt (I8# x) = I# (int8ToInt# x) +int8ToInt (I8# x) = I# (i8ToInt# x) +int8ToInt# (I8# x) = i8ToInt# x -int8ToInt# :: Int# -> Int# -int8ToInt# x = if x' <=# 0x7f# then x' else x' -# 0x100# +i8ToInt# :: Int# -> Int# +i8ToInt# x = if x' <=# 0x7f# then x' else x' -# 0x100# where x' = word2Int# (int2Word# x `and#` int2Word# 0xff#) -- @@ -180,7 +190,7 @@ instance Eq Int8 where (I8# x#) /= (I8# y#) = x# /=# y# instance Ord Int8 where - compare (I8# x#) (I8# y#) = compareInt# (int8ToInt# x#) (int8ToInt# y#) + compare (I8# x#) (I8# y#) = compareInt# (i8ToInt# x#) (i8ToInt# y#) compareInt# :: Int# -> Int# -> Ordering compareInt# x# y# @@ -232,8 +242,8 @@ instance Integral Int8 where toInt i8 = int8ToInt i8 remInt8, quotInt8 :: Int8 -> Int8 -> Int8 -remInt8 (I8# x) (I8# y) = I8# (intToInt8# ((int8ToInt# x) `remInt#` (int8ToInt# y))) -quotInt8 (I8# x) (I8# y) = I8# (intToInt8# ((int8ToInt# x) `quotInt#` (int8ToInt# y))) +remInt8 (I8# x) (I8# y) = I8# (intToInt8# ((i8ToInt# x) `remInt#` (i8ToInt# y))) +quotInt8 (I8# x) (I8# y) = I8# (intToInt8# ((i8ToInt# x) `quotInt#` (i8ToInt# y))) instance Ix Int8 where range (m,n) = [m..n] @@ -280,13 +290,13 @@ instance Bits Int8 where (I8# x) `xor` (I8# y) = I8# (word2Int# ((int2Word# x) `xor#` (int2Word# y))) complement (I8# x) = I8# (word2Int# ((int2Word# x) `xor#` (int2Word# 0xff#))) shift (I8# x) i@(I# i#) - | i > 0 = I8# (intToInt8# (iShiftL# (int8ToInt# x) i#)) - | otherwise = I8# (intToInt8# (iShiftRA# (int8ToInt# x) (negateInt# i#))) + | i > 0 = I8# (intToInt8# (iShiftL# (i8ToInt# x) i#)) + | otherwise = I8# (intToInt8# (iShiftRA# (i8ToInt# x) (negateInt# i#))) i8@(I8# x) `rotate` (I# i) | i ==# 0# = i8 | i ># 0# = I8# (intToInt8# ( word2Int# ( - (int2Word# (iShiftL# (int8ToInt# x) i')) + (int2Word# (iShiftL# (i8ToInt# x) i')) `or#` (int2Word# (iShiftRA# (word2Int# ( (int2Word# x) `and#` @@ -321,10 +331,11 @@ data Int16 = I16# Int# instance CCallable Int16 instance CReturnable Int16 -int16ToInt (I16# x) = I# (int16ToInt# x) +int16ToInt (I16# x) = I# (i16ToInt# x) +int16ToInt# (I16# x) = i16ToInt# x -int16ToInt# :: Int# -> Int# -int16ToInt# x = if x' <=# 0x7fff# then x' else x' -# 0x10000# +i16ToInt# :: Int# -> Int# +i16ToInt# x = if x' <=# 0x7fff# then x' else x' -# 0x10000# where x' = word2Int# (int2Word# x `and#` int2Word# 0xffff#) intToInt16 (I# x) = I16# (intToInt16# x) @@ -337,7 +348,7 @@ instance Eq Int16 where (I16# x#) /= (I16# y#) = x# /=# y# instance Ord Int16 where - compare (I16# x#) (I16# y#) = compareInt# (int16ToInt# x#) (int16ToInt# y#) + compare (I16# x#) (I16# y#) = compareInt# (i16ToInt# x#) (i16ToInt# y#) instance Num Int16 where (I16# x#) + (I16# y#) = I16# (intToInt16# (x# +# y#)) @@ -382,8 +393,8 @@ instance Integral Int16 where toInt i16 = int16ToInt i16 remInt16, quotInt16 :: Int16 -> Int16 -> Int16 -remInt16 (I16# x) (I16# y) = I16# (intToInt16# ((int16ToInt# x) `remInt#` (int16ToInt# y))) -quotInt16 (I16# x) (I16# y) = I16# (intToInt16# ((int16ToInt# x) `quotInt#` (int16ToInt# y))) +remInt16 (I16# x) (I16# y) = I16# (intToInt16# ((i16ToInt# x) `remInt#` (i16ToInt# y))) +quotInt16 (I16# x) (I16# y) = I16# (intToInt16# ((i16ToInt# x) `quotInt#` (i16ToInt# y))) instance Ix Int16 where range (m,n) = [m..n] @@ -430,13 +441,13 @@ instance Bits Int16 where (I16# x) `xor` (I16# y) = I16# (word2Int# ((int2Word# x) `xor#` (int2Word# y))) complement (I16# x) = I16# (word2Int# ((int2Word# x) `xor#` (int2Word# 0xffff#))) shift (I16# x) i@(I# i#) - | i > 0 = I16# (intToInt16# (iShiftL# (int16ToInt# x) i#)) - | otherwise = I16# (intToInt16# (iShiftRA# (int16ToInt# x) (negateInt# i#))) + | i > 0 = I16# (intToInt16# (iShiftL# (i16ToInt# x) i#)) + | otherwise = I16# (intToInt16# (iShiftRA# (i16ToInt# x) (negateInt# i#))) i16@(I16# x) `rotate` (I# i) | i ==# 0# = i16 | i ># 0# = I16# (intToInt16# (word2Int# ( - (int2Word# (iShiftL# (int16ToInt# x) i')) + (int2Word# (iShiftL# (i16ToInt# x) i')) `or#` (int2Word# (iShiftRA# ( word2Int# ( (int2Word# x) `and#` (int2Word# (0x100# -# pow2# i2)))) @@ -468,14 +479,15 @@ data Int32 = I32# Int# instance CCallable Int32 instance CReturnable Int32 -int32ToInt (I32# x) = I# (int32ToInt# x) +int32ToInt (I32# x) = I# (i32ToInt# x) +int32ToInt# (I32# x) = i32ToInt# x -int32ToInt# :: Int# -> Int# +i32ToInt# :: Int# -> Int# #if WORD_SIZE_IN_BYTES > 4 -int32ToInt# x = if x' <=# 0x7fffffff# then x' else x' -# 0x100000000# +i32ToInt# x = if x' <=# 0x7fffffff# then x' else x' -# 0x100000000# where x' = word2Int# (int2Word# x `and#` int2Word# 0xffffffff#) #else -int32ToInt# x = x +i32ToInt# x = x #endif intToInt32 (I# x) = I32# (intToInt32# x) @@ -491,7 +503,7 @@ instance Eq Int32 where (I32# x#) /= (I32# y#) = x# /=# y# instance Ord Int32 where - compare (I32# x#) (I32# y#) = compareInt# (int32ToInt# x#) (int32ToInt# y#) + compare (I32# x#) (I32# y#) = compareInt# (i32ToInt# x#) (i32ToInt# y#) instance Num Int32 where (I32# x#) + (I32# y#) = I32# (intToInt32# (x# +# y#)) @@ -539,8 +551,8 @@ instance Integral Int32 where toInt i32 = int32ToInt i32 remInt32, quotInt32 :: Int32 -> Int32 -> Int32 -remInt32 (I32# x) (I32# y) = I32# (intToInt32# ((int32ToInt# x) `remInt#` (int32ToInt# y))) -quotInt32 (I32# x) (I32# y) = I32# (intToInt32# ((int32ToInt# x) `quotInt#` (int32ToInt# y))) +remInt32 (I32# x) (I32# y) = I32# (intToInt32# ((i32ToInt# x) `remInt#` (i32ToInt# y))) +quotInt32 (I32# x) (I32# y) = I32# (intToInt32# ((i32ToInt# x) `quotInt#` (i32ToInt# y))) instance Ix Int32 where range (m,n) = [m..n] @@ -591,14 +603,14 @@ instance Bits Int32 where complement (I32# x) = I32# (word2Int# ((int2Word# x) `xor#` (int2Word# (negateInt# 1#)))) #endif shift (I32# x) i@(I# i#) - | i > 0 = I32# (intToInt32# (iShiftL# (int32ToInt# x) i#)) - | otherwise = I32# (intToInt32# (iShiftRA# (int32ToInt# x) (negateInt# i#))) + | i > 0 = I32# (intToInt32# (iShiftL# (i32ToInt# x) i#)) + | otherwise = I32# (intToInt32# (iShiftRA# (i32ToInt# x) (negateInt# i#))) i32@(I32# x) `rotate` (I# i) | i ==# 0# = i32 | i ># 0# = -- ( (x<>i2) I32# (intToInt32# ( word2Int# ( - (int2Word# (iShiftL# (int32ToInt# x) i')) + (int2Word# (iShiftL# (i32ToInt# x) i')) `or#` (int2Word# (iShiftRA# (word2Int# ( (int2Word# x) diff --git a/ghc/lib/exts/Word.lhs b/ghc/lib/exts/Word.lhs index 1e68948..2b3c347 100644 --- a/ghc/lib/exts/Word.lhs +++ b/ghc/lib/exts/Word.lhs @@ -108,12 +108,17 @@ module Word -- non-standard, GHC specific , wordToInt + -- Internal, do not use. + , word8ToWord# + , word16ToWord# + , word32ToWord# + ) where #ifdef __HUGS__ import PreludeBuiltin #else -import GlaExts +import PrelBase import CCall import PrelForeign import PrelIOBase @@ -1193,19 +1198,30 @@ the GHC specific Word type: \begin{code} wordToWord8 :: Word -> Word8 -word8ToWord :: Word8 -> Word wordToWord16 :: Word -> Word16 -word16ToWord :: Word16 -> Word wordToWord32 :: Word -> Word32 + +word8ToWord :: Word8 -> Word +word16ToWord :: Word16 -> Word word32ToWord :: Word32 -> Word -word8ToWord (W8# w#) = W# w# +word8ToWord# :: Word8 -> Word# +word16ToWord# :: Word16 -> Word# +word32ToWord# :: Word32 -> Word# + +word8ToWord (W8# w#) = W# w# +word8ToWord# (W8# w#) = w# + wordToWord8 (W# w#) = W8# (w# `and#` (case (maxBound::Word8) of W8# x# -> x#)) -word16ToWord (W16# w#) = W# w# +word16ToWord (W16# w#) = W# w# +word16ToWord# (W16# w#) = w# + wordToWord16 (W# w#) = W16# (w# `and#` (case (maxBound::Word16) of W16# x# -> x#)) -word32ToWord (W32# w#) = W# w# wordToWord32 (W# w#) = W32# (w# `and#` (case (maxBound::Word32) of W32# x# -> x#)) +word32ToWord (W32# w#) = W# w# +word32ToWord# (W32# w#) = w# + wordToWord64 :: Word -> Word64 wordToWord64 (W# w#) = W64# (wordToWord64# w#) -- 1.7.10.4