(SCM_DEFINE_PUBLIC): New.
[bpt/guile.git] / libguile / snarf.h
1 /* classes: h_files */
2
3 #ifndef SCM_SNARF_H
4 #define SCM_SNARF_H
5
6 /* Copyright (C) 1995,1996,1997,1998,1999,2000,2001, 2002 Free Software Foundation, Inc.
7 *
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)
11 * any later version.
12 *
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.
17 *
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
22 *
23 * As a special exception, the Free Software Foundation gives permission
24 * for additional uses of the text contained in its release of GUILE.
25 *
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.
31 *
32 * This exception does not however invalidate any other reasons why
33 * the executable file might be covered by the GNU General Public License.
34 *
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.
42 *
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. */
46
47 \f
48
49 /* Macros for snarfing initialization actions from C source. */
50
51 #if defined(__cplusplus) || defined(GUILE_CPLUSPLUS_SNARF)
52
53 /* This used to be "SCM (*)(...)" but GCC on RedHat 7.1 doesn't seem
54 to like it.
55 */
56 #define SCM_FUNC_CAST_ARBITRARY_ARGS SCM (*)()
57
58 #else
59 #define SCM_FUNC_CAST_ARBITRARY_ARGS SCM (*)()
60 #endif
61
62 /* Generic macros to be used in user macro definitions.
63 *
64 * For example, in order to define a macro which creates ints and
65 * initializes them to the result of foo (), do:
66 *
67 * #define SCM_FOO(NAME) \
68 * SCM_SNARF_HERE (int NAME) \
69 * SCM_SNARF_INIT (NAME = foo ())
70 *
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
73 * line, if any.
74 */
75
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)
80 #else
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) \
85 ^^ { \
86 cname CNAME ^^ \
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, CNAME, 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, FNAME, PRIMNAME, ARGLIST, REQ, OPT, VAR, DOCSTRING)
110
111 #define SCM_DEFINE_PUBLIC(FNAME, PRIMNAME, REQ, OPT, VAR, ARGLIST, DOCSTRING) \
112 SCM_SNARF_HERE(\
113 static const char s_ ## FNAME [] = PRIMNAME; \
114 SCM FNAME ARGLIST\
115 )\
116 SCM_SNARF_INIT(\
117 scm_c_define_gsubr (s_ ## FNAME, REQ, OPT, VAR, \
118 (SCM_FUNC_CAST_ARBITRARY_ARGS) FNAME); \
119 scm_c_export (s_ ## FNAME, NULL); \
120 )\
121 SCM_SNARF_DOCS(primitive, FNAME, PRIMNAME, ARGLIST, REQ, OPT, VAR, DOCSTRING)
122
123 #define SCM_DEFINE1(FNAME, PRIMNAME, TYPE, ARGLIST, DOCSTRING) \
124 SCM_SNARF_HERE(\
125 static const char s_ ## FNAME [] = PRIMNAME; \
126 SCM FNAME ARGLIST\
127 )\
128 SCM_SNARF_INIT(scm_c_define_subr (s_ ## FNAME, TYPE, FNAME); ) \
129 SCM_SNARF_DOCS(1, FNAME, PRIMNAME, ARGLIST, 2, 0, 0, DOCSTRING)
130
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))
135
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 "\"")
142
143 #define SCM_GPROC(RANAME, STR, REQ, OPT, VAR, CFN, GF) \
144 SCM_SNARF_HERE(\
145 static const char RANAME[]=STR;\
146 static SCM GF \
147 )SCM_SNARF_INIT(\
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) \
151 )
152
153 #define SCM_PROC1(RANAME, STR, TYPE, CFN) \
154 SCM_SNARF_HERE(static const char RANAME[]=STR) \
155 SCM_SNARF_INIT(\
156 scm_c_define_subr (RANAME, TYPE, (SCM_FUNC_CAST_ARBITRARY_ARGS) CFN) \
157 )
158
159
160 #define SCM_GPROC1(RANAME, STR, TYPE, CFN, GF) \
161 SCM_SNARF_HERE(\
162 static const char RANAME[]=STR; \
163 static SCM GF \
164 )SCM_SNARF_INIT(\
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) \
168 )
169
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))
173
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)))
177
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)))
181
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)))
185
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)))
189
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));)
193
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));)
197
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));)
201
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));)
205
206 #ifdef SCM_MAGIC_SNARF_DOCS
207 #undef SCM_ASSERT
208 #define SCM_ASSERT(_cond, _arg, _pos, _subr) ^^ argpos _arg _pos __LINE__ ^^
209 #endif /* SCM_MAGIC_SNARF_DOCS */
210
211 #endif /* SCM_SNARF_H */
212
213 /*
214 Local Variables:
215 c-file-style: "gnu"
216 End:
217 */