diff --git a/ghc/lib/std/IO.lhs b/ghc/lib/std/IO.lhs index 7f0eb6ed95d960e54e0410365b86ddbd2f460a49..5fca791aaec0825c2a27a505160fd46fad5dc151 100644 --- a/ghc/lib/std/IO.lhs +++ b/ghc/lib/std/IO.lhs @@ -121,35 +121,6 @@ import Char ( ord, chr ) \end{code} #ifndef __HUGS__ - -Standard instances for @Handle@: - -\begin{code} -instance Eq IOError where - (IOError h1 e1 loc1 str1) == (IOError h2 e2 loc2 str2) = - e1==e2 && str1==str2 && h1==h2 && loc1 == loc2 - -instance Eq Handle where - (Handle h1) == (Handle h2) = h1 == h2 - ---Type declared in IOHandle, instance here because it depends on Eq.Handle -instance Eq HandlePosn where - (HandlePosn h1 p1) == (HandlePosn h2 p2) = p1==p2 && h1==h2 - --- Type declared in IOBase, instance here because it --- depends on PrelRead.(Read Maybe) instance. -instance Read BufferMode where - readsPrec _ = - readParen False - (\r -> let lr = lex r - in - [(NoBuffering, rest) | ("NoBuffering", rest) <- lr] ++ - [(LineBuffering,rest) | ("LineBuffering",rest) <- lr] ++ - [(BlockBuffering mb,rest2) | ("BlockBuffering",rest1) <- lr, - (mb, rest2) <- reads rest1]) - -\end{code} - %********************************************************* %* * \subsection{Simple input operations} diff --git a/ghc/lib/std/PrelAddr.lhs b/ghc/lib/std/PrelAddr.lhs index 510feb69dc61625654191de6d395a9fc63ecda61..70f4a7c0686f64fed88fcb8b0f7681708b03c6a4 100644 --- a/ghc/lib/std/PrelAddr.lhs +++ b/ghc/lib/std/PrelAddr.lhs @@ -36,11 +36,9 @@ plusAddr :: Addr -> Int -> Addr plusAddr (A# addr) (I# off) = A# (int2Addr# (addr2Int# addr +# off)) instance CCallable Addr -instance CCallable Addr# instance CReturnable Addr instance CCallable Word -instance CCallable Word# instance CReturnable Word wordToInt :: Word -> Int @@ -52,9 +50,6 @@ data Int64 = I64# Int# #else data Word64 = W64# Word64# --deriving (Eq, Ord) -- Glasgow extension data Int64 = I64# Int64# --deriving (Eq, Ord) -- Glasgow extension - -instance CCallable Word64# -instance CCallable Int64# #endif instance CCallable Word64 diff --git a/ghc/lib/std/PrelArr.lhs b/ghc/lib/std/PrelArr.lhs index dea699a9002e99a5b46968391c6d13b11a8f6848..e1d1f2b7ce7ce7c86d5e7b78e004b0d5afa837c4 100644 --- a/ghc/lib/std/PrelArr.lhs +++ b/ghc/lib/std/PrelArr.lhs @@ -59,10 +59,7 @@ data Ix ix => MutableArray s ix elt = MutableArray ix ix (MutableArray# data Ix ix => MutableByteArray s ix = MutableByteArray ix ix (MutableByteArray# s) instance CCallable (MutableByteArray s ix) -instance CCallable (MutableByteArray# s) - instance CCallable (ByteArray ix) -instance CCallable ByteArray# data MutableVar s a = MutableVar (MutVar# s a) diff --git a/ghc/lib/std/PrelBase.lhs b/ghc/lib/std/PrelBase.lhs index 9f8cb50f846ca8a4bf9a9bc97458e1b15139c7a4..89b069444830c7787610c567950a98303bbc6d69 100644 --- a/ghc/lib/std/PrelBase.lhs +++ b/ghc/lib/std/PrelBase.lhs @@ -382,6 +382,47 @@ instance Eq Integer where (S# i) /= (J# s d) = cmpIntegerInt# s d i /=# 0# (J# s d) /= (S# i) = cmpIntegerInt# s d i /=# 0# (J# s1 d1) /= (J# s2 d2) = (cmpInteger# s1 d1 s2 d2) /=# 0# + +instance Ord Integer where + (S# i) <= (S# j) = i <=# j + (J# s d) <= (S# i) = cmpIntegerInt# s d i <=# 0# + (S# i) <= (J# s d) = cmpIntegerInt# s d i >=# 0# + (J# s1 d1) <= (J# s2 d2) = (cmpInteger# s1 d1 s2 d2) <=# 0# + + (S# i) > (S# j) = i ># j + (J# s d) > (S# i) = cmpIntegerInt# s d i ># 0# + (S# i) > (J# s d) = cmpIntegerInt# s d i <# 0# + (J# s1 d1) > (J# s2 d2) = (cmpInteger# s1 d1 s2 d2) ># 0# + + (S# i) < (S# j) = i <# j + (J# s d) < (S# i) = cmpIntegerInt# s d i <# 0# + (S# i) < (J# s d) = cmpIntegerInt# s d i ># 0# + (J# s1 d1) < (J# s2 d2) = (cmpInteger# s1 d1 s2 d2) <# 0# + + (S# i) >= (S# j) = i >=# j + (J# s d) >= (S# i) = cmpIntegerInt# s d i >=# 0# + (S# i) >= (J# s d) = cmpIntegerInt# s d i <=# 0# + (J# s1 d1) >= (J# s2 d2) = (cmpInteger# s1 d1 s2 d2) >=# 0# + + compare (S# i) (S# j) + | i ==# j = EQ + | i <=# j = LT + | otherwise = GT + compare (J# s d) (S# i) + = case cmpIntegerInt# s d i of { res# -> + if res# <# 0# then LT else + if res# ># 0# then GT else EQ + } + compare (S# i) (J# s d) + = case cmpIntegerInt# s d i of { res# -> + if res# ># 0# then LT else + if res# <# 0# then GT else EQ + } + compare (J# s1 d1) (J# s2 d2) + = case cmpInteger# s1 d1 s2 d2 of { res# -> + if res# <# 0# then LT else + if res# ># 0# then GT else EQ + } \end{code} diff --git a/ghc/lib/std/PrelCCall.lhs b/ghc/lib/std/PrelCCall.lhs index 55266993cc462a1db927f3703a5b37859314caec..d8c1eb4f4b487f5772a9e1fd8918ffa2a265e957 100644 --- a/ghc/lib/std/PrelCCall.lhs +++ b/ghc/lib/std/PrelCCall.lhs @@ -24,22 +24,18 @@ import PrelGHC \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 instance CReturnable () -- Why, exactly? diff --git a/ghc/lib/std/PrelConc.lhs b/ghc/lib/std/PrelConc.lhs index 320ebff427b9c90749044dbc80aaec0d22b1b8ad..e327827f48c3b8a16bf53f531f0342a9eb03ced3 100644 --- a/ghc/lib/std/PrelConc.lhs +++ b/ghc/lib/std/PrelConc.lhs @@ -119,9 +119,6 @@ writes. \begin{code} --Defined in IOBase to avoid cycle: data MVar a = MVar (SynchVar# RealWorld a) -instance Eq (MVar a) where - (MVar mvar1#) == (MVar mvar2#) = sameMVar# mvar1# mvar2# - newEmptyMVar :: IO (MVar a) newEmptyMVar = IO $ \ s# -> diff --git a/ghc/lib/std/PrelForeign.lhs b/ghc/lib/std/PrelForeign.lhs index ed575ef6040d161affb4b2e5228cce688d5b4c7e..4dc8f3f5ecd86e224c30c579713a7b54ef81dd0a 100644 --- a/ghc/lib/std/PrelForeign.lhs +++ b/ghc/lib/std/PrelForeign.lhs @@ -41,21 +41,11 @@ makeForeignObj (A# obj) = IO ( \ s# -> case makeForeignObj# obj s# of (# s1#, fo# #) -> (# s1#, ForeignObj fo# #) ) -eqForeignObj :: ForeignObj -> ForeignObj -> Bool --makeForeignObj :: Addr -> Addr -> IO ForeignObj writeForeignObj :: ForeignObj -> Addr -> IO () writeForeignObj (ForeignObj fo#) (A# datum#) = IO ( \ s# -> case writeForeignObj# fo# datum# s# of { s1# -> (# s1#, () #) } ) - -eqForeignObj mp1 mp2 - = unsafePerformIO (primEqForeignObj mp1 mp2) /= (0::Int) - -foreign import "eqForeignObj" unsafe primEqForeignObj :: ForeignObj -> ForeignObj -> IO Int - -instance Eq ForeignObj where - p == q = eqForeignObj p q - p /= q = not (eqForeignObj p q) #endif /* !__PARALLEL_HASKELL__ */ \end{code} diff --git a/ghc/lib/std/PrelHandle.lhs b/ghc/lib/std/PrelHandle.lhs index 89bbef2358a27585111c284c3bb8b0697cc15e62..5e32122c47c09779fd6f41ac28951439a8d5cbe3 100644 --- a/ghc/lib/std/PrelHandle.lhs +++ b/ghc/lib/std/PrelHandle.lhs @@ -177,9 +177,9 @@ mkErrorHandle__ ioe = %********************************************************* \begin{code} -foreign import "libHS_cbits" "freeStdFileObject" +foreign import "libHS_cbits" "freeStdFileObject" unsafe freeStdFileObject :: FILE_OBJECT -> IO () -foreign import "libHS_cbits" "freeFileObject" +foreign import "libHS_cbits" "freeFileObject" unsafe freeFileObject :: FILE_OBJECT -> IO () \end{code} @@ -554,6 +554,9 @@ data HandlePosn -- [what's the winning argument for it not being strong? --sof] HandlePosition +instance Eq HandlePosn where + (HandlePosn h1 p1) == (HandlePosn h2 p2) = p1==p2 && h1==h2 + -- HandlePosition is the Haskell equivalent of POSIX' off_t. -- We represent it as an Integer on the Haskell side, but -- cheat slightly in that hGetPosn calls upon a C helper diff --git a/ghc/lib/std/PrelIOBase.lhs b/ghc/lib/std/PrelIOBase.lhs index caa50db1f8b10beb8b4e56f4ed3a43c4e91b4c7f..1dd7d7606895081708141f2f28f78017f2de0c24 100644 --- a/ghc/lib/std/PrelIOBase.lhs +++ b/ghc/lib/std/PrelIOBase.lhs @@ -1,5 +1,5 @@ % ----------------------------------------------------------------------------- -% $Id: PrelIOBase.lhs,v 1.13 1999/09/19 19:12:41 sof Exp $ +% $Id: PrelIOBase.lhs,v 1.14 1999/11/22 15:55:51 simonmar Exp $ % % (c) The AQUA Project, Glasgow University, 1994-1998 % @@ -146,6 +146,9 @@ data IOError String -- location String -- error type specific information. +instance Eq IOError where + (IOError h1 e1 loc1 str1) == (IOError h2 e2 loc2 str2) = + e1==e2 && str1==str2 && h1==h2 && loc1 == loc2 data IOErrorType = AlreadyExists | HardwareFault @@ -367,12 +370,25 @@ a handles reside in @IOHandle@. -} data MVar a = MVar (MVar# RealWorld a) +-- pull in Eq (Mvar a) too, to avoid PrelConc being an orphan-instance module +instance Eq (MVar a) where + (MVar mvar1#) == (MVar mvar2#) = sameMVar# mvar1# mvar2# + {- Double sigh - ForeignObj is needed here too to break a cycle. -} data ForeignObj = ForeignObj ForeignObj# -- another one instance CCallable ForeignObj -instance CCallable ForeignObj# + +eqForeignObj :: ForeignObj -> ForeignObj -> Bool +eqForeignObj mp1 mp2 + = unsafePerformIO (primEqForeignObj mp1 mp2) /= (0::Int) + +foreign import "eqForeignObj" unsafe primEqForeignObj :: ForeignObj -> ForeignObj -> IO Int + +instance Eq ForeignObj where + p == q = eqForeignObj p q + p /= q = not (eqForeignObj p q) #endif /* ndef __HUGS__ */ #if defined(__CONCURRENT_HASKELL__) @@ -381,6 +397,9 @@ newtype Handle = Handle (MVar Handle__) newtype Handle = Handle (MutableVar RealWorld Handle__) #endif +instance Eq Handle where + (Handle h1) == (Handle h2) = h1 == h2 + {- A Handle is represented by (a reference to) a record containing the state of the I/O port/device. We record diff --git a/ghc/lib/std/PrelNum.lhs b/ghc/lib/std/PrelNum.lhs index 7c70f0f037bd35c41ec219aeee040d2fb39d6eb8..34ce2967aa1a499a1eb82d0f891298f7105b4103 100644 --- a/ghc/lib/std/PrelNum.lhs +++ b/ghc/lib/std/PrelNum.lhs @@ -205,47 +205,6 @@ instance Integral Int where %********************************************************* \begin{code} -instance Ord Integer where - (S# i) <= (S# j) = i <=# j - (J# s d) <= (S# i) = cmpIntegerInt# s d i <=# 0# - (S# i) <= (J# s d) = cmpIntegerInt# s d i >=# 0# - (J# s1 d1) <= (J# s2 d2) = (cmpInteger# s1 d1 s2 d2) <=# 0# - - (S# i) > (S# j) = i ># j - (J# s d) > (S# i) = cmpIntegerInt# s d i ># 0# - (S# i) > (J# s d) = cmpIntegerInt# s d i <# 0# - (J# s1 d1) > (J# s2 d2) = (cmpInteger# s1 d1 s2 d2) ># 0# - - (S# i) < (S# j) = i <# j - (J# s d) < (S# i) = cmpIntegerInt# s d i <# 0# - (S# i) < (J# s d) = cmpIntegerInt# s d i ># 0# - (J# s1 d1) < (J# s2 d2) = (cmpInteger# s1 d1 s2 d2) <# 0# - - (S# i) >= (S# j) = i >=# j - (J# s d) >= (S# i) = cmpIntegerInt# s d i >=# 0# - (S# i) >= (J# s d) = cmpIntegerInt# s d i <=# 0# - (J# s1 d1) >= (J# s2 d2) = (cmpInteger# s1 d1 s2 d2) >=# 0# - - compare (S# i) (S# j) - | i ==# j = EQ - | i <=# j = LT - | otherwise = GT - compare (J# s d) (S# i) - = case cmpIntegerInt# s d i of { res# -> - if res# <# 0# then LT else - if res# ># 0# then GT else EQ - } - compare (S# i) (J# s d) - = case cmpIntegerInt# s d i of { res# -> - if res# ># 0# then LT else - if res# <# 0# then GT else EQ - } - compare (J# s1 d1) (J# s2 d2) - = case cmpInteger# s1 d1 s2 d2 of { res# -> - if res# <# 0# then LT else - if res# ># 0# then GT else EQ - } - toBig (S# i) = case int2Integer# i of { (# s, d #) -> J# s d } toBig i@(J# _ _) = i @@ -405,14 +364,19 @@ dn_list x delta lim = go (x::Integer) "enumDeltaInteger" enumDeltaIntegerFB (:) = enumDeltaIntegerList "enumDeltaToInteger" enumDeltaToIntegerFB (:) [] = enumDeltaToIntegerList #-} +\end{code} ------------------------------------------------------------------------- +%********************************************************* +%* * +\subsection{Show code for Integers} +%* * +%********************************************************* +\begin{code} instance Show Integer where showsPrec x = showSignedInteger x showList = showList__ (showsPrec 0) - showSignedInteger :: Int -> Integer -> ShowS showSignedInteger p n r | n < 0 && p > 6 = '(':jtos n (')':r) diff --git a/ghc/lib/std/PrelRead.lhs b/ghc/lib/std/PrelRead.lhs index 596b0c75a8148f269e488068455a0904b36ccbdf..6c8da898ffe3ae4b14f0b5121cdfedc89aef7014 100644 --- a/ghc/lib/std/PrelRead.lhs +++ b/ghc/lib/std/PrelRead.lhs @@ -22,8 +22,8 @@ import PrelShow -- isAlpha etc import PrelBase import Monad --- needed for readIO. -import PrelIOBase ( IO, userError ) +-- needed for readIO and instance Read Buffermode +import PrelIOBase ( IO, userError, BufferMode(..) ) import PrelException ( ioError ) \end{code} @@ -604,3 +604,26 @@ readRational__ top_s #endif \end{code} + +%********************************************************* +%* * +\subsection{Reading BufferMode} +%* * +%********************************************************* + +This instance decl is here rather than somewhere more appropriate in +order that we can avoid both orphan-instance modules and recursive +dependencies. + +\begin{code} +instance Read BufferMode where + readsPrec _ = + readParen False + (\r -> let lr = lex r + in + [(NoBuffering, rest) | ("NoBuffering", rest) <- lr] ++ + [(LineBuffering,rest) | ("LineBuffering",rest) <- lr] ++ + [(BlockBuffering mb,rest2) | ("BlockBuffering",rest1) <- lr, + (mb, rest2) <- reads rest1]) + +\end{code} diff --git a/ghc/lib/std/PrelShow.lhs b/ghc/lib/std/PrelShow.lhs index c6312650e6ba1f326fb47a83b46fcb747fdb3c9c..44e336482d5ffad51b2e04a4755e8c3b66d37870 100644 --- a/ghc/lib/std/PrelShow.lhs +++ b/ghc/lib/std/PrelShow.lhs @@ -245,8 +245,6 @@ itos n r (C# (chr# (x `remInt#` 10# +# ord# '0'#)) : cs) \end{code} - - %********************************************************* %* * \subsection{Character stuff}