*** empty log message ***
[bpt/guile.git] / libguile / snarf.h
CommitLineData
5b4215a8
JB
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
e282f286 8/* Copyright (C) 1995, 96, 97, 98, 99, 2000 Free Software Foundation, Inc.
5b4215a8
JB
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
82892bed
JB
22 * the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
23 * Boston, MA 02111-1307 USA
5b4215a8
JB
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. */
1bbd0b84
GB
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
5b4215a8
JB
52\f
53
4b4d0898 54#if defined(__cplusplus) || defined(GUILE_CPLUSPLUS_SNARF)
e1fbffa9
MV
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
bfe19b46 61#else
4b4d0898 62#define SCM_FUNC_CAST_ARBITRARY_ARGS SCM (*)()
bfe19b46
MD
63#endif
64
73d8385e
MD
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) \
94a70859
MD
71 * SCM_SNARF_HERE (int NAME) \
72 * SCM_SNARF_INIT (NAME = foo ())
1e76143f 73 *
94a70859 74 * The SCM_SNARF_INIT text goes into the corresponding .x file
3c6d9d71
DH
75 * up through the first occurrence of SCM_SNARF_DOC_START on that
76 * line, if any.
73d8385e
MD
77 */
78
c99f9605
ML
79#ifdef SCM_MAGIC_SNARF_INITS
80# define SCM_SNARF_HERE(X)
81# define SCM_SNARF_INIT(X) ^^ X
82# define SCM_SNARF_DOCS(TYPE, FNAME, ARGLIST, REQ, OPT, VAR, DOCSTRING)
1e76143f 83#else
c99f9605 84# ifdef SCM_MAGIC_SNARF_DOCS
94a70859 85# define SCM_SNARF_HERE(X)
c99f9605
ML
86# define SCM_SNARF_INIT(X)
87# define SCM_SNARF_DOCS(TYPE, FNAME, ARGLIST, REQ, OPT, VAR, DOCSTRING) \
ac13d9d2
ML
88^^ { \
89fname FNAME ^^ \
90type TYPE ^^ \
91location __FILE__ __LINE__ ^^ \
92arglist ARGLIST ^^ \
93argsig REQ OPT VAR ^^ \
94DOCSTRING ^^ }
c99f9605
ML
95# else
96# define SCM_SNARF_HERE(X) X
97# define SCM_SNARF_INIT(X)
98# define SCM_SNARF_DOCS(TYPE, FNAME, ARGLIST, REQ, OPT, VAR, DOCSTRING)
99# endif
1e76143f 100#endif
73d8385e 101
a1ec6916 102#define SCM_DEFINE(FNAME, PRIMNAME, REQ, OPT, VAR, ARGLIST, DOCSTRING) \
94a70859 103SCM_SNARF_HERE(\
4b4d0898
GB
104static const char s_ ## FNAME [] = PRIMNAME; \
105SCM FNAME ARGLIST\
106)\
94a70859 107SCM_SNARF_INIT(\
9a441ddb
MV
108scm_c_define_gsubr (s_ ## FNAME, REQ, OPT, VAR, \
109 (SCM_FUNC_CAST_ARBITRARY_ARGS) FNAME); \
2fdcf8bd 110)\
c99f9605 111SCM_SNARF_DOCS(primitive, PRIMNAME, ARGLIST, REQ, OPT, VAR, DOCSTRING)
1bbd0b84 112
c3ee7520 113#define SCM_DEFINE1(FNAME, PRIMNAME, TYPE, ARGLIST, DOCSTRING) \
94a70859 114SCM_SNARF_HERE(\
4b4d0898
GB
115static const char s_ ## FNAME [] = PRIMNAME; \
116SCM FNAME ARGLIST\
2fdcf8bd 117)\
9a441ddb 118SCM_SNARF_INIT(scm_c_define_subr (s_ ## FNAME, TYPE, FNAME); ) \
c99f9605 119SCM_SNARF_DOCS(1, PRIMNAME, ARGLIST, 2, 0, 0, DOCSTRING)
1bbd0b84 120
9b1594fd 121#define SCM_PROC(RANAME, STR, REQ, OPT, VAR, CFN) \
94a70859 122SCM_SNARF_HERE(static const char RANAME[]=STR) \
9a441ddb
MV
123SCM_SNARF_INIT(scm_c_define_gsubr (RANAME, REQ, OPT, VAR, \
124 (SCM_FUNC_CAST_ARBITRARY_ARGS) CFN))
9b1594fd 125
1bbd0b84 126#define SCM_REGISTER_PROC(RANAME, STR, REQ, OPT, VAR, CFN) \
94a70859 127SCM_SNARF_HERE(static const char RANAME[]=STR) \
9a441ddb
MV
128SCM_SNARF_INIT(scm_c_define_gsubr (RANAME, REQ, OPT, VAR, \
129 (SCM_FUNC_CAST_ARBITRARY_ARGS) CFN);) \
c99f9605
ML
130SCM_SNARF_DOCS(register, STR, (), REQ, OPT, VAR, \
131 "implemented by the C function \"" #CFN "\"")
3dc81fba 132
9de33deb 133#define SCM_GPROC(RANAME, STR, REQ, OPT, VAR, CFN, GF) \
94a70859 134SCM_SNARF_HERE(\
4b4d0898 135static const char RANAME[]=STR;\
54778cd3 136static SCM GF \
94a70859 137)SCM_SNARF_INIT(\
54778cd3 138GF = SCM_PACK (0); /* Dirk:FIXME:: Can we safely use #f instead of 0? */ \
9a441ddb
MV
139scm_c_define_gsubr_with_generic (RANAME, REQ, OPT, VAR, \
140 (SCM_FUNC_CAST_ARBITRARY_ARGS) CFN, &GF) \
4b4d0898 141)
3dc81fba 142
4b4d0898 143#define SCM_PROC1(RANAME, STR, TYPE, CFN) \
94a70859
MD
144SCM_SNARF_HERE(static const char RANAME[]=STR) \
145SCM_SNARF_INIT(\
9a441ddb 146scm_c_define_subr (RANAME, TYPE, (SCM_FUNC_CAST_ARBITRARY_ARGS) CFN) \
4b4d0898 147)
9b1594fd 148
9b1594fd 149
4b4d0898 150#define SCM_GPROC1(RANAME, STR, TYPE, CFN, GF) \
94a70859 151SCM_SNARF_HERE(\
4b4d0898 152static const char RANAME[]=STR; \
54778cd3 153static SCM GF \
94a70859 154)SCM_SNARF_INIT(\
54778cd3 155GF = SCM_PACK (0); /* Dirk:FIXME:: Can we safely use #f instead of 0? */ \
9a441ddb
MV
156scm_c_define_subr_with_generic (RANAME, TYPE, \
157 (SCM_FUNC_CAST_ARBITRARY_ARGS) CFN, &GF) \
4b4d0898 158)
5b4215a8 159
b8229a3b 160#define SCM_SYNTAX(RANAME, STR, TYPE, CFN) \
94a70859
MD
161SCM_SNARF_HERE(static const char RANAME[]=STR)\
162SCM_SNARF_INIT(scm_make_synt (RANAME, TYPE, CFN))
b8229a3b 163
5b4215a8 164#define SCM_SYMBOL(c_name, scheme_name) \
94a70859 165SCM_SNARF_HERE(static SCM c_name) \
38ae064c 166SCM_SNARF_INIT(c_name = scm_permanent_object (scm_str2symbol (scheme_name)))
5b4215a8 167
78f9f47b 168#define SCM_GLOBAL_SYMBOL(c_name, scheme_name) \
94a70859 169SCM_SNARF_HERE(SCM c_name) \
38ae064c 170SCM_SNARF_INIT(c_name = scm_permanent_object (scm_str2symbol (scheme_name)))
78f9f47b 171
37b83f68 172#define SCM_KEYWORD(c_name, scheme_name) \
94a70859
MD
173SCM_SNARF_HERE(static SCM c_name) \
174SCM_SNARF_INIT(c_name = scm_permanent_object (scm_c_make_keyword (scheme_name)))
37b83f68 175
37b83f68 176#define SCM_GLOBAL_KEYWORD(c_name, scheme_name) \
94a70859
MD
177SCM_SNARF_HERE(SCM c_name) \
178SCM_SNARF_INIT(c_name = scm_permanent_object (scm_c_make_keyword (scheme_name)))
5b4215a8 179
86d31dfe
MV
180#define SCM_VARIABLE(c_name, scheme_name) \
181SCM_SNARF_HERE(static SCM c_name) \
182SCM_SNARF_INIT(c_name = scm_permanent_object (scm_c_define (scheme_name, SCM_BOOL_F));)
183
184#define SCM_GLOBAL_VARIABLE(c_name, scheme_name) \
185SCM_SNARF_HERE(SCM c_name) \
186SCM_SNARF_INIT(c_name = scm_permanent_object (scm_c_define (scheme_name, SCM_BOOL_F));)
187
188#define SCM_VARIABLE_INIT(c_name, scheme_name, init_val) \
189SCM_SNARF_HERE(static SCM c_name) \
190SCM_SNARF_INIT(c_name = scm_permanent_object (scm_c_define (scheme_name, init_val));)
191
192#define SCM_GLOBAL_VARIABLE_INIT(c_name, scheme_name, init_val) \
193SCM_SNARF_HERE(SCM c_name) \
194SCM_SNARF_INIT(c_name = scm_permanent_object (scm_c_define (scheme_name, init_val));)
195
196#if (SCM_DEBUG_DEPRECATED == 0)
197
198#define SCM_CONST_LONG(c_name, scheme_name,value) \
a0f3e747 199SCM_VCELL_INIT(c_name, scheme_name, scm_long2num(value))
86d31dfe 200
78f9f47b 201#define SCM_VCELL(c_name, scheme_name) \
94a70859 202SCM_SNARF_HERE(static SCM c_name) \
a3fc3be9 203SCM_SNARF_INIT(c_name = scm_permanent_object (scm_sysintern (scheme_name, SCM_BOOL_F));)
78f9f47b 204
78f9f47b 205#define SCM_GLOBAL_VCELL(c_name, scheme_name) \
94a70859 206SCM_SNARF_HERE(SCM c_name) \
a3fc3be9 207SCM_SNARF_INIT(c_name = scm_permanent_object (scm_sysintern (scheme_name, SCM_BOOL_F));)
5b4215a8 208
2e07d033 209#define SCM_VCELL_INIT(c_name, scheme_name, init_val) \
94a70859 210SCM_SNARF_HERE(static SCM c_name) \
a3fc3be9 211SCM_SNARF_INIT(c_name = scm_permanent_object (scm_sysintern (scheme_name, init_val));)
5b4215a8 212
2e07d033 213#define SCM_GLOBAL_VCELL_INIT(c_name, scheme_name, init_val) \
94a70859 214SCM_SNARF_HERE(SCM c_name) \
a3fc3be9 215SCM_SNARF_INIT(c_name = scm_permanent_object (scm_sysintern (scheme_name, init_val));)
5b4215a8 216
a9205f07
KN
217#endif /* (SCM_DEBUG_DEPRECATED == 0) */
218
c99f9605 219#ifdef SCM_MAGIC_SNARF_DOCS
4b4d0898 220#undef SCM_ASSERT
ac13d9d2 221#define SCM_ASSERT(_cond, _arg, _pos, _subr) ^^ argpos _arg _pos __LINE__ ^^
c99f9605 222#endif /* SCM_MAGIC_SNARF_DOCS */
2e07d033 223
5b4215a8 224#endif /* LIBGUILE_SNARF_H */
4b4d0898 225
89e00824
ML
226
227/*
228 Local Variables:
229 c-file-style: "gnu"
230 End:
231*/