diff options
| author | simonm <unknown> | 1998-02-02 17:35:59 +0000 |
|---|---|---|
| committer | simonm <unknown> | 1998-02-02 17:35:59 +0000 |
| commit | 28139aea50376444d56f43f0914291348a51a7e7 (patch) | |
| tree | 595c378188638ef16462972c1e7fcdb8409c7f16 /ghc/lib/glaExts | |
| parent | 98a1ebecb6d22d793b1d9f8e1d24ecbb5a2d130f (diff) | |
| download | haskell-28139aea50376444d56f43f0914291348a51a7e7.tar.gz | |
[project @ 1998-02-02 17:27:26 by simonm]
Library re-organisation:
All libraries now live under ghc/lib, which has the following structure:
ghc/lib/std -- all prelude files (libHS.a)
ghc/lib/std/cbits
ghc/lib/exts -- standard Hugs/GHC extensions (libHSexts.a)
-- available with '-fglasgow-exts'
ghc/lib/posix -- POSIX library (libHSposix.a)
ghc/lib/posix/cbits -- available with '-syslib posix'
ghc/lib/misc -- used to be hslibs/ghc (libHSmisc.a)
ghc/lib/misc/cbits -- available with '-syslib misc'
ghc/lib/concurrent -- Concurrent libraries (libHSconc.a)
-- available with '-concurrent'
Also, several non-standard prelude modules had their names changed to begin
with 'Prel' to reduce namespace pollution.
Addr ==> PrelAddr (Addr interface available in 'exts')
ArrBase ==> PrelArr
CCall ==> PrelCCall (CCall interface available in 'exts')
ConcBase ==> PrelConc
GHCerr ==> PrelErr
Foreign ==> PrelForeign (Foreign interface available in 'exts')
GHC ==> PrelGHC
IOHandle ==> PrelHandle
IOBase ==> PrelIOBase
GHCmain ==> PrelMain
STBase ==> PrelST
Unsafe ==> PrelUnsafe
UnsafeST ==> PrelUnsafeST
Diffstat (limited to 'ghc/lib/glaExts')
| -rw-r--r-- | ghc/lib/glaExts/Addr.lhs | 84 | ||||
| -rw-r--r-- | ghc/lib/glaExts/Bits.lhs | 41 | ||||
| -rw-r--r-- | ghc/lib/glaExts/ByteArray.lhs | 40 | ||||
| -rw-r--r-- | ghc/lib/glaExts/CCall.lhs | 53 | ||||
| -rw-r--r-- | ghc/lib/glaExts/Foreign.lhs | 162 | ||||
| -rw-r--r-- | ghc/lib/glaExts/GlaExts.lhs | 97 | ||||
| -rw-r--r-- | ghc/lib/glaExts/IOExts.lhs | 86 | ||||
| -rw-r--r-- | ghc/lib/glaExts/Int.lhs | 499 | ||||
| -rw-r--r-- | ghc/lib/glaExts/LazyST.lhs | 122 | ||||
| -rw-r--r-- | ghc/lib/glaExts/MutableArray.lhs | 62 | ||||
| -rw-r--r-- | ghc/lib/glaExts/NumExts.lhs | 55 | ||||
| -rw-r--r-- | ghc/lib/glaExts/ST.lhs | 94 | ||||
| -rw-r--r-- | ghc/lib/glaExts/Word.lhs | 535 |
13 files changed, 0 insertions, 1930 deletions
diff --git a/ghc/lib/glaExts/Addr.lhs b/ghc/lib/glaExts/Addr.lhs deleted file mode 100644 index c592d50a9f..0000000000 --- a/ghc/lib/glaExts/Addr.lhs +++ /dev/null @@ -1,84 +0,0 @@ -% -% (c) The AQUA Project, Glasgow University, 1994-1996 -% - -\section[Addr]{Module @Addr@} - -\begin{code} -{-# OPTIONS -fno-implicit-prelude #-} - -module Addr ( - Addr(..), - nullAddr, -- :: Addr - plusAddr, -- :: Addr -> Int -> Addr - ) where - -import GHC -import PrelBase -import STBase -import CCall -\end{code} - -\begin{code} -data Addr = A# Addr# deriving (Eq, Ord) - -instance Show Addr where - showsPrec p (A# a) = showsPrec p (I# (addr2Int# a)) - -nullAddr = ``NULL'' :: Addr - -plusAddr :: Addr -> Int -> Addr -plusAddr (A# addr) (I# off) = A# (int2Addr# (addr2Int# addr +# off)) - -instance CCallable Addr -instance CCallable Addr# -instance CReturnable Addr -\end{code} - -ToDo: - --- read value out of _immutable_ memory - indexCharOffAddr :: Addr -> Int -> Char - indexIntOffAddr :: Addr -> Int -> Int -- should we drop this? - indexAddrOffAddr :: Addr -> Int -> Addr - indexFloatOffAddr :: Addr -> Int -> Float - indexDoubleOffAddr :: Addr -> Int -> Double - indexWord8OffAddr :: Addr -> Int -> Word8 - indexWord16OffAddr :: Addr -> Int -> Word16 - indexWord32OffAddr :: Addr -> Int -> Word32 - indexWord64OffAddr :: Addr -> Int -> Word64 - indexInt8OffAddr :: Addr -> Int -> Int8 - indexInt16OffAddr :: Addr -> Int -> Int16 - indexInt32OffAddr :: Addr -> Int -> Int32 - indexInt64OffAddr :: Addr -> Int -> Int64 - - -- read value out of mutable memory - readCharOffAddr :: Addr -> Int -> IO Char - readIntOffAddr :: Addr -> Int -> IO Int -- should we drop this? - readAddrOffAddr :: Addr -> Int -> IO Addr - readFloatOffAddr :: Addr -> Int -> IO Float - readDoubleOffAddr :: Addr -> Int -> IO Double - readWord8OffAddr :: Addr -> Int -> IO Word8 - readWord16OffAddr :: Addr -> Int -> IO Word16 - readWord32OffAddr :: Addr -> Int -> IO Word32 - readWord64OffAddr :: Addr -> Int -> IO Word64 - readInt8OffAddr :: Addr -> Int -> IO Int8 - readInt16OffAddr :: Addr -> Int -> IO Int16 - readInt32OffAddr :: Addr -> Int -> IO Int32 - readInt64OffAddr :: Addr -> Int -> IO Int64 - - -- write value into mutable memory - writeCharOffAddr :: Addr -> Int -> Char -> IO () - writeIntOffAddr :: Addr -> Int -> Int -> IO () -- should we drop this? - writeAddrOffAddr :: Addr -> Int -> Addr -> IO () - writeFloatOffAddr :: Addr -> Int -> Float -> IO () - writeDoubleOffAddr :: Addr -> Int -> Double -> IO () - writeWord8OffAddr :: Addr -> Int -> Word8 -> IO () - writeWord16OffAddr :: Addr -> Int -> Word16 -> IO () - writeWord32OffAddr :: Addr -> Int -> Word32 -> IO () - writeWord64OffAddr :: Addr -> Int -> Word64 -> IO () - writeInt8OffAddr :: Addr -> Int -> Int8 -> IO () - writeInt16OffAddr :: Addr -> Int -> Int16 -> IO () - writeInt32OffAddr :: Addr -> Int -> Int32 -> IO () - writeInt64OffAddr :: Addr -> Int -> Int64 -> IO () - diff --git a/ghc/lib/glaExts/Bits.lhs b/ghc/lib/glaExts/Bits.lhs deleted file mode 100644 index f47aa8fe0c..0000000000 --- a/ghc/lib/glaExts/Bits.lhs +++ /dev/null @@ -1,41 +0,0 @@ -% -% (c) The GRASP/AQUA Project, Glasgow University, 1998 -% -\section[Bits]{The @Bits@ interface} - -Defines the @Bits@ class containing bit-based operations. -See library document for details on the semantics of the -individual operations. - -\begin{code} -{-# OPTIONS -fno-implicit-prelude #-} - -module Bits where - -import PrelBase - -infixl 8 `shift`, `rotate` -infixl 7 .&. -infixl 6 `xor` -infixl 5 .|. - -class Bits a where - (.&.), (.|.), xor :: a -> a -> a - complement :: a -> a - shift :: a -> Int -> a - rotate :: a -> Int -> a - bit :: Int -> a - setBit :: a -> Int -> a - clearBit :: a -> Int -> a - complementBit :: a -> Int -> a - testBit :: a -> Int -> Bool - bitSize :: a -> Int - isSigned :: a -> Bool - -shiftL, shiftR :: Bits a => a -> Int -> a -rotateL, rotateR :: Bits a => a -> Int -> a -shiftL a i = shift a i -shiftR a i = shift a (-i) -rotateL a i = rotate a i -rotateR a i = rotate a (-i) -\end{code} diff --git a/ghc/lib/glaExts/ByteArray.lhs b/ghc/lib/glaExts/ByteArray.lhs deleted file mode 100644 index d6326dc9ea..0000000000 --- a/ghc/lib/glaExts/ByteArray.lhs +++ /dev/null @@ -1,40 +0,0 @@ -% -% (c) The AQUA Project, Glasgow University, 1994-1997 -% -\section[ByteArray]{The @ByteArray@ interface} - -Immutable, read-only chunks of bytes, the @ByteArray@ collects -together the definitions in @ArrBase@ and exports them as one. - -\begin{code} -module ByteArray - ( - ByteArray(..), -- not abstract, for now. - Ix, - - --Indexing of ordinary @Arrays@ is standard Haskell and isn't defined here. - indexCharArray, --:: Ix ix => ByteArray ix -> ix -> Char - indexIntArray, --:: Ix ix => ByteArray ix -> ix -> Int - indexAddrArray, --:: Ix ix => ByteArray ix -> ix -> Addr - indexFloatArray, --:: Ix ix => ByteArray ix -> ix -> Float - indexDoubleArray, --:: Ix ix => ByteArray ix -> ix -> Double - - --Indexing off @Addrs@ is similar, and therefore given here. - indexCharOffAddr, --:: Addr -> Int -> Char - indexIntOffAddr, --:: Addr -> Int -> Int - indexAddrOffAddr, --:: Addr -> Int -> Addr - indexFloatOffAddr, --:: Addr -> Int -> Float - indexDoubleOffAddr, --:: Addr -> Int -> Double - - Addr, - Word - - ) where - -import ArrBase -import Ix -import Foreign (Word) -import Addr - -\end{code} - diff --git a/ghc/lib/glaExts/CCall.lhs b/ghc/lib/glaExts/CCall.lhs deleted file mode 100644 index f1205e89fd..0000000000 --- a/ghc/lib/glaExts/CCall.lhs +++ /dev/null @@ -1,53 +0,0 @@ -% -% (c) The AQUA Project, Glasgow University, 1994-1996 -% - -\section[CCall]{Module @CCall@} - -\begin{code} -{-# OPTIONS -fno-implicit-prelude #-} - -module CCall ( - CCallable(..), CReturnable(..), - Word(..) - ) where - -import PrelBase -import GHC -\end{code} - -%********************************************************* -%* * -\subsection{Classes @CCallable@ and @CReturnable@} -%* * -%********************************************************* - -\begin{code} -instance CCallable Char -instance CCallable Char# -instance CReturnable Char - -instance CCallable Int -instance CCallable Int# -instance CReturnable Int - --- DsCCall knows how to pass strings... -instance CCallable [Char] - -instance CCallable Float -instance CCallable Float# -instance CReturnable Float - -instance CCallable Double -instance CCallable Double# -instance CReturnable Double - -data Word = W# Word# deriving (Eq, Ord) -- Glasgow extension - -instance CCallable Word -instance CCallable Word# -instance CReturnable Word - -instance CReturnable () -- Why, exactly? -\end{code} - diff --git a/ghc/lib/glaExts/Foreign.lhs b/ghc/lib/glaExts/Foreign.lhs deleted file mode 100644 index 34d09908fa..0000000000 --- a/ghc/lib/glaExts/Foreign.lhs +++ /dev/null @@ -1,162 +0,0 @@ -% -% (c) The AQUA Project, Glasgow University, 1994-1996 -% - -\section[Foreign]{Module @Foreign@} - -\begin{code} -{-# OPTIONS -fno-implicit-prelude #-} - -module Foreign ( - module Foreign, -#ifndef __PARALLEL_HASKELL__ - ForeignObj(..), -#endif - Word(..), - -#ifndef __PARALLEL_HASKELL__ - unpackCStringFO, -- :: ForeignObj -> [Char] - unpackNBytesFO, -- :: ForeignObj -> Int -> [Char] - unpackCStringFO#, -- :: ForeignObj# -> [Char] - unpackNBytesFO# -- :: ForeignObj# -> Int# -> [Char] -#endif - ) where - -import IOBase -import STBase -import Unsafe -import PrelBase -import CCall -import Addr -import GHC -\end{code} - - -%********************************************************* -%* * -\subsection{Type @ForeignObj@ and its operations} -%* * -%********************************************************* - -\begin{code} -#ifndef __PARALLEL_HASKELL__ -instance CCallable ForeignObj -instance CCallable ForeignObj# - -eqForeignObj :: ForeignObj -> ForeignObj -> Bool -makeForeignObj :: Addr -> Addr -> IO ForeignObj -writeForeignObj :: ForeignObj -> Addr -> IO () - -{- derived op - attaching a free() finaliser to a malloc() allocated reference. -} -makeMallocPtr :: Addr -> IO ForeignObj - -makeForeignObj (A# obj) (A# finaliser) = IO ( \ s# -> - case makeForeignObj# obj finaliser s# of - StateAndForeignObj# s1# fo# -> IOok s1# (ForeignObj fo#)) - -writeForeignObj (ForeignObj fo#) (A# datum#) = IO ( \ s# -> - case writeForeignObj# fo# datum# s# of { s1# -> IOok s1# () } ) - -makeMallocPtr a = makeForeignObj a (``&free''::Addr) - -eqForeignObj mp1 mp2 - = unsafePerformIO (_ccall_ eqForeignObj mp1 mp2) /= (0::Int) - -instance Eq ForeignObj where - p == q = eqForeignObj p q - p /= q = not (eqForeignObj p q) -#endif /* !__PARALLEL_HASKELL__ */ -\end{code} - -%********************************************************* -%* * -\subsection{Type @StablePtr@ and its operations} -%* * -%********************************************************* - -\begin{code} -#ifndef __PARALLEL_HASKELL__ -data StablePtr a = StablePtr (StablePtr# a) -instance CCallable (StablePtr a) -instance CCallable (StablePtr# a) -instance CReturnable (StablePtr a) - --- Nota Bene: it is important {\em not\/} to inline calls to --- @makeStablePtr#@ since the corresponding macro is very long and we'll --- get terrible code-bloat. - -makeStablePtr :: a -> IO (StablePtr a) -deRefStablePtr :: StablePtr a -> IO a -freeStablePtr :: StablePtr a -> IO () - -{-# INLINE deRefStablePtr #-} -{-# INLINE freeStablePtr #-} - -makeStablePtr f = IO $ \ rw1# -> - case makeStablePtr# f rw1# of - StateAndStablePtr# rw2# sp# -> IOok rw2# (StablePtr sp#) - -deRefStablePtr (StablePtr sp#) = IO $ \ rw1# -> - case deRefStablePtr# sp# rw1# of - StateAndPtr# rw2# a -> IOok rw2# a - -freeStablePtr sp = _ccall_ freeStablePointer sp - -#endif /* !__PARALLEL_HASKELL__ */ -\end{code} - -%********************************************************* -%* * -\subsection{Ghastly return types} -%* * -%********************************************************* - -\begin{code} -#ifndef __PARALLEL_HASKELL__ -data StateAndStablePtr# s a = StateAndStablePtr# (State# s) (StablePtr# a) -#endif -data StateAndForeignObj# s = StateAndForeignObj# (State# s) ForeignObj# -\end{code} - -%********************************************************* -%* * -\subsection{Unpacking Foreigns} -%* * -%********************************************************* - -Primitives for converting Foreigns pointing to external -sequence of bytes into a list of @Char@s (a renamed version -of the code above). - -\begin{code} -#ifndef __PARALLEL_HASKELL__ -unpackCStringFO :: ForeignObj -> [Char] -unpackCStringFO (ForeignObj fo#) = unpackCStringFO# fo# - -unpackCStringFO# :: ForeignObj# -> [Char] -unpackCStringFO# fo {- ptr. to NUL terminated string-} - = unpack 0# - where - unpack nh - | ch `eqChar#` '\0'# = [] - | otherwise = C# ch : unpack (nh +# 1#) - where - ch = indexCharOffForeignObj# fo nh - -unpackNBytesFO :: ForeignObj -> Int -> [Char] -unpackNBytesFO (ForeignObj fo) (I# l) = unpackNBytesFO# fo l - -unpackNBytesFO# :: ForeignObj# -> Int# -> [Char] - -- This one is called by the compiler to unpack literal strings with NULs in them; rare. -unpackNBytesFO# fo len - = unpack 0# - where - unpack i - | i >=# len = [] - | otherwise = C# ch : unpack (i +# 1#) - where - ch = indexCharOffForeignObj# fo i -#endif -\end{code} - - diff --git a/ghc/lib/glaExts/GlaExts.lhs b/ghc/lib/glaExts/GlaExts.lhs deleted file mode 100644 index 98d48bd27d..0000000000 --- a/ghc/lib/glaExts/GlaExts.lhs +++ /dev/null @@ -1,97 +0,0 @@ -% -% (c) The AQUA Project, Glasgow University, 1994-1996 -% -\section[GlaExts]{The @GlaExts@ interface} - -Compatibility cruft: Deprecated! Don't use! This rug will -dissappear from underneath your feet very soon. - -This module will eventually be the interface to GHC-ONLY extensions: -i.e. unboxery and primitive operations over unboxed values. - -OLD: -The @GlaExts@ packages up various Glasgow extensions and -exports them all through one interface. The Idea being that -a Haskell program using a Glasgow extension doesn't have to -selective import of obscure/likely-to-move (believe me, we -really like to move functions around for the prelude bits!) -GHC interfaces - instead import the GlaExts rag bag and you should be away! - -\begin{code} -module GlaExts - - ( - ST, RealWorld, - - unsafePerformIO, - unsafeInterleaveIO, - - -- operations for interfacing IO and ST - -- - stToIO, -- :: ST RealWorld a -> IO a - ioToST, -- :: IO a -> ST RealWorld a - - -- compatibility cruft - PrimIO, - ioToPrimIO, - primIOToIO, - unsafePerformPrimIO, - thenPrimIO, thenIO_Prim, - seqPrimIO, returnPrimIO, - - seqST, thenST, returnST, - - -- Everything from module ByteArray: - module ByteArray, - - -- Same for Mutable(Byte)Array interface: - module MutableArray, - - -- the representation of some basic types: - Int(..),Addr(..),Word(..),Float(..),Double(..),Integer(..),Char(..), - - -- misc bits - trace, - Lift(..), - - -- and finally, all the unboxed primops of GHC! - module GHC - - ) where - -import GHC -import STBase -import IOExts -import PrelBase -import ByteArray -import MutableArray -import Monad -import IOBase -import Foreign - -type PrimIO a = IO a -primIOToIO io = io -ioToPrimIO io = io -unsafePerformPrimIO = unsafePerformIO -thenPrimIO :: PrimIO a -> (a -> PrimIO b) -> PrimIO b -thenPrimIO = (>>=) - -seqPrimIO :: PrimIO a -> PrimIO b -> PrimIO b -seqPrimIO = (>>) - -returnPrimIO :: a -> PrimIO a -returnPrimIO = return - -thenIO_Prim :: PrimIO a -> (a -> IO b) -> IO b -thenIO_Prim = (>>=) - --- ST compatibility stubs. -thenST :: ST s a -> ( a -> ST s b) -> ST s b -thenST = (>>=) - -seqST :: ST s a -> ST s b -> ST s b -seqST = (>>) - -returnST :: a -> ST s a -returnST = return -\end{code} diff --git a/ghc/lib/glaExts/IOExts.lhs b/ghc/lib/glaExts/IOExts.lhs deleted file mode 100644 index 9f108b14a5..0000000000 --- a/ghc/lib/glaExts/IOExts.lhs +++ /dev/null @@ -1,86 +0,0 @@ -% -% (c) The AQUA Project, Glasgow University, 1994-1996 -% - -\section[IOExts]{Module @IOExts@} - -\begin{code} -{-# OPTIONS -fno-implicit-prelude #-} - -module IOExts - ( fixIO - , unsafePerformIO - , unsafeInterleaveIO - - , IORef - -- instance Eq (IORef a) - , newIORef - , readIORef - , writeIORef - - , IOArray - -- instance Eq (IOArray ix a) - , newIOArray - , boundsIOArray - , readIOArray - , writeIOArray - , freezeIOArray - - , trace - , performGC - - , reallyUnsafePtrEq - ) where -\end{code} - -\begin{code} -import PrelBase -import IOBase -import STBase -import Unsafe -import GHC -import ArrBase -import Ix - -reallyUnsafePtrEq a b = - case reallyUnsafePtrEquality# a b of - 0# -> False - _ -> True -\end{code} - -\begin{code} -newtype IORef a = IORef (MutableVar RealWorld a) - deriving Eq - -newIORef :: a -> IO (IORef a) -newIORef v = stToIO (newVar v) >>= \ var -> return (IORef var) - -readIORef :: IORef a -> IO a -readIORef (IORef var) = stToIO (readVar var) - -writeIORef :: IORef a -> a -> IO () -writeIORef (IORef var) v = stToIO (writeVar var v) -\end{code} - -\begin{code} -newtype IOArray ix elt = IOArray (MutableArray RealWorld ix elt) - deriving Eq - -newIOArray :: Ix ix => (ix,ix) -> elt -> IO (IOArray ix elt) -boundsIOArray :: Ix ix => IOArray ix elt -> (ix, ix) -readIOArray :: Ix ix => IOArray ix elt -> ix -> IO elt -writeIOArray :: Ix ix => IOArray ix elt -> ix -> elt -> IO () -freezeIOArray :: Ix ix => IOArray ix elt -> IO (Array ix elt) - -newIOArray ixs elt = - stToIO (newArray ixs elt) >>= \arr -> - return (IOArray arr) - -boundsIOArray (IOArray arr) = boundsOfArray arr - -readIOArray (IOArray arr) ix = stToIO (readArray arr ix) - -writeIOArray (IOArray arr) ix elt = stToIO (writeArray arr ix elt) - -freezeIOArray (IOArray arr) = stToIO (freezeArray arr) -\end{code} diff --git a/ghc/lib/glaExts/Int.lhs b/ghc/lib/glaExts/Int.lhs deleted file mode 100644 index 5fa62e6501..0000000000 --- a/ghc/lib/glaExts/Int.lhs +++ /dev/null @@ -1,499 +0,0 @@ -% -% (c) The AQUA Project, Glasgow University, 1997-1998 -% - -\section[Int]{Module @Int@} - -This code is largely copied from the Hugs library of the same name. - -\begin{code} -{-# OPTIONS -fno-implicit-prelude #-} - ------------------------------------------------------------------------------ --- Signed Integers --- Suitable for use with Hugs 1.4 on 32 bit systems. ------------------------------------------------------------------------------ - -module Int - ( Int8 - , Int16 - , Int32 - --, Int64 - , int8ToInt -- :: Int8 -> Int - , intToInt8 -- :: Int -> Int8 - , int16ToInt -- :: Int16 -> Int - , intToInt16 -- :: Int -> Int16 - , int32ToInt -- :: Int32 -> Int - , intToInt32 -- :: Int -> Int32 - -- plus Eq, Ord, Num, Bounded, Real, Integral, Ix, Enum, Read, - -- Show and Bits instances for each of Int8, Int16 and Int32 - ) where - -import PrelBase -import PrelNum -import PrelRead -import Ix -import GHCerr ( error ) -import Bits -import GHC -import CCall - ------------------------------------------------------------------------------ --- The "official" coercion functions ------------------------------------------------------------------------------ - -int8ToInt :: Int8 -> Int -intToInt8 :: Int -> Int8 -int16ToInt :: Int16 -> Int -intToInt16 :: Int -> Int16 -int32ToInt :: Int32 -> Int -intToInt32 :: Int -> Int32 - --- And some non-exported ones - -int8ToInt16 :: Int8 -> Int16 -int8ToInt32 :: Int8 -> Int32 -int16ToInt8 :: Int16 -> Int8 -int16ToInt32 :: Int16 -> Int32 -int32ToInt8 :: Int32 -> Int8 -int32ToInt16 :: Int32 -> Int16 - -int8ToInt16 (I8# x) = I16# x -int8ToInt32 (I8# x) = I32# x -int16ToInt8 (I16# x) = I8# x -int16ToInt32 (I16# x) = I32# x -int32ToInt8 (I32# x) = I8# x -int32ToInt16 (I32# x) = I16# x -\end{code} - -\subsection[Int8]{The @Int8@ interface} - -\begin{code} -data Int8 = I8# Int# -instance CCallable Int8 -instance CReturnable Int8 - -int8ToInt (I8# x) = I# (int8ToInt# x) -int8ToInt# x = if x' <=# 0x7f# then x' else x' -# 0x100# - where x' = word2Int# (int2Word# x `and#` int2Word# 0xff#) - --- --- This doesn't perform any bounds checking --- on the value it is passed, nor its sign. --- i.e., show (intToInt8 511) => "-1" --- -intToInt8 (I# x) = I8# (intToInt8# x) -intToInt8# i# = word2Int# ((int2Word# i#) `and#` int2Word# 0xff#) - -instance Eq Int8 where - (I8# x#) == (I8# y#) = x# ==# y# - (I8# x#) /= (I8# y#) = x# /=# y# - -instance Ord Int8 where - compare (I8# x#) (I8# y#) = compareInt# (int8ToInt# x#) (int8ToInt# y#) - -compareInt# :: Int# -> Int# -> Ordering -compareInt# x# y# - | x# <# y# = LT - | x# ==# y# = EQ - | otherwise = GT - -instance Num Int8 where - (I8# x#) + (I8# y#) = I8# (intToInt8# (x# +# y#)) - (I8# x#) - (I8# y#) = I8# (intToInt8# (x# -# y#)) - (I8# x#) * (I8# y#) = I8# (intToInt8# (x# *# y#)) - negate i@(I8# x#) = - if x# ==# 0# - then i - else I8# (0x100# -# x#) - - abs = absReal - signum = signumReal - fromInteger (J# a# s# d#) - = case (integer2Int# a# s# d#) of { i# -> I8# (intToInt8# i#) } - fromInt = intToInt8 - -instance Bounded Int8 where - minBound = 0x80 - maxBound = 0x7f - -instance Real Int8 where - toRational x = toInteger x % 1 - -instance Integral Int8 where - div x@(I8# x#) y@(I8# y#) = - if x > 0 && y < 0 then quotInt8 (x-y-1) y - else if x < 0 && y > 0 then quotInt8 (x-y+1) y - else quotInt8 x y - quot x@(I8# _) y@(I8# y#) = - if y# /=# 0# - then x `quotInt8` y - else error "Integral.Int8.quot: divide by 0\n" - rem x@(I8# _) y@(I8# y#) = - if y# /=# 0# - then x `remInt8` y - else error "Integral.Int8.rem: divide by 0\n" - mod x@(I8# x#) y@(I8# y#) = - if x > 0 && y < 0 || x < 0 && y > 0 then - if r/=0 then r+y else 0 - else - r - where r = remInt8 x y - a@(I8# _) `quotRem` b@(I8# _) = (a `quotInt8` b, a `remInt8` b) - toInteger i8 = toInteger (int8ToInt i8) - toInt i8 = int8ToInt i8 - -remInt8 (I8# x) (I8# y) = I8# (intToInt8# ((int8ToInt# x) `remInt#` (int8ToInt# y))) -quotInt8 (I8# x) (I8# y) = I8# (intToInt8# ((int8ToInt# x) `quotInt#` (int8ToInt# y))) - -instance Ix Int8 where - range (m,n) = [m..n] - index b@(m,n) i - | inRange b i = int8ToInt (i - m) - | otherwise = error (showString "Ix{Int8}.index: Index " . - showParen True (showsPrec 0 i) . - showString " out of range " $ - showParen True (showsPrec 0 b) "") - inRange (m,n) i = m <= i && i <= n - -instance Enum Int8 where - toEnum = intToInt8 - fromEnum = int8ToInt - enumFrom c = map toEnum [fromEnum c .. fromEnum (maxBound::Int8)] - enumFromThen c d = map toEnum [fromEnum c, fromEnum d .. fromEnum (last::Int8)] - where last = if d < c then minBound else maxBound - -instance Read Int8 where - readsPrec p s = [ (intToInt8 x,r) | (x,r) <- readsPrec p s ] - -instance Show Int8 where - showsPrec p i8 = showsPrec p (int8ToInt i8) - -binop8 :: (Int32 -> Int32 -> a) -> (Int8 -> Int8 -> a) -binop8 op x y = int8ToInt32 x `op` int8ToInt32 y - -instance Bits Int8 where - (I8# x) .&. (I8# y) = I8# (word2Int# ((int2Word# x) `and#` (int2Word# y))) - (I8# x) .|. (I8# y) = I8# (word2Int# ((int2Word# x) `or#` (int2Word# y))) - (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) i#)) - i8@(I8# x) `rotate` (I# i) - | i ==# 0# = i8 - | i ># 0# = - I8# (intToInt8# ( word2Int# ( - (int2Word# (iShiftL# (int8ToInt# x) i')) - `or#` - (int2Word# (iShiftRA# (word2Int# ( - (int2Word# x) `and#` - (int2Word# (0x100# -# pow2# i2)))) - i2))))) - | otherwise = rotate i8 (I# (8# +# i)) - where - i' = word2Int# (int2Word# i `and#` int2Word# 7#) - i2 = 8# -# i' - bit i = shift 1 i - setBit x i = x .|. bit i - clearBit x i = x .&. complement (bit i) - complementBit x i = x `xor` bit i - testBit x i = (x .&. bit i) /= 0 - bitSize _ = 8 - isSigned _ = True - -pow2# :: Int# -> Int# -pow2# x# = iShiftL# 1# x# -\end{code} - -\subsection[Int16]{The @Int16@ interface} - -\begin{code} -data Int16 = I16# Int# -instance CCallable Int16 -instance CReturnable Int16 - -int16ToInt (I16# x) = I# (int16ToInt# x) - -int16ToInt# x = if x' <=# 0x7fff# then x' else x' -# 0x10000# - where x' = word2Int# (int2Word# x `and#` int2Word# 0xffff#) - -intToInt16 (I# x) = I16# (intToInt16# x) -intToInt16# i# = word2Int# ((int2Word# i#) `and#` int2Word# 0xffff#) - -instance Eq Int16 where - (I16# x#) == (I16# y#) = x# ==# y# - (I16# x#) /= (I16# y#) = x# /=# y# - -instance Ord Int16 where - compare (I16# x#) (I16# y#) = compareInt# (int16ToInt# x#) (int16ToInt# y#) - -instance Num Int16 where - (I16# x#) + (I16# y#) = I16# (intToInt16# (x# +# y#)) - (I16# x#) - (I16# y#) = I16# (intToInt16# (x# -# y#)) - (I16# x#) * (I16# y#) = I16# (intToInt16# (x# *# y#)) - negate i@(I16# x#) = - if x# ==# 0# - then i - else I16# (0x10000# -# x#) - abs = absReal - signum = signumReal - fromInteger (J# a# s# d#) - = case (integer2Int# a# s# d#) of { i# -> I16# (intToInt16# i#) } - fromInt = intToInt16 - -instance Bounded Int16 where - minBound = 0x8000 - maxBound = 0x7fff - -instance Real Int16 where - toRational x = toInteger x % 1 - -instance Integral Int16 where - div x@(I16# x#) y@(I16# y#) = - if x > 0 && y < 0 then quotInt16 (x-y-1) y - else if x < 0 && y > 0 then quotInt16 (x-y+1) y - else quotInt16 x y - quot x@(I16# _) y@(I16# y#) = - if y# /=# 0# - then x `quotInt16` y - else error "Integral.Int16.quot: divide by 0\n" - rem x@(I16# _) y@(I16# y#) = - if y# /=# 0# - then x `remInt16` y - else error "Integral.Int16.rem: divide by 0\n" - mod x@(I16# x#) y@(I16# y#) = - if x > 0 && y < 0 || x < 0 && y > 0 then - if r/=0 then r+y else 0 - else - r - where r = remInt16 x y - a@(I16# _) `quotRem` b@(I16# _) = (a `quotInt16` b, a `remInt16` b) - toInteger i16 = toInteger (int16ToInt i16) - toInt i16 = int16ToInt i16 - -remInt16 (I16# x) (I16# y) = I16# (intToInt16# ((int16ToInt# x) `remInt#` (int16ToInt# y))) -quotInt16 (I16# x) (I16# y) = I16# (intToInt16# ((int16ToInt# x) `quotInt#` (int16ToInt# y))) - -instance Ix Int16 where - range (m,n) = [m..n] - index b@(m,n) i - | inRange b i = int16ToInt (i - m) - | otherwise = error (showString "Ix{Int16}.index: Index " . - showParen True (showsPrec 0 i) . - showString " out of range " $ - showParen True (showsPrec 0 b) "") - inRange (m,n) i = m <= i && i <= n - -instance Enum Int16 where - toEnum = intToInt16 - fromEnum = int16ToInt - enumFrom c = map toEnum [fromEnum c .. fromEnum (maxBound::Int16)] - enumFromThen c d = map toEnum [fromEnum c, fromEnum d .. fromEnum (last::Int16)] - where last = if d < c then minBound else maxBound - -instance Read Int16 where - readsPrec p s = [ (intToInt16 x,r) | (x,r) <- readsPrec p s ] - -instance Show Int16 where - showsPrec p i16 = showsPrec p (int16ToInt i16) - -binop16 :: (Int32 -> Int32 -> a) -> (Int16 -> Int16 -> a) -binop16 op x y = int16ToInt32 x `op` int16ToInt32 y - -instance Bits Int16 where - (I16# x) .&. (I16# y) = I16# (word2Int# ((int2Word# x) `and#` (int2Word# y))) - (I16# x) .|. (I16# y) = I16# (word2Int# ((int2Word# x) `or#` (int2Word# y))) - (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) i#)) - i16@(I16# x) `rotate` (I# i) - | i ==# 0# = i16 - | i ># 0# = - I16# (intToInt16# (word2Int# ( - (int2Word# (iShiftL# (int16ToInt# x) i')) - `or#` - (int2Word# (iShiftRA# ( word2Int# ( - (int2Word# x) `and#` (int2Word# (0x100# -# pow2# i2)))) - i2))))) - | otherwise = rotate i16 (I# (16# +# i)) - where - i' = word2Int# (int2Word# i `and#` int2Word# 15#) - i2 = 16# -# i' - bit i = shift 1 i - setBit x i = x .|. bit i - clearBit x i = x .&. complement (bit i) - complementBit x i = x `xor` bit i - testBit x i = (x .&. bit i) /= 0 - bitSize _ = 16 - isSigned _ = True -\end{code} - -\subsection[Int32]{The @Int32@ interface} - -\begin{code} -data Int32 = I32# Int# -instance CCallable Int32 -instance CReturnable Int32 - -int32ToInt (I32# x) = I# (int32ToInt# x) - -int32ToInt# :: Int# -> Int# -#if WORD_SIZE_IN_BYTES > 4 -int32ToInt# x = if x' <=# 0x7fffffff# then x' else x' -# 0x100000000# - where x' = word2Int# (int2Word# x `and#` int2Word# 0xffffffff#) -#else -int32ToInt# x = x -#endif - -intToInt32 (I# x) = I32# (intToInt32# x) -intToInt32# :: Int# -> Int# -#if WORD_SIZE_IN_BYTES > 4 -intToInt32# i# = word2Int# ((int2Word# i#) `and#` int2Word# 0xffffffff#) -#else -intToInt32# i# = i# -#endif - -instance Eq Int32 where - (I32# x#) == (I32# y#) = x# ==# y# - (I32# x#) /= (I32# y#) = x# /=# y# - -instance Ord Int32 where - compare (I32# x#) (I32# y#) = compareInt# (int32ToInt# x#) (int32ToInt# y#) - -instance Num Int32 where - (I32# x#) + (I32# y#) = I32# (intToInt32# (x# +# y#)) - (I32# x#) - (I32# y#) = I32# (intToInt32# (x# -# y#)) - (I32# x#) * (I32# y#) = I32# (intToInt32# (x# *# y#)) -#if WORD_SIZE_IN_BYTES > 4 - negate i@(I32# x) = - if x ==# 0# - then i - else I32# (intToInt32# (0x100000000# -# x')) -#else - negate (I32# x) = I32# (negateInt# x) -#endif - abs = absReal - signum = signumReal - fromInteger (J# a# s# d#) - = case (integer2Int# a# s# d#) of { i# -> I32# (intToInt32# i#) } - fromInt = intToInt32 - --- ToDo: remove LitLit when minBound::Int is fixed (currently it's one --- too high, and doesn't allow the correct minBound to be defined here). -instance Bounded Int32 where - minBound = case ``0x80000000'' of { I# x -> I32# x } - maxBound = I32# 0x7fffffff# - -instance Real Int32 where - toRational x = toInteger x % 1 - -instance Integral Int32 where - div x@(I32# x#) y@(I32# y#) = - if x > 0 && y < 0 then quotInt32 (x-y-1) y - else if x < 0 && y > 0 then quotInt32 (x-y+1) y - else quotInt32 x y - quot x@(I32# _) y@(I32# y#) = - if y# /=# 0# - then x `quotInt32` y - else error "Integral.Int32.quot: divide by 0\n" - rem x@(I32# _) y@(I32# y#) = - if y# /=# 0# - then x `remInt32` y - else error "Integral.Int32.rem: divide by 0\n" - mod x@(I32# x#) y@(I32# y#) = - if x > 0 && y < 0 || x < 0 && y > 0 then - if r/=0 then r+y else 0 - else - r - where r = remInt32 x y - a@(I32# _) `quotRem` b@(I32# _) = (a `quotInt32` b, a `remInt32` b) - toInteger i32 = toInteger (int32ToInt i32) - toInt i32 = int32ToInt i32 - -remInt32 (I32# x) (I32# y) = I32# (intToInt32# ((int32ToInt# x) `remInt#` (int32ToInt# y))) -quotInt32 (I32# x) (I32# y) = I32# (intToInt32# ((int32ToInt# x) `quotInt#` (int32ToInt# y))) - -instance Ix Int32 where - range (m,n) = [m..n] - index b@(m,n) i - | inRange b i = int32ToInt (i - m) - | otherwise = error (showString "Ix{Int32}.index: Index " . - showParen True (showsPrec 0 i) . - showString " out of range " $ - showParen True (showsPrec 0 b) "") - inRange (m,n) i = m <= i && i <= n - -instance Enum Int32 where - toEnum = intToInt32 - fromEnum = int32ToInt - enumFrom c = map toEnum [fromEnum c .. fromEnum (maxBound::Int32)] - enumFromThen c d = map toEnum [fromEnum c, fromEnum d .. fromEnum (last::Int32)] - where last = if d < c then minBound else maxBound - -instance Read Int32 where - readsPrec p s = [ (intToInt32 x,r) | (x,r) <- readsPrec p s ] - -instance Show Int32 where - showsPrec p i32 = showsPrec p (int32ToInt i32) - -instance Bits Int32 where - (I32# x) .&. (I32# y) = I32# (word2Int# ((int2Word# x) `and#` (int2Word# y))) - (I32# x) .|. (I32# y) = I32# (word2Int# ((int2Word# x) `or#` (int2Word# y))) - (I32# x) `xor` (I32# y) = I32# (word2Int# ((int2Word# x) `xor#` (int2Word# y))) -#if WORD_SIZE_IN_BYTES > 4 - complement (I32# x) = I32# (word2Int# ((int2Word# x) `xor#` (int2Word# 0xffffffff#))) -#else - 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) i#)) - i32@(I32# x) `rotate` (I# i) - | i ==# 0# = i32 - | i ># 0# = - -- ( (x<<i') | ((x&(0x100000000-2^i2))>>i2) - I32# (intToInt32# ( word2Int# ( - (int2Word# (iShiftL# (int32ToInt# x) i')) - `or#` - (int2Word# (iShiftRA# (word2Int# ( - (int2Word# x) - `and#` - (int2Word# (maxBound# -# pow2# i2 +# 1#)))) - i2))))) - | otherwise = rotate i32 (I# (32# +# i)) - where - i' = word2Int# (int2Word# i `and#` int2Word# 31#) - i2 = 32# -# i' - (I32# maxBound#) = maxBound - bit i = shift 1 i - setBit x i = x .|. bit i - clearBit x i = x .&. complement (bit i) - complementBit x i = x `xor` bit i - testBit x i = (x .&. bit i) /= 0 - bitSize _ = 32 - isSigned _ = True - -{-# INLINE wordop #-} -wordop op (I# x) (I# y) = I# (word2Int# (int2Word# x `op` int2Word# y)) - ------------------------------------------------------------------------------ --- End of exported definitions --- --- The remainder of this file consists of definitions which are only --- used in the implementation. ------------------------------------------------------------------------------ - ------------------------------------------------------------------------------ --- Code copied from the Prelude ------------------------------------------------------------------------------ - -absReal x | x >= 0 = x - | otherwise = -x - -signumReal x | x == 0 = 0 - | x > 0 = 1 - | otherwise = -1 -\end{code} diff --git a/ghc/lib/glaExts/LazyST.lhs b/ghc/lib/glaExts/LazyST.lhs deleted file mode 100644 index d18b71608e..0000000000 --- a/ghc/lib/glaExts/LazyST.lhs +++ /dev/null @@ -1,122 +0,0 @@ -% -% (c) The GRASP/AQUA Project, Glasgow University, 1992-1997 -% - -\section[LazyST]{The Lazy State Transformer Monad, @LazyST@} - -This module presents an identical interface to ST, but the underlying -implementation of the state thread is lazy. - -\begin{code} -module LazyST ( - - ST, - - runST, - unsafeInterleaveST, - - -- ST is one, so you'll likely need some Monad bits - module Monad, - - ST.STRef, - newSTRef, readSTRef, writeSTRef, - - STArray, - newSTArray, readSTArray, writeSTArray, boundsSTArray, - thawSTArray, freezeSTArray, unsafeFreezeSTArray, - Ix, - - strictToLazyST, lazyToStrictST - ) where - -import qualified ST -import qualified STBase -import ArrBase -import qualified UnsafeST ( unsafeInterleaveST ) -import PrelBase ( Eq(..), Int, Bool, ($), ()(..) ) -import Monad -import Ix -import GHC - -newtype ST s a = ST (STBase.State s -> (a,STBase.State s)) - -instance Monad (ST s) where - - return a = ST $ \ s -> (a,s) - m >> k = m >>= \ _ -> k - - (ST m) >>= k - = ST $ \ s -> - let - (r,new_s) = m s - ST k_a = k r - in - k_a new_s - --- ToDo: un-inline this, it could cause problems... -runST :: (All s => ST s a) -> a -runST st = case st of ST st -> let (r,_) = st (STBase.S# realWorld#) in r -\end{code} - -%********************************************************* -%* * -\subsection{Variables} -%* * -%********************************************************* - -\begin{code} -newSTRef :: a -> ST s (ST.STRef s a) -readSTRef :: ST.STRef s a -> ST s a -writeSTRef :: ST.STRef s a -> a -> ST s () - -newSTRef = strictToLazyST . ST.newSTRef -readSTRef = strictToLazyST . ST.readSTRef -writeSTRef r a = strictToLazyST (ST.writeSTRef r a) -\end{code} - -%********************************************************* -%* * -\subsection{Arrays} -%* * -%********************************************************* - -\begin{code} -newtype STArray s ix elt = STArray (MutableArray s ix elt) - -newSTArray :: Ix ix => (ix,ix) -> elt -> ST s (STArray s ix elt) -readSTArray :: Ix ix => STArray s ix elt -> ix -> ST s elt -writeSTArray :: Ix ix => STArray s ix elt -> ix -> elt -> ST s () -boundsSTArray :: Ix ix => STArray s ix elt -> (ix, ix) -thawSTArray :: Ix ix => Array ix elt -> ST s (STArray s ix elt) -freezeSTArray :: Ix ix => STArray s ix elt -> ST s (Array ix elt) -unsafeFreezeSTArray :: Ix ix => STArray s ix elt -> ST s (Array ix elt) - -newSTArray ixs init = - strictToLazyST (newArray ixs init) >>= \arr -> - return (STArray arr) - -readSTArray (STArray arr) ix = strictToLazyST (readArray arr ix) -writeSTArray (STArray arr) ix v = strictToLazyST (writeArray arr ix v) -boundsSTArray (STArray arr) = boundsOfArray arr -thawSTArray arr = - strictToLazyST (thawArray arr) >>= \arr -> - return (STArray arr) -freezeSTArray (STArray arr) = strictToLazyST (freezeArray arr) -unsafeFreezeSTArray (STArray arr) = strictToLazyST (unsafeFreezeArray arr) - -strictToLazyST :: STBase.ST s a -> ST s a -strictToLazyST (STBase.ST m) = ST $ \s -> - let - STBase.S# s# = s - STBase.STret s2# r = m s# - in - (r, STBase.S# s2#) - -lazyToStrictST :: ST s a -> STBase.ST s a -lazyToStrictST (ST m) = STBase.ST $ \s -> - case (m (STBase.S# s)) of (a, STBase.S# s') -> STBase.STret s' a - -unsafeInterleaveST :: ST s a -> ST s a -unsafeInterleaveST = strictToLazyST . ST.unsafeInterleaveST . lazyToStrictST - -\end{code} diff --git a/ghc/lib/glaExts/MutableArray.lhs b/ghc/lib/glaExts/MutableArray.lhs deleted file mode 100644 index eead4b692a..0000000000 --- a/ghc/lib/glaExts/MutableArray.lhs +++ /dev/null @@ -1,62 +0,0 @@ -% -% (c) The AQUA Project, Glasgow University, 1997 -% -\section[MutableArray]{The @MutableArray@ interface} - -Mutable (byte)arrays interface, re-exports type types and operations -over them from @ArrBase@. Have to be used in conjunction with -@ST@. - -\begin{code} -module MutableArray - ( - MutableArray(..), -- not abstract - MutableByteArray(..), - - ST, - Ix, - - -- Creators: - newArray, -- :: Ix ix => (ix,ix) -> elt -> ST s (MutableArray s ix elt) - newCharArray, - newAddrArray, - newIntArray, - newFloatArray, - newDoubleArray, -- :: Ix ix => (ix,ix) -> ST s (MutableByteArray s ix) - - boundsOfArray, -- :: Ix ix => MutableArray s ix elt -> (ix, ix) - boundsOfByteArray, -- :: Ix ix => MutableByteArray s ix -> (ix, ix) - - readArray, -- :: Ix ix => MutableArray s ix elt -> ix -> ST s elt - - readCharArray, -- :: Ix ix => MutableByteArray s ix -> ix -> ST s Char - readIntArray, -- :: Ix ix => MutableByteArray s ix -> ix -> ST s Int - readAddrArray, -- :: Ix ix => MutableByteArray s ix -> ix -> ST s Addr - readFloatArray, -- :: Ix ix => MutableByteArray s ix -> ix -> ST s Float - readDoubleArray, -- :: Ix ix => MutableByteArray s ix -> ix -> ST s Double - - writeArray, -- :: Ix ix => MutableArray s ix elt -> ix -> elt -> ST s () - writeCharArray, -- :: Ix ix => MutableByteArray s ix -> ix -> Char -> ST s () - writeIntArray, -- :: Ix ix => MutableByteArray s ix -> ix -> Int -> ST s () - writeAddrArray, -- :: Ix ix => MutableByteArray s ix -> ix -> Addr -> ST s () - writeFloatArray, -- :: Ix ix => MutableByteArray s ix -> ix -> Float -> ST s () - writeDoubleArray, -- :: Ix ix => MutableByteArray s ix -> ix -> Double -> ST s () - - freezeArray, -- :: Ix ix => MutableArray s ix elt -> ST s (Array ix elt) - freezeCharArray, -- :: Ix ix => MutableByteArray s ix -> ST s (ByteArray ix) - freezeIntArray, -- :: Ix ix => MutableByteArray s ix -> ST s (ByteArray ix) - freezeAddrArray, -- :: Ix ix => MutableByteArray s ix -> ST s (ByteArray ix) - freezeFloatArray, -- :: Ix ix => MutableByteArray s ix -> ST s (ByteArray ix) - freezeDoubleArray, -- :: Ix ix => MutableByteArray s ix -> ST s (ByteArray ix) - - unsafeFreezeArray, -- :: Ix ix => MutableArray s ix elt -> ST s (Array ix elt) - unsafeFreezeByteArray, -- :: Ix ix => MutableByteArray s ix -> ST s (ByteArray ix) - thawArray -- :: Ix ix => Array ix elt -> ST s (MutableArray s ix elt) - - ) where - -import ArrBase -import ST -import Ix - -\end{code} diff --git a/ghc/lib/glaExts/NumExts.lhs b/ghc/lib/glaExts/NumExts.lhs deleted file mode 100644 index e2f053aa80..0000000000 --- a/ghc/lib/glaExts/NumExts.lhs +++ /dev/null @@ -1,55 +0,0 @@ -% -% (c) The AQUA Project, Glasgow University, 1998 -% - -\section[NumExts]{Misc numeric bits} - -\begin{code} -module NumExts - - ( - doubleToFloat -- :: Double -> Float - , floatToDouble -- :: Double -> Float - , showHex -- :: Integral a => a -> ShowS - , showOct -- :: Integral a => a -> ShowS - ) where - -import Char (ord, chr) -import PrelBase (ord_0) -import GlaExts -\end{code} - -\begin{code} -doubleToFloat :: Double -> Float -doubleToFloat (D# d#) = F# (double2Float# d#) - -floatToDouble :: Float -> Double -floatToDouble (F# f#) = D# (float2Double# f#) - -showIntAtBase :: Integral a => a -> (a -> Char) -> a -> ShowS -showIntAtBase base toChr n r - | n < 0 = error ("NumExts.showIntAtBase: applied to negative number " ++ show n) - | otherwise = - case quotRem n base of { (n', d) -> - case toChr d of { C# c# -> -- stricter than necessary - let - r' = C# c# : r - in - if n' == 0 then r' else showIntAtBase base toChr n' r' - }} - -showHex :: Integral a => a -> ShowS -showHex n r = - showString "0x" $ - showIntAtBase 16 (toChrHex) n r - where - toChrHex d - | d < 10 = chr (ord_0 + fromIntegral d) - | otherwise = chr (ord 'a' + fromIntegral (d - 10)) - -showOct :: Integral a => a -> ShowS -showOct n r = - showString "0o" $ - showIntAtBase 8 (toChrOct) n r - where toChrOct d = chr (ord_0 + fromIntegral d) -\end{code} diff --git a/ghc/lib/glaExts/ST.lhs b/ghc/lib/glaExts/ST.lhs deleted file mode 100644 index 1df58dcca0..0000000000 --- a/ghc/lib/glaExts/ST.lhs +++ /dev/null @@ -1,94 +0,0 @@ -% -% (c) The GRASP/AQUA Project, Glasgow University, 1992-1996 -% -\section[module_ST]{The State Transformer Monad, @ST@} - -\begin{code} -{-# OPTIONS -fno-implicit-prelude #-} - -module ST ( - - ST, - - runST, -- :: (All s => ST s a) -> a - fixST, -- :: (a -> ST s a) -> ST s a - - unsafeInterleaveST, - - -- ST is one, so you'll likely need some Monad bits - module Monad, - - STRef, - newSTRef, readSTRef, writeSTRef, - - STArray, - newSTArray, readSTArray, writeSTArray, boundsSTArray, - thawSTArray, freezeSTArray, unsafeFreezeSTArray, - Ix - - ) where - -import ArrBase -import UnsafeST -import STBase -import PrelBase ( Eq(..), Int, Bool, ($), ()(..) ) -import Monad -import Ix - -\end{code} - -%********************************************************* -%* * -\subsection{Variables} -%* * -%********************************************************* - -\begin{code} -newtype STRef s a = STRef (MutableVar s a) - deriving Eq - -newSTRef :: a -> ST s (STRef s a) -newSTRef v = newVar v >>= \ var -> return (STRef var) - -readSTRef :: STRef s a -> ST s a -readSTRef (STRef var) = readVar var - -writeSTRef :: STRef s a -> a -> ST s () -writeSTRef (STRef var) v = writeVar var v -\end{code} - -%********************************************************* -%* * -\subsection{Arrays} -%* * -%********************************************************* - -\begin{code} -newtype STArray s ix elt = STArray (MutableArray s ix elt) - deriving Eq - -newSTArray :: Ix ix => (ix,ix) -> elt -> ST s (STArray s ix elt) -writeSTArray :: Ix ix => STArray s ix elt -> ix -> elt -> ST s () -readSTArray :: Ix ix => STArray s ix elt -> ix -> ST s elt -boundsSTArray :: Ix ix => STArray s ix elt -> (ix, ix) -thawSTArray :: Ix ix => Array ix elt -> ST s (STArray s ix elt) -freezeSTArray :: Ix ix => STArray s ix elt -> ST s (Array ix elt) -unsafeFreezeSTArray :: Ix ix => STArray s ix elt -> ST s (Array ix elt) - -newSTArray ixs elt = - newArray ixs elt >>= \arr -> - return (STArray arr) - -boundsSTArray (STArray arr) = boundsOfArray arr - -readSTArray (STArray arr) ix = readArray arr ix - -writeSTArray (STArray arr) ix elt = writeArray arr ix elt - -thawSTArray arr = thawArray arr >>= \starr -> return (STArray starr) - -freezeSTArray (STArray arr) = freezeArray arr - -unsafeFreezeSTArray (STArray arr) = unsafeFreezeArray arr -\end{code} - diff --git a/ghc/lib/glaExts/Word.lhs b/ghc/lib/glaExts/Word.lhs deleted file mode 100644 index 9e4f7dd564..0000000000 --- a/ghc/lib/glaExts/Word.lhs +++ /dev/null @@ -1,535 +0,0 @@ -% -% (c) The AQUA Project, Glasgow University, 1997 -% -\section[Word]{Module @Word@} - -GHC implementation of the standard Hugs/GHC @Word@ -interface, types and operations over unsigned, sized -quantities. - -\begin{code} -{-# OPTIONS -fno-implicit-prelude #-} -module Word - ( Word8 -- all abstract. - , Word16 -- instances: Eq, Ord - , Word32 -- Num, Bounded, Real, - , Word64 -- Integral, Ix, Enum, - -- Read, Show, Bits, - -- CCallable, CReturnable - -- (last two - - , word8ToWord32 -- :: Word8 -> Word32 - , word32ToWord8 -- :: Word32 -> Word8 - , word16ToWord32 -- :: Word16 -> Word32 - , word32ToWord16 -- :: Word32 -> Word16 - , word8ToInt -- :: Word8 -> Int - , intToWord8 -- :: Int -> Word8 - , word16ToInt -- :: Word16 -> Int - , intToWord16 -- :: Int -> Word16 - , word32ToInt -- :: Word32 -> Int - , intToWord32 -- :: Int -> Word32 - ) where - -import PrelBase -import PrelNum -import PrelRead -import Ix -import GHCerr ( error ) -import Bits -import GHC -import CCall - ------------------------------------------------------------------------------ --- The "official" coercion functions ------------------------------------------------------------------------------ - -word8ToWord32 :: Word8 -> Word32 -word32ToWord8 :: Word32 -> Word8 -word16ToWord32 :: Word16 -> Word32 -word32ToWord16 :: Word32 -> Word16 - -word8ToInt :: Word8 -> Int -intToWord8 :: Int -> Word8 -word16ToInt :: Word16 -> Int -intToWord16 :: Int -> Word16 - -word8ToInt = word32ToInt . word8ToWord32 -intToWord8 = word32ToWord8 . intToWord32 -word16ToInt = word32ToInt . word16ToWord32 -intToWord16 = word32ToWord16 . intToWord32 - -intToWord32 (I# x) = W32# (int2Word# x) -word32ToInt (W32# x) = I# (word2Int# x) -\end{code} - -\subsection[Word8]{The @Word8@ interface} - -The byte type @Word8@ is represented in the Haskell -heap by boxing up a 32-bit quantity, @Word#@. An invariant -for this representation is that the higher 24 bits are -*always* zeroed out. A consequence of this is that -operations that could possibly overflow have to mask -out the top three bytes before building the resulting @Word8@. - -\begin{code} -data Word8 = W8# Word# - -instance CCallable Word8 -instance CReturnable Word8 - -word8ToWord32 (W8# x) = W32# x -word32ToWord8 (W32# x) = W8# (wordToWord8# x) - --- mask out upper three bytes. -intToWord8# :: Int# -> Word# -intToWord8# i# = (int2Word# i#) `and#` (int2Word# 0xff#) - -wordToWord8# :: Word# -> Word# -wordToWord8# w# = w# `and#` (int2Word# 0xff#) - -instance Eq Word8 where - (W8# x) == (W8# y) = x `eqWord#` y - (W8# x) /= (W8# y) = x `neWord#` y - -instance Ord Word8 where - compare (W8# x#) (W8# y#) = compareWord# x# y# - (<) (W8# x) (W8# y) = x `ltWord#` y - (<=) (W8# x) (W8# y) = x `leWord#` y - (>=) (W8# x) (W8# y) = x `geWord#` y - (>) (W8# x) (W8# y) = x `gtWord#` y - max x@(W8# x#) y@(W8# y#) = - case (compareWord# x# y#) of { LT -> y ; EQ -> x ; GT -> x } - min x@(W8# x#) y@(W8# y#) = - case (compareWord# x# y#) of { LT -> x ; EQ -> x ; GT -> y } - --- Helper function, used by Ord Word* instances. -compareWord# :: Word# -> Word# -> Ordering -compareWord# x# y# - | x# `ltWord#` y# = LT - | x# `eqWord#` y# = EQ - | otherwise = GT - -instance Num Word8 where - (W8# x) + (W8# y) = - W8# (intToWord8# (word2Int# x +# word2Int# y)) - (W8# x) - (W8# y) = - W8# (intToWord8# (word2Int# x -# word2Int# y)) - (W8# x) * (W8# y) = - W8# (intToWord8# (word2Int# x *# word2Int# y)) - negate w@(W8# x) = - if x' ==# 0# - then w - else W8# (int2Word# (0x100# -# x')) - where - x' = word2Int# x - abs x = x - signum = signumReal - fromInteger (J# a# s# d#) = W8# (intToWord8# (integer2Int# a# s# d#)) - fromInt = intToWord8 - -instance Bounded Word8 where - minBound = 0 - maxBound = 0xff - -instance Real Word8 where - toRational x = toInteger x % 1 - --- Note: no need to mask results here --- as they cannot overflow. -instance Integral Word8 where - div (W8# x) (W8# y) = W8# (x `quotWord#` y) - quot (W8# x) (W8# y) = W8# (x `quotWord#` y) - rem (W8# x) (W8# y) = W8# (x `remWord#` y) - mod (W8# x) (W8# y) = W8# (x `remWord#` y) - quotRem (W8# x) (W8# y) = (W8# (x `quotWord#` y), W8# (x `remWord#` y)) - divMod (W8# x) (W8# y) = (W8# (x `quotWord#` y), W8# (x `remWord#` y)) - toInteger (W8# x) = word2Integer# x - toInt x = word8ToInt x - -instance Ix Word8 where - range (m,n) = [m..n] - index b@(m,n) i - | inRange b i = word8ToInt (i-m) - | otherwise = error (showString "Ix{Word8}.index: Index " . - showParen True (showsPrec 0 i) . - showString " out of range " $ - showParen True (showsPrec 0 b) "") - inRange (m,n) i = m <= i && i <= n - -instance Enum Word8 where - toEnum (I# i) = W8# (intToWord8# i) - fromEnum (W8# w) = I# (word2Int# w) - enumFrom c = map toEnum [fromEnum c .. fromEnum (maxBound::Word8)] - enumFromThen c d = map toEnum [fromEnum c, fromEnum d .. fromEnum (last::Word8)] - where last = if d < c then minBound else maxBound - -instance Read Word8 where - readsPrec p = readDec - -instance Show Word8 where - showsPrec p = showInt - --- --- Word8s are represented by an (unboxed) 32-bit Word. --- The invariant is that the upper 24 bits are always zeroed out. --- -instance Bits Word8 where - (W8# x) .&. (W8# y) = W8# (x `and#` y) - (W8# x) .|. (W8# y) = W8# (x `or#` y) - (W8# x) `xor` (W8# y) = W8# (x `xor#` y) - complement (W8# x) = W8# (x `xor#` int2Word# 0xff#) - shift (W8# x#) i@(I# i#) - | i > 0 = W8# (wordToWord8# (shiftL# x# i#)) - | otherwise = W8# (wordToWord8# (shiftRL# x# (negateInt# i#))) - w@(W8# x) `rotate` (I# i) - | i ==# 0# = w - | i ># 0# = W8# ((wordToWord8# (shiftL# x i')) `or#` - (shiftRL# (x `and#` - (int2Word# (0x100# -# pow2# i2))) - i2)) - | otherwise = rotate w (I# (8# +# i)) - where - i' = word2Int# (int2Word# i `and#` int2Word# 7#) - i2 = 8# -# i' - - bit (I# i#) - | i# >=# 0# && i# <=# 7# = W8# (wordToWord8# (shiftL# (int2Word# 1#) i#)) - | otherwise = 0 -- We'll be overbearing, for now.. - - setBit x i = x .|. bit i - clearBit x i = x .&. complement (bit i) - complementBit x i = x `xor` bit i - - testBit (W8# x#) (I# i#) - | i# <# 8# && i# >=# 0# = (word2Int# (x# `and#` (shiftL# (int2Word# 1#) i#))) /=# 0# - | otherwise = False -- for now, this is really an error. - - bitSize _ = 8 - isSigned _ = False - -pow2# :: Int# -> Int# -pow2# x# = word2Int# (shiftL# (int2Word# 1#) x#) - -\end{code} - -\subsection[Word16]{The @Word16@ interface} - -The double byte type @Word16@ is represented in the Haskell -heap by boxing up a machine word, @Word#@. An invariant -for this representation is that only the lower 16 bits are -`active', any bits above are {\em always} zeroed out. -A consequence of this is that operations that could possibly -overflow have to mask out anything above the lower two bytes -before putting together the resulting @Word16@. - -\begin{code} -data Word16 = W16# Word# -instance CCallable Word16 -instance CReturnable Word16 - -word16ToWord32 (W16# x) = W32# x -word32ToWord16 (W32# x) = W16# (wordToWord16# x) - --- mask out upper 16 bits. -intToWord16# :: Int# -> Word# -intToWord16# i# = ((int2Word# i#) `and#` (int2Word# 0xffff#)) - -wordToWord16# :: Word# -> Word# -wordToWord16# w# = w# `and#` (int2Word# 0xffff#) - -instance Eq Word16 where - (W16# x) == (W16# y) = x `eqWord#` y - (W16# x) /= (W16# y) = x `neWord#` y - -instance Ord Word16 where - compare (W16# x#) (W16# y#) = compareWord# x# y# - (<) (W16# x) (W16# y) = x `ltWord#` y - (<=) (W16# x) (W16# y) = x `leWord#` y - (>=) (W16# x) (W16# y) = x `geWord#` y - (>) (W16# x) (W16# y) = x `gtWord#` y - max x@(W16# x#) y@(W16# y#) = - case (compareWord# x# y#) of { LT -> y ; EQ -> x ; GT -> x } - min x@(W16# x#) y@(W16# y#) = - case (compareWord# x# y#) of { LT -> x ; EQ -> x ; GT -> y } - -instance Num Word16 where - (W16# x) + (W16# y) = - W16# (intToWord16# (word2Int# x +# word2Int# y)) - (W16# x) - (W16# y) = - W16# (intToWord16# (word2Int# x -# word2Int# y)) - (W16# x) * (W16# y) = - W16# (intToWord16# (word2Int# x *# word2Int# y)) - negate w@(W16# x) = - if x' ==# 0# - then w - else W16# (int2Word# (0x10000# -# x')) - where - x' = word2Int# x - abs x = x - signum = signumReal - fromInteger (J# a# s# d#) = W16# (intToWord16# (integer2Int# a# s# d#)) - fromInt = intToWord16 - -instance Bounded Word16 where - minBound = 0 - maxBound = 0xffff - -instance Real Word16 where - toRational x = toInteger x % 1 - -instance Integral Word16 where - div (W16# x) (W16# y) = W16# (x `quotWord#` y) - quot (W16# x) (W16# y) = W16# (x `quotWord#` y) - rem (W16# x) (W16# y) = W16# (x `remWord#` y) - mod (W16# x) (W16# y) = W16# (x `remWord#` y) - quotRem (W16# x) (W16# y) = (W16# (x `quotWord#` y), W16# (x `remWord#` y)) - divMod (W16# x) (W16# y) = (W16# (x `quotWord#` y), W16# (x `remWord#` y)) - toInteger (W16# x) = word2Integer# x - toInt x = word16ToInt x - -instance Ix Word16 where - range (m,n) = [m..n] - index b@(m,n) i - | inRange b i = word16ToInt (i - m) - | otherwise = error (showString "Ix{Word16}.index: Index " . - showParen True (showsPrec 0 i) . - showString " out of range " $ - showParen True (showsPrec 0 b) "") - inRange (m,n) i = m <= i && i <= n - -instance Enum Word16 where - toEnum (I# i) = W16# (intToWord16# i) - fromEnum (W16# w) = I# (word2Int# w) - enumFrom c = map toEnum [fromEnum c .. fromEnum (maxBound::Word16)] - enumFromThen c d = map toEnum [fromEnum c, fromEnum d .. fromEnum (last::Word16)] - where last = if d < c then minBound else maxBound - -instance Read Word16 where - readsPrec p = readDec - -instance Show Word16 where - showsPrec p = showInt - -instance Bits Word16 where - (W16# x) .&. (W16# y) = W16# (x `and#` y) - (W16# x) .|. (W16# y) = W16# (x `or#` y) - (W16# x) `xor` (W16# y) = W16# (x `xor#` y) - complement (W16# x) = W16# (x `xor#` int2Word# 0xffff#) - shift (W16# x#) i@(I# i#) - | i > 0 = W16# (wordToWord16# (shiftL# x# i#)) - | otherwise = W16# (shiftRL# x# (negateInt# i#)) - w@(W16# x) `rotate` (I# i) - | i ==# 0# = w - | i ># 0# = W16# ((wordToWord16# (shiftL# x i')) `or#` - (shiftRL# (x `and#` - (int2Word# (0x10000# -# pow2# i2))) - i2)) - | otherwise = rotate w (I# (16# +# i')) - where - i' = word2Int# (int2Word# i `and#` int2Word# 15#) - i2 = 16# -# i' - bit (I# i#) - | i# >=# 0# && i# <=# 15# = W16# (shiftL# (int2Word# 1#) i#) - | otherwise = 0 -- We'll be overbearing, for now.. - - setBit x i = x .|. bit i - clearBit x i = x .&. complement (bit i) - complementBit x i = x `xor` bit i - - testBit (W16# x#) (I# i#) - | i# <# 16# && i# >=# 0# = (word2Int# (x# `and#` (shiftL# (int2Word# 1#) i#))) /=# 0# - | otherwise = False -- for now, this is really an error. - - bitSize _ = 16 - isSigned _ = False - -\end{code} - -\subsection[Word32]{The @Word32@ interface} - -The quad byte type @Word32@ is represented in the Haskell -heap by boxing up a machine word, @Word#@. An invariant -for this representation is that any bits above the lower -32 are {\em always} zeroed out. A consequence of this is that -operations that could possibly overflow have to mask -the result before building the resulting @Word16@. - -\begin{code} -data Word32 = W32# Word# -instance CCallable Word32 -instance CReturnable Word32 - -instance Eq Word32 where - (W32# x) == (W32# y) = x `eqWord#` y - (W32# x) /= (W32# y) = x `neWord#` y - -instance Ord Word32 where - compare (W32# x#) (W32# y#) = compareWord# x# y# - (<) (W32# x) (W32# y) = x `ltWord#` y - (<=) (W32# x) (W32# y) = x `leWord#` y - (>=) (W32# x) (W32# y) = x `geWord#` y - (>) (W32# x) (W32# y) = x `gtWord#` y - max x@(W32# x#) y@(W32# y#) = - case (compareWord# x# y#) of { LT -> y ; EQ -> x ; GT -> x } - min x@(W32# x#) y@(W32# y#) = - case (compareWord# x# y#) of { LT -> x ; EQ -> x ; GT -> y } - -instance Num Word32 where - (W32# x) + (W32# y) = - W32# (intToWord32# (word2Int# x +# word2Int# y)) - (W32# x) - (W32# y) = - W32# (intToWord32# (word2Int# x -# word2Int# y)) - (W32# x) * (W32# y) = - W32# (intToWord32# (word2Int# x *# word2Int# y)) -#if WORD_SIZE_IN_BYTES > 4 - negate w@(W32# x) = - if x' ==# 0# - then w - else W32# (intToWord32# (0x100000000# -# x')) - where - x' = word2Int# x -#else - negate (W32# x) = W32# (intToWord32# (negateInt# (word2Int# x))) -#endif - abs x = x - signum = signumReal - fromInteger (J# a# s# d#) = W32# (intToWord32# (integer2Int# a# s# d#)) - fromInt (I# x) = W32# (intToWord32# x) - -- ToDo: restrict fromInt{eger} range. - -intToWord32# :: Int# -> Word# -wordToWord32# :: Word# -> Word# - -#if WORD_SIZE_IN_BYTES > 4 -intToWord32# i# = (int2Word# i#) `and#` (int2Word# 0xffffffff) -wordToWord32# w# = w# `and#` (int2Word# 0xffffffff) -#else -intToWord32# i# = int2Word# i# -wordToWord32# w# = w# -#endif - -instance Bounded Word32 where - minBound = 0 -#if WORD_SIZE_IN_BYTES > 4 - maxBound = 0xffffffff -#else - maxBound = minBound - 1 -#endif - -instance Real Word32 where - toRational x = toInteger x % 1 - -instance Integral Word32 where - div x y = quotWord32 x y - quot x y = quotWord32 x y - rem x y = remWord32 x y - mod x y = remWord32 x y - quotRem a b = (a `quotWord32` b, a `remWord32` b) - divMod x y = quotRem x y - toInteger (W32# x) = word2Integer# x - toInt (W32# x) = I# (word2Int# x) - -{-# INLINE quotWord32 #-} -{-# INLINE remWord32 #-} -(W32# x) `quotWord32` (W32# y) = W32# (x `quotWord#` y) -(W32# x) `remWord32` (W32# y) = W32# (x `remWord#` y) - -instance Ix Word32 where - range (m,n) = [m..n] - index b@(m,n) i - | inRange b i = word32ToInt (i - m) - | otherwise = error (showString "Ix{Word32}.index: Index " . - showParen True (showsPrec 0 i) . - showString " out of range " $ - showParen True (showsPrec 0 b) "") - inRange (m,n) i = m <= i && i <= n - -instance Enum Word32 where - toEnum = intToWord32 - fromEnum = word32ToInt - enumFrom c = map toEnum [fromEnum c .. fromEnum (maxBound::Word32)] - enumFromThen c d = map toEnum [fromEnum c, fromEnum d .. fromEnum (last::Word32)] - where last = if d < c then minBound else maxBound - -instance Read Word32 where - readsPrec p = readDec - -instance Show Word32 where - showsPrec p = showInt - -instance Bits Word32 where - (W32# x) .&. (W32# y) = W32# (x `and#` y) - (W32# x) .|. (W32# y) = W32# (x `or#` y) - (W32# x) `xor` (W32# y) = W32# (x `xor#` y) - complement (W32# x) = W32# (x `xor#` mb#) where (W32# mb#) = maxBound - shift (W32# x) i@(I# i#) - | i > 0 = W32# (wordToWord32# (shiftL# x i#)) - | otherwise = W32# (shiftRL# x (negateInt# i#)) - w@(W32# x) `rotate` (I# i) - | i ==# 0# = w - | i ># 0# = W32# ((wordToWord32# (shiftL# x i')) `or#` - (shiftRL# (x `and#` - (int2Word# (word2Int# maxBound# -# pow2# i2 +# 1#))) - i2)) - | otherwise = rotate w (I# (32# +# i)) - where - i' = word2Int# (int2Word# i `and#` int2Word# 31#) - i2 = 32# -# i' - (W32# maxBound#) = maxBound - - bit (I# i#) - | i# >=# 0# && i# <=# 31# = W32# (shiftL# (int2Word# 1#) i#) - | otherwise = 0 -- We'll be overbearing, for now.. - - setBit x i = x .|. bit i - clearBit x i = x .&. complement (bit i) - complementBit x i = x `xor` bit i - - testBit (W32# x#) (I# i#) - | i# <# 32# && i# >=# 0# = (word2Int# (x# `and#` (shiftL# (int2Word# 1#) i#))) /=# 0# - | otherwise = False -- for now, this is really an error. - bitSize _ = 32 - isSigned _ = False - -\end{code} - -\subsection[Word64]{The @Word64@ interface} - -\begin{code} -data Word64 = W64 {lo,hi::Word32} deriving (Eq, Ord, Bounded) - -w64ToInteger W64{lo,hi} = toInteger lo + 0x100000000 * toInteger hi -integerToW64 x = case x `quotRem` 0x100000000 of - (h,l) -> W64{lo=fromInteger l, hi=fromInteger h} - -instance Show Word64 where - showsPrec p x = showsPrec p (w64ToInteger x) - -instance Read Word64 where - readsPrec p s = [ (integerToW64 x,r) | (x,r) <- readDec s ] - ------------------------------------------------------------------------------ --- End of exported definitions --- --- The remainder of this file consists of definitions which are only --- used in the implementation. ------------------------------------------------------------------------------ - ------------------------------------------------------------------------------ --- Code copied from the Prelude ------------------------------------------------------------------------------ - -signumReal x | x == 0 = 0 - | x > 0 = 1 - | otherwise = -1 - --- showInt is used for positive numbers only --- stolen from Hugs prelude --SDM -showInt :: Integral a => a -> ShowS -showInt n r | n < 0 = error "Word.showInt: can't show negative numbers" - | otherwise = - let (n',d) = quotRem n 10 - r' = toEnum (fromEnum '0' + fromIntegral d) : r - in if n' == 0 then r' else showInt n' r' - -\end{code} |
