Merge from mvo-vcell-cleanup-1-branch.
[bpt/guile.git] / libguile / snarf.h
1 /* classes: h_files */
2
3 /* Macros for snarfing initialization actions from C source. */
4
5 #ifndef LIBGUILE_SNARF_H
6 #define LIBGUILE_SNARF_H
7
8 /* Copyright (C) 1995, 96, 97, 98, 99, 2000 Free Software Foundation, Inc.
9 *
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)
13 * any later version.
14 *
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.
19 *
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
24 *
25 * As a special exception, the Free Software Foundation gives permission
26 * for additional uses of the text contained in its release of GUILE.
27 *
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.
33 *
34 * This exception does not however invalidate any other reasons why
35 * the executable file might be covered by the GNU General Public License.
36 *
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.
44 *
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. */
48
49 /* Software engineering face-lift by Greg J. Badros, 11-Dec-1999,
50 gjb@cs.washington.edu, http://www.cs.washington.edu/homes/gjb */
51
52 \f
53
54 #if defined(__cplusplus) || defined(GUILE_CPLUSPLUS_SNARF)
55
56 /* This used to be "SCM (*)(...)" but GCC on RedHat 7.1 doesn't seem
57 to like it.
58 */
59 #define SCM_FUNC_CAST_ARBITRARY_ARGS SCM (*)()
60
61 #else
62 #define SCM_FUNC_CAST_ARBITRARY_ARGS SCM (*)()
63 #endif
64
65 /* Generic macros to be used in user macro definitions.
66 *
67 * For example, in order to define a macro which creates ints and
68 * initializes them to the result of foo (), do:
69 *
70 * #define SCM_FOO(NAME) \
71 * SCM_SNARF_HERE (int NAME) \
72 * SCM_SNARF_INIT (NAME = foo ())
73 *
74 * The SCM_SNARF_INIT text goes into the corresponding .x file
75 * up through the first occurrence of SCM_SNARF_DOC_START on that
76 * line, if any.
77 */
78
79 #ifndef SCM_MAGIC_SNARFER
80 # define SCM_SNARF_HERE(X) X
81 # define SCM_SNARF_INIT(X)
82 # define SCM_SNARF_DOCS(X)
83 #else
84 # define SCM_SNARF_HERE(X)
85 # define SCM_SNARF_INIT(X) SCM_SNARF_INIT_START X
86 # define SCM_SNARF_DOCS(X) X
87 #endif
88
89 #define SCM_DEFINE(FNAME, PRIMNAME, REQ, OPT, VAR, ARGLIST, DOCSTRING) \
90 SCM_SNARF_HERE(\
91 static const char s_ ## FNAME [] = PRIMNAME; \
92 SCM FNAME ARGLIST\
93 )\
94 SCM_SNARF_INIT(\
95 scm_make_gsubr (s_ ## FNAME, REQ, OPT, VAR, \
96 (SCM_FUNC_CAST_ARBITRARY_ARGS) FNAME); \
97 )\
98 SCM_SNARF_DOCS(\
99 SCM_SNARF_DOC_STARTP PRIMNAME #ARGLIST | REQ | OPT | VAR | __FILE__:__LINE__ | \
100 SCM_SNARF_DOCSTRING_START DOCSTRING SCM_SNARF_DOCSTRING_END \
101 )
102
103 #define SCM_DEFINE1(FNAME, PRIMNAME, TYPE, ARGLIST, DOCSTRING) \
104 SCM_SNARF_HERE(\
105 static const char s_ ## FNAME [] = PRIMNAME; \
106 SCM FNAME ARGLIST\
107 )\
108 SCM_SNARF_INIT(scm_make_subr (s_ ## FNAME, TYPE, FNAME); ) \
109 SCM_SNARF_DOCS(\
110 SCM_SNARF_DOC_START1 PRIMNAME #ARGLIST | 2 | 0 | 0 | __FILE__:__LINE__ | \
111 SCM_SNARF_DOCSTRING_START DOCSTRING SCM_SNARF_DOCSTRING_END \
112 )
113
114 #define SCM_PROC(RANAME, STR, REQ, OPT, VAR, CFN) \
115 SCM_SNARF_HERE(static const char RANAME[]=STR) \
116 SCM_SNARF_INIT(scm_make_gsubr (RANAME, REQ, OPT, VAR, \
117 (SCM_FUNC_CAST_ARBITRARY_ARGS) CFN))
118
119 #define SCM_REGISTER_PROC(RANAME, STR, REQ, OPT, VAR, CFN) \
120 SCM_SNARF_HERE(static const char RANAME[]=STR) \
121 SCM_SNARF_INIT(scm_make_gsubr (RANAME, REQ, OPT, VAR, \
122 (SCM_FUNC_CAST_ARBITRARY_ARGS) CFN);) \
123 SCM_SNARF_DOCS(\
124 SCM_SNARF_DOC_STARTR STR | REQ | OPT | VAR | __FILE__:__LINE__ | \
125 SCM_SNARF_DOCSTRING_START CFN SCM_SNARF_DOCSTRING_END \
126 )
127
128 #define SCM_GPROC(RANAME, STR, REQ, OPT, VAR, CFN, GF) \
129 SCM_SNARF_HERE(\
130 static const char RANAME[]=STR;\
131 static SCM GF \
132 )SCM_SNARF_INIT(\
133 GF = SCM_PACK (0); /* Dirk:FIXME:: Can we safely use #f instead of 0? */ \
134 scm_make_gsubr_with_generic (RANAME, REQ, OPT, VAR, \
135 (SCM_FUNC_CAST_ARBITRARY_ARGS) CFN, &GF) \
136 )
137
138 #define SCM_PROC1(RANAME, STR, TYPE, CFN) \
139 SCM_SNARF_HERE(static const char RANAME[]=STR) \
140 SCM_SNARF_INIT(\
141 scm_make_subr (RANAME, TYPE, (SCM_FUNC_CAST_ARBITRARY_ARGS) CFN) \
142 )
143
144
145 #define SCM_GPROC1(RANAME, STR, TYPE, CFN, GF) \
146 SCM_SNARF_HERE(\
147 static const char RANAME[]=STR; \
148 static SCM GF \
149 )SCM_SNARF_INIT(\
150 GF = SCM_PACK (0); /* Dirk:FIXME:: Can we safely use #f instead of 0? */ \
151 scm_make_subr_with_generic (RANAME, TYPE, \
152 (SCM_FUNC_CAST_ARBITRARY_ARGS) CFN, &GF) \
153 )
154
155 #define SCM_SYNTAX(RANAME, STR, TYPE, CFN) \
156 SCM_SNARF_HERE(static const char RANAME[]=STR)\
157 SCM_SNARF_INIT(scm_make_synt (RANAME, TYPE, CFN))
158
159 #define SCM_SYMBOL(c_name, scheme_name) \
160 SCM_SNARF_HERE(static SCM c_name) \
161 SCM_SNARF_INIT(c_name = scm_permanent_object (scm_str2symbol (scheme_name)))
162
163 #define SCM_GLOBAL_SYMBOL(c_name, scheme_name) \
164 SCM_SNARF_HERE(SCM c_name) \
165 SCM_SNARF_INIT(c_name = scm_permanent_object (scm_str2symbol (scheme_name)))
166
167 #define SCM_KEYWORD(c_name, scheme_name) \
168 SCM_SNARF_HERE(static SCM c_name) \
169 SCM_SNARF_INIT(c_name = scm_permanent_object (scm_c_make_keyword (scheme_name)))
170
171 #define SCM_GLOBAL_KEYWORD(c_name, scheme_name) \
172 SCM_SNARF_HERE(SCM c_name) \
173 SCM_SNARF_INIT(c_name = scm_permanent_object (scm_c_make_keyword (scheme_name)))
174
175 #define SCM_VARIABLE(c_name, scheme_name) \
176 SCM_SNARF_HERE(static SCM c_name) \
177 SCM_SNARF_INIT(c_name = scm_permanent_object (scm_c_define (scheme_name, SCM_BOOL_F));)
178
179 #define SCM_GLOBAL_VARIABLE(c_name, scheme_name) \
180 SCM_SNARF_HERE(SCM c_name) \
181 SCM_SNARF_INIT(c_name = scm_permanent_object (scm_c_define (scheme_name, SCM_BOOL_F));)
182
183 #define SCM_VARIABLE_INIT(c_name, scheme_name, init_val) \
184 SCM_SNARF_HERE(static SCM c_name) \
185 SCM_SNARF_INIT(c_name = scm_permanent_object (scm_c_define (scheme_name, init_val));)
186
187 #define SCM_GLOBAL_VARIABLE_INIT(c_name, scheme_name, init_val) \
188 SCM_SNARF_HERE(SCM c_name) \
189 SCM_SNARF_INIT(c_name = scm_permanent_object (scm_c_define (scheme_name, init_val));)
190
191 #if (SCM_DEBUG_DEPRECATED == 0)
192
193 #define SCM_CONST_LONG(c_name, scheme_name,value) \
194 SCM_VARIABLE_INIT(c_name, scheme_name, scm_long2num(value))
195
196 #define SCM_VCELL(c_name, scheme_name) \
197 SCM_SNARF_HERE(static SCM c_name) \
198 SCM_SNARF_INIT(c_name = scm_permanent_object (scm_sysintern (scheme_name, SCM_BOOL_F));)
199
200 #define SCM_GLOBAL_VCELL(c_name, scheme_name) \
201 SCM_SNARF_HERE(SCM c_name) \
202 SCM_SNARF_INIT(c_name = scm_permanent_object (scm_sysintern (scheme_name, SCM_BOOL_F));)
203
204 #define SCM_VCELL_INIT(c_name, scheme_name, init_val) \
205 SCM_SNARF_HERE(static SCM c_name) \
206 SCM_SNARF_INIT(c_name = scm_permanent_object (scm_sysintern (scheme_name, init_val));)
207
208 #define SCM_GLOBAL_VCELL_INIT(c_name, scheme_name, init_val) \
209 SCM_SNARF_HERE(SCM c_name) \
210 SCM_SNARF_INIT(c_name = scm_permanent_object (scm_sysintern (scheme_name, init_val));)
211
212 #endif /* (SCM_DEBUG_DEPRECATED == 0) */
213
214 #ifdef SCM_MAGIC_SNARFER
215 #undef SCM_ASSERT
216 #define SCM_ASSERT(_cond, _arg, _pos, _subr) *&*&*&*SCM_ARG_BETTER_BE_IN_POSITION(_arg,_pos,__LINE__)
217 #endif /* SCM_MAGIC_SNARFER */
218
219 #endif /* LIBGUILE_SNARF_H */
220
221
222 /*
223 Local Variables:
224 c-file-style: "gnu"
225 End:
226 */