add support for flattening recursive-let
[ghc-hetmet.git] / includes / HsFFI.h
1 /* -----------------------------------------------------------------------------
2  *
3  * (c) The GHC Team, 2000
4  *
5  * A mapping for Haskell types to C types, including the corresponding bounds.
6  * Intended to be used in conjuction with the FFI.
7  *
8  * WARNING: Keep this file and StgTypes.h in synch!
9  *
10  * ---------------------------------------------------------------------------*/
11
12 #ifndef HSFFI_H
13 #define HSFFI_H
14
15 #ifdef __cplusplus
16 extern "C" {
17 #endif
18
19 /* get types from GHC's runtime system */
20 #include "ghcconfig.h"
21 #include "stg/Types.h"
22
23 /* get limits for integral types */
24 #ifdef HAVE_STDINT_H
25 /* ISO C 99 says:
26  * "C++ implementations should define these macros only when
27  * __STDC_LIMIT_MACROS is defined before <stdint.h> is included."
28  */
29 #define __STDC_LIMIT_MACROS
30 #include <stdint.h>
31 #elif defined(HAVE_INTTYPES_H)
32 #include <inttypes.h>
33 #else
34 /* second best guess (e.g. on Solaris) */
35 #include <limits.h>
36 #endif
37
38 #ifdef INT8_MIN
39 #define __INT8_MIN              INT8_MIN
40 #define __INT16_MIN             INT16_MIN
41 #define __INT32_MIN             INT32_MIN
42 #define __INT64_MIN             INT64_MIN
43 #define __INT8_MAX              INT8_MAX
44 #define __INT16_MAX             INT16_MAX
45 #define __INT32_MAX             INT32_MAX
46 #define __INT64_MAX             INT64_MAX
47 #define __UINT8_MAX             UINT8_MAX
48 #define __UINT16_MAX            UINT16_MAX
49 #define __UINT32_MAX            UINT32_MAX
50 #define __UINT64_MAX            UINT64_MAX
51 #else
52 /* if we had no luck, let's do it for ourselves (assuming 64bit long longs) */
53 #define __INT8_MIN              (-128)
54 #define __INT16_MIN             (-32767-1)
55 #define __INT32_MIN             (-2147483647-1)
56 #define __INT64_MIN             (-9223372036854775807LL-1)
57 #define __INT8_MAX              (127)
58 #define __INT16_MAX             (32767)
59 #define __INT32_MAX             (2147483647)
60 #define __INT64_MAX             (9223372036854775807LL)
61 #define __UINT8_MAX             (255U)
62 #define __UINT16_MAX            (65535U)
63 #define __UINT32_MAX            (4294967295U)
64 #define __UINT64_MAX            (18446744073709551615ULL)
65 #endif
66
67 /* get limits for floating point types */
68 #include <float.h>
69
70 typedef StgChar                 HsChar;
71 typedef StgInt                  HsInt;
72 typedef StgInt8                 HsInt8;
73 typedef StgInt16                HsInt16;
74 typedef StgInt32                HsInt32;
75 typedef StgInt64                HsInt64;
76 typedef StgWord                 HsWord;
77 typedef StgWord8                HsWord8;
78 typedef StgWord16               HsWord16;
79 typedef StgWord32               HsWord32;
80 typedef StgWord64               HsWord64;
81 typedef StgFloat                HsFloat;
82 typedef StgDouble               HsDouble;
83 typedef StgInt                  HsBool;
84 typedef void*                   HsPtr;          /* this should better match StgAddr */
85 typedef void                    (*HsFunPtr)(void); /* this should better match StgAddr */
86 typedef void*                   HsStablePtr;
87
88 /* this should correspond to the type of StgChar in StgTypes.h */
89 #define HS_CHAR_MIN             0
90 #define HS_CHAR_MAX             0x10FFFF
91
92 /* is it true or not?  */
93 #define HS_BOOL_FALSE           0
94 #define HS_BOOL_TRUE            1
95
96 #define HS_BOOL_MIN             HS_BOOL_FALSE
97 #define HS_BOOL_MAX             HS_BOOL_TRUE
98
99 /* this mirrors the distinction of cases in StgTypes.h */
100 #if   SIZEOF_VOID_P == 8
101 #define HS_INT_MIN              __INT64_MIN
102 #define HS_INT_MAX              __INT64_MAX
103 #define HS_WORD_MAX             __UINT64_MAX
104 #elif SIZEOF_VOID_P == 4
105 #define HS_INT_MIN              __INT32_MIN
106 #define HS_INT_MAX              __INT32_MAX
107 #define HS_WORD_MAX             __UINT32_MAX
108 #else
109 #error GHC untested on this architecture: sizeof(void *) != 4 or 8
110 #endif
111
112 #define HS_INT8_MIN             __INT8_MIN
113 #define HS_INT8_MAX             __INT8_MAX
114 #define HS_INT16_MIN            __INT16_MIN
115 #define HS_INT16_MAX            __INT16_MAX
116 #define HS_INT32_MIN            __INT32_MIN
117 #define HS_INT32_MAX            __INT32_MAX
118 #define HS_INT64_MIN            __INT64_MIN
119 #define HS_INT64_MAX            __INT64_MAX
120 #define HS_WORD8_MAX            __UINT8_MAX
121 #define HS_WORD16_MAX           __UINT16_MAX
122 #define HS_WORD32_MAX           __UINT32_MAX
123 #define HS_WORD64_MAX           __UINT64_MAX
124
125 #define HS_FLOAT_RADIX          FLT_RADIX
126 #define HS_FLOAT_ROUNDS         FLT_ROUNDS
127 #define HS_FLOAT_EPSILON        FLT_EPSILON
128 #define HS_FLOAT_DIG            FLT_DIG
129 #define HS_FLOAT_MANT_DIG       FLT_MANT_DIG
130 #define HS_FLOAT_MIN            FLT_MIN
131 #define HS_FLOAT_MIN_EXP        FLT_MIN_EXP
132 #define HS_FLOAT_MIN_10_EXP     FLT_MIN_10_EXP
133 #define HS_FLOAT_MAX            FLT_MAX
134 #define HS_FLOAT_MAX_EXP        FLT_MAX_EXP
135 #define HS_FLOAT_MAX_10_EXP     FLT_MAX_10_EXP
136
137 #define HS_DOUBLE_RADIX         DBL_RADIX
138 #define HS_DOUBLE_ROUNDS        DBL_ROUNDS
139 #define HS_DOUBLE_EPSILON       DBL_EPSILON
140 #define HS_DOUBLE_DIG           DBL_DIG
141 #define HS_DOUBLE_MANT_DIG      DBL_MANT_DIG
142 #define HS_DOUBLE_MIN           DBL_MIN
143 #define HS_DOUBLE_MIN_EXP       DBL_MIN_EXP
144 #define HS_DOUBLE_MIN_10_EXP    DBL_MIN_10_EXP
145 #define HS_DOUBLE_MAX           DBL_MAX
146 #define HS_DOUBLE_MAX_EXP       DBL_MAX_EXP
147 #define HS_DOUBLE_MAX_10_EXP    DBL_MAX_10_EXP
148
149 extern void hs_init     (int *argc, char **argv[]);
150 extern void hs_exit     (void);
151 extern void hs_set_argv (int argc, char *argv[]);
152 extern void hs_add_root (void (*init_root)(void));
153
154 extern void hs_perform_gc (void);
155
156 extern void hs_free_stable_ptr (HsStablePtr sp);
157 extern void hs_free_fun_ptr    (HsFunPtr fp);
158
159 /* -------------------------------------------------------------------------- */
160
161 #ifdef __cplusplus
162 }
163 #endif
164
165 #endif /* HSFFI_H */