53478a7a5ef465fdab87e654ef78bc627ac84784
[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 "stg/Types.h"
22
23 /* get limits for floating point types */
24 #include <float.h>
25
26 typedef StgChar HsChar;
27 typedef StgInt HsInt;
28 typedef StgInt8 HsInt8;
29 typedef StgInt16 HsInt16;
30 typedef StgInt32 HsInt32;
31 typedef StgInt64 HsInt64;
32 typedef StgWord HsWord;
33 typedef StgWord8 HsWord8;
34 typedef StgWord16 HsWord16;
35 typedef StgWord32 HsWord32;
36 typedef StgWord64 HsWord64;
37 typedef StgFloat HsFloat;
38 typedef StgDouble HsDouble;
39 typedef StgInt HsBool;
40 typedef void* HsPtr; /* this should better match StgAddr */
41 typedef void (*HsFunPtr)(void); /* this should better match StgAddr */
42 typedef void* HsStablePtr;
43
44 /* this should correspond to the type of StgChar in StgTypes.h */
45 #define HS_CHAR_MIN 0
46 #define HS_CHAR_MAX 0x10FFFF
47
48 /* is it true or not? */
49 #define HS_BOOL_FALSE 0
50 #define HS_BOOL_TRUE 1
51
52 #define HS_BOOL_MIN HS_BOOL_FALSE
53 #define HS_BOOL_MAX HS_BOOL_TRUE
54
55
56 #define HS_INT_MIN STG_INT_MIN
57 #define HS_INT_MAX STG_INT_MAX
58 #define HS_WORD_MAX STG_WORD_MAX
59
60 #define HS_INT8_MIN STG_INT8_MIN
61 #define HS_INT8_MAX STG_INT8_MAX
62 #define HS_INT16_MIN STG_INT16_MIN
63 #define HS_INT16_MAX STG_INT16_MAX
64 #define HS_INT32_MIN STG_INT32_MIN
65 #define HS_INT32_MAX STG_INT32_MAX
66 #define HS_INT64_MIN STG_INT64_MIN
67 #define HS_INT64_MAX STG_INT64_MAX
68 #define HS_WORD8_MAX STG_WORD8_MAX
69 #define HS_WORD16_MAX STG_WORD16_MAX
70 #define HS_WORD32_MAX STG_WORD32_MAX
71 #define HS_WORD64_MAX STG_WORD64_MAX
72
73 #define HS_FLOAT_RADIX FLT_RADIX
74 #define HS_FLOAT_ROUNDS FLT_ROUNDS
75 #define HS_FLOAT_EPSILON FLT_EPSILON
76 #define HS_FLOAT_DIG FLT_DIG
77 #define HS_FLOAT_MANT_DIG FLT_MANT_DIG
78 #define HS_FLOAT_MIN FLT_MIN
79 #define HS_FLOAT_MIN_EXP FLT_MIN_EXP
80 #define HS_FLOAT_MIN_10_EXP FLT_MIN_10_EXP
81 #define HS_FLOAT_MAX FLT_MAX
82 #define HS_FLOAT_MAX_EXP FLT_MAX_EXP
83 #define HS_FLOAT_MAX_10_EXP FLT_MAX_10_EXP
84
85 #define HS_DOUBLE_RADIX DBL_RADIX
86 #define HS_DOUBLE_ROUNDS DBL_ROUNDS
87 #define HS_DOUBLE_EPSILON DBL_EPSILON
88 #define HS_DOUBLE_DIG DBL_DIG
89 #define HS_DOUBLE_MANT_DIG DBL_MANT_DIG
90 #define HS_DOUBLE_MIN DBL_MIN
91 #define HS_DOUBLE_MIN_EXP DBL_MIN_EXP
92 #define HS_DOUBLE_MIN_10_EXP DBL_MIN_10_EXP
93 #define HS_DOUBLE_MAX DBL_MAX
94 #define HS_DOUBLE_MAX_EXP DBL_MAX_EXP
95 #define HS_DOUBLE_MAX_10_EXP DBL_MAX_10_EXP
96
97 extern void hs_init (int *argc, char **argv[]);
98 extern void hs_exit (void);
99 extern void hs_exit_nowait(void);
100 extern void hs_set_argv (int argc, char *argv[]);
101 extern void hs_thread_done (void);
102
103 extern void hs_perform_gc (void);
104
105 extern void hs_lock_stable_tables (void);
106 extern void hs_unlock_stable_tables (void);
107 extern void hs_free_stable_ptr_unsafe (HsStablePtr sp);
108
109 extern void hs_free_stable_ptr (HsStablePtr sp);
110 extern void hs_free_fun_ptr (HsFunPtr fp);
111
112 extern StgPtr hs_spt_lookup(StgWord64 key[2]);
113 extern int hs_spt_keys(StgPtr keys[], int szKeys);
114 extern int hs_spt_key_count (void);
115
116 extern void hs_try_putmvar (int capability, HsStablePtr sp);
117
118 /* -------------------------------------------------------------------------- */
119
120
121
122 #ifdef __cplusplus
123 }
124 #endif
125
126 #endif /* HSFFI_H */