1 % -----------------------------------------------------------------------------
2 % $Id: PrelCTypesISO.lhs,v 1.6 2001/05/18 16:54:05 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"
13 {-# OPTIONS -fno-implicit-prelude #-}
16 ( -- Integral types, instances of: Eq, Ord, Num, Read, Show, Enum,
17 -- Typeable, Storable, Bounded, Real, Integral, Bits
18 CPtrdiff(..), CSize(..), CWchar(..), CSigAtomic(..)
20 -- Numeric types, instances of: Eq, Ord, Num, Read, Show, Enum,
22 , CClock(..), CTime(..),
24 , CFile, CFpos, CJmpBuf
36 import PrelBase ( unsafeCoerce# )
37 import PrelBits ( Bits(..) )
38 import PrelInt ( Int8, Int16, Int32, Int64 )
39 import PrelWord ( Word8, Word16, Word32, Word64 )
43 INTEGRAL_TYPE(CPtrdiff,tyConCPtrdiff,"CPtrdiff",HTYPE_PTRDIFF_T)
44 INTEGRAL_TYPE(CSize,tyConCSize,"CSize",HTYPE_SIZE_T)
45 INTEGRAL_TYPE(CWchar,tyConCWchar,"CWchar",HTYPE_WCHAR_T)
46 INTEGRAL_TYPE(CSigAtomic,tyConCSigAtomic,"CSigAtomic",HTYPE_SIG_ATOMIC_T)
49 "fromIntegral/a->CPtrdiff" fromIntegral = \x -> CPtrdiff (fromIntegral x)
50 "fromIntegral/a->CSize" fromIntegral = \x -> CSize (fromIntegral x)
51 "fromIntegral/a->CWchar" fromIntegral = \x -> CWchar (fromIntegral x)
52 "fromIntegral/a->CSigAtomic" fromIntegral = \x -> CSigAtomic (fromIntegral x)
54 "fromIntegral/CPtrdiff->a" fromIntegral = \(CPtrdiff x) -> fromIntegral x
55 "fromIntegral/CSize->a" fromIntegral = \(CSize x) -> fromIntegral x
56 "fromIntegral/CWchar->a" fromIntegral = \(CWchar x) -> fromIntegral x
57 "fromIntegral/CSigAtomic->a" fromIntegral = \(CSigAtomic x) -> fromIntegral x
60 INTEGRAL_TYPE(CClock,tyConCClock,"CClock",HTYPE_CLOCK_T)
61 INTEGRAL_TYPE(CTime,tyConCTime,"CTime",HTYPE_TIME_T)
63 -- TODO: Instances. But which...? :-}
69 data CJmpBuf = CJmpBuf
71 -- C99 types which are still missing include:
72 -- intptr_t, uintptr_t, intmax_t, uintmax_t, wint_t, wctrans_t, wctype_t