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