* __scm.h (SCM_ALLOW_INTS_ONLY): Removed.
[bpt/guile.git] / libguile / snarf.h
CommitLineData
5b4215a8
JB
1/* classes: h_files */
2
b29058ff
DH
3#ifndef SCM_SNARF_H
4#define SCM_SNARF_H
5b4215a8 5
5527702a 6/* Copyright (C) 1995,1996,1997,1998,1999,2000,2001, 2002 Free Software Foundation, Inc.
b29058ff 7 *
5b4215a8
JB
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.
b29058ff 12 *
5b4215a8
JB
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.
b29058ff 17 *
5b4215a8
JB
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
82892bed
JB
20 * the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
21 * Boston, MA 02111-1307 USA
5b4215a8
JB
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. */
1bbd0b84 46
5b4215a8
JB
47\f
48
b29058ff
DH
49/* Macros for snarfing initialization actions from C source. */
50
4b4d0898 51#if defined(__cplusplus) || defined(GUILE_CPLUSPLUS_SNARF)
e1fbffa9
MV
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
bfe19b46 58#else
4b4d0898 59#define SCM_FUNC_CAST_ARBITRARY_ARGS SCM (*)()
bfe19b46
MD
60#endif
61
73d8385e
MD
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) \
94a70859
MD
68 * SCM_SNARF_HERE (int NAME) \
69 * SCM_SNARF_INIT (NAME = foo ())
1e76143f 70 *
94a70859 71 * The SCM_SNARF_INIT text goes into the corresponding .x file
3c6d9d71
DH
72 * up through the first occurrence of SCM_SNARF_DOC_START on that
73 * line, if any.
73d8385e
MD
74 */
75
c99f9605
ML
76#ifdef SCM_MAGIC_SNARF_INITS
77# define SCM_SNARF_HERE(X)
09e804ff 78# define SCM_SNARF_INIT(X) ^^ X ^:^
cecb4a5e 79# define SCM_SNARF_DOCS(TYPE, CNAME, FNAME, ARGLIST, REQ, OPT, VAR, DOCSTRING)
1e76143f 80#else
c99f9605 81# ifdef SCM_MAGIC_SNARF_DOCS
94a70859 82# define SCM_SNARF_HERE(X)
c99f9605 83# define SCM_SNARF_INIT(X)
cecb4a5e 84# define SCM_SNARF_DOCS(TYPE, CNAME, FNAME, ARGLIST, REQ, OPT, VAR, DOCSTRING) \
ac13d9d2 85^^ { \
cecb4a5e 86cname CNAME ^^ \
ac13d9d2
ML
87fname FNAME ^^ \
88type TYPE ^^ \
89location __FILE__ __LINE__ ^^ \
90arglist ARGLIST ^^ \
91argsig REQ OPT VAR ^^ \
92DOCSTRING ^^ }
c99f9605
ML
93# else
94# define SCM_SNARF_HERE(X) X
95# define SCM_SNARF_INIT(X)
cecb4a5e 96# define SCM_SNARF_DOCS(TYPE, CNAME, FNAME, ARGLIST, REQ, OPT, VAR, DOCSTRING)
c99f9605 97# endif
1e76143f 98#endif
73d8385e 99
a1ec6916 100#define SCM_DEFINE(FNAME, PRIMNAME, REQ, OPT, VAR, ARGLIST, DOCSTRING) \
94a70859 101SCM_SNARF_HERE(\
4b4d0898
GB
102static const char s_ ## FNAME [] = PRIMNAME; \
103SCM FNAME ARGLIST\
104)\
94a70859 105SCM_SNARF_INIT(\
9a441ddb
MV
106scm_c_define_gsubr (s_ ## FNAME, REQ, OPT, VAR, \
107 (SCM_FUNC_CAST_ARBITRARY_ARGS) FNAME); \
2fdcf8bd 108)\
cecb4a5e 109SCM_SNARF_DOCS(primitive, FNAME, PRIMNAME, ARGLIST, REQ, OPT, VAR, DOCSTRING)
1bbd0b84 110
5527702a
MV
111#define SCM_DEFINE_PUBLIC(FNAME, PRIMNAME, REQ, OPT, VAR, ARGLIST, DOCSTRING) \
112SCM_SNARF_HERE(\
113static const char s_ ## FNAME [] = PRIMNAME; \
114SCM FNAME ARGLIST\
115)\
116SCM_SNARF_INIT(\
117scm_c_define_gsubr (s_ ## FNAME, REQ, OPT, VAR, \
118 (SCM_FUNC_CAST_ARBITRARY_ARGS) FNAME); \
119scm_c_export (s_ ## FNAME, NULL); \
120)\
121SCM_SNARF_DOCS(primitive, FNAME, PRIMNAME, ARGLIST, REQ, OPT, VAR, DOCSTRING)
122
c3ee7520 123#define SCM_DEFINE1(FNAME, PRIMNAME, TYPE, ARGLIST, DOCSTRING) \
94a70859 124SCM_SNARF_HERE(\
4b4d0898
GB
125static const char s_ ## FNAME [] = PRIMNAME; \
126SCM FNAME ARGLIST\
2fdcf8bd 127)\
9a441ddb 128SCM_SNARF_INIT(scm_c_define_subr (s_ ## FNAME, TYPE, FNAME); ) \
cecb4a5e 129SCM_SNARF_DOCS(1, FNAME, PRIMNAME, ARGLIST, 2, 0, 0, DOCSTRING)
1bbd0b84 130
9b1594fd 131#define SCM_PROC(RANAME, STR, REQ, OPT, VAR, CFN) \
94a70859 132SCM_SNARF_HERE(static const char RANAME[]=STR) \
9a441ddb
MV
133SCM_SNARF_INIT(scm_c_define_gsubr (RANAME, REQ, OPT, VAR, \
134 (SCM_FUNC_CAST_ARBITRARY_ARGS) CFN))
9b1594fd 135
1bbd0b84 136#define SCM_REGISTER_PROC(RANAME, STR, REQ, OPT, VAR, CFN) \
94a70859 137SCM_SNARF_HERE(static const char RANAME[]=STR) \
9a441ddb
MV
138SCM_SNARF_INIT(scm_c_define_gsubr (RANAME, REQ, OPT, VAR, \
139 (SCM_FUNC_CAST_ARBITRARY_ARGS) CFN);) \
cecb4a5e 140SCM_SNARF_DOCS(register, CFN, STR, (), REQ, OPT, VAR, \
c99f9605 141 "implemented by the C function \"" #CFN "\"")
3dc81fba 142
9de33deb 143#define SCM_GPROC(RANAME, STR, REQ, OPT, VAR, CFN, GF) \
94a70859 144SCM_SNARF_HERE(\
4b4d0898 145static const char RANAME[]=STR;\
54778cd3 146static SCM GF \
94a70859 147)SCM_SNARF_INIT(\
54778cd3 148GF = SCM_PACK (0); /* Dirk:FIXME:: Can we safely use #f instead of 0? */ \
9a441ddb
MV
149scm_c_define_gsubr_with_generic (RANAME, REQ, OPT, VAR, \
150 (SCM_FUNC_CAST_ARBITRARY_ARGS) CFN, &GF) \
4b4d0898 151)
3dc81fba 152
4b4d0898 153#define SCM_PROC1(RANAME, STR, TYPE, CFN) \
94a70859
MD
154SCM_SNARF_HERE(static const char RANAME[]=STR) \
155SCM_SNARF_INIT(\
9a441ddb 156scm_c_define_subr (RANAME, TYPE, (SCM_FUNC_CAST_ARBITRARY_ARGS) CFN) \
4b4d0898 157)
9b1594fd 158
9b1594fd 159
4b4d0898 160#define SCM_GPROC1(RANAME, STR, TYPE, CFN, GF) \
94a70859 161SCM_SNARF_HERE(\
4b4d0898 162static const char RANAME[]=STR; \
54778cd3 163static SCM GF \
94a70859 164)SCM_SNARF_INIT(\
54778cd3 165GF = SCM_PACK (0); /* Dirk:FIXME:: Can we safely use #f instead of 0? */ \
9a441ddb
MV
166scm_c_define_subr_with_generic (RANAME, TYPE, \
167 (SCM_FUNC_CAST_ARBITRARY_ARGS) CFN, &GF) \
4b4d0898 168)
5b4215a8 169
b8229a3b 170#define SCM_SYNTAX(RANAME, STR, TYPE, CFN) \
94a70859
MD
171SCM_SNARF_HERE(static const char RANAME[]=STR)\
172SCM_SNARF_INIT(scm_make_synt (RANAME, TYPE, CFN))
b8229a3b 173
5b4215a8 174#define SCM_SYMBOL(c_name, scheme_name) \
94a70859 175SCM_SNARF_HERE(static SCM c_name) \
38ae064c 176SCM_SNARF_INIT(c_name = scm_permanent_object (scm_str2symbol (scheme_name)))
5b4215a8 177
78f9f47b 178#define SCM_GLOBAL_SYMBOL(c_name, scheme_name) \
94a70859 179SCM_SNARF_HERE(SCM c_name) \
38ae064c 180SCM_SNARF_INIT(c_name = scm_permanent_object (scm_str2symbol (scheme_name)))
78f9f47b 181
37b83f68 182#define SCM_KEYWORD(c_name, scheme_name) \
94a70859
MD
183SCM_SNARF_HERE(static SCM c_name) \
184SCM_SNARF_INIT(c_name = scm_permanent_object (scm_c_make_keyword (scheme_name)))
37b83f68 185
37b83f68 186#define SCM_GLOBAL_KEYWORD(c_name, scheme_name) \
94a70859
MD
187SCM_SNARF_HERE(SCM c_name) \
188SCM_SNARF_INIT(c_name = scm_permanent_object (scm_c_make_keyword (scheme_name)))
5b4215a8 189
86d31dfe
MV
190#define SCM_VARIABLE(c_name, scheme_name) \
191SCM_SNARF_HERE(static SCM c_name) \
192SCM_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) \
195SCM_SNARF_HERE(SCM c_name) \
196SCM_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) \
199SCM_SNARF_HERE(static SCM c_name) \
200SCM_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) \
203SCM_SNARF_HERE(SCM c_name) \
204SCM_SNARF_INIT(c_name = scm_permanent_object (scm_c_define (scheme_name, init_val));)
205
9bc4701c
MD
206#define SCM_NONREC_CRITICAL_SECTION(prefix) \
207SCM_SNARF_HERE(static scm_t_mutex prefix ## _mutex) \
208SCM_SNARF_INIT(scm_i_plugin_mutex_init (&prefix ## _mutex, 0))
209
210#define SCM_GLOBAL_NONREC_CRITICAL_SECTION(prefix) \
211SCM_SNARF_HERE(scm_t_mutex prefix ## _mutex) \
212SCM_SNARF_INIT(scm_i_plugin_mutex_init (&prefix ## _mutex, 0))
213
214#define SCM_REC_CRITICAL_SECTION(prefix) \
215SCM_SNARF_HERE(\
216static scm_t_mutex prefix ## _mutex; \
217static int prefix ## _count; \
218static scm_thread *prefix ## _owner\
219)SCM_SNARF_INIT(\
220scm_i_plugin_mutex_init (&prefix ## _mutex, 0)\
221)
222
223#define SCM_GLOBAL_REC_CRITICAL_SECTION(prefix) \
224SCM_SNARF_HERE(\
225scm_t_mutex prefix ## _mutex; \
226int prefix ## _count; \
227scm_thread *prefix ## _owner\
228)SCM_SNARF_INIT(\
229scm_i_plugin_mutex_init (&prefix ## _mutex, 0); \
230prefix ## _count = 0; \
231prefix ## _owner = 0\
232)
233
c99f9605 234#ifdef SCM_MAGIC_SNARF_DOCS
4b4d0898 235#undef SCM_ASSERT
ac13d9d2 236#define SCM_ASSERT(_cond, _arg, _pos, _subr) ^^ argpos _arg _pos __LINE__ ^^
c99f9605 237#endif /* SCM_MAGIC_SNARF_DOCS */
2e07d033 238
b29058ff 239#endif /* SCM_SNARF_H */
89e00824
ML
240
241/*
242 Local Variables:
243 c-file-style: "gnu"
244 End:
245*/