Hadrian: various improvements around the 'test' rule
[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 #pragma once
13
14 #if defined(__cplusplus)
15 extern "C" {
16 #endif
17
18 /* get types from GHC's runtime system */
19 #include "ghcconfig.h"
20 #include "stg/Types.h"
21
22 /* get limits for floating point types */
23 #include <float.h>
24
25 typedef StgChar HsChar;
26 typedef StgInt HsInt;
27 typedef StgInt8 HsInt8;
28 typedef StgInt16 HsInt16;
29 typedef StgInt32 HsInt32;
30 typedef StgInt64 HsInt64;
31 typedef StgWord HsWord;
32 typedef StgWord8 HsWord8;
33 typedef StgWord16 HsWord16;
34 typedef StgWord32 HsWord32;
35 typedef StgWord64 HsWord64;
36 typedef StgFloat HsFloat;
37 typedef StgDouble HsDouble;
38 typedef StgInt HsBool;
39 typedef void* HsPtr; /* this should better match StgAddr */
40 typedef void (*HsFunPtr)(void); /* this should better match StgAddr */
41 typedef void* HsStablePtr;
42
43 /* this should correspond to the type of StgChar in StgTypes.h */
44 #define HS_CHAR_MIN 0
45 #define HS_CHAR_MAX 0x10FFFF
46
47 /* is it true or not? */
48 #define HS_BOOL_FALSE 0
49 #define HS_BOOL_TRUE 1
50
51 #define HS_BOOL_MIN HS_BOOL_FALSE
52 #define HS_BOOL_MAX HS_BOOL_TRUE
53
54
55 #define HS_INT_MIN STG_INT_MIN
56 #define HS_INT_MAX STG_INT_MAX
57 #define HS_WORD_MAX STG_WORD_MAX
58
59 #define HS_INT8_MIN STG_INT8_MIN
60 #define HS_INT8_MAX STG_INT8_MAX
61 #define HS_INT16_MIN STG_INT16_MIN
62 #define HS_INT16_MAX STG_INT16_MAX
63 #define HS_INT32_MIN STG_INT32_MIN
64 #define HS_INT32_MAX STG_INT32_MAX
65 #define HS_INT64_MIN STG_INT64_MIN
66 #define HS_INT64_MAX STG_INT64_MAX
67 #define HS_WORD8_MAX STG_WORD8_MAX
68 #define HS_WORD16_MAX STG_WORD16_MAX
69 #define HS_WORD32_MAX STG_WORD32_MAX
70 #define HS_WORD64_MAX STG_WORD64_MAX
71
72 #define HS_FLOAT_RADIX FLT_RADIX
73 #define HS_FLOAT_ROUNDS FLT_ROUNDS
74 #define HS_FLOAT_EPSILON FLT_EPSILON
75 #define HS_FLOAT_DIG FLT_DIG
76 #define HS_FLOAT_MANT_DIG FLT_MANT_DIG
77 #define HS_FLOAT_MIN FLT_MIN
78 #define HS_FLOAT_MIN_EXP FLT_MIN_EXP
79 #define HS_FLOAT_MIN_10_EXP FLT_MIN_10_EXP
80 #define HS_FLOAT_MAX FLT_MAX
81 #define HS_FLOAT_MAX_EXP FLT_MAX_EXP
82 #define HS_FLOAT_MAX_10_EXP FLT_MAX_10_EXP
83
84 #define HS_DOUBLE_RADIX DBL_RADIX
85 #define HS_DOUBLE_ROUNDS DBL_ROUNDS
86 #define HS_DOUBLE_EPSILON DBL_EPSILON
87 #define HS_DOUBLE_DIG DBL_DIG
88 #define HS_DOUBLE_MANT_DIG DBL_MANT_DIG
89 #define HS_DOUBLE_MIN DBL_MIN
90 #define HS_DOUBLE_MIN_EXP DBL_MIN_EXP
91 #define HS_DOUBLE_MIN_10_EXP DBL_MIN_10_EXP
92 #define HS_DOUBLE_MAX DBL_MAX
93 #define HS_DOUBLE_MAX_EXP DBL_MAX_EXP
94 #define HS_DOUBLE_MAX_10_EXP DBL_MAX_10_EXP
95
96 extern void hs_init (int *argc, char **argv[]);
97 extern void hs_exit (void);
98 extern void hs_exit_nowait(void);
99 extern void hs_set_argv (int argc, char *argv[]);
100 extern void hs_thread_done (void);
101
102 extern void hs_perform_gc (void);
103
104 // Lock the stable pointer table. The table must be unlocked
105 // again before calling any Haskell functions, even if those
106 // functions do not manipulate stable pointers. The Haskell
107 // garbage collector will not be able to run until this lock
108 // is released! It is also forbidden to call hs_free_fun_ptr
109 // or any stable pointer-related FFI functions other than
110 // hs_free_stable_ptr_unsafe while the table is locked.
111 extern void hs_lock_stable_ptr_table (void);
112
113 // A deprecated synonym.
114 extern void hs_lock_stable_tables (void);
115
116 // Unlock the stable pointer table.
117 extern void hs_unlock_stable_ptr_table (void);
118
119 // A deprecated synonym.
120 extern void hs_unlock_stable_tables (void);
121
122 // Free a stable pointer assuming that the stable pointer
123 // table is already locked.
124 extern void hs_free_stable_ptr_unsafe (HsStablePtr sp);
125
126 extern void hs_free_stable_ptr (HsStablePtr sp);
127 extern void hs_free_fun_ptr (HsFunPtr fp);
128
129 extern StgPtr hs_spt_lookup(StgWord64 key1, StgWord64 key2);
130 extern int hs_spt_keys(StgPtr keys[], int szKeys);
131 extern int hs_spt_key_count (void);
132
133 extern void hs_try_putmvar (int capability, HsStablePtr sp);
134
135 /* -------------------------------------------------------------------------- */
136
137
138
139 #if defined(__cplusplus)
140 }
141 #endif