summaryrefslogtreecommitdiff
path: root/includes/HsFFI.h
blob: 7c25599f83bc7842f1fb6d8a7ae67abe7e9f5a52 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/* -----------------------------------------------------------------------------
 *
 * (c) The GHC Team, 2000
 *
 * A mapping for Haskell types to C types, including the corresponding bounds.
 * Intended to be used in conjunction with the FFI.
 *
 * WARNING: Keep this file and StgTypes.h in synch!
 *
 * ---------------------------------------------------------------------------*/

/* N.B. Only use C-style multi-line comments in this file to avoid upsetting
 * dtrace on SmartOS, which doesn't support C++-style single-line comments.
 */

#pragma once

#if defined(__cplusplus)
extern "C" {
#endif

/* get types from GHC's runtime system */
#include "ghcconfig.h"
#include "stg/Types.h"

/* get limits for floating point types */
#include <float.h>

typedef StgChar                 HsChar;
typedef StgInt                  HsInt;
typedef StgInt8                 HsInt8;
typedef StgInt16                HsInt16;
typedef StgInt32                HsInt32;
typedef StgInt64                HsInt64;
typedef StgWord                 HsWord;
typedef StgWord8                HsWord8;
typedef StgWord16               HsWord16;
typedef StgWord32               HsWord32;
typedef StgWord64               HsWord64;
typedef StgFloat                HsFloat;
typedef StgDouble               HsDouble;
typedef StgInt                  HsBool;
typedef void*                   HsPtr;          /* this should better match StgAddr */
typedef void                    (*HsFunPtr)(void); /* this should better match StgAddr */
typedef void*                   HsStablePtr;

/* this should correspond to the type of StgChar in StgTypes.h */
#define HS_CHAR_MIN             0
#define HS_CHAR_MAX             0x10FFFF

/* is it true or not?  */
#define HS_BOOL_FALSE           0
#define HS_BOOL_TRUE            1

#define HS_BOOL_MIN             HS_BOOL_FALSE
#define HS_BOOL_MAX             HS_BOOL_TRUE


#define HS_INT_MIN              STG_INT_MIN
#define HS_INT_MAX              STG_INT_MAX
#define HS_WORD_MAX             STG_WORD_MAX

#define HS_INT8_MIN             STG_INT8_MIN
#define HS_INT8_MAX             STG_INT8_MAX
#define HS_INT16_MIN            STG_INT16_MIN
#define HS_INT16_MAX            STG_INT16_MAX
#define HS_INT32_MIN            STG_INT32_MIN
#define HS_INT32_MAX            STG_INT32_MAX
#define HS_INT64_MIN            STG_INT64_MIN
#define HS_INT64_MAX            STG_INT64_MAX
#define HS_WORD8_MAX            STG_WORD8_MAX
#define HS_WORD16_MAX           STG_WORD16_MAX
#define HS_WORD32_MAX           STG_WORD32_MAX
#define HS_WORD64_MAX           STG_WORD64_MAX

#define HS_FLOAT_RADIX          FLT_RADIX
#define HS_FLOAT_ROUNDS         FLT_ROUNDS
#define HS_FLOAT_EPSILON        FLT_EPSILON
#define HS_FLOAT_DIG            FLT_DIG
#define HS_FLOAT_MANT_DIG       FLT_MANT_DIG
#define HS_FLOAT_MIN            FLT_MIN
#define HS_FLOAT_MIN_EXP        FLT_MIN_EXP
#define HS_FLOAT_MIN_10_EXP     FLT_MIN_10_EXP
#define HS_FLOAT_MAX            FLT_MAX
#define HS_FLOAT_MAX_EXP        FLT_MAX_EXP
#define HS_FLOAT_MAX_10_EXP     FLT_MAX_10_EXP

#define HS_DOUBLE_RADIX         DBL_RADIX
#define HS_DOUBLE_ROUNDS        DBL_ROUNDS
#define HS_DOUBLE_EPSILON       DBL_EPSILON
#define HS_DOUBLE_DIG           DBL_DIG
#define HS_DOUBLE_MANT_DIG      DBL_MANT_DIG
#define HS_DOUBLE_MIN           DBL_MIN
#define HS_DOUBLE_MIN_EXP       DBL_MIN_EXP
#define HS_DOUBLE_MIN_10_EXP    DBL_MIN_10_EXP
#define HS_DOUBLE_MAX           DBL_MAX
#define HS_DOUBLE_MAX_EXP       DBL_MAX_EXP
#define HS_DOUBLE_MAX_10_EXP    DBL_MAX_10_EXP

extern void hs_init     (int *argc, char **argv[]);
extern void hs_exit     (void);
extern void hs_exit_nowait(void);
extern void hs_set_argv (int argc, char *argv[]);
extern void hs_thread_done (void);
extern void hs_restoreConsoleCP (void);

extern void hs_perform_gc (void);

/* Lock the stable pointer table. The table must be unlocked
 * again before calling any Haskell functions, even if those
 * functions do not manipulate stable pointers. The Haskell
 * garbage collector will not be able to run until this lock
 * is released! It is also forbidden to call hs_free_fun_ptr
 * or any stable pointer-related FFI functions other than
 * hs_free_stable_ptr_unsafe while the table is locked.
 */
extern void hs_lock_stable_ptr_table (void);

/* A deprecated synonym. */
extern void hs_lock_stable_tables (void);

/* Unlock the stable pointer table. */
extern void hs_unlock_stable_ptr_table (void);

/* A deprecated synonym. */
extern void hs_unlock_stable_tables (void);

/* Free a stable pointer assuming that the stable pointer
 * table is already locked.
 */
extern void hs_free_stable_ptr_unsafe (HsStablePtr sp);

extern void hs_free_stable_ptr (HsStablePtr sp);
extern void hs_free_fun_ptr    (HsFunPtr fp);

extern StgPtr hs_spt_lookup(StgWord64 key[2]);
extern int hs_spt_keys(StgPtr keys[], int szKeys);
extern int hs_spt_key_count (void);

extern void hs_try_putmvar (int capability, HsStablePtr sp);

/* -------------------------------------------------------------------------- */



#if defined(__cplusplus)
}
#endif