8c03c3874acb0bdb86160ccaf37f102d70a65130
[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, 2001 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
50 \f
51
52 #if defined(__cplusplus) || defined(GUILE_CPLUSPLUS_SNARF)
53
54 /* This used to be "SCM (*)(...)" but GCC on RedHat 7.1 doesn't seem
55 to like it.
56 */
57 #define SCM_FUNC_CAST_ARBITRARY_ARGS SCM (*)()
58
59 #else
60 #define SCM_FUNC_CAST_ARBITRARY_ARGS SCM (*)()
61 #endif
62
63 /* Generic macros to be used in user macro definitions.
64 *
65 * For example, in order to define a macro which creates ints and
66 * initializes them to the result of foo (), do:
67 *
68 * #define SCM_FOO(NAME) \
69 * SCM_SNARF_HERE (int NAME) \
70 * SCM_SNARF_INIT (NAME = foo ())
71 *
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
74 * line, if any.
75 */
76
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)
81 #else
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) \
86 ^^ { \
87 fname FNAME ^^ \
88 type TYPE ^^ \
89 location __FILE__ __LINE__ ^^ \
90 arglist ARGLIST ^^ \
91 argsig REQ OPT VAR ^^ \
92 DOCSTRING ^^ }
93 # else
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)
97 # endif
98 #endif
99
100 #define SCM_DEFINE(FNAME, PRIMNAME, REQ, OPT, VAR, ARGLIST, DOCSTRING) \
101 SCM_SNARF_HERE(\
102 static const char s_ ## FNAME [] = PRIMNAME; \
103 SCM FNAME ARGLIST\
104 )\
105 SCM_SNARF_INIT(\
106 scm_c_define_gsubr (s_ ## FNAME, REQ, OPT, VAR, \
107 (SCM_FUNC_CAST_ARBITRARY_ARGS) FNAME); \
108 )\
109 SCM_SNARF_DOCS(primitive, PRIMNAME, ARGLIST, REQ, OPT, VAR, DOCSTRING)
110
111 #define SCM_DEFINE1(FNAME, PRIMNAME, TYPE, ARGLIST, DOCSTRING) \
112 SCM_SNARF_HERE(\
113 static const char s_ ## FNAME [] = PRIMNAME; \
114 SCM FNAME ARGLIST\
115 )\
116 SCM_SNARF_INIT(scm_c_define_subr (s_ ## FNAME, TYPE, FNAME); ) \
117 SCM_SNARF_DOCS(1, PRIMNAME, ARGLIST, 2, 0, 0, DOCSTRING)
118
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))
123
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 "\"")
130
131 #define SCM_GPROC(RANAME, STR, REQ, OPT, VAR, CFN, GF) \
132 SCM_SNARF_HERE(\
133 static const char RANAME[]=STR;\
134 static SCM GF \
135 )SCM_SNARF_INIT(\
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) \
139 )
140
141 #define SCM_PROC1(RANAME, STR, TYPE, CFN) \
142 SCM_SNARF_HERE(static const char RANAME[]=STR) \
143 SCM_SNARF_INIT(\
144 scm_c_define_subr (RANAME, TYPE, (SCM_FUNC_CAST_ARBITRARY_ARGS) CFN) \
145 )
146
147
148 #define SCM_GPROC1(RANAME, STR, TYPE, CFN, GF) \
149 SCM_SNARF_HERE(\
150 static const char RANAME[]=STR; \
151 static SCM GF \
152 )SCM_SNARF_INIT(\
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) \
156 )
157
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))
161
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)))
165
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)))
169
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)))
173
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)))
177
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));)
181
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));)
185
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));)
189
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));)
193
194 #if (SCM_DEBUG_DEPRECATED == 0)
195
196 #define SCM_CONST_LONG(c_name, scheme_name,value) \
197 SCM_VCELL_INIT(c_name, scheme_name, scm_long2num(value))
198
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));)
202
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));)
206
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));)
210
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));)
214
215 #endif /* (SCM_DEBUG_DEPRECATED == 0) */
216
217 #ifdef SCM_MAGIC_SNARF_DOCS
218 #undef SCM_ASSERT
219 #define SCM_ASSERT(_cond, _arg, _pos, _subr) ^^ argpos _arg _pos __LINE__ ^^
220 #endif /* SCM_MAGIC_SNARF_DOCS */
221
222 #endif /* LIBGUILE_SNARF_H */
223
224
225 /*
226 Local Variables:
227 c-file-style: "gnu"
228 End:
229 */