79ea7b54da54b1e51e7e67ad500515d85f63584f
[ghc-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/base/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 -- #hide
18 module Foreign.C.TypesISO
19 #ifndef __NHC__
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 #else
28         ( -- For nhc98, these are exported non-abstractly to work around
29           -- an interface-file problem.
30           CPtrdiff(..), CSize(..), CWchar(..), CSigAtomic(..)
31         , CClock(..),   CTime(..)
32 #endif
33
34           -- Instances of: Eq and Storable
35         , CFile,        CFpos,     CJmpBuf
36         ) where
37
38 #ifdef __NHC__
39 import NHC.FFI
40   ( CPtrdiff(..)
41   , CSize(..)
42   , CWchar(..)
43   , CSigAtomic(..)
44   , CClock(..)
45   , CTime(..)
46   , CFile
47   , CFpos
48   , CJmpBuf
49   )
50 #else
51
52 import Data.Bits        ( Bits(..) )
53 import Data.Int
54 import Data.Word
55 import Data.Dynamic
56 import Foreign.Storable
57
58 #ifdef __GLASGOW_HASKELL__
59 import GHC.Base
60 import GHC.Enum
61 import GHC.Real
62 import GHC.Show
63 import GHC.Read
64 import GHC.Num
65 #else
66 import Control.Monad
67 import Foreign.Ptr
68 #endif
69
70 #include "Typeable.h"
71 #include "CTypes.h"
72
73 INTEGRAL_TYPE(CPtrdiff,tyConCPtrdiff,"CPtrdiff",HTYPE_PTRDIFF_T)
74 INTEGRAL_TYPE(CSize,tyConCSize,"CSize",HTYPE_SIZE_T)
75 INTEGRAL_TYPE(CWchar,tyConCWchar,"CWchar",HTYPE_WCHAR_T)
76 INTEGRAL_TYPE(CSigAtomic,tyConCSigAtomic,"CSigAtomic",HTYPE_SIG_ATOMIC_T)
77
78 {-# RULES
79 "fromIntegral/a->CPtrdiff"   fromIntegral = \x -> CPtrdiff   (fromIntegral x)
80 "fromIntegral/a->CSize"      fromIntegral = \x -> CSize      (fromIntegral x)
81 "fromIntegral/a->CWchar"     fromIntegral = \x -> CWchar     (fromIntegral x)
82 "fromIntegral/a->CSigAtomic" fromIntegral = \x -> CSigAtomic (fromIntegral x)
83
84 "fromIntegral/CPtrdiff->a"   fromIntegral = \(CPtrdiff   x) -> fromIntegral x
85 "fromIntegral/CSize->a"      fromIntegral = \(CSize      x) -> fromIntegral x
86 "fromIntegral/CWchar->a"     fromIntegral = \(CWchar     x) -> fromIntegral x
87 "fromIntegral/CSigAtomic->a" fromIntegral = \(CSigAtomic x) -> fromIntegral x
88  #-}
89
90 INTEGRAL_TYPE(CClock,tyConCClock,"CClock",HTYPE_CLOCK_T)
91 INTEGRAL_TYPE(CTime,tyConCTime,"CTime",HTYPE_TIME_T)
92
93 -- FIXME: Implement and provide instances for Eq and Storable
94 data CFile = CFile
95 data CFpos = CFpos
96 data CJmpBuf = CJmpBuf
97
98 -- C99 types which are still missing include:
99 -- intptr_t, uintptr_t, intmax_t, uintmax_t, wint_t, wctrans_t, wctype_t
100
101 #endif