*** empty log message ***
[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
b29058ff
DH
6/* Copyright (C) 1995,1996,1997,1998,1999,2000,2001 Free Software Foundation, Inc.
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
c3ee7520 111#define SCM_DEFINE1(FNAME, PRIMNAME, TYPE, ARGLIST, DOCSTRING) \
94a70859 112SCM_SNARF_HERE(\
4b4d0898
GB
113static const char s_ ## FNAME [] = PRIMNAME; \
114SCM FNAME ARGLIST\
2fdcf8bd 115)\
9a441ddb 116SCM_SNARF_INIT(scm_c_define_subr (s_ ## FNAME, TYPE, FNAME); ) \
cecb4a5e 117SCM_SNARF_DOCS(1, FNAME, PRIMNAME, ARGLIST, 2, 0, 0, DOCSTRING)
1bbd0b84 118
9b1594fd 119#define SCM_PROC(RANAME, STR, REQ, OPT, VAR, CFN) \
94a70859 120SCM_SNARF_HERE(static const char RANAME[]=STR) \
9a441ddb
MV
121SCM_SNARF_INIT(scm_c_define_gsubr (RANAME, REQ, OPT, VAR, \
122 (SCM_FUNC_CAST_ARBITRARY_ARGS) CFN))
9b1594fd 123
1bbd0b84 124#define SCM_REGISTER_PROC(RANAME, STR, REQ, OPT, VAR, CFN) \
94a70859 125SCM_SNARF_HERE(static const char RANAME[]=STR) \
9a441ddb
MV
126SCM_SNARF_INIT(scm_c_define_gsubr (RANAME, REQ, OPT, VAR, \
127 (SCM_FUNC_CAST_ARBITRARY_ARGS) CFN);) \
cecb4a5e 128SCM_SNARF_DOCS(register, CFN, STR, (), REQ, OPT, VAR, \
c99f9605 129 "implemented by the C function \"" #CFN "\"")
3dc81fba 130
9de33deb 131#define SCM_GPROC(RANAME, STR, REQ, OPT, VAR, CFN, GF) \
94a70859 132SCM_SNARF_HERE(\
4b4d0898 133static const char RANAME[]=STR;\
54778cd3 134static SCM GF \
94a70859 135)SCM_SNARF_INIT(\
54778cd3 136GF = SCM_PACK (0); /* Dirk:FIXME:: Can we safely use #f instead of 0? */ \
9a441ddb
MV
137scm_c_define_gsubr_with_generic (RANAME, REQ, OPT, VAR, \
138 (SCM_FUNC_CAST_ARBITRARY_ARGS) CFN, &GF) \
4b4d0898 139)
3dc81fba 140
4b4d0898 141#define SCM_PROC1(RANAME, STR, TYPE, CFN) \
94a70859
MD
142SCM_SNARF_HERE(static const char RANAME[]=STR) \
143SCM_SNARF_INIT(\
9a441ddb 144scm_c_define_subr (RANAME, TYPE, (SCM_FUNC_CAST_ARBITRARY_ARGS) CFN) \
4b4d0898 145)
9b1594fd 146
9b1594fd 147
4b4d0898 148#define SCM_GPROC1(RANAME, STR, TYPE, CFN, GF) \
94a70859 149SCM_SNARF_HERE(\
4b4d0898 150static const char RANAME[]=STR; \
54778cd3 151static SCM GF \
94a70859 152)SCM_SNARF_INIT(\
54778cd3 153GF = SCM_PACK (0); /* Dirk:FIXME:: Can we safely use #f instead of 0? */ \
9a441ddb
MV
154scm_c_define_subr_with_generic (RANAME, TYPE, \
155 (SCM_FUNC_CAST_ARBITRARY_ARGS) CFN, &GF) \
4b4d0898 156)
5b4215a8 157
b8229a3b 158#define SCM_SYNTAX(RANAME, STR, TYPE, CFN) \
94a70859
MD
159SCM_SNARF_HERE(static const char RANAME[]=STR)\
160SCM_SNARF_INIT(scm_make_synt (RANAME, TYPE, CFN))
b8229a3b 161
5b4215a8 162#define SCM_SYMBOL(c_name, scheme_name) \
94a70859 163SCM_SNARF_HERE(static SCM c_name) \
38ae064c 164SCM_SNARF_INIT(c_name = scm_permanent_object (scm_str2symbol (scheme_name)))
5b4215a8 165
78f9f47b 166#define SCM_GLOBAL_SYMBOL(c_name, scheme_name) \
94a70859 167SCM_SNARF_HERE(SCM c_name) \
38ae064c 168SCM_SNARF_INIT(c_name = scm_permanent_object (scm_str2symbol (scheme_name)))
78f9f47b 169
37b83f68 170#define SCM_KEYWORD(c_name, scheme_name) \
94a70859
MD
171SCM_SNARF_HERE(static SCM c_name) \
172SCM_SNARF_INIT(c_name = scm_permanent_object (scm_c_make_keyword (scheme_name)))
37b83f68 173
37b83f68 174#define SCM_GLOBAL_KEYWORD(c_name, scheme_name) \
94a70859
MD
175SCM_SNARF_HERE(SCM c_name) \
176SCM_SNARF_INIT(c_name = scm_permanent_object (scm_c_make_keyword (scheme_name)))
5b4215a8 177
86d31dfe
MV
178#define SCM_VARIABLE(c_name, scheme_name) \
179SCM_SNARF_HERE(static SCM c_name) \
180SCM_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) \
183SCM_SNARF_HERE(SCM c_name) \
184SCM_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) \
187SCM_SNARF_HERE(static SCM c_name) \
188SCM_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) \
191SCM_SNARF_HERE(SCM c_name) \
192SCM_SNARF_INIT(c_name = scm_permanent_object (scm_c_define (scheme_name, init_val));)
193
c99f9605 194#ifdef SCM_MAGIC_SNARF_DOCS
4b4d0898 195#undef SCM_ASSERT
ac13d9d2 196#define SCM_ASSERT(_cond, _arg, _pos, _subr) ^^ argpos _arg _pos __LINE__ ^^
c99f9605 197#endif /* SCM_MAGIC_SNARF_DOCS */
2e07d033 198
b29058ff 199#endif /* SCM_SNARF_H */
89e00824
ML
200
201/*
202 Local Variables:
203 c-file-style: "gnu"
204 End:
205*/