e9d19a8401b6e0ee667ebb86d3bfd9c84d4cbabd
[ghc.git] / libraries / base / include / CTypes.h
1 {- --------------------------------------------------------------------------
2 // Dirty CPP hackery for CTypes/CTypesISO
3 //
4 // (c) The FFI task force, 2000
5 // --------------------------------------------------------------------------
6 -}
7
8 #ifndef CTYPES__H
9 #define CTYPES__H
10
11 {-
12 // As long as there is no automatic derivation of classes for newtypes we resort
13 // to extremely dirty cpp-hackery. :-P Some care has to be taken when the
14 // macros below are modified, otherwise the layout rule will bite you.
15 -}
16
17 -- // GHC can derive any class for a newtype, so we make use of that here...
18
19 #define ARITHMETIC_CLASSES Eq,Ord,Num,Enum,Storable,Real
20 #define INTEGRAL_CLASSES Bounded,Integral,Bits,FiniteBits
21 #define FLOATING_CLASSES Fractional,Floating,RealFrac,RealFloat
22 #define OPAQUE_CLASSES Eq,Ord,Storable
23
24 #define ARITHMETIC_TYPE(T,B) \
25 newtype T = T B deriving (ARITHMETIC_CLASSES) \
26 deriving newtype (Read, Show);
27
28 #define INTEGRAL_TYPE(T,B) \
29 newtype T = T B deriving (ARITHMETIC_CLASSES, INTEGRAL_CLASSES) \
30 deriving newtype (Read, Show);
31
32 #define INTEGRAL_TYPE_WITH_CTYPE(T,THE_CTYPE,B) \
33 newtype {-# CTYPE "THE_CTYPE" #-} T = T B \
34 deriving (ARITHMETIC_CLASSES, INTEGRAL_CLASSES) \
35 deriving newtype (Read, Show);
36
37 #define FLOATING_TYPE(T,B) \
38 newtype T = T B deriving (ARITHMETIC_CLASSES, FLOATING_CLASSES) \
39 deriving newtype (Read, Show);
40
41 #define FLOATING_TYPE_WITH_CTYPE(T,THE_CTYPE,B) \
42 newtype {-# CTYPE "THE_CTYPE" #-} T = T B \
43 deriving (ARITHMETIC_CLASSES, FLOATING_CLASSES) \
44 deriving newtype (Read, Show);
45
46 #define OPAQUE_TYPE_WITH_CTYPE(T,THE_CTYPE,B) \
47 newtype {-# CTYPE "THE_CTYPE" #-} T = T (B) \
48 deriving (OPAQUE_CLASSES) \
49 deriving newtype Show;
50
51 #endif