[project @ 2002-02-12 11:44:54 by simonmar]
[ghc-hetmet.git] / ghc / lib / std / PrelCTypes.lhs
1 % -----------------------------------------------------------------------------
2 % $Id: PrelCTypes.lhs,v 1.5 2002/02/04 09:05:46 chak Exp $
3 %
4 % (c) The FFI task force, 2000
5 %
6
7 A mapping of C types to corresponding Haskell types. A cool hack...
8
9 #include "cbits/CTypes.h"
10
11 \begin{code}
12 {-# OPTIONS -fno-implicit-prelude #-}
13
14 module PrelCTypes
15         ( -- Integral types, instances of: Eq, Ord, Num, Read, Show, Enum,
16           -- Typeable, Storable, Bounded, Real, Integral, Bits
17           CChar(..),  CSChar(..),  CUChar(..)
18         , CShort(..), CUShort(..), CInt(..),   CUInt(..)
19         , CLong(..),  CULong(..),  CLLong(..), CULLong(..)
20
21           -- Floating types, instances of: Eq, Ord, Num, Read, Show, Enum,
22           -- Typeable, Storable, Real, Fractional, Floating, RealFrac,
23           -- RealFloat 
24         , CFloat(..),  CDouble(..), CLDouble(..)
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 PrelBits ( Bits(..) )
37 import PrelInt  ( Int8,  Int16,  Int32,  Int64  )
38 import PrelWord ( Word8, Word16, Word32, Word64 )
39 \end{code}
40
41 \begin{code}
42 INTEGRAL_TYPE(CChar,tyConCChar,"CChar",HTYPE_CHAR)
43 INTEGRAL_TYPE(CSChar,tyConCSChar,"CSChar",HTYPE_SIGNED_CHAR)
44 INTEGRAL_TYPE(CUChar,tyConCUChar,"CUChar",HTYPE_UNSIGNED_CHAR)
45
46 INTEGRAL_TYPE(CShort,tyConCShort,"CShort",HTYPE_SHORT)
47 INTEGRAL_TYPE(CUShort,tyConCUShort,"CUShort",HTYPE_UNSIGNED_SHORT)
48
49 INTEGRAL_TYPE(CInt,tyConCInt,"CInt",HTYPE_INT)
50 INTEGRAL_TYPE(CUInt,tyConCUInt,"CUInt",HTYPE_UNSIGNED_INT)
51
52 INTEGRAL_TYPE(CLong,tyConCLong,"CLong",HTYPE_LONG)
53 INTEGRAL_TYPE(CULong,tyConCULong,"CULong",HTYPE_UNSIGNED_LONG)
54
55 INTEGRAL_TYPE(CLLong,tyConCLLong,"CLLong",HTYPE_LONG_LONG)
56 INTEGRAL_TYPE(CULLong,tyConCULLong,"CULLong",HTYPE_UNSIGNED_LONG_LONG)
57
58 {-# RULES
59 "fromIntegral/a->CChar"   fromIntegral = \x -> CChar   (fromIntegral x)
60 "fromIntegral/a->CSChar"  fromIntegral = \x -> CSChar  (fromIntegral x)
61 "fromIntegral/a->CUChar"  fromIntegral = \x -> CUChar  (fromIntegral x)
62 "fromIntegral/a->CShort"  fromIntegral = \x -> CShort  (fromIntegral x)
63 "fromIntegral/a->CUShort" fromIntegral = \x -> CUShort (fromIntegral x)
64 "fromIntegral/a->CInt"    fromIntegral = \x -> CInt    (fromIntegral x)
65 "fromIntegral/a->CUInt"   fromIntegral = \x -> CUInt   (fromIntegral x)
66 "fromIntegral/a->CLong"   fromIntegral = \x -> CLong   (fromIntegral x)
67 "fromIntegral/a->CULong"  fromIntegral = \x -> CULong  (fromIntegral x)
68 "fromIntegral/a->CLLong"  fromIntegral = \x -> CLLong  (fromIntegral x)
69 "fromIntegral/a->CULLong" fromIntegral = \x -> CULLong (fromIntegral x)
70
71 "fromIntegral/CChar->a"   fromIntegral = \(CChar   x) -> fromIntegral x
72 "fromIntegral/CSChar->a"  fromIntegral = \(CSChar  x) -> fromIntegral x
73 "fromIntegral/CUChar->a"  fromIntegral = \(CUChar  x) -> fromIntegral x
74 "fromIntegral/CShort->a"  fromIntegral = \(CShort  x) -> fromIntegral x
75 "fromIntegral/CUShort->a" fromIntegral = \(CUShort x) -> fromIntegral x
76 "fromIntegral/CInt->a"    fromIntegral = \(CInt    x) -> fromIntegral x
77 "fromIntegral/CUInt->a"   fromIntegral = \(CUInt   x) -> fromIntegral x
78 "fromIntegral/CLong->a"   fromIntegral = \(CLong   x) -> fromIntegral x
79 "fromIntegral/CULong->a"  fromIntegral = \(CULong  x) -> fromIntegral x
80 "fromIntegral/CLLong->a"  fromIntegral = \(CLLong  x) -> fromIntegral x
81 "fromIntegral/CULLong->a" fromIntegral = \(CULLong x) -> fromIntegral x
82  #-}
83
84 FLOATING_TYPE(CFloat,tyConCFloat,"CFloat",HTYPE_FLOAT)
85 FLOATING_TYPE(CDouble,tyConCDouble,"CDouble",HTYPE_DOUBLE)
86 -- HACK: Currently no long double in the FFI, so we simply re-use double
87 FLOATING_TYPE(CLDouble,tyConCLDouble,"CLDouble",HTYPE_DOUBLE)
88 \end{code}