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