1 % -----------------------------------------------------------------------------
2 % $Id: PrelCTypesISO.lhs,v 1.1 2001/01/11 17:25:57 simonmar 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 PrelReal ( Integral(toInt) )
29 import PrelBits ( Bits(..) )
30 import PrelNum ( Num(fromInt) )
31 import PrelInt ( Int8, Int16, Int32, Int64 )
32 import PrelWord ( Word8, Word16, Word32, Word64 )
36 INTEGRAL_TYPE(CPtrdiff,tyConCPtrdiff,"CPtrdiff",HTYPE_PTRDIFF_T)
37 INTEGRAL_TYPE(CSize,tyConCSize,"CSize",HTYPE_SIZE_T)
38 INTEGRAL_TYPE(CWchar,tyConCWchar,"CWchar",HTYPE_WCHAR_T)
39 INTEGRAL_TYPE(CSigAtomic,tyConCSigAtomic,"CSigAtomic",HTYPE_SIG_ATOMIC_T)
42 "fromIntegral/a->CPtrdiff" fromIntegral = \x -> CPtrdiff (fromIntegral x)
43 "fromIntegral/a->CSize" fromIntegral = \x -> CSize (fromIntegral x)
44 "fromIntegral/a->CWchar" fromIntegral = \x -> CWchar (fromIntegral x)
45 "fromIntegral/a->CSigAtomic" fromIntegral = \x -> CSigAtomic (fromIntegral x)
47 "fromIntegral/CPtrdiff->a" fromIntegral = \(CPtrdiff x) -> fromIntegral x
48 "fromIntegral/CSize->a" fromIntegral = \(CSize x) -> fromIntegral x
49 "fromIntegral/CWchar->a" fromIntegral = \(CWchar x) -> fromIntegral x
50 "fromIntegral/CSigAtomic->a" fromIntegral = \(CSigAtomic x) -> fromIntegral x
53 NUMERIC_TYPE(CClock,tyConCClock,"CClock",HTYPE_CLOCK_T)
54 NUMERIC_TYPE(CTime,tyConCTime,"CTime",HTYPE_TIME_T)
56 -- TODO: Instances. But which...? :-}
62 data CJmpBuf = CJmpBuf
64 -- C99 types which are still missing include:
65 -- intptr_t, uintptr_t, intmax_t, uintmax_t, wint_t, wctrans_t, wctype_t