6e430aa632125451127206d85d0c58f6ab1e501f
[ghc-hetmet.git] / ghc / lib / std / PrelCTypesISO.lhs
1 % -----------------------------------------------------------------------------
2 % $Id: PrelCTypesISO.lhs,v 1.6 2001/05/18 16:54:05 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 {-# 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         , CFile,        CFpos,     CJmpBuf
25         ) where
26 \end{code}
27
28 \begin{code}
29 import PrelBase
30 import PrelFloat
31 import PrelEnum
32 import PrelReal
33 import PrelShow
34 import PrelRead
35 import PrelNum
36 import PrelBase ( unsafeCoerce# )
37 import PrelBits ( Bits(..) )
38 import PrelInt  ( Int8,  Int16,  Int32,  Int64  )
39 import PrelWord ( Word8, Word16, Word32, Word64 )
40 \end{code}
41
42 \begin{code}
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)
47
48 {-# RULES
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)
53
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
58  #-}
59
60 INTEGRAL_TYPE(CClock,tyConCClock,"CClock",HTYPE_CLOCK_T)
61 INTEGRAL_TYPE(CTime,tyConCTime,"CTime",HTYPE_TIME_T)
62
63 -- TODO: Instances. But which...?  :-}
64
65 data CFile = CFile
66
67 data CFpos = CFpos
68
69 data CJmpBuf = CJmpBuf
70
71 -- C99 types which are still missing include:
72 -- intptr_t, uintptr_t, intmax_t, uintmax_t, wint_t, wctrans_t, wctype_t
73 \end{code}