6 /* Copyright (C) 1995,1996,1997,1998,1999,2000,2001, 2002 Free Software Foundation, Inc.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2, or (at your option)
13 * This program 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
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this software; see the file COPYING. If not, write to
20 * the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
21 * Boston, MA 02111-1307 USA
23 * As a special exception, the Free Software Foundation gives permission
24 * for additional uses of the text contained in its release of GUILE.
26 * The exception is that, if you link the GUILE library with other files
27 * to produce an executable, this does not by itself cause the
28 * resulting executable to be covered by the GNU General Public License.
29 * Your use of that executable is in no way restricted on account of
30 * linking the GUILE library code into it.
32 * This exception does not however invalidate any other reasons why
33 * the executable file might be covered by the GNU General Public License.
35 * This exception applies only to the code released by the
36 * Free Software Foundation under the name GUILE. If you copy
37 * code from other Free Software Foundation releases into a copy of
38 * GUILE, as the General Public License permits, the exception does
39 * not apply to the code that you add in this way. To avoid misleading
40 * anyone as to the status of such modified files, you must delete
41 * this exception notice from them.
43 * If you write modifications of your own for GUILE, it is your choice
44 * whether to permit this exception to apply to your modifications.
45 * If you do not wish that, delete this exception notice. */
49 /* Macros for snarfing initialization actions from C source. */
51 #if defined(__cplusplus) || defined(GUILE_CPLUSPLUS_SNARF)
53 /* This used to be "SCM (*)(...)" but GCC on RedHat 7.1 doesn't seem
56 #define SCM_FUNC_CAST_ARBITRARY_ARGS SCM (*)()
59 #define SCM_FUNC_CAST_ARBITRARY_ARGS SCM (*)()
62 /* Generic macros to be used in user macro definitions.
64 * For example, in order to define a macro which creates ints and
65 * initializes them to the result of foo (), do:
67 * #define SCM_FOO(NAME) \
68 * SCM_SNARF_HERE (int NAME) \
69 * SCM_SNARF_INIT (NAME = foo ())
71 * The SCM_SNARF_INIT text goes into the corresponding .x file
72 * up through the first occurrence of SCM_SNARF_DOC_START on that
76 #ifdef SCM_MAGIC_SNARF_INITS
77 # define SCM_SNARF_HERE(X)
78 # define SCM_SNARF_INIT(X) ^^ X ^:^
79 # define SCM_SNARF_DOCS(TYPE, CNAME, FNAME, ARGLIST, REQ, OPT, VAR, DOCSTRING)
81 # ifdef SCM_MAGIC_SNARF_DOCS
82 # define SCM_SNARF_HERE(X)
83 # define SCM_SNARF_INIT(X)
84 # define SCM_SNARF_DOCS(TYPE, CNAME, FNAME, ARGLIST, REQ, OPT, VAR, DOCSTRING) \
89 location __FILE__ __LINE__ ^^ \
91 argsig REQ OPT VAR ^^ \
94 # define SCM_SNARF_HERE(X) X
95 # define SCM_SNARF_INIT(X)
96 # define SCM_SNARF_DOCS(TYPE, CNAME, FNAME, ARGLIST, REQ, OPT, VAR, DOCSTRING)
100 #define SCM_DEFINE(FNAME, PRIMNAME, REQ, OPT, VAR, ARGLIST, DOCSTRING) \
102 static const char s_ ## FNAME [] = PRIMNAME; \
106 scm_c_define_gsubr (s_ ## FNAME, REQ, OPT, VAR, \
107 (SCM_FUNC_CAST_ARBITRARY_ARGS) FNAME); \
109 SCM_SNARF_DOCS(primitive, FNAME, PRIMNAME, ARGLIST, REQ, OPT, VAR, DOCSTRING)
111 #define SCM_DEFINE_PUBLIC(FNAME, PRIMNAME, REQ, OPT, VAR, ARGLIST, DOCSTRING) \
113 static const char s_ ## FNAME [] = PRIMNAME; \
117 scm_c_define_gsubr (s_ ## FNAME, REQ, OPT, VAR, \
118 (SCM_FUNC_CAST_ARBITRARY_ARGS) FNAME); \
119 scm_c_export (s_ ## FNAME, NULL); \
121 SCM_SNARF_DOCS(primitive, FNAME, PRIMNAME, ARGLIST, REQ, OPT, VAR, DOCSTRING)
123 #define SCM_DEFINE1(FNAME, PRIMNAME, TYPE, ARGLIST, DOCSTRING) \
125 static const char s_ ## FNAME [] = PRIMNAME; \
128 SCM_SNARF_INIT(scm_c_define_subr (s_ ## FNAME, TYPE, FNAME); ) \
129 SCM_SNARF_DOCS(1, FNAME, PRIMNAME, ARGLIST, 2, 0, 0, DOCSTRING)
131 #define SCM_PROC(RANAME, STR, REQ, OPT, VAR, CFN) \
132 SCM_SNARF_HERE(static const char RANAME[]=STR) \
133 SCM_SNARF_INIT(scm_c_define_gsubr (RANAME, REQ, OPT, VAR, \
134 (SCM_FUNC_CAST_ARBITRARY_ARGS) CFN))
136 #define SCM_REGISTER_PROC(RANAME, STR, REQ, OPT, VAR, CFN) \
137 SCM_SNARF_HERE(static const char RANAME[]=STR) \
138 SCM_SNARF_INIT(scm_c_define_gsubr (RANAME, REQ, OPT, VAR, \
139 (SCM_FUNC_CAST_ARBITRARY_ARGS) CFN);) \
140 SCM_SNARF_DOCS(register, CFN, STR, (), REQ, OPT, VAR, \
141 "implemented by the C function \"" #CFN "\"")
143 #define SCM_GPROC(RANAME, STR, REQ, OPT, VAR, CFN, GF) \
145 static const char RANAME[]=STR;\
148 GF = SCM_PACK (0); /* Dirk:FIXME:: Can we safely use #f instead of 0? */ \
149 scm_c_define_gsubr_with_generic (RANAME, REQ, OPT, VAR, \
150 (SCM_FUNC_CAST_ARBITRARY_ARGS) CFN, &GF) \
153 #define SCM_PROC1(RANAME, STR, TYPE, CFN) \
154 SCM_SNARF_HERE(static const char RANAME[]=STR) \
156 scm_c_define_subr (RANAME, TYPE, (SCM_FUNC_CAST_ARBITRARY_ARGS) CFN) \
160 #define SCM_GPROC1(RANAME, STR, TYPE, CFN, GF) \
162 static const char RANAME[]=STR; \
165 GF = SCM_PACK (0); /* Dirk:FIXME:: Can we safely use #f instead of 0? */ \
166 scm_c_define_subr_with_generic (RANAME, TYPE, \
167 (SCM_FUNC_CAST_ARBITRARY_ARGS) CFN, &GF) \
170 #define SCM_SYNTAX(RANAME, STR, TYPE, CFN) \
171 SCM_SNARF_HERE(static const char RANAME[]=STR)\
172 SCM_SNARF_INIT(scm_make_synt (RANAME, TYPE, CFN))
174 #define SCM_SYMBOL(c_name, scheme_name) \
175 SCM_SNARF_HERE(static SCM c_name) \
176 SCM_SNARF_INIT(c_name = scm_permanent_object (scm_str2symbol (scheme_name)))
178 #define SCM_GLOBAL_SYMBOL(c_name, scheme_name) \
179 SCM_SNARF_HERE(SCM c_name) \
180 SCM_SNARF_INIT(c_name = scm_permanent_object (scm_str2symbol (scheme_name)))
182 #define SCM_KEYWORD(c_name, scheme_name) \
183 SCM_SNARF_HERE(static SCM c_name) \
184 SCM_SNARF_INIT(c_name = scm_permanent_object (scm_c_make_keyword (scheme_name)))
186 #define SCM_GLOBAL_KEYWORD(c_name, scheme_name) \
187 SCM_SNARF_HERE(SCM c_name) \
188 SCM_SNARF_INIT(c_name = scm_permanent_object (scm_c_make_keyword (scheme_name)))
190 #define SCM_VARIABLE(c_name, scheme_name) \
191 SCM_SNARF_HERE(static SCM c_name) \
192 SCM_SNARF_INIT(c_name = scm_permanent_object (scm_c_define (scheme_name, SCM_BOOL_F));)
194 #define SCM_GLOBAL_VARIABLE(c_name, scheme_name) \
195 SCM_SNARF_HERE(SCM c_name) \
196 SCM_SNARF_INIT(c_name = scm_permanent_object (scm_c_define (scheme_name, SCM_BOOL_F));)
198 #define SCM_VARIABLE_INIT(c_name, scheme_name, init_val) \
199 SCM_SNARF_HERE(static SCM c_name) \
200 SCM_SNARF_INIT(c_name = scm_permanent_object (scm_c_define (scheme_name, init_val));)
202 #define SCM_GLOBAL_VARIABLE_INIT(c_name, scheme_name, init_val) \
203 SCM_SNARF_HERE(SCM c_name) \
204 SCM_SNARF_INIT(c_name = scm_permanent_object (scm_c_define (scheme_name, init_val));)
206 #define SCM_MUTEX(c_name) \
207 SCM_SNARF_HERE(static scm_t_mutex c_name) \
208 SCM_SNARF_INIT(scm_i_plugin_mutex_init (&c_name, &scm_i_plugin_mutex))
210 #define SCM_GLOBAL_MUTEX(c_name) \
211 SCM_SNARF_HERE(scm_t_mutex c_name) \
212 SCM_SNARF_INIT(scm_i_plugin_mutex_init (&c_name, &scm_i_plugin_mutex))
214 #define SCM_REC_MUTEX(c_name) \
215 SCM_SNARF_HERE(static scm_t_rec_mutex c_name) \
216 SCM_SNARF_INIT(scm_i_plugin_rec_mutex_init (&c_name, &scm_i_plugin_rec_mutex))
218 #define SCM_GLOBAL_REC_MUTEX(c_name) \
219 SCM_SNARF_HERE(scm_t_rec_mutex c_name) \
220 SCM_SNARF_INIT(scm_i_plugin_mutex_init (&c_name, &scm_i_plugin_rec_mutex))
222 #ifdef SCM_MAGIC_SNARF_DOCS
224 #define SCM_ASSERT(_cond, _arg, _pos, _subr) ^^ argpos _arg _pos __LINE__ ^^
225 #endif /* SCM_MAGIC_SNARF_DOCS */
227 #endif /* SCM_SNARF_H */