[project @ 2002-04-26 13:34:05 by simonmar]
[packages/old-locale.git] / Foreign / C / TypesISO.hs
1 {-# OPTIONS -fno-implicit-prelude #-}
2 -----------------------------------------------------------------------------
3 -- |
4 -- Module : Foreign.C.TypesISO
5 -- Copyright : (c) The FFI task force 2001
6 -- License : BSD-style (see the file libraries/core/LICENSE)
7 --
8 -- Maintainer : ffi@haskell.org
9 -- Stability : provisional
10 -- Portability : portable
11 --
12 -- A mapping of C types defined by the ISO C standard to corresponding Haskell
13 -- types. Like CTypes, this is a cool hack...
14 --
15 -----------------------------------------------------------------------------
16
17 module Foreign.C.TypesISO
18 ( -- Integral types, instances of: Eq, Ord, Num, Read, Show, Enum,
19 -- Typeable, Storable, Bounded, Real, Integral, Bits
20 CPtrdiff(..), CSize(..), CWchar(..), CSigAtomic(..)
21
22 -- Numeric types, instances of: Eq, Ord, Num, Read, Show, Enum,
23 -- Typeable, Storable
24 , CClock(..), CTime(..),
25
26 -- Instances of: Eq and Storable
27 , CFile, CFpos, CJmpBuf
28 ) where
29
30 import Data.Bits ( Bits(..) )
31 import Data.Int
32 import Data.Word
33 import Data.Dynamic
34
35 #ifdef __GLASGOW_HASKELL__
36 import GHC.Base
37 import GHC.Enum
38 import GHC.Real
39 import GHC.Show
40 import GHC.Read
41 import GHC.Num
42 #endif
43
44 #include "CTypes.h"
45
46 INTEGRAL_TYPE(CPtrdiff,tyConCPtrdiff,"CPtrdiff",HTYPE_PTRDIFF_T)
47 INTEGRAL_TYPE(CSize,tyConCSize,"CSize",HTYPE_SIZE_T)
48 INTEGRAL_TYPE(CWchar,tyConCWchar,"CWchar",HTYPE_WCHAR_T)
49 INTEGRAL_TYPE(CSigAtomic,tyConCSigAtomic,"CSigAtomic",HTYPE_SIG_ATOMIC_T)
50
51 {-# RULES
52 "fromIntegral/a->CPtrdiff" fromIntegral = \x -> CPtrdiff (fromIntegral x)
53 "fromIntegral/a->CSize" fromIntegral = \x -> CSize (fromIntegral x)
54 "fromIntegral/a->CWchar" fromIntegral = \x -> CWchar (fromIntegral x)
55 "fromIntegral/a->CSigAtomic" fromIntegral = \x -> CSigAtomic (fromIntegral x)
56
57 "fromIntegral/CPtrdiff->a" fromIntegral = \(CPtrdiff x) -> fromIntegral x
58 "fromIntegral/CSize->a" fromIntegral = \(CSize x) -> fromIntegral x
59 "fromIntegral/CWchar->a" fromIntegral = \(CWchar x) -> fromIntegral x
60 "fromIntegral/CSigAtomic->a" fromIntegral = \(CSigAtomic x) -> fromIntegral x
61 #-}
62
63 INTEGRAL_TYPE(CClock,tyConCClock,"CClock",HTYPE_CLOCK_T)
64 INTEGRAL_TYPE(CTime,tyConCTime,"CTime",HTYPE_TIME_T)
65
66 -- FIXME: Implement and provide instances for Eq and Storable
67 data CFile = CFile
68 data CFpos = CFpos
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
74 #include "Dynamic.h"
75 INSTANCE_TYPEABLE0(CPtrdiff,cPtrdiffTc,"CPtrdiff")
76 INSTANCE_TYPEABLE0(CSize,cSizeTc,"CSize")
77 INSTANCE_TYPEABLE0(CWchar,cWcharTc,"CWchar")
78 INSTANCE_TYPEABLE0(CSigAtomic,cSigAtomicTc,"CSigAtomic")
79 INSTANCE_TYPEABLE0(CClock,cClockTc,"CClock")
80 INSTANCE_TYPEABLE0(CTime,cTimeTc,"CTime")