* snarf.h (SCM_INSITU, SCM_INIT): New snarf macros for use in user
[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-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 /* Generic macros to be used in user macro definitions.
55 *
56 * For example, the SCM_PROC macro could have been defined by the user:
57 *
58 * #define SCM_PROC(RANAME, STR, REQ, OPT, VAR, CFN) \
59 * SCM_INSITU (static const char RANAME[]=STR) \
60 * SCM_INIT (scm_make_gsubr (RANAME, REQ, OPT, VAR, (SCM (*)(...)) CFN))
61 */
62
63 #ifndef SCM_MAGIC_SNARFER
64 # define SCM_INSITU(X) X
65 # define SCM_INIT(X)
66 #else
67 # define SCM_INSITU(X)
68 # define SCM_INIT(X) \
69 %%% X
70 #endif
71
72 #ifndef SCM_MAGIC_SNARFER
73
74 #define SCM_DEFINE(FNAME, PRIMNAME, REQ, OPT, VAR, ARGLIST, DOCSTRING) \
75 static const char s_ ## FNAME [] = PRIMNAME; \
76 SCM FNAME ARGLIST
77 #define SCM_DEFINE1(FNAME, PRIMNAME, TYPE, ARGLIST, DOCSTRING) \
78 static const char s_ ## FNAME [] = PRIMNAME; \
79 SCM FNAME ARGLIST
80
81 #define SCM_PROC(RANAME, STR, REQ, OPT, VAR, CFN) \
82 static const char RANAME[]=STR
83
84 #define SCM_REGISTER_PROC(RANAME, STR, REQ, OPT, VAR, CFN) \
85 static const char RANAME[]=STR
86
87 #define SCM_GPROC(RANAME, STR, REQ, OPT, VAR, CFN, GF) \
88 static const char RANAME[]=STR; \
89 static SCM GF = 0
90
91 #define SCM_PROC1(RANAME, STR, TYPE, CFN) \
92 static const char RANAME[]=STR
93
94 #define SCM_GPROC1(RANAME, STR, TYPE, CFN, GF) \
95 static const char RANAME[]=STR; \
96 static SCM GF = 0
97 #else
98 #if defined(__cplusplus) || defined(GUILE_CPLUSPLUS_SNARF)
99 /* for C++ snarfing */
100
101 #undef SCM_ASSERT
102 #define SCM_ASSERT(_cond, _arg, _pos, _subr) *&*&*&*SCM_ARG_BETTER_BE_IN_POSITION(_arg,_pos,__LINE__)
103
104 #define SCM_DEFINE(FNAME, PRIMNAME, REQ, OPT, VAR, ARGLIST, DOCSTRING) \
105 %%% scm_make_gsubr (s_ ## FNAME, REQ, OPT, VAR, (SCM (*)(...)) FNAME); \
106 $$$P PRIMNAME #ARGLIST | REQ | OPT | VAR | __FILE__:__LINE__ | @@@ DOCSTRING @!!!
107
108 #define SCM_DEFINE1(FNAME, PRIMNAME, TYPE, ARGLIST, DOCSTRING) \
109 %%% scm_make_subr (s_ ## FNAME, TYPE, FNAME); \
110 $$$1 PRIMNAME #ARGLIST | 2 | 0 | 0 | __FILE__:__LINE__ | @@@ DOCSTRING @!!!
111
112 #define SCM_PROC(RANAME, STR, REQ, OPT, VAR, CFN) \
113 %%% scm_make_gsubr (RANAME, REQ, OPT, VAR, (SCM (*)(...)) CFN)
114
115 #define SCM_REGISTER_PROC(RANAME, STR, REQ, OPT, VAR, CFN) \
116 %%% scm_make_gsubr (RANAME, REQ, OPT, VAR, (SCM (*)(...)) CFN); \
117 $$$R STR | REQ | OPT | VAR | __FILE__:__LINE__ | @@@ CFN @!!!
118
119 #define SCM_GPROC(RANAME, STR, REQ, OPT, VAR, CFN, GF) \
120 %%% scm_make_gsubr_with_generic (RANAME, REQ, OPT, VAR, (SCM (*)(...))CFN, &GF)
121
122 #define SCM_PROC1(RANAME, STR, TYPE, CFN) \
123 %%% scm_make_subr(RANAME, TYPE, (SCM (*)(...))CFN)
124
125 #define SCM_GPROC1(RANAME, STR, TYPE, CFN, GF) \
126 %%% scm_make_subr_with_generic(RANAME, TYPE, (SCM (*)(...))CFN, &GF)
127
128 #else
129 /* for ANSI C snarfing, not C++ */
130
131 #undef SCM_ASSERT
132 #define SCM_ASSERT(_cond, _arg, _pos, _subr) *&*&*&*SCM_ARG_BETTER_BE_IN_POSITION(_arg,_pos,__LINE__)
133
134 #define SCM_DEFINE(FNAME, PRIMNAME, REQ, OPT, VAR, ARGLIST, DOCSTRING) \
135 %%% scm_make_gsubr (s_ ## FNAME, REQ, OPT, VAR, (SCM (*)()) FNAME); \
136 $$$P PRIMNAME #ARGLIST | REQ | OPT | VAR | __FILE__:__LINE__ | @@@ DOCSTRING @!!!
137
138 #define SCM_DEFINE1(FNAME, PRIMNAME, TYPE, ARGLIST, DOCSTRING) \
139 %%% scm_make_subr (s_ ## FNAME, TYPE, FNAME); \
140 $$$1 PRIMNAME #ARGLIST | 2 | 0 | 0 | __FILE__:__LINE__ | @@@ DOCSTRING @!!!
141
142 #define SCM_PROC(RANAME, STR, REQ, OPT, VAR, CFN) \
143 %%% scm_make_gsubr (RANAME, REQ, OPT, VAR, (SCM (*)()) CFN)
144
145 #define SCM_REGISTER_PROC(RANAME, STR, REQ, OPT, VAR, CFN) \
146 %%% scm_make_gsubr (RANAME, REQ, OPT, VAR, (SCM (*)()) CFN); \
147 $$$R STR | REQ | OPT | VAR | __FILE__:__LINE__ | @@@ CFN @!!!
148
149 #define SCM_GPROC(RANAME, STR, REQ, OPT, VAR, CFN, GF) \
150 %%% scm_make_gsubr_with_generic (RANAME, REQ, OPT, VAR, (SCM (*)()) CFN, &GF)
151
152 #define SCM_PROC1(RANAME, STR, TYPE, CFN) \
153 %%% scm_make_subr(RANAME, TYPE, CFN)
154
155 #define SCM_GPROC1(RANAME, STR, TYPE, CFN, GF) \
156 %%% scm_make_subr_with_generic(RANAME, TYPE, CFN, &GF)
157
158 #endif
159 #endif
160
161 #ifndef SCM_MAGIC_SNARFER
162 #define SCM_SYNTAX(RANAME, STR, TYPE, CFN) \
163 static const char RANAME[]=STR
164 #else
165 #define SCM_SYNTAX(RANAME, STR, TYPE, CFN) \
166 %%% scm_make_synt (RANAME, TYPE, CFN)
167 #endif
168
169 #ifndef SCM_MAGIC_SNARFER
170 #define SCM_SYMBOL(c_name, scheme_name) \
171 static SCM c_name = SCM_BOOL_F
172 #else
173 #define SCM_SYMBOL(C_NAME, SCHEME_NAME) \
174 %%% C_NAME = scm_permanent_object (SCM_CAR (scm_intern0 (SCHEME_NAME)))
175 #endif
176
177 #ifndef SCM_MAGIC_SNARFER
178 #define SCM_GLOBAL_SYMBOL(c_name, scheme_name) \
179 SCM c_name = SCM_BOOL_F
180 #else
181 #define SCM_GLOBAL_SYMBOL(C_NAME, SCHEME_NAME) \
182 %%% C_NAME = scm_permanent_object (SCM_CAR (scm_intern0 (SCHEME_NAME)))
183 #endif
184
185 #ifndef SCM_MAGIC_SNARFER
186 #define SCM_KEYWORD(c_name, scheme_name) \
187 static SCM c_name = SCM_BOOL_F
188 #else
189 #define SCM_KEYWORD(C_NAME, SCHEME_NAME) \
190 %%% C_NAME = scm_permanent_object (scm_c_make_keyword (SCHEME_NAME))
191 #endif
192
193 #ifndef SCM_MAGIC_SNARFER
194 #define SCM_GLOBAL_KEYWORD(c_name, scheme_name) \
195 SCM c_name = SCM_BOOL_F
196 #else
197 #define SCM_GLOBAL_KEYWORD(C_NAME, SCHEME_NAME) \
198 %%% C_NAME = scm_permanent_object (scm_c_make_keyword (SCHEME_NAME))
199 #endif
200
201 #ifndef SCM_MAGIC_SNARFER
202 #define SCM_VCELL(c_name, scheme_name) \
203 static SCM c_name = SCM_BOOL_F
204 #else
205 #define SCM_VCELL(C_NAME, SCHEME_NAME) \
206 %%% C_NAME = scm_permanent_object (scm_intern0 (SCHEME_NAME)); SCM_SETCDR (C_NAME, SCM_BOOL_F)
207 #endif
208
209 #ifndef SCM_MAGIC_SNARFER
210 #define SCM_GLOBAL_VCELL(c_name, scheme_name) \
211 SCM c_name = SCM_BOOL_F
212 #else
213 #define SCM_GLOBAL_VCELL(C_NAME, SCHEME_NAME) \
214 %%% C_NAME = scm_permanent_object (scm_intern0 (SCHEME_NAME)); SCM_SETCDR (C_NAME, SCM_BOOL_F)
215 #endif
216
217 #ifndef SCM_MAGIC_SNARFER
218 #define SCM_VCELL_INIT(c_name, scheme_name, init_val) \
219 static SCM c_name = SCM_BOOL_F
220 #else
221 #define SCM_VCELL_INIT(C_NAME, SCHEME_NAME, init_val) \
222 %%% C_NAME = scm_permanent_object (scm_intern0 (SCHEME_NAME)); SCM_SETCDR (C_NAME, init_val)
223 #endif
224
225 #ifndef SCM_MAGIC_SNARFER
226 #define SCM_GLOBAL_VCELL_INIT(c_name, scheme_name, init_val) \
227 SCM c_name = SCM_BOOL_F
228 #else
229 #define SCM_GLOBAL_VCELL_INIT(C_NAME, SCHEME_NAME, init_val) \
230 %%% C_NAME = scm_permanent_object (scm_intern0 (SCHEME_NAME)); SCM_SETCDR (C_NAME, init_val)
231 #endif
232
233 #define SCM_CONST_LONG(C_NAME, SCHEME_NAME,VALUE) SCM_VCELL_INIT(C_NAME, SCHEME_NAME, scm_long2num(VALUE))
234
235 #endif /* LIBGUILE_SNARF_H */