aboutsummaryrefslogtreecommitdiffstats
path: root/src/module.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/module.h')
-rw-r--r--src/module.h299
1 files changed, 136 insertions, 163 deletions
diff --git a/src/module.h b/src/module.h
index 9f43c898af4..d4fad9d32a0 100644
--- a/src/module.h
+++ b/src/module.h
@@ -24,206 +24,179 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
24#include <stdlib.h> 24#include <stdlib.h>
25#include <stdbool.h> 25#include <stdbool.h>
26 26
27#ifdef __cplusplus 27#if defined __cplusplus && __cplusplus >= 201103L
28#define EMACS_EXTERN_C_BEGIN extern "C" { 28# define EMACS_NOEXCEPT noexcept
29#define EMACS_EXTERN_C_END }
30#else 29#else
31#define EMACS_EXTERN_C_BEGIN 30# define EMACS_NOEXCEPT
32#define EMACS_EXTERN_C_END
33#endif 31#endif
34 32
35#if defined(__cplusplus) && __cplusplus >= 201103L 33#ifdef __cplusplus
36#define EMACS_NOEXCEPT noexcept 34extern "C" {
37#else
38#define EMACS_NOEXCEPT
39#endif 35#endif
40 36
41EMACS_EXTERN_C_BEGIN 37/* Current environment. */
42
43/* Current environement */
44typedef struct emacs_env_25 emacs_env; 38typedef struct emacs_env_25 emacs_env;
45 39
46/* Opaque structure pointer representing an Emacs Lisp value */ 40/* Opaque structure pointer representing an Emacs Lisp value. */
47typedef struct emacs_value_tag* emacs_value; 41typedef struct emacs_value_tag *emacs_value;
48 42
49enum emacs_arity { 43enum emacs_arity { emacs_variadic_function = -2 };
50 emacs_variadic_function = -2
51};
52 44
53/* Struct passed to a module init function (emacs_module_init) */ 45/* Struct passed to a module init function (emacs_module_init). */
54struct emacs_runtime { 46struct emacs_runtime
55 /* Structure size (for version checking) */ 47{
48 /* Structure size (for version checking). */
56 size_t size; 49 size_t size;
57 50
58 /* Private data; users should not touch this */ 51 /* Private data; users should not touch this. */
59 struct emacs_runtime_private *private_members; 52 struct emacs_runtime_private *private_members;
60 53
61 /* Returns an environment pointer. */ 54 /* Return an environment pointer. */
62 emacs_env* (*get_environment)(struct emacs_runtime *ert); 55 emacs_env *(*get_environment) (struct emacs_runtime *ert);
63}; 56};
64 57
65 58
66/* Function prototype for the module init function */ 59/* Function prototype for the module init function. */
67typedef int (*emacs_init_function)(struct emacs_runtime *ert); 60typedef int (*emacs_init_function) (struct emacs_runtime *ert);
68 61
69/* Function prototype for the module Lisp functions */ 62/* Function prototype for the module Lisp functions. */
70typedef emacs_value (*emacs_subr)(emacs_env *env, 63typedef emacs_value (*emacs_subr) (emacs_env *env, int nargs, emacs_value args[],
71 int nargs, 64 void *data);
72 emacs_value args[],
73 void *data);
74 65
75/* Function prototype for module user-pointer finalizers */ 66/* Function prototype for module user-pointer finalizers. */
76typedef void (*emacs_finalizer_function)(void*); 67typedef void (*emacs_finalizer_function) (void *);
77 68
78/* Possible Emacs function call outcomes. */ 69/* Possible Emacs function call outcomes. */
79enum emacs_funcall_exit { 70enum emacs_funcall_exit
80 /* Function has returned normally. */ 71{
72 /* Function has returned normally. */
81 emacs_funcall_exit_return = 0, 73 emacs_funcall_exit_return = 0,
82 /* Function has signaled an error using `signal'. */ 74
75 /* Function has signaled an error using `signal'. */
83 emacs_funcall_exit_signal = 1, 76 emacs_funcall_exit_signal = 1,
84 /* Function has exit using `throw'. */ 77
78 /* Function has exit using `throw'. */
85 emacs_funcall_exit_throw = 2, 79 emacs_funcall_exit_throw = 2,
86}; 80};
87 81
88struct emacs_env_25 { 82struct emacs_env_25
89 /* 83{
90 * Structure size (for version checking) 84 /* Structure size (for version checking). */
91 */
92
93 size_t size; 85 size_t size;
94 86
95 /* Private data; users should not touch this */ 87 /* Private data; users should not touch this. */
96 struct emacs_env_private *private_members; 88 struct emacs_env_private *private_members;
97 89
98 /* 90 /* Memory management. */
99 * Memory management 91
100 */ 92 emacs_value (*make_global_ref) (emacs_env *env,
93 emacs_value any_reference);
94
95 void (*free_global_ref) (emacs_env *env,
96 emacs_value global_reference);
97
98 /* Non-local exit handling. */
99
100 enum emacs_funcall_exit (*non_local_exit_check) (emacs_env *env);
101
102 void (*non_local_exit_clear) (emacs_env *env);
103
104 enum emacs_funcall_exit (*non_local_exit_get)
105 (emacs_env *env,
106 emacs_value *non_local_exit_symbol_out,
107 emacs_value *non_local_exit_data_out);
108
109 void (*non_local_exit_signal) (emacs_env *env,
110 emacs_value non_local_exit_symbol,
111 emacs_value non_local_exit_data);
112
113 void (*non_local_exit_throw) (emacs_env *env,
114 emacs_value tag,
115 emacs_value value);
116
117 /* Function registration. */
118
119 emacs_value (*make_function) (emacs_env *env,
120 int min_arity,
121 int max_arity,
122 emacs_value (*function) (emacs_env *, int,
123 emacs_value *, void *)
124 EMACS_NOEXCEPT,
125 const char *documentation,
126 void *data);
101 127
128 emacs_value (*funcall) (emacs_env *env,
129 emacs_value function,
130 int nargs,
131 emacs_value args[]);
102 132
103 emacs_value (*make_global_ref)(emacs_env *env, 133 emacs_value (*intern) (emacs_env *env,
104 emacs_value any_reference); 134 const char *symbol_name);
105 135
106 void (*free_global_ref)(emacs_env *env, 136 /* Type conversion. */
107 emacs_value global_reference);
108 137
109 /* 138 emacs_value (*type_of) (emacs_env *env,
110 * Non-local exit handling 139 emacs_value value);
111 */
112 140
113 enum emacs_funcall_exit (*non_local_exit_check)(emacs_env *env); 141 bool (*is_not_nil) (emacs_env *env, emacs_value value);
114 142
115 void (*non_local_exit_clear)(emacs_env *env); 143 bool (*eq) (emacs_env *env, emacs_value a, emacs_value b);
116 144
117 enum emacs_funcall_exit (*non_local_exit_get)(emacs_env *env, 145 int_fast64_t (*extract_integer) (emacs_env *env,
118 emacs_value *non_local_exit_symbol_out, 146 emacs_value value);
119 emacs_value *non_local_exit_data_out); 147
120 148 emacs_value (*make_integer) (emacs_env *env, int_fast64_t value);
121 void (*non_local_exit_signal)(emacs_env *env, 149
122 emacs_value non_local_exit_symbol, 150 double (*extract_float) (emacs_env *env, emacs_value value);
123 emacs_value non_local_exit_data); 151
124 152 emacs_value (*make_float) (emacs_env *env, double value);
125 void (*non_local_exit_throw)(emacs_env *env, 153
126 emacs_value tag, 154 /* Copy the content of the Lisp string VALUE to BUFFER as an utf8
127 emacs_value value); 155 null-terminated string.
128 156
129 /* 157 SIZE must point to the total size of the buffer. If BUFFER is
130 * Function registration 158 NULL or if SIZE is not big enough, write the required buffer size
131 */ 159 to SIZE and return false.
132 160
133 emacs_value (*make_function)(emacs_env *env, 161 Note that SIZE must include the last null byte (e.g. "abc" needs
134 int min_arity, 162 a buffer of size 4).
135 int max_arity, 163
136 emacs_value (*function)(emacs_env*, int, emacs_value*, void*) EMACS_NOEXCEPT, 164 Return true if the string was successfully copied. */
137 const char *documentation, 165
138 void *data); 166 bool (*copy_string_contents) (emacs_env *env,
139 167 emacs_value value,
140 emacs_value (*funcall)(emacs_env *env, 168 char *buffer,
141 emacs_value function, 169 size_t *size_inout);
142 int nargs, 170
143 emacs_value args[]); 171 /* Create a Lisp string from a utf8 encoded string. */
144 172 emacs_value (*make_string) (emacs_env *env,
145 emacs_value (*intern)(emacs_env *env, 173 const char *contents, size_t length);
146 const char *symbol_name); 174
147 175 /* Embedded pointer type. */
148 /* 176 emacs_value (*make_user_ptr) (emacs_env *env,
149 * Type conversion 177 void (*fin) (void *) EMACS_NOEXCEPT,
150 */ 178 void *ptr);
151 179
152 emacs_value (*type_of)(emacs_env *env, 180 void *(*get_user_ptr) (emacs_env *env, emacs_value uptr);
153 emacs_value value); 181 void (*set_user_ptr) (emacs_env *env, emacs_value uptr, void *ptr);
154 182
155 bool (*is_not_nil)(emacs_env *env, emacs_value value); 183 void (*(*get_user_finalizer) (emacs_env *env, emacs_value uptr))
156 184 (void *) EMACS_NOEXCEPT;
157 bool (*eq)(emacs_env *env, emacs_value a, emacs_value b); 185 void (*set_user_finalizer) (emacs_env *env,
158 186 emacs_value uptr,
159 int64_t (*extract_integer)(emacs_env *env, 187 void (*fin) (void *) EMACS_NOEXCEPT);
160 emacs_value value); 188
161 189 /* Vector functions. */
162 emacs_value (*make_integer)(emacs_env *env, 190 emacs_value (*vec_get) (emacs_env *env, emacs_value vec, size_t i);
163 int64_t value); 191
164 192 void (*vec_set) (emacs_env *env, emacs_value vec, size_t i,
165 double (*extract_float)(emacs_env *env,
166 emacs_value value);
167
168 emacs_value (*make_float)(emacs_env *env,
169 double value);
170
171 /*
172 * Copy the content of the lisp string VALUE to BUFFER as an utf8
173 * null-terminated string.
174 *
175 * SIZE must point to the total size of the buffer. If BUFFER is
176 * NULL or if SIZE is not big enough, write the required buffer size
177 * to SIZE and return false.
178 *
179 * Note that SIZE must include the last null byte (e.g. "abc" needs
180 * a buffer of size 4).
181 *
182 * Returns true if the string was successfully copied.
183 */
184
185 bool (*copy_string_contents)(emacs_env *env,
186 emacs_value value,
187 char *buffer,
188 size_t *size_inout);
189
190 /*
191 * Create a lisp string from a utf8 encoded string.
192 */
193 emacs_value (*make_string)(emacs_env *env,
194 const char *contents, size_t length);
195
196 /*
197 * Embedded pointer type
198 */
199 emacs_value (*make_user_ptr)(emacs_env *env,
200 void (*fin)(void *) EMACS_NOEXCEPT,
201 void *ptr);
202
203 void* (*get_user_ptr)(emacs_env *env, emacs_value uptr);
204 void (*set_user_ptr)(emacs_env *env, emacs_value uptr, void *ptr);
205
206 void (*(*get_user_finalizer)(emacs_env *env, emacs_value uptr))(void *) EMACS_NOEXCEPT;
207 void (*set_user_finalizer)(emacs_env *env,
208 emacs_value uptr,
209 void (*fin)(void *) EMACS_NOEXCEPT);
210
211 /*
212 * Vector functions
213 */
214 emacs_value (*vec_get) (emacs_env *env,
215 emacs_value vec,
216 size_t i);
217
218 void (*vec_set) (emacs_env *env,
219 emacs_value vec,
220 size_t i,
221 emacs_value val); 193 emacs_value val);
222 194
223 size_t (*vec_size) (emacs_env *env, 195 size_t (*vec_size) (emacs_env *env, emacs_value vec);
224 emacs_value vec);
225}; 196};
226 197
227EMACS_EXTERN_C_END 198#ifdef __cplusplus
199}
200#endif
228 201
229#endif /* EMACS_MODULE_H */ 202#endif /* EMACS_MODULE_H */