-- Removing all fixities is a fairly safe fix; fixing the "one fixity
-- per symbol per program" limitation in Hugs would take a lot longer.
#ifndef __HUGS__
-infixl 8 `shift`, `rotate`
+infixl 8 `shift`, `rotate`, `shiftL`, `shiftR`, `rotateL`, `rotateR`
infixl 7 .&.
infixl 6 `xor`
infixl 5 .|.
% -----------------------------------------------------------------------------
-% $Id: PrelCTypes.lhs,v 1.4 2001/05/18 16:54:05 simonmar Exp $
+% $Id: PrelCTypes.lhs,v 1.5 2002/02/04 09:05:46 chak Exp $
%
% (c) The FFI task force, 2000
%
module PrelCTypes
( -- Integral types, instances of: Eq, Ord, Num, Read, Show, Enum,
-- Typeable, Storable, Bounded, Real, Integral, Bits
- CChar(..), CSChar(..), CUChar(..)
- , CShort(..), CUShort(..), CInt(..), CUInt(..)
- , CLong(..), CULong(..), CLLong(..), CULLong(..)
+ CChar(..), CSChar(..), CUChar(..)
+ , CShort(..), CUShort(..), CInt(..), CUInt(..)
+ , CLong(..), CULong(..), CLLong(..), CULLong(..)
-- Floating types, instances of: Eq, Ord, Num, Read, Show, Enum,
- -- Typeable, Storable, Real, Fractional, Floating, RealFrac, RealFloat
- , CFloat(..), CDouble(..), CLDouble(..)
+ -- Typeable, Storable, Real, Fractional, Floating, RealFrac,
+ -- RealFloat
+ , CFloat(..), CDouble(..), CLDouble(..)
) where
\end{code}
% -----------------------------------------------------------------------------
-% $Id: PrelCTypesISO.lhs,v 1.6 2001/05/18 16:54:05 simonmar Exp $
+% $Id: PrelCTypesISO.lhs,v 1.7 2002/02/04 09:05:46 chak Exp $
%
% (c) The FFI task force, 2000
%
-- Typeable, Storable
, CClock(..), CTime(..),
+ -- Instances of: Eq and Storable
, CFile, CFpos, CJmpBuf
) where
\end{code}
INTEGRAL_TYPE(CClock,tyConCClock,"CClock",HTYPE_CLOCK_T)
INTEGRAL_TYPE(CTime,tyConCTime,"CTime",HTYPE_TIME_T)
--- TODO: Instances. But which...? :-}
-
+-- FIXME: Implement and provide instances for Eq and Storable
data CFile = CFile
-
data CFpos = CFpos
-
data CJmpBuf = CJmpBuf
-- C99 types which are still missing include:
% -----------------------------------------------------------------------------
-% $Id: PrelMarshalArray.lhs,v 1.8 2001/08/15 09:54:38 qrczak Exp $
+% $Id: PrelMarshalArray.lhs,v 1.9 2002/02/04 09:05:46 chak Exp $
%
% (c) The FFI task force, 2000
%
withArray, -- :: Storable a => [a] -> (Ptr a -> IO b) -> IO b
withArray0, -- :: Storable a => a -> [a] -> (Ptr a -> IO b) -> IO b
- -- destruction
- --
- destructArray, -- :: Storable a => Int -> Ptr a -> IO ()
- destructArray0, -- :: (Storable a, Eq a) => a -> Ptr a -> IO ()
-
-- copying (argument order: destination, source)
--
copyArray, -- :: Storable a => Ptr a -> Ptr a -> Int -> IO ()
-- indexing
--
- advancePtr -- :: Storable a => Ptr a -> Int -> Ptr a
+ advancePtr, -- :: Storable a => Ptr a -> Int -> Ptr a
+
+ -- DEPRECATED: Don't use!
+ destructArray, -- :: Storable a => Int -> Ptr a -> IO ()
+ destructArray0, -- :: (Storable a, Eq a) => a -> Ptr a -> IO ()
) where
import Monad
-- destruct each element of an array (in reverse order)
--
destructArray :: Storable a => Int -> Ptr a -> IO ()
+{-# DEPRECATED destructArray "This function is not standards complaint" #-}
destructArray size ptr =
sequence_ [destruct (ptr `advancePtr` i)
| i <- [size-1, size-2 .. 0]]
-- like `destructArray', but a terminator indicates where the array ends
--
destructArray0 :: (Storable a, Eq a) => a -> Ptr a -> IO ()
+{-# DEPRECATED destructArray0 "This function is not standards complaint" #-}
destructArray0 marker ptr = do
size <- lengthArray0 marker ptr
sequence_ [destruct (ptr `advancePtr` i)
% -----------------------------------------------------------------------------
-% $Id: PrelMarshalError.lhs,v 1.2 2001/05/18 16:54:05 simonmar Exp $
+% $Id: PrelMarshalError.lhs,v 1.3 2002/02/04 09:05:46 chak Exp $
%
-% (c) The FFI task force, 2000
+% (c) The FFI task force, [2000..2002]
%
Marshalling support: Handling of common error conditions
module PrelMarshalError (
+ -- I/O errors
+ -- ----------
+
+ IOErrorType, -- abstract data type
+
+ mkIOError, -- :: IOErrorType
+ -- -> String
+ -- -> Maybe FilePath
+ -- -> Maybe Handle
+ -- -> IOError
+
+ alreadyExistsErrorType, -- :: IOErrorType
+ doesNotExistErrorType, -- :: IOErrorType
+ alreadyInUseErrorType, -- :: IOErrorType
+ fullErrorType, -- :: IOErrorType
+ eofErrorType, -- :: IOErrorType
+ illegalOperationType, -- :: IOErrorType
+ permissionErrorType, -- :: IOErrorType
+ userErrorType, -- :: IOErrorType
+
+ annotateIOError, -- :: IOError
+ -- -> String
+ -- -> Maybe FilePath
+ -- -> Maybe Handle
+ -- -> IOError
+
+ -- Result value checks
+ -- -------------------
+
-- throw an exception on specific return values
--
throwIf, -- :: (a -> Bool) -> (a -> String) -> IO a -> IO a
import PrelPtr
import PrelIOBase
+import PrelMaybe
import PrelNum
import PrelBase
--- exported functions
--- ------------------
+
+-- I/O errors
+-- ----------
+
+-- construct an IO error
+--
+mkIOError :: IOErrorType -> String -> Maybe FilePath -> Maybe Handle -> IOError
+mkIOError errTy loc path hdl =
+ IOException $ IOError hdl errTy loc "" path
+
+-- pre-defined error types corresponding to the predicates in the standard
+-- library `IO'
+--
+alreadyExistsErrorType, doesNotExistErrorType, alreadyInUseErrorType,
+ fullErrorType, eofErrorType, illegalOperationType, permissionErrorType,
+ userErrorType :: IOErrorType
+alreadyExistsErrorType = AlreadyExists
+doesNotExistErrorType = NoSuchThing
+alreadyInUseErrorType = ResourceBusy
+fullErrorType = ResourceExhausted
+eofErrorType = EOF
+illegalOperationType = IllegalOperation
+permissionErrorType = PermissionDenied
+userErrorType = OtherError
+
+-- add location information and possibly a path and handle to an existing I/O
+-- error
+--
+-- * if no file path or handle is given, the corresponding value that's in the
+-- error is left unaltered
+--
+annotateIOError :: IOError
+ -> String
+ -> Maybe FilePath
+ -> Maybe Handle
+ -> IOError
+annotateIOError (IOException (IOError hdl errTy _ str path)) loc opath ohdl =
+ IOException (IOError (hdl `mplus` ohdl) errTy loc str (path `mplus` opath))
+ where
+ Nothing `mplus` ys = ys
+ xs `mplus` _ = xs
+annotateIOError exc _ _ _ =
+ exc
+
+
+-- Result value checks
+-- -------------------
-- guard an IO operation and throw an exception if the result meets the given
-- predicate
% -----------------------------------------------------------------------------
-% $Id: PrelStorable.lhs,v 1.10 2001/10/03 13:57:42 simonmar Exp $
+% $Id: PrelStorable.lhs,v 1.11 2002/02/04 09:05:46 chak Exp $
%
% (c) The FFI task force, 2000
%
pokeByteOff, -- :: Ptr b -> Int -> a -> IO ()
peek, -- :: Ptr a -> IO a
poke, -- :: Ptr a -> a -> IO ()
+
+ -- DEPRECATED: Don't use!
destruct) -- :: Ptr a -> IO ()
) where
\end{code}
poke ptr = pokeElemOff ptr 0
destruct _ = return ()
+{-# DEPRECATED destruct "This function is not standards complaint" #-}
\end{code}
System-dependent, but rather obvious instances