[project @ 2001-06-28 14:15:04 by simonmar]
[packages/pretty.git] / Foreign / C / Types.hs
1 {-# OPTIONS -fno-implicit-prelude #-}
2 -----------------------------------------------------------------------------
3 --
4 -- Module : Foreign.C.Types
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 : experimental
10 -- Portability : non-portable
11 --
12 -- $Id: Types.hs,v 1.1 2001/06/28 14:15:03 simonmar Exp $
13 --
14 -- Mapping of C types to corresponding Haskell types. A cool hack...
15 --
16 -----------------------------------------------------------------------------
17
18 module Foreign.C.Types
19 ( -- Integral types, instances of: Eq, Ord, Num, Read, Show, Enum,
20 -- Typeable, Storable, Bounded, Real, Integral, Bits
21 CChar(..), CSChar(..), CUChar(..)
22 , CShort(..), CUShort(..), CInt(..), CUInt(..)
23 , CLong(..), CULong(..), CLLong(..), CULLong(..)
24
25 -- Floating types, instances of: Eq, Ord, Num, Read, Show, Enum,
26 -- Typeable, Storable, Real, Fractional, Floating, RealFrac, RealFloat
27 , CFloat(..), CDouble(..), CLDouble(..)
28 ) where
29
30 import Data.Bits ( Bits(..) )
31 import Data.Int ( Int8, Int16, Int32, Int64 )
32 import Data.Word ( Word8, Word16, Word32, Word64 )
33 import Data.Dynamic
34
35 #ifdef __GLASGOW_HASKELL__
36 import GHC.Base
37 import GHC.Float
38 import GHC.Enum
39 import GHC.Real
40 import GHC.Show
41 import GHC.Read
42 import GHC.Num
43 #endif
44
45 #include "CTypes.h"
46
47 INTEGRAL_TYPE(CChar,tyConCChar,"CChar",HTYPE_CHAR)
48 INTEGRAL_TYPE(CSChar,tyConCSChar,"CSChar",HTYPE_SIGNED_CHAR)
49 INTEGRAL_TYPE(CUChar,tyConCUChar,"CUChar",HTYPE_UNSIGNED_CHAR)
50
51 INTEGRAL_TYPE(CShort,tyConCShort,"CShort",HTYPE_SHORT)
52 INTEGRAL_TYPE(CUShort,tyConCUShort,"CUShort",HTYPE_UNSIGNED_SHORT)
53
54 INTEGRAL_TYPE(CInt,tyConCInt,"CInt",HTYPE_INT)
55 INTEGRAL_TYPE(CUInt,tyConCUInt,"CUInt",HTYPE_UNSIGNED_INT)
56
57 INTEGRAL_TYPE(CLong,tyConCLong,"CLong",HTYPE_LONG)
58 INTEGRAL_TYPE(CULong,tyConCULong,"CULong",HTYPE_UNSIGNED_LONG)
59
60 INTEGRAL_TYPE(CLLong,tyConCLLong,"CLLong",HTYPE_LONG_LONG)
61 INTEGRAL_TYPE(CULLong,tyConCULLong,"CULLong",HTYPE_UNSIGNED_LONG_LONG)
62
63 {-# RULES
64 "fromIntegral/a->CChar" fromIntegral = \x -> CChar (fromIntegral x)
65 "fromIntegral/a->CSChar" fromIntegral = \x -> CSChar (fromIntegral x)
66 "fromIntegral/a->CUChar" fromIntegral = \x -> CUChar (fromIntegral x)
67 "fromIntegral/a->CShort" fromIntegral = \x -> CShort (fromIntegral x)
68 "fromIntegral/a->CUShort" fromIntegral = \x -> CUShort (fromIntegral x)
69 "fromIntegral/a->CInt" fromIntegral = \x -> CInt (fromIntegral x)
70 "fromIntegral/a->CUInt" fromIntegral = \x -> CUInt (fromIntegral x)
71 "fromIntegral/a->CLong" fromIntegral = \x -> CLong (fromIntegral x)
72 "fromIntegral/a->CULong" fromIntegral = \x -> CULong (fromIntegral x)
73 "fromIntegral/a->CLLong" fromIntegral = \x -> CLLong (fromIntegral x)
74 "fromIntegral/a->CULLong" fromIntegral = \x -> CULLong (fromIntegral x)
75
76 "fromIntegral/CChar->a" fromIntegral = \(CChar x) -> fromIntegral x
77 "fromIntegral/CSChar->a" fromIntegral = \(CSChar x) -> fromIntegral x
78 "fromIntegral/CUChar->a" fromIntegral = \(CUChar x) -> fromIntegral x
79 "fromIntegral/CShort->a" fromIntegral = \(CShort x) -> fromIntegral x
80 "fromIntegral/CUShort->a" fromIntegral = \(CUShort x) -> fromIntegral x
81 "fromIntegral/CInt->a" fromIntegral = \(CInt x) -> fromIntegral x
82 "fromIntegral/CUInt->a" fromIntegral = \(CUInt x) -> fromIntegral x
83 "fromIntegral/CLong->a" fromIntegral = \(CLong x) -> fromIntegral x
84 "fromIntegral/CULong->a" fromIntegral = \(CULong x) -> fromIntegral x
85 "fromIntegral/CLLong->a" fromIntegral = \(CLLong x) -> fromIntegral x
86 "fromIntegral/CULLong->a" fromIntegral = \(CULLong x) -> fromIntegral x
87 #-}
88
89 FLOATING_TYPE(CFloat,tyConCFloat,"CFloat",HTYPE_FLOAT)
90 FLOATING_TYPE(CDouble,tyConCDouble,"CDouble",HTYPE_DOUBLE)
91 -- HACK: Currently no long double in the FFI, so we simply re-use double
92 FLOATING_TYPE(CLDouble,tyConCLDouble,"CLDouble",HTYPE_DOUBLE)
93
94
95 #include "Dynamic.h"
96 INSTANCE_TYPEABLE0(CChar,cCharTc,"CChar")
97 INSTANCE_TYPEABLE0(CSChar,cSCharTc,"CSChar")
98 INSTANCE_TYPEABLE0(CUChar,cUCharTc,"CUChar")
99
100 INSTANCE_TYPEABLE0(CShort,cShortTc,"CShort")
101 INSTANCE_TYPEABLE0(CUShort,cUShortTc,"CUShort")
102
103 INSTANCE_TYPEABLE0(CInt,cIntTc,"CInt")
104 INSTANCE_TYPEABLE0(CUInt,cUIntTc,"CUInt")
105
106 INSTANCE_TYPEABLE0(CLong,cLongTc,"CLong")
107 INSTANCE_TYPEABLE0(CULong,cULongTc,"CULong")
108
109 INSTANCE_TYPEABLE0(CLLong,cLLongTc,"CLLong")
110 INSTANCE_TYPEABLE0(CULLong,cULLongTc,"CULLong")
111
112 INSTANCE_TYPEABLE0(CFloat,cFloatTc,"CFloat")
113 INSTANCE_TYPEABLE0(CDouble,cDoubleTc,"CDouble")
114 INSTANCE_TYPEABLE0(CLDouble,cLDoubleTc,"CLDouble")