-
Notifications
You must be signed in to change notification settings - Fork 2
/
emacs-module.h
215 lines (152 loc) · 6.14 KB
/
emacs-module.h
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
/* emacs-module.h - GNU Emacs module API.
Copyright (C) 2015 Free Software Foundation, Inc.
This file is part of GNU Emacs.
GNU Emacs is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
GNU Emacs is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
#ifndef EMACS_MODULE_H
#define EMACS_MODULE_H
#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>
#if defined __cplusplus && __cplusplus >= 201103L
# define EMACS_NOEXCEPT noexcept
/* Function prototype for module user-pointer finalizers.
NOTE: C++11 15.4: An exception-specification shall not appear in a
typedef declaration or alias-declaration.
*/
void emacs_dummy_finalizer_function (void *) noexcept;
typedef decltype(emacs_dummy_finalizer_function) *emacs_finalizer_function;
#else
# define EMACS_NOEXCEPT
typedef void (*emacs_finalizer_function) (void *);
#endif
#ifdef __cplusplus
extern "C" {
#endif
/* Current environment. */
typedef struct emacs_env_25 emacs_env;
/* Opaque pointer representing an Emacs Lisp value.
BEWARE: Do not assume NULL is a valid value! */
typedef struct emacs_value_tag *emacs_value;
enum emacs_arity { emacs_variadic_function = -2 };
/* Struct passed to a module init function (emacs_module_init). */
struct emacs_runtime
{
/* Structure size (for version checking). */
ptrdiff_t size;
/* Private data; users should not touch this. */
struct emacs_runtime_private *private_members;
/* Return an environment pointer. */
emacs_env *(*get_environment) (struct emacs_runtime *ert);
};
/* Function prototype for the module init function. */
typedef int (*emacs_init_function) (struct emacs_runtime *ert);
/* Function prototype for the module Lisp functions. */
typedef emacs_value (*emacs_subr) (emacs_env *env, ptrdiff_t nargs,
emacs_value args[], void *data);
/* Possible Emacs function call outcomes. */
enum emacs_funcall_exit
{
/* Function has returned normally. */
emacs_funcall_exit_return = 0,
/* Function has signaled an error using `signal'. */
emacs_funcall_exit_signal = 1,
/* Function has exit using `throw'. */
emacs_funcall_exit_throw = 2,
};
struct emacs_env_25
{
/* Structure size (for version checking). */
ptrdiff_t size;
/* Private data; users should not touch this. */
struct emacs_env_private *private_members;
/* Memory management. */
emacs_value (*make_global_ref) (emacs_env *env,
emacs_value any_reference);
void (*free_global_ref) (emacs_env *env,
emacs_value global_reference);
/* Non-local exit handling. */
enum emacs_funcall_exit (*non_local_exit_check) (emacs_env *env);
void (*non_local_exit_clear) (emacs_env *env);
enum emacs_funcall_exit (*non_local_exit_get)
(emacs_env *env,
emacs_value *non_local_exit_symbol_out,
emacs_value *non_local_exit_data_out);
void (*non_local_exit_signal) (emacs_env *env,
emacs_value non_local_exit_symbol,
emacs_value non_local_exit_data);
void (*non_local_exit_throw) (emacs_env *env,
emacs_value tag,
emacs_value value);
/* Function registration. */
emacs_value (*make_function) (emacs_env *env,
ptrdiff_t min_arity,
ptrdiff_t max_arity,
emacs_value (*function) (emacs_env *env,
ptrdiff_t nargs,
emacs_value args[],
void *)
EMACS_NOEXCEPT,
const char *documentation,
void *data);
emacs_value (*funcall) (emacs_env *env,
emacs_value function,
ptrdiff_t nargs,
emacs_value args[]);
emacs_value (*intern) (emacs_env *env,
const char *symbol_name);
/* Type conversion. */
emacs_value (*type_of) (emacs_env *env,
emacs_value value);
bool (*is_not_nil) (emacs_env *env, emacs_value value);
bool (*eq) (emacs_env *env, emacs_value a, emacs_value b);
intmax_t (*extract_integer) (emacs_env *env, emacs_value value);
emacs_value (*make_integer) (emacs_env *env, intmax_t value);
double (*extract_float) (emacs_env *env, emacs_value value);
emacs_value (*make_float) (emacs_env *env, double value);
/* Copy the content of the Lisp string VALUE to BUFFER as an utf8
null-terminated string.
SIZE must point to the total size of the buffer. If BUFFER is
NULL or if SIZE is not big enough, write the required buffer size
to SIZE and return false.
Note that SIZE must include the last null byte (e.g. "abc" needs
a buffer of size 4).
Return true if the string was successfully copied. */
bool (*copy_string_contents) (emacs_env *env,
emacs_value value,
char *buffer,
ptrdiff_t *size_inout);
/* Create a Lisp string from a utf8 encoded string. */
emacs_value (*make_string) (emacs_env *env,
const char *contents, ptrdiff_t length);
/* Embedded pointer type. */
emacs_value (*make_user_ptr) (emacs_env *env,
emacs_finalizer_function fin,
void *ptr);
void *(*get_user_ptr) (emacs_env *env, emacs_value uptr);
void (*set_user_ptr) (emacs_env *env, emacs_value uptr, void *ptr);
emacs_finalizer_function (*get_user_finalizer) (emacs_env *env,
emacs_value uptr);
void (*set_user_finalizer) (emacs_env *env,
emacs_value uptr,
emacs_finalizer_function fin);
/* Vector functions. */
emacs_value (*vec_get) (emacs_env *env, emacs_value vec, ptrdiff_t i);
void (*vec_set) (emacs_env *env, emacs_value vec, ptrdiff_t i,
emacs_value val);
ptrdiff_t (*vec_size) (emacs_env *env, emacs_value vec);
};
/* Every module should define a function as follows. */
extern int emacs_module_init (struct emacs_runtime *ert);
#ifdef __cplusplus
}
#endif
#endif /* EMACS_MODULE_H */