drop extra 2006-02-06 heading
[bpt/guile.git] / libguile / snarf.h
CommitLineData
5b4215a8
JB
1/* classes: h_files */
2
b29058ff
DH
3#ifndef SCM_SNARF_H
4#define SCM_SNARF_H
5b4215a8 5
2b829bbb 6/* Copyright (C) 1995,1996,1997,1998,1999,2000,2001, 2002, 2003, 2004, 2006 Free Software Foundation, Inc.
b29058ff 7 *
73be1d9e
MV
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.
b29058ff 12 *
73be1d9e 13 * This library is distributed in the hope that it will be useful,
5b4215a8 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
73be1d9e
MV
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
b29058ff 17 *
73be1d9e
MV
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
92205699 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
73be1d9e 21 */
1bbd0b84 22
5b4215a8
JB
23\f
24
b29058ff
DH
25/* Macros for snarfing initialization actions from C source. */
26
4b4d0898 27#if defined(__cplusplus) || defined(GUILE_CPLUSPLUS_SNARF)
e1fbffa9
MV
28
29/* This used to be "SCM (*)(...)" but GCC on RedHat 7.1 doesn't seem
30 to like it.
31 */
32#define SCM_FUNC_CAST_ARBITRARY_ARGS SCM (*)()
33
bfe19b46 34#else
4b4d0898 35#define SCM_FUNC_CAST_ARBITRARY_ARGS SCM (*)()
bfe19b46
MD
36#endif
37
73d8385e
MD
38/* Generic macros to be used in user macro definitions.
39 *
40 * For example, in order to define a macro which creates ints and
41 * initializes them to the result of foo (), do:
42 *
43 * #define SCM_FOO(NAME) \
94a70859
MD
44 * SCM_SNARF_HERE (int NAME) \
45 * SCM_SNARF_INIT (NAME = foo ())
1e76143f 46 *
94a70859 47 * The SCM_SNARF_INIT text goes into the corresponding .x file
3c6d9d71
DH
48 * up through the first occurrence of SCM_SNARF_DOC_START on that
49 * line, if any.
73d8385e
MD
50 */
51
c99f9605
ML
52#ifdef SCM_MAGIC_SNARF_INITS
53# define SCM_SNARF_HERE(X)
09e804ff 54# define SCM_SNARF_INIT(X) ^^ X ^:^
cecb4a5e 55# define SCM_SNARF_DOCS(TYPE, CNAME, FNAME, ARGLIST, REQ, OPT, VAR, DOCSTRING)
1e76143f 56#else
c99f9605 57# ifdef SCM_MAGIC_SNARF_DOCS
94a70859 58# define SCM_SNARF_HERE(X)
c99f9605 59# define SCM_SNARF_INIT(X)
cecb4a5e 60# define SCM_SNARF_DOCS(TYPE, CNAME, FNAME, ARGLIST, REQ, OPT, VAR, DOCSTRING) \
ac13d9d2 61^^ { \
cecb4a5e 62cname CNAME ^^ \
ac13d9d2
ML
63fname FNAME ^^ \
64type TYPE ^^ \
65location __FILE__ __LINE__ ^^ \
66arglist ARGLIST ^^ \
67argsig REQ OPT VAR ^^ \
68DOCSTRING ^^ }
c99f9605
ML
69# else
70# define SCM_SNARF_HERE(X) X
71# define SCM_SNARF_INIT(X)
cecb4a5e 72# define SCM_SNARF_DOCS(TYPE, CNAME, FNAME, ARGLIST, REQ, OPT, VAR, DOCSTRING)
c99f9605 73# endif
1e76143f 74#endif
73d8385e 75
a1ec6916 76#define SCM_DEFINE(FNAME, PRIMNAME, REQ, OPT, VAR, ARGLIST, DOCSTRING) \
94a70859 77SCM_SNARF_HERE(\
4b4d0898
GB
78static const char s_ ## FNAME [] = PRIMNAME; \
79SCM FNAME ARGLIST\
80)\
94a70859 81SCM_SNARF_INIT(\
9a441ddb
MV
82scm_c_define_gsubr (s_ ## FNAME, REQ, OPT, VAR, \
83 (SCM_FUNC_CAST_ARBITRARY_ARGS) FNAME); \
2fdcf8bd 84)\
cecb4a5e 85SCM_SNARF_DOCS(primitive, FNAME, PRIMNAME, ARGLIST, REQ, OPT, VAR, DOCSTRING)
1bbd0b84 86
a48d60b1
MD
87#define SCM_PRIMITIVE_GENERIC(FNAME, PRIMNAME, REQ, OPT, VAR, ARGLIST, DOCSTRING) \
88SCM_SNARF_HERE(\
89static const char s_ ## FNAME [] = PRIMNAME; \
90static SCM g_ ## FNAME; \
91SCM FNAME ARGLIST\
92)\
93SCM_SNARF_INIT(\
94g_ ## FNAME = SCM_PACK (0); \
95scm_c_define_gsubr_with_generic (s_ ## FNAME, REQ, OPT, VAR, \
96 (SCM_FUNC_CAST_ARBITRARY_ARGS) FNAME, \
97 &g_ ## FNAME); \
98)\
99SCM_SNARF_DOCS(primitive, FNAME, PRIMNAME, ARGLIST, REQ, OPT, VAR, DOCSTRING)
100
5527702a
MV
101#define SCM_DEFINE_PUBLIC(FNAME, PRIMNAME, REQ, OPT, VAR, ARGLIST, DOCSTRING) \
102SCM_SNARF_HERE(\
103static const char s_ ## FNAME [] = PRIMNAME; \
104SCM FNAME ARGLIST\
105)\
106SCM_SNARF_INIT(\
107scm_c_define_gsubr (s_ ## FNAME, REQ, OPT, VAR, \
108 (SCM_FUNC_CAST_ARBITRARY_ARGS) FNAME); \
109scm_c_export (s_ ## FNAME, NULL); \
110)\
111SCM_SNARF_DOCS(primitive, FNAME, PRIMNAME, ARGLIST, REQ, OPT, VAR, DOCSTRING)
112
c3ee7520 113#define SCM_DEFINE1(FNAME, PRIMNAME, TYPE, ARGLIST, DOCSTRING) \
94a70859 114SCM_SNARF_HERE(\
4b4d0898
GB
115static const char s_ ## FNAME [] = PRIMNAME; \
116SCM FNAME ARGLIST\
2fdcf8bd 117)\
9a441ddb 118SCM_SNARF_INIT(scm_c_define_subr (s_ ## FNAME, TYPE, FNAME); ) \
cecb4a5e 119SCM_SNARF_DOCS(1, FNAME, PRIMNAME, ARGLIST, 2, 0, 0, DOCSTRING)
1bbd0b84 120
a48d60b1
MD
121#define SCM_PRIMITIVE_GENERIC_1(FNAME, PRIMNAME, TYPE, ARGLIST, DOCSTRING) \
122SCM_SNARF_HERE(\
123static const char s_ ## FNAME [] = PRIMNAME; \
124static SCM g_ ## FNAME; \
125SCM FNAME ARGLIST\
126)\
127SCM_SNARF_INIT(\
128g_ ## FNAME = SCM_PACK (0); \
129scm_c_define_subr_with_generic (s_ ## FNAME, TYPE, FNAME, &g_ ## FNAME); \
130)\
131SCM_SNARF_DOCS(1, FNAME, PRIMNAME, ARGLIST, 2, 0, 0, DOCSTRING)
132
9b1594fd 133#define SCM_PROC(RANAME, STR, REQ, OPT, VAR, CFN) \
94a70859 134SCM_SNARF_HERE(static const char RANAME[]=STR) \
9a441ddb
MV
135SCM_SNARF_INIT(scm_c_define_gsubr (RANAME, REQ, OPT, VAR, \
136 (SCM_FUNC_CAST_ARBITRARY_ARGS) CFN))
9b1594fd 137
1bbd0b84 138#define SCM_REGISTER_PROC(RANAME, STR, REQ, OPT, VAR, CFN) \
94a70859 139SCM_SNARF_HERE(static const char RANAME[]=STR) \
9a441ddb
MV
140SCM_SNARF_INIT(scm_c_define_gsubr (RANAME, REQ, OPT, VAR, \
141 (SCM_FUNC_CAST_ARBITRARY_ARGS) CFN);) \
cecb4a5e 142SCM_SNARF_DOCS(register, CFN, STR, (), REQ, OPT, VAR, \
c99f9605 143 "implemented by the C function \"" #CFN "\"")
3dc81fba 144
9de33deb 145#define SCM_GPROC(RANAME, STR, REQ, OPT, VAR, CFN, GF) \
94a70859 146SCM_SNARF_HERE(\
4b4d0898 147static const char RANAME[]=STR;\
54778cd3 148static SCM GF \
94a70859 149)SCM_SNARF_INIT(\
54778cd3 150GF = SCM_PACK (0); /* Dirk:FIXME:: Can we safely use #f instead of 0? */ \
9a441ddb
MV
151scm_c_define_gsubr_with_generic (RANAME, REQ, OPT, VAR, \
152 (SCM_FUNC_CAST_ARBITRARY_ARGS) CFN, &GF) \
4b4d0898 153)
3dc81fba 154
4b4d0898 155#define SCM_PROC1(RANAME, STR, TYPE, CFN) \
94a70859
MD
156SCM_SNARF_HERE(static const char RANAME[]=STR) \
157SCM_SNARF_INIT(\
9a441ddb 158scm_c_define_subr (RANAME, TYPE, (SCM_FUNC_CAST_ARBITRARY_ARGS) CFN) \
4b4d0898 159)
9b1594fd 160
9b1594fd 161
4b4d0898 162#define SCM_GPROC1(RANAME, STR, TYPE, CFN, GF) \
94a70859 163SCM_SNARF_HERE(\
4b4d0898 164static const char RANAME[]=STR; \
54778cd3 165static SCM GF \
94a70859 166)SCM_SNARF_INIT(\
54778cd3 167GF = SCM_PACK (0); /* Dirk:FIXME:: Can we safely use #f instead of 0? */ \
9a441ddb
MV
168scm_c_define_subr_with_generic (RANAME, TYPE, \
169 (SCM_FUNC_CAST_ARBITRARY_ARGS) CFN, &GF) \
4b4d0898 170)
5b4215a8 171
b8229a3b 172#define SCM_SYNTAX(RANAME, STR, TYPE, CFN) \
94a70859
MD
173SCM_SNARF_HERE(static const char RANAME[]=STR)\
174SCM_SNARF_INIT(scm_make_synt (RANAME, TYPE, CFN))
b8229a3b 175
5b4215a8 176#define SCM_SYMBOL(c_name, scheme_name) \
94a70859 177SCM_SNARF_HERE(static SCM c_name) \
cc95e00a 178SCM_SNARF_INIT(c_name = scm_permanent_object (scm_from_locale_symbol (scheme_name)))
5b4215a8 179
78f9f47b 180#define SCM_GLOBAL_SYMBOL(c_name, scheme_name) \
94a70859 181SCM_SNARF_HERE(SCM c_name) \
cc95e00a 182SCM_SNARF_INIT(c_name = scm_permanent_object (scm_from_locale_symbol (scheme_name)))
78f9f47b 183
37b83f68 184#define SCM_KEYWORD(c_name, scheme_name) \
94a70859 185SCM_SNARF_HERE(static SCM c_name) \
ee4140fb 186SCM_SNARF_INIT(c_name = scm_permanent_object (scm_from_locale_keyword (scheme_name)))
37b83f68 187
37b83f68 188#define SCM_GLOBAL_KEYWORD(c_name, scheme_name) \
94a70859 189SCM_SNARF_HERE(SCM c_name) \
ee4140fb 190SCM_SNARF_INIT(c_name = scm_permanent_object (scm_from_locale_keyword (scheme_name)))
5b4215a8 191
86d31dfe
MV
192#define SCM_VARIABLE(c_name, scheme_name) \
193SCM_SNARF_HERE(static SCM c_name) \
194SCM_SNARF_INIT(c_name = scm_permanent_object (scm_c_define (scheme_name, SCM_BOOL_F));)
195
196#define SCM_GLOBAL_VARIABLE(c_name, scheme_name) \
197SCM_SNARF_HERE(SCM c_name) \
198SCM_SNARF_INIT(c_name = scm_permanent_object (scm_c_define (scheme_name, SCM_BOOL_F));)
199
200#define SCM_VARIABLE_INIT(c_name, scheme_name, init_val) \
201SCM_SNARF_HERE(static SCM c_name) \
202SCM_SNARF_INIT(c_name = scm_permanent_object (scm_c_define (scheme_name, init_val));)
203
204#define SCM_GLOBAL_VARIABLE_INIT(c_name, scheme_name, init_val) \
205SCM_SNARF_HERE(SCM c_name) \
206SCM_SNARF_INIT(c_name = scm_permanent_object (scm_c_define (scheme_name, init_val));)
207
28d52ebb
MD
208#define SCM_MUTEX(c_name) \
209SCM_SNARF_HERE(static scm_t_mutex c_name) \
210SCM_SNARF_INIT(scm_i_plugin_mutex_init (&c_name, &scm_i_plugin_mutex))
9bc4701c 211
28d52ebb
MD
212#define SCM_GLOBAL_MUTEX(c_name) \
213SCM_SNARF_HERE(scm_t_mutex c_name) \
214SCM_SNARF_INIT(scm_i_plugin_mutex_init (&c_name, &scm_i_plugin_mutex))
9bc4701c 215
28d52ebb
MD
216#define SCM_REC_MUTEX(c_name) \
217SCM_SNARF_HERE(static scm_t_rec_mutex c_name) \
218SCM_SNARF_INIT(scm_i_plugin_rec_mutex_init (&c_name, &scm_i_plugin_rec_mutex))
9bc4701c 219
28d52ebb
MD
220#define SCM_GLOBAL_REC_MUTEX(c_name) \
221SCM_SNARF_HERE(scm_t_rec_mutex c_name) \
0b6843b1 222SCM_SNARF_INIT(scm_i_plugin_rec_mutex_init (&c_name, &scm_i_plugin_rec_mutex))
9bc4701c 223
94e38a65
MV
224#define SCM_SMOB(tag, scheme_name, size) \
225SCM_SNARF_HERE(static scm_t_bits tag) \
226SCM_SNARF_INIT((tag)=scm_make_smob_type((scheme_name), (size));)
227
228#define SCM_GLOBAL_SMOB(tag, scheme_name, size) \
229SCM_SNARF_HERE(scm_t_bits tag) \
230SCM_SNARF_INIT((tag)=scm_make_smob_type((scheme_name), (size));)
231
232#define SCM_SMOB_MARK(tag, c_name, arg) \
233SCM_SNARF_HERE(static SCM c_name(SCM arg)) \
234SCM_SNARF_INIT(scm_set_smob_mark((tag), (c_name));)
235
236#define SCM_GLOBAL_SMOB_MARK(tag, c_name, arg) \
237SCM_SNARF_HERE(SCM c_name(SCM arg)) \
238SCM_SNARF_INIT(scm_set_smob_mark((tag), (c_name));)
239
240#define SCM_SMOB_FREE(tag, c_name, arg) \
241SCM_SNARF_HERE(static size_t c_name(SCM arg)) \
242SCM_SNARF_INIT(scm_set_smob_free((tag), (c_name));)
243
244#define SCM_GLOBAL_SMOB_FREE(tag, c_name, arg) \
245SCM_SNARF_HERE(size_t c_name(SCM arg)) \
246SCM_SNARF_INIT(scm_set_smob_free((tag), (c_name));)
247
248#define SCM_SMOB_PRINT(tag, c_name, obj, port, pstate) \
249SCM_SNARF_HERE(static int c_name(SCM obj, SCM port, scm_print_state* pstate)) \
250SCM_SNARF_INIT(scm_set_smob_print((tag), (c_name));)
251
252#define SCM_GLOBAL_SMOB_PRINT(tag, c_name, obj, port, pstate) \
253SCM_SNARF_HERE(int c_name(SCM obj, SCM port, scm_print_state* pstate)) \
254SCM_SNARF_INIT(scm_set_smob_print((tag), (c_name));)
255
256#define SCM_SMOB_EQUALP(tag, c_name, obj1, obj2) \
257SCM_SNARF_HERE(static SCM c_name(SCM obj1, SCM obj2)) \
258SCM_SNARF_INIT(scm_set_smob_equalp((tag), (c_name));)
259
260#define SCM_GLOBAL_SMOB_EQUALP(tag, c_name, obj1, obj2) \
261SCM_SNARF_HERE(SCM c_name(SCM obj1, SCM obj2)) \
262SCM_SNARF_INIT(scm_set_smob_equalp((tag), (c_name));)
263
264#define SCM_SMOB_APPLY(tag, c_name, req, opt, rest, arglist) \
265SCM_SNARF_HERE(static SCM c_name arglist) \
266SCM_SNARF_INIT(scm_set_smob_apply((tag), (c_name), (req), (opt), (rest));)
267
268#define SCM_GLOBAL_SMOB_APPLY(tag, c_name, req, opt, rest, arglist) \
269SCM_SNARF_HERE(SCM c_name arglist) \
270SCM_SNARF_INIT(scm_set_smob_apply((tag), (c_name), (req), (opt), (rest));)
271
272
c99f9605 273#ifdef SCM_MAGIC_SNARF_DOCS
4b4d0898 274#undef SCM_ASSERT
ac13d9d2 275#define SCM_ASSERT(_cond, _arg, _pos, _subr) ^^ argpos _arg _pos __LINE__ ^^
c99f9605 276#endif /* SCM_MAGIC_SNARF_DOCS */
2e07d033 277
b29058ff 278#endif /* SCM_SNARF_H */
89e00824
ML
279
280/*
281 Local Variables:
282 c-file-style: "gnu"
283 End:
284*/