[project @ 2001-01-11 17:25:56 by simonmar]
[ghc-hetmet.git] / ghc / lib / std / PrelCTypesISO.lhs
1 % -----------------------------------------------------------------------------
2 % $Id: PrelCTypesISO.lhs,v 1.1 2001/01/11 17:25:57 simonmar 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 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 )
33 \end{code}
34
35 \begin{code}
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)
40
41 {-# RULES
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)
46
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
51  #-}
52
53 NUMERIC_TYPE(CClock,tyConCClock,"CClock",HTYPE_CLOCK_T)
54 NUMERIC_TYPE(CTime,tyConCTime,"CTime",HTYPE_TIME_T)
55
56 -- TODO: Instances. But which...?  :-}
57
58 data CFile = CFile
59
60 data CFpos = CFpos
61
62 data CJmpBuf = CJmpBuf
63
64 -- C99 types which are still missing include:
65 -- intptr_t, uintptr_t, intmax_t, uintmax_t, wint_t, wctrans_t, wctype_t
66 \end{code}