6
/* Copyright (C) 1995,1996,1997,1998,1999,2000,2001, 2002, 2003, 2004, 2006 Free Software Foundation, Inc.
8
* This library is free software; you can redistribute it and/or
9
* modify it under the terms of the GNU Lesser General Public
10
* License as published by the Free Software Foundation; either
11
* version 2.1 of the License, or (at your option) any later version.
13
* This library is distributed in the hope that it will be useful,
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16
* Lesser General Public License for more details.
18
* You should have received a copy of the GNU Lesser General Public
19
* License along with this library; if not, write to the Free Software
20
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
25
/* Macros for snarfing initialization actions from C source. */
27
#if defined(__cplusplus) || defined(GUILE_CPLUSPLUS_SNARF)
29
/* This used to be "SCM (*)(...)" but GCC on RedHat 7.1 doesn't seem
32
#define SCM_FUNC_CAST_ARBITRARY_ARGS SCM (*)()
35
#define SCM_FUNC_CAST_ARBITRARY_ARGS SCM (*)()
38
/* Generic macros to be used in user macro definitions.
40
* For example, in order to define a macro which creates ints and
41
* initializes them to the result of foo (), do:
43
* #define SCM_FOO(NAME) \
44
* SCM_SNARF_HERE (int NAME) \
45
* SCM_SNARF_INIT (NAME = foo ())
47
* The SCM_SNARF_INIT text goes into the corresponding .x file
48
* up through the first occurrence of SCM_SNARF_DOC_START on that
52
#ifdef SCM_MAGIC_SNARF_INITS
53
# define SCM_SNARF_HERE(X)
54
# define SCM_SNARF_INIT(X) ^^ X ^:^
55
# define SCM_SNARF_DOCS(TYPE, CNAME, FNAME, ARGLIST, REQ, OPT, VAR, DOCSTRING)
57
# ifdef SCM_MAGIC_SNARF_DOCS
58
# define SCM_SNARF_HERE(X)
59
# define SCM_SNARF_INIT(X)
60
# define SCM_SNARF_DOCS(TYPE, CNAME, FNAME, ARGLIST, REQ, OPT, VAR, DOCSTRING) \
65
location __FILE__ __LINE__ ^^ \
67
argsig REQ OPT VAR ^^ \
70
# define SCM_SNARF_HERE(X) X
71
# define SCM_SNARF_INIT(X)
72
# define SCM_SNARF_DOCS(TYPE, CNAME, FNAME, ARGLIST, REQ, OPT, VAR, DOCSTRING)
76
#define SCM_DEFINE(FNAME, PRIMNAME, REQ, OPT, VAR, ARGLIST, DOCSTRING) \
78
static const char s_ ## FNAME [] = PRIMNAME; \
82
scm_c_define_gsubr (s_ ## FNAME, REQ, OPT, VAR, \
83
(SCM_FUNC_CAST_ARBITRARY_ARGS) FNAME); \
85
SCM_SNARF_DOCS(primitive, FNAME, PRIMNAME, ARGLIST, REQ, OPT, VAR, DOCSTRING)
87
#define SCM_PRIMITIVE_GENERIC(FNAME, PRIMNAME, REQ, OPT, VAR, ARGLIST, DOCSTRING) \
89
static const char s_ ## FNAME [] = PRIMNAME; \
90
static SCM g_ ## FNAME; \
94
g_ ## FNAME = SCM_PACK (0); \
95
scm_c_define_gsubr_with_generic (s_ ## FNAME, REQ, OPT, VAR, \
96
(SCM_FUNC_CAST_ARBITRARY_ARGS) FNAME, \
99
SCM_SNARF_DOCS(primitive, FNAME, PRIMNAME, ARGLIST, REQ, OPT, VAR, DOCSTRING)
101
#define SCM_DEFINE_PUBLIC(FNAME, PRIMNAME, REQ, OPT, VAR, ARGLIST, DOCSTRING) \
103
static const char s_ ## FNAME [] = PRIMNAME; \
107
scm_c_define_gsubr (s_ ## FNAME, REQ, OPT, VAR, \
108
(SCM_FUNC_CAST_ARBITRARY_ARGS) FNAME); \
109
scm_c_export (s_ ## FNAME, NULL); \
111
SCM_SNARF_DOCS(primitive, FNAME, PRIMNAME, ARGLIST, REQ, OPT, VAR, DOCSTRING)
113
#define SCM_DEFINE1(FNAME, PRIMNAME, TYPE, ARGLIST, DOCSTRING) \
115
static const char s_ ## FNAME [] = PRIMNAME; \
118
SCM_SNARF_INIT(scm_c_define_subr (s_ ## FNAME, TYPE, FNAME); ) \
119
SCM_SNARF_DOCS(1, FNAME, PRIMNAME, ARGLIST, 2, 0, 0, DOCSTRING)
121
#define SCM_PRIMITIVE_GENERIC_1(FNAME, PRIMNAME, TYPE, ARGLIST, DOCSTRING) \
123
static const char s_ ## FNAME [] = PRIMNAME; \
124
static SCM g_ ## FNAME; \
128
g_ ## FNAME = SCM_PACK (0); \
129
scm_c_define_subr_with_generic (s_ ## FNAME, TYPE, FNAME, &g_ ## FNAME); \
131
SCM_SNARF_DOCS(1, FNAME, PRIMNAME, ARGLIST, 2, 0, 0, DOCSTRING)
133
#define SCM_PROC(RANAME, STR, REQ, OPT, VAR, CFN) \
134
SCM_SNARF_HERE(static const char RANAME[]=STR) \
135
SCM_SNARF_INIT(scm_c_define_gsubr (RANAME, REQ, OPT, VAR, \
136
(SCM_FUNC_CAST_ARBITRARY_ARGS) CFN))
138
#define SCM_REGISTER_PROC(RANAME, STR, REQ, OPT, VAR, CFN) \
139
SCM_SNARF_HERE(static const char RANAME[]=STR) \
140
SCM_SNARF_INIT(scm_c_define_gsubr (RANAME, REQ, OPT, VAR, \
141
(SCM_FUNC_CAST_ARBITRARY_ARGS) CFN);) \
142
SCM_SNARF_DOCS(register, CFN, STR, (), REQ, OPT, VAR, \
143
"implemented by the C function \"" #CFN "\"")
145
#define SCM_GPROC(RANAME, STR, REQ, OPT, VAR, CFN, GF) \
147
static const char RANAME[]=STR;\
150
GF = SCM_PACK (0); /* Dirk:FIXME:: Can we safely use #f instead of 0? */ \
151
scm_c_define_gsubr_with_generic (RANAME, REQ, OPT, VAR, \
152
(SCM_FUNC_CAST_ARBITRARY_ARGS) CFN, &GF) \
155
#define SCM_PROC1(RANAME, STR, TYPE, CFN) \
156
SCM_SNARF_HERE(static const char RANAME[]=STR) \
158
scm_c_define_subr (RANAME, TYPE, (SCM_FUNC_CAST_ARBITRARY_ARGS) CFN) \
162
#define SCM_GPROC1(RANAME, STR, TYPE, CFN, GF) \
164
static const char RANAME[]=STR; \
167
GF = SCM_PACK (0); /* Dirk:FIXME:: Can we safely use #f instead of 0? */ \
168
scm_c_define_subr_with_generic (RANAME, TYPE, \
169
(SCM_FUNC_CAST_ARBITRARY_ARGS) CFN, &GF) \
172
#define SCM_SYNTAX(RANAME, STR, TYPE, CFN) \
173
SCM_SNARF_HERE(static const char RANAME[]=STR)\
174
SCM_SNARF_INIT(scm_make_synt (RANAME, TYPE, CFN))
176
#define SCM_SYMBOL(c_name, scheme_name) \
177
SCM_SNARF_HERE(static SCM c_name) \
178
SCM_SNARF_INIT(c_name = scm_permanent_object (scm_from_locale_symbol (scheme_name)))
180
#define SCM_GLOBAL_SYMBOL(c_name, scheme_name) \
181
SCM_SNARF_HERE(SCM c_name) \
182
SCM_SNARF_INIT(c_name = scm_permanent_object (scm_from_locale_symbol (scheme_name)))
184
#define SCM_KEYWORD(c_name, scheme_name) \
185
SCM_SNARF_HERE(static SCM c_name) \
186
SCM_SNARF_INIT(c_name = scm_permanent_object (scm_from_locale_keyword (scheme_name)))
188
#define SCM_GLOBAL_KEYWORD(c_name, scheme_name) \
189
SCM_SNARF_HERE(SCM c_name) \
190
SCM_SNARF_INIT(c_name = scm_permanent_object (scm_from_locale_keyword (scheme_name)))
192
#define SCM_VARIABLE(c_name, scheme_name) \
193
SCM_SNARF_HERE(static SCM c_name) \
194
SCM_SNARF_INIT(c_name = scm_permanent_object (scm_c_define (scheme_name, SCM_BOOL_F));)
196
#define SCM_GLOBAL_VARIABLE(c_name, scheme_name) \
197
SCM_SNARF_HERE(SCM c_name) \
198
SCM_SNARF_INIT(c_name = scm_permanent_object (scm_c_define (scheme_name, SCM_BOOL_F));)
200
#define SCM_VARIABLE_INIT(c_name, scheme_name, init_val) \
201
SCM_SNARF_HERE(static SCM c_name) \
202
SCM_SNARF_INIT(c_name = scm_permanent_object (scm_c_define (scheme_name, init_val));)
204
#define SCM_GLOBAL_VARIABLE_INIT(c_name, scheme_name, init_val) \
205
SCM_SNARF_HERE(SCM c_name) \
206
SCM_SNARF_INIT(c_name = scm_permanent_object (scm_c_define (scheme_name, init_val));)
208
#define SCM_MUTEX(c_name) \
209
SCM_SNARF_HERE(static scm_t_mutex c_name) \
210
SCM_SNARF_INIT(scm_i_plugin_mutex_init (&c_name, &scm_i_plugin_mutex))
212
#define SCM_GLOBAL_MUTEX(c_name) \
213
SCM_SNARF_HERE(scm_t_mutex c_name) \
214
SCM_SNARF_INIT(scm_i_plugin_mutex_init (&c_name, &scm_i_plugin_mutex))
216
#define SCM_REC_MUTEX(c_name) \
217
SCM_SNARF_HERE(static scm_t_rec_mutex c_name) \
218
SCM_SNARF_INIT(scm_i_plugin_rec_mutex_init (&c_name, &scm_i_plugin_rec_mutex))
220
#define SCM_GLOBAL_REC_MUTEX(c_name) \
221
SCM_SNARF_HERE(scm_t_rec_mutex c_name) \
222
SCM_SNARF_INIT(scm_i_plugin_rec_mutex_init (&c_name, &scm_i_plugin_rec_mutex))
224
#define SCM_SMOB(tag, scheme_name, size) \
225
SCM_SNARF_HERE(static scm_t_bits tag) \
226
SCM_SNARF_INIT((tag)=scm_make_smob_type((scheme_name), (size));)
228
#define SCM_GLOBAL_SMOB(tag, scheme_name, size) \
229
SCM_SNARF_HERE(scm_t_bits tag) \
230
SCM_SNARF_INIT((tag)=scm_make_smob_type((scheme_name), (size));)
232
#define SCM_SMOB_MARK(tag, c_name, arg) \
233
SCM_SNARF_HERE(static SCM c_name(SCM arg)) \
234
SCM_SNARF_INIT(scm_set_smob_mark((tag), (c_name));)
236
#define SCM_GLOBAL_SMOB_MARK(tag, c_name, arg) \
237
SCM_SNARF_HERE(SCM c_name(SCM arg)) \
238
SCM_SNARF_INIT(scm_set_smob_mark((tag), (c_name));)
240
#define SCM_SMOB_FREE(tag, c_name, arg) \
241
SCM_SNARF_HERE(static size_t c_name(SCM arg)) \
242
SCM_SNARF_INIT(scm_set_smob_free((tag), (c_name));)
244
#define SCM_GLOBAL_SMOB_FREE(tag, c_name, arg) \
245
SCM_SNARF_HERE(size_t c_name(SCM arg)) \
246
SCM_SNARF_INIT(scm_set_smob_free((tag), (c_name));)
248
#define SCM_SMOB_PRINT(tag, c_name, obj, port, pstate) \
249
SCM_SNARF_HERE(static int c_name(SCM obj, SCM port, scm_print_state* pstate)) \
250
SCM_SNARF_INIT(scm_set_smob_print((tag), (c_name));)
252
#define SCM_GLOBAL_SMOB_PRINT(tag, c_name, obj, port, pstate) \
253
SCM_SNARF_HERE(int c_name(SCM obj, SCM port, scm_print_state* pstate)) \
254
SCM_SNARF_INIT(scm_set_smob_print((tag), (c_name));)
256
#define SCM_SMOB_EQUALP(tag, c_name, obj1, obj2) \
257
SCM_SNARF_HERE(static SCM c_name(SCM obj1, SCM obj2)) \
258
SCM_SNARF_INIT(scm_set_smob_equalp((tag), (c_name));)
260
#define SCM_GLOBAL_SMOB_EQUALP(tag, c_name, obj1, obj2) \
261
SCM_SNARF_HERE(SCM c_name(SCM obj1, SCM obj2)) \
262
SCM_SNARF_INIT(scm_set_smob_equalp((tag), (c_name));)
264
#define SCM_SMOB_APPLY(tag, c_name, req, opt, rest, arglist) \
265
SCM_SNARF_HERE(static SCM c_name arglist) \
266
SCM_SNARF_INIT(scm_set_smob_apply((tag), (c_name), (req), (opt), (rest));)
268
#define SCM_GLOBAL_SMOB_APPLY(tag, c_name, req, opt, rest, arglist) \
269
SCM_SNARF_HERE(SCM c_name arglist) \
270
SCM_SNARF_INIT(scm_set_smob_apply((tag), (c_name), (req), (opt), (rest));)
273
#ifdef SCM_MAGIC_SNARF_DOCS
275
#define SCM_ASSERT(_cond, _arg, _pos, _subr) ^^ argpos _arg _pos __LINE__ ^^
276
#endif /* SCM_MAGIC_SNARF_DOCS */
278
#endif /* SCM_SNARF_H */