0ecffdb5fcd2e7507c672eb215b1d53cf5687ee3
[packages/base.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 -- $Id: TypesISO.hs,v 1.3 2002/02/05 17:32:25 simonmar Exp $
13 --
14 -- A mapping of C types defined by the ISO C standard to corresponding Haskell
15 -- types. Like CTypes, this is a cool hack...
16 --
17 -----------------------------------------------------------------------------
18
19 module Foreign.C.TypesISO
20 ( -- Integral types, instances of: Eq, Ord, Num, Read, Show, Enum,
21 -- Typeable, Storable, Bounded, Real, Integral, Bits
22 CPtrdiff(..), CSize(..), CWchar(..), CSigAtomic(..)
23
24 -- Numeric types, instances of: Eq, Ord, Num, Read, Show, Enum,
25 -- Typeable, Storable
26 , CClock(..), CTime(..),
27
28 -- Instances of: Eq and Storable
29 , CFile, CFpos, CJmpBuf
30 ) where
31
32 import Data.Bits ( Bits(..) )
33 import Data.Int
34 import Data.Word
35 import Data.Dynamic
36
37 #ifdef __GLASGOW_HASKELL__
38 import GHC.Base
39 import GHC.Enum
40 import GHC.Real
41 import GHC.Show
42 import GHC.Read
43 import GHC.Num
44 #endif
45
46 #include "CTypes.h"
47
48 INTEGRAL_TYPE(CPtrdiff,tyConCPtrdiff,"CPtrdiff",HTYPE_PTRDIFF_T)
49 INTEGRAL_TYPE(CSize,tyConCSize,"CSize",HTYPE_SIZE_T)
50 INTEGRAL_TYPE(CWchar,tyConCWchar,"CWchar",HTYPE_WCHAR_T)
51 INTEGRAL_TYPE(CSigAtomic,tyConCSigAtomic,"CSigAtomic",HTYPE_SIG_ATOMIC_T)
52
53 {-# RULES
54 "fromIntegral/a->CPtrdiff" fromIntegral = \x -> CPtrdiff (fromIntegral x)
55 "fromIntegral/a->CSize" fromIntegral = \x -> CSize (fromIntegral x)
56 "fromIntegral/a->CWchar" fromIntegral = \x -> CWchar (fromIntegral x)
57 "fromIntegral/a->CSigAtomic" fromIntegral = \x -> CSigAtomic (fromIntegral x)
58
59 "fromIntegral/CPtrdiff->a" fromIntegral = \(CPtrdiff x) -> fromIntegral x
60 "fromIntegral/CSize->a" fromIntegral = \(CSize x) -> fromIntegral x
61 "fromIntegral/CWchar->a" fromIntegral = \(CWchar x) -> fromIntegral x
62 "fromIntegral/CSigAtomic->a" fromIntegral = \(CSigAtomic x) -> fromIntegral x
63 #-}
64
65 INTEGRAL_TYPE(CClock,tyConCClock,"CClock",HTYPE_CLOCK_T)
66 INTEGRAL_TYPE(CTime,tyConCTime,"CTime",HTYPE_TIME_T)
67
68 -- FIXME: Implement and provide instances for Eq and Storable
69 data CFile = CFile
70 data CFpos = CFpos
71 data CJmpBuf = CJmpBuf
72
73 -- C99 types which are still missing include:
74 -- intptr_t, uintptr_t, intmax_t, uintmax_t, wint_t, wctrans_t, wctype_t
75
76 #include "Dynamic.h"
77 INSTANCE_TYPEABLE0(CPtrdiff,cPtrdiffTc,"CPtrdiff")
78 INSTANCE_TYPEABLE0(CSize,cSizeTc,"CSize")
79 INSTANCE_TYPEABLE0(CWchar,cWcharTc,"CWchar")
80 INSTANCE_TYPEABLE0(CSigAtomic,cSigAtomicTc,"CSigAtomic")
81 INSTANCE_TYPEABLE0(CClock,cClockTc,"CClock")
82 INSTANCE_TYPEABLE0(CTime,cTimeTc,"CTime")