1 % -----------------------------------------------------------------------------
2 % $Id: PrelCTypesISO.lhs,v 1.5 2001/02/22 16:48:24 qrczak Exp $
4 % (c) The FFI task force, 2000
7 A mapping of C types defined by the ISO C standard to corresponding Haskell
8 types. Like CTypes, this is a cool hack...
10 #include "cbits/CTypes.h"
14 ( -- Integral types, instances of: Eq, Ord, Num, Read, Show, Enum,
15 -- Typeable, Storable, Bounded, Real, Integral, Bits
16 CPtrdiff(..), CSize(..), CWchar(..), CSigAtomic(..)
18 -- Numeric types, instances of: Eq, Ord, Num, Read, Show, Enum,
20 , CClock(..), CTime(..),
22 , CFile, CFpos, CJmpBuf
27 import PrelBase ( unsafeCoerce# )
28 import PrelBits ( Bits(..) )
29 import PrelInt ( Int8, Int16, Int32, Int64 )
30 import PrelWord ( Word8, Word16, Word32, Word64 )
34 INTEGRAL_TYPE(CPtrdiff,tyConCPtrdiff,"CPtrdiff",HTYPE_PTRDIFF_T)
35 INTEGRAL_TYPE(CSize,tyConCSize,"CSize",HTYPE_SIZE_T)
36 INTEGRAL_TYPE(CWchar,tyConCWchar,"CWchar",HTYPE_WCHAR_T)
37 INTEGRAL_TYPE(CSigAtomic,tyConCSigAtomic,"CSigAtomic",HTYPE_SIG_ATOMIC_T)
40 "fromIntegral/a->CPtrdiff" fromIntegral = \x -> CPtrdiff (fromIntegral x)
41 "fromIntegral/a->CSize" fromIntegral = \x -> CSize (fromIntegral x)
42 "fromIntegral/a->CWchar" fromIntegral = \x -> CWchar (fromIntegral x)
43 "fromIntegral/a->CSigAtomic" fromIntegral = \x -> CSigAtomic (fromIntegral x)
45 "fromIntegral/CPtrdiff->a" fromIntegral = \(CPtrdiff x) -> fromIntegral x
46 "fromIntegral/CSize->a" fromIntegral = \(CSize x) -> fromIntegral x
47 "fromIntegral/CWchar->a" fromIntegral = \(CWchar x) -> fromIntegral x
48 "fromIntegral/CSigAtomic->a" fromIntegral = \(CSigAtomic x) -> fromIntegral x
51 INTEGRAL_TYPE(CClock,tyConCClock,"CClock",HTYPE_CLOCK_T)
52 INTEGRAL_TYPE(CTime,tyConCTime,"CTime",HTYPE_TIME_T)
54 -- TODO: Instances. But which...? :-}
60 data CJmpBuf = CJmpBuf
62 -- C99 types which are still missing include:
63 -- intptr_t, uintptr_t, intmax_t, uintmax_t, wint_t, wctrans_t, wctype_t