8c03c3874acb0bdb86160ccaf37f102d70a65130
3 /* Macros for snarfing initialization actions from C source. */
5 #ifndef LIBGUILE_SNARF_H
6 #define LIBGUILE_SNARF_H
8 /* Copyright (C) 1995, 96, 97, 98, 99, 2000, 2001 Free Software Foundation, Inc.
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2, or (at your option)
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this software; see the file COPYING. If not, write to
22 * the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
23 * Boston, MA 02111-1307 USA
25 * As a special exception, the Free Software Foundation gives permission
26 * for additional uses of the text contained in its release of GUILE.
28 * The exception is that, if you link the GUILE library with other files
29 * to produce an executable, this does not by itself cause the
30 * resulting executable to be covered by the GNU General Public License.
31 * Your use of that executable is in no way restricted on account of
32 * linking the GUILE library code into it.
34 * This exception does not however invalidate any other reasons why
35 * the executable file might be covered by the GNU General Public License.
37 * This exception applies only to the code released by the
38 * Free Software Foundation under the name GUILE. If you copy
39 * code from other Free Software Foundation releases into a copy of
40 * GUILE, as the General Public License permits, the exception does
41 * not apply to the code that you add in this way. To avoid misleading
42 * anyone as to the status of such modified files, you must delete
43 * this exception notice from them.
45 * If you write modifications of your own for GUILE, it is your choice
46 * whether to permit this exception to apply to your modifications.
47 * If you do not wish that, delete this exception notice. */
52 #if defined(__cplusplus) || defined(GUILE_CPLUSPLUS_SNARF)
54 /* This used to be "SCM (*)(...)" but GCC on RedHat 7.1 doesn't seem
57 #define SCM_FUNC_CAST_ARBITRARY_ARGS SCM (*)()
60 #define SCM_FUNC_CAST_ARBITRARY_ARGS SCM (*)()
63 /* Generic macros to be used in user macro definitions.
65 * For example, in order to define a macro which creates ints and
66 * initializes them to the result of foo (), do:
68 * #define SCM_FOO(NAME) \
69 * SCM_SNARF_HERE (int NAME) \
70 * SCM_SNARF_INIT (NAME = foo ())
72 * The SCM_SNARF_INIT text goes into the corresponding .x file
73 * up through the first occurrence of SCM_SNARF_DOC_START on that
77 #ifdef SCM_MAGIC_SNARF_INITS
78 # define SCM_SNARF_HERE(X)
79 # define SCM_SNARF_INIT(X) ^^ X
80 # define SCM_SNARF_DOCS(TYPE, FNAME, ARGLIST, REQ, OPT, VAR, DOCSTRING)
82 # ifdef SCM_MAGIC_SNARF_DOCS
83 # define SCM_SNARF_HERE(X)
84 # define SCM_SNARF_INIT(X)
85 # define SCM_SNARF_DOCS(TYPE, 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, 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, PRIMNAME, ARGLIST, REQ, OPT, VAR, DOCSTRING)
111 #define SCM_DEFINE1(FNAME, PRIMNAME, TYPE, ARGLIST, DOCSTRING) \
113 static const char s_ ## FNAME [] = PRIMNAME; \
116 SCM_SNARF_INIT(scm_c_define_subr (s_ ## FNAME, TYPE, FNAME); ) \
117 SCM_SNARF_DOCS(1, PRIMNAME, ARGLIST, 2, 0, 0, DOCSTRING)
119 #define SCM_PROC(RANAME, STR, REQ, OPT, VAR, CFN) \
120 SCM_SNARF_HERE(static const char RANAME[]=STR) \
121 SCM_SNARF_INIT(scm_c_define_gsubr (RANAME, REQ, OPT, VAR, \
122 (SCM_FUNC_CAST_ARBITRARY_ARGS) CFN))
124 #define SCM_REGISTER_PROC(RANAME, STR, REQ, OPT, VAR, CFN) \
125 SCM_SNARF_HERE(static const char RANAME[]=STR) \
126 SCM_SNARF_INIT(scm_c_define_gsubr (RANAME, REQ, OPT, VAR, \
127 (SCM_FUNC_CAST_ARBITRARY_ARGS) CFN);) \
128 SCM_SNARF_DOCS(register, STR, (), REQ, OPT, VAR, \
129 "implemented by the C function \"" #CFN "\"")
131 #define SCM_GPROC(RANAME, STR, REQ, OPT, VAR, CFN, GF) \
133 static const char RANAME[]=STR;\
136 GF = SCM_PACK (0); /* Dirk:FIXME:: Can we safely use #f instead of 0? */ \
137 scm_c_define_gsubr_with_generic (RANAME, REQ, OPT, VAR, \
138 (SCM_FUNC_CAST_ARBITRARY_ARGS) CFN, &GF) \
141 #define SCM_PROC1(RANAME, STR, TYPE, CFN) \
142 SCM_SNARF_HERE(static const char RANAME[]=STR) \
144 scm_c_define_subr (RANAME, TYPE, (SCM_FUNC_CAST_ARBITRARY_ARGS) CFN) \
148 #define SCM_GPROC1(RANAME, STR, TYPE, CFN, GF) \
150 static const char RANAME[]=STR; \
153 GF = SCM_PACK (0); /* Dirk:FIXME:: Can we safely use #f instead of 0? */ \
154 scm_c_define_subr_with_generic (RANAME, TYPE, \
155 (SCM_FUNC_CAST_ARBITRARY_ARGS) CFN, &GF) \
158 #define SCM_SYNTAX(RANAME, STR, TYPE, CFN) \
159 SCM_SNARF_HERE(static const char RANAME[]=STR)\
160 SCM_SNARF_INIT(scm_make_synt (RANAME, TYPE, CFN))
162 #define SCM_SYMBOL(c_name, scheme_name) \
163 SCM_SNARF_HERE(static SCM c_name) \
164 SCM_SNARF_INIT(c_name = scm_permanent_object (scm_str2symbol (scheme_name)))
166 #define SCM_GLOBAL_SYMBOL(c_name, scheme_name) \
167 SCM_SNARF_HERE(SCM c_name) \
168 SCM_SNARF_INIT(c_name = scm_permanent_object (scm_str2symbol (scheme_name)))
170 #define SCM_KEYWORD(c_name, scheme_name) \
171 SCM_SNARF_HERE(static SCM c_name) \
172 SCM_SNARF_INIT(c_name = scm_permanent_object (scm_c_make_keyword (scheme_name)))
174 #define SCM_GLOBAL_KEYWORD(c_name, scheme_name) \
175 SCM_SNARF_HERE(SCM c_name) \
176 SCM_SNARF_INIT(c_name = scm_permanent_object (scm_c_make_keyword (scheme_name)))
178 #define SCM_VARIABLE(c_name, scheme_name) \
179 SCM_SNARF_HERE(static SCM c_name) \
180 SCM_SNARF_INIT(c_name = scm_permanent_object (scm_c_define (scheme_name, SCM_BOOL_F));)
182 #define SCM_GLOBAL_VARIABLE(c_name, scheme_name) \
183 SCM_SNARF_HERE(SCM c_name) \
184 SCM_SNARF_INIT(c_name = scm_permanent_object (scm_c_define (scheme_name, SCM_BOOL_F));)
186 #define SCM_VARIABLE_INIT(c_name, scheme_name, init_val) \
187 SCM_SNARF_HERE(static SCM c_name) \
188 SCM_SNARF_INIT(c_name = scm_permanent_object (scm_c_define (scheme_name, init_val));)
190 #define SCM_GLOBAL_VARIABLE_INIT(c_name, scheme_name, init_val) \
191 SCM_SNARF_HERE(SCM c_name) \
192 SCM_SNARF_INIT(c_name = scm_permanent_object (scm_c_define (scheme_name, init_val));)
194 #if (SCM_DEBUG_DEPRECATED == 0)
196 #define SCM_CONST_LONG(c_name, scheme_name,value) \
197 SCM_VCELL_INIT(c_name, scheme_name, scm_long2num(value))
199 #define SCM_VCELL(c_name, scheme_name) \
200 SCM_SNARF_HERE(static SCM c_name) \
201 SCM_SNARF_INIT(c_name = scm_permanent_object (scm_sysintern (scheme_name, SCM_BOOL_F));)
203 #define SCM_GLOBAL_VCELL(c_name, scheme_name) \
204 SCM_SNARF_HERE(SCM c_name) \
205 SCM_SNARF_INIT(c_name = scm_permanent_object (scm_sysintern (scheme_name, SCM_BOOL_F));)
207 #define SCM_VCELL_INIT(c_name, scheme_name, init_val) \
208 SCM_SNARF_HERE(static SCM c_name) \
209 SCM_SNARF_INIT(c_name = scm_permanent_object (scm_sysintern (scheme_name, init_val));)
211 #define SCM_GLOBAL_VCELL_INIT(c_name, scheme_name, init_val) \
212 SCM_SNARF_HERE(SCM c_name) \
213 SCM_SNARF_INIT(c_name = scm_permanent_object (scm_sysintern (scheme_name, init_val));)
215 #endif /* (SCM_DEBUG_DEPRECATED == 0) */
217 #ifdef SCM_MAGIC_SNARF_DOCS
219 #define SCM_ASSERT(_cond, _arg, _pos, _subr) ^^ argpos _arg _pos __LINE__ ^^
220 #endif /* SCM_MAGIC_SNARF_DOCS */
222 #endif /* LIBGUILE_SNARF_H */