Avoid unpacking symbols in GOOPS
[bpt/guile.git] / libguile / snarf.h
... / ...
CommitLineData
1/* classes: h_files */
2
3#ifndef SCM_SNARF_H
4#define SCM_SNARF_H
5
6/* Copyright (C) 1995,1996,1997,1998,1999,2000,2001, 2002, 2003, 2004, 2006 Free Software Foundation, Inc.
7 *
8 * This library is free software; you can redistribute it and/or
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.
12 *
13 * This library is distributed in the hope that it will be useful, but
14 * 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.
17 *
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
21 * 02110-1301 USA
22 */
23
24\f
25
26/* Macros for snarfing initialization actions from C source. */
27
28#if defined(__cplusplus) || defined(GUILE_CPLUSPLUS_SNARF)
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
35#else
36#define SCM_FUNC_CAST_ARBITRARY_ARGS SCM (*)()
37#endif
38
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) \
45 * SCM_SNARF_HERE (int NAME) \
46 * SCM_SNARF_INIT (NAME = foo ())
47 *
48 * The SCM_SNARF_INIT text goes into the corresponding .x file
49 * up through the first occurrence of SCM_SNARF_DOC_START on that
50 * line, if any.
51 */
52
53#ifdef SCM_MAGIC_SNARF_INITS
54# define SCM_SNARF_HERE(X)
55# define SCM_SNARF_INIT(X) ^^ X ^:^
56# define SCM_SNARF_DOCS(TYPE, CNAME, FNAME, ARGLIST, REQ, OPT, VAR, DOCSTRING)
57#else
58# ifdef SCM_MAGIC_SNARF_DOCS
59# define SCM_SNARF_HERE(X)
60# define SCM_SNARF_INIT(X)
61# define SCM_SNARF_DOCS(TYPE, CNAME, FNAME, ARGLIST, REQ, OPT, VAR, DOCSTRING) \
62^^ { \
63cname CNAME ^^ \
64fname FNAME ^^ \
65type TYPE ^^ \
66location __FILE__ __LINE__ ^^ \
67arglist ARGLIST ^^ \
68argsig REQ OPT VAR ^^ \
69DOCSTRING ^^ }
70# else
71# define SCM_SNARF_HERE(X) X
72# define SCM_SNARF_INIT(X)
73# define SCM_SNARF_DOCS(TYPE, CNAME, FNAME, ARGLIST, REQ, OPT, VAR, DOCSTRING)
74# endif
75#endif
76
77#define SCM_DEFINE(FNAME, PRIMNAME, REQ, OPT, VAR, ARGLIST, DOCSTRING) \
78SCM_SNARF_HERE(\
79static const char s_ ## FNAME [] = PRIMNAME; \
80SCM FNAME ARGLIST\
81)\
82SCM_SNARF_INIT(\
83scm_c_define_gsubr (s_ ## FNAME, REQ, OPT, VAR, \
84 (SCM_FUNC_CAST_ARBITRARY_ARGS) FNAME); \
85)\
86SCM_SNARF_DOCS(primitive, FNAME, PRIMNAME, ARGLIST, REQ, OPT, VAR, DOCSTRING)
87
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
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
114#define SCM_DEFINE1(FNAME, PRIMNAME, TYPE, ARGLIST, DOCSTRING) \
115SCM_SNARF_HERE(\
116static const char s_ ## FNAME [] = PRIMNAME; \
117SCM FNAME ARGLIST\
118)\
119SCM_SNARF_INIT(scm_c_define_subr (s_ ## FNAME, TYPE, FNAME); ) \
120SCM_SNARF_DOCS(1, FNAME, PRIMNAME, ARGLIST, 2, 0, 0, DOCSTRING)
121
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
134#define SCM_PROC(RANAME, STR, REQ, OPT, VAR, CFN) \
135SCM_SNARF_HERE(static const char RANAME[]=STR) \
136SCM_SNARF_INIT(scm_c_define_gsubr (RANAME, REQ, OPT, VAR, \
137 (SCM_FUNC_CAST_ARBITRARY_ARGS) CFN))
138
139#define SCM_REGISTER_PROC(RANAME, STR, REQ, OPT, VAR, CFN) \
140SCM_SNARF_HERE(static const char RANAME[]=STR) \
141SCM_SNARF_INIT(scm_c_define_gsubr (RANAME, REQ, OPT, VAR, \
142 (SCM_FUNC_CAST_ARBITRARY_ARGS) CFN);) \
143SCM_SNARF_DOCS(register, CFN, STR, (), REQ, OPT, VAR, \
144 "implemented by the C function \"" #CFN "\"")
145
146#define SCM_GPROC(RANAME, STR, REQ, OPT, VAR, CFN, GF) \
147SCM_SNARF_HERE(\
148static const char RANAME[]=STR;\
149static SCM GF \
150)SCM_SNARF_INIT(\
151GF = SCM_PACK (0); /* Dirk:FIXME:: Can we safely use #f instead of 0? */ \
152scm_c_define_gsubr_with_generic (RANAME, REQ, OPT, VAR, \
153 (SCM_FUNC_CAST_ARBITRARY_ARGS) CFN, &GF) \
154)
155
156#define SCM_PROC1(RANAME, STR, TYPE, CFN) \
157SCM_SNARF_HERE(static const char RANAME[]=STR) \
158SCM_SNARF_INIT(\
159scm_c_define_subr (RANAME, TYPE, (SCM_FUNC_CAST_ARBITRARY_ARGS) CFN) \
160)
161
162
163#define SCM_GPROC1(RANAME, STR, TYPE, CFN, GF) \
164SCM_SNARF_HERE(\
165static const char RANAME[]=STR; \
166static SCM GF \
167)SCM_SNARF_INIT(\
168GF = SCM_PACK (0); /* Dirk:FIXME:: Can we safely use #f instead of 0? */ \
169scm_c_define_subr_with_generic (RANAME, TYPE, \
170 (SCM_FUNC_CAST_ARBITRARY_ARGS) CFN, &GF) \
171)
172
173#define SCM_SYNTAX(RANAME, STR, TYPE, CFN) \
174SCM_SNARF_HERE(static const char RANAME[]=STR)\
175SCM_SNARF_INIT(scm_make_synt (RANAME, TYPE, CFN))
176
177#define SCM_SYMBOL(c_name, scheme_name) \
178SCM_SNARF_HERE(static SCM c_name) \
179SCM_SNARF_INIT(c_name = scm_permanent_object (scm_from_locale_symbol (scheme_name)))
180
181#define SCM_GLOBAL_SYMBOL(c_name, scheme_name) \
182SCM_SNARF_HERE(SCM c_name) \
183SCM_SNARF_INIT(c_name = scm_permanent_object (scm_from_locale_symbol (scheme_name)))
184
185#define SCM_KEYWORD(c_name, scheme_name) \
186SCM_SNARF_HERE(static SCM c_name) \
187SCM_SNARF_INIT(c_name = scm_permanent_object (scm_from_locale_keyword (scheme_name)))
188
189#define SCM_GLOBAL_KEYWORD(c_name, scheme_name) \
190SCM_SNARF_HERE(SCM c_name) \
191SCM_SNARF_INIT(c_name = scm_permanent_object (scm_from_locale_keyword (scheme_name)))
192
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
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))
212
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))
216
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))
220
221#define SCM_GLOBAL_REC_MUTEX(c_name) \
222SCM_SNARF_HERE(scm_t_rec_mutex c_name) \
223SCM_SNARF_INIT(scm_i_plugin_rec_mutex_init (&c_name, &scm_i_plugin_rec_mutex))
224
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
274#ifdef SCM_MAGIC_SNARF_DOCS
275#undef SCM_ASSERT
276#define SCM_ASSERT(_cond, _arg, _pos, _subr) ^^ argpos _arg _pos __LINE__ ^^
277#endif /* SCM_MAGIC_SNARF_DOCS */
278
279#endif /* SCM_SNARF_H */
280
281/*
282 Local Variables:
283 c-file-style: "gnu"
284 End:
285*/