[project @ 2001-02-22 16:48:24 by qrczak]
[ghc-hetmet.git] / ghc / lib / std / PrelCTypesISO.lhs
1 % -----------------------------------------------------------------------------
2 % $Id: PrelCTypesISO.lhs,v 1.5 2001/02/22 16:48:24 qrczak Exp $
3 %
4 % (c) The FFI task force, 2000
5 %
6
7 A mapping of C types defined by the ISO C standard to corresponding Haskell
8 types. Like CTypes, this is a cool hack...
9
10 #include "cbits/CTypes.h"
11
12 \begin{code}
13 module PrelCTypesISO
14         ( -- Integral types, instances of: Eq, Ord, Num, Read, Show, Enum,
15           -- Typeable, Storable, Bounded, Real, Integral, Bits
16           CPtrdiff(..), CSize(..), CWchar(..), CSigAtomic(..)
17
18           -- Numeric types, instances of: Eq, Ord, Num, Read, Show, Enum,
19           -- Typeable, Storable
20         , CClock(..),   CTime(..),
21
22         , CFile,        CFpos,     CJmpBuf
23         ) where
24 \end{code}
25
26 \begin{code}
27 import PrelBase ( unsafeCoerce# )
28 import PrelBits ( Bits(..) )
29 import PrelInt  ( Int8,  Int16,  Int32,  Int64  )
30 import PrelWord ( Word8, Word16, Word32, Word64 )
31 \end{code}
32
33 \begin{code}
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)
38
39 {-# RULES
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)
44
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
49  #-}
50
51 INTEGRAL_TYPE(CClock,tyConCClock,"CClock",HTYPE_CLOCK_T)
52 INTEGRAL_TYPE(CTime,tyConCTime,"CTime",HTYPE_TIME_T)
53
54 -- TODO: Instances. But which...?  :-}
55
56 data CFile = CFile
57
58 data CFpos = CFpos
59
60 data CJmpBuf = CJmpBuf
61
62 -- C99 types which are still missing include:
63 -- intptr_t, uintptr_t, intmax_t, uintmax_t, wint_t, wctrans_t, wctype_t
64 \end{code}