[project @ 2002-02-12 11:44:54 by simonmar]
[ghc-hetmet.git] / ghc / lib / std / PrelCTypesISO.lhs
1 % -----------------------------------------------------------------------------
2 % $Id: PrelCTypesISO.lhs,v 1.7 2002/02/04 09:05:46 chak 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 {-# OPTIONS -fno-implicit-prelude #-}
14
15 module PrelCTypesISO
16         ( -- Integral types, instances of: Eq, Ord, Num, Read, Show, Enum,
17           -- Typeable, Storable, Bounded, Real, Integral, Bits
18           CPtrdiff(..), CSize(..), CWchar(..), CSigAtomic(..)
19
20           -- Numeric types, instances of: Eq, Ord, Num, Read, Show, Enum,
21           -- Typeable, Storable
22         , CClock(..),   CTime(..),
23
24           -- Instances of: Eq and Storable
25         , CFile,        CFpos,     CJmpBuf
26         ) where
27 \end{code}
28
29 \begin{code}
30 import PrelBase
31 import PrelFloat
32 import PrelEnum
33 import PrelReal
34 import PrelShow
35 import PrelRead
36 import PrelNum
37 import PrelBase ( unsafeCoerce# )
38 import PrelBits ( Bits(..) )
39 import PrelInt  ( Int8,  Int16,  Int32,  Int64  )
40 import PrelWord ( Word8, Word16, Word32, Word64 )
41 \end{code}
42
43 \begin{code}
44 INTEGRAL_TYPE(CPtrdiff,tyConCPtrdiff,"CPtrdiff",HTYPE_PTRDIFF_T)
45 INTEGRAL_TYPE(CSize,tyConCSize,"CSize",HTYPE_SIZE_T)
46 INTEGRAL_TYPE(CWchar,tyConCWchar,"CWchar",HTYPE_WCHAR_T)
47 INTEGRAL_TYPE(CSigAtomic,tyConCSigAtomic,"CSigAtomic",HTYPE_SIG_ATOMIC_T)
48
49 {-# RULES
50 "fromIntegral/a->CPtrdiff"   fromIntegral = \x -> CPtrdiff   (fromIntegral x)
51 "fromIntegral/a->CSize"      fromIntegral = \x -> CSize      (fromIntegral x)
52 "fromIntegral/a->CWchar"     fromIntegral = \x -> CWchar     (fromIntegral x)
53 "fromIntegral/a->CSigAtomic" fromIntegral = \x -> CSigAtomic (fromIntegral x)
54
55 "fromIntegral/CPtrdiff->a"   fromIntegral = \(CPtrdiff   x) -> fromIntegral x
56 "fromIntegral/CSize->a"      fromIntegral = \(CSize      x) -> fromIntegral x
57 "fromIntegral/CWchar->a"     fromIntegral = \(CWchar     x) -> fromIntegral x
58 "fromIntegral/CSigAtomic->a" fromIntegral = \(CSigAtomic x) -> fromIntegral x
59  #-}
60
61 INTEGRAL_TYPE(CClock,tyConCClock,"CClock",HTYPE_CLOCK_T)
62 INTEGRAL_TYPE(CTime,tyConCTime,"CTime",HTYPE_TIME_T)
63
64 -- FIXME: Implement and provide instances for Eq and Storable
65 data CFile = CFile
66 data CFpos = CFpos
67 data CJmpBuf = CJmpBuf
68
69 -- C99 types which are still missing include:
70 -- intptr_t, uintptr_t, intmax_t, uintmax_t, wint_t, wctrans_t, wctype_t
71 \end{code}