Remove dump facilities.
[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
GB
54#if defined(__cplusplus) || defined(GUILE_CPLUSPLUS_SNARF)
55#define SCM_FUNC_CAST_ARBITRARY_ARGS SCM (*)(...)
bfe19b46 56#else
4b4d0898 57#define SCM_FUNC_CAST_ARBITRARY_ARGS SCM (*)()
bfe19b46
MD
58#endif
59
73d8385e
MD
60/* Generic macros to be used in user macro definitions.
61 *
62 * For example, in order to define a macro which creates ints and
63 * initializes them to the result of foo (), do:
64 *
65 * #define SCM_FOO(NAME) \
94a70859
MD
66 * SCM_SNARF_HERE (int NAME) \
67 * SCM_SNARF_INIT (NAME = foo ())
1e76143f 68 *
94a70859 69 * The SCM_SNARF_INIT text goes into the corresponding .x file
3c6d9d71
DH
70 * up through the first occurrence of SCM_SNARF_DOC_START on that
71 * line, if any.
73d8385e
MD
72 */
73
1e76143f 74#ifndef SCM_MAGIC_SNARFER
94a70859
MD
75# define SCM_SNARF_HERE(X) X
76# define SCM_SNARF_INIT(X)
77# define SCM_SNARF_DOCS(X)
1e76143f 78#else
94a70859 79# define SCM_SNARF_HERE(X)
3c6d9d71 80# define SCM_SNARF_INIT(X) SCM_SNARF_INIT_START X
94a70859 81# define SCM_SNARF_DOCS(X) X
1e76143f 82#endif
73d8385e 83
a1ec6916 84#define SCM_DEFINE(FNAME, PRIMNAME, REQ, OPT, VAR, ARGLIST, DOCSTRING) \
94a70859 85SCM_SNARF_HERE(\
4b4d0898
GB
86static const char s_ ## FNAME [] = PRIMNAME; \
87SCM FNAME ARGLIST\
88)\
94a70859
MD
89SCM_SNARF_INIT(\
90scm_make_gsubr (s_ ## FNAME, REQ, OPT, VAR, \
91 (SCM_FUNC_CAST_ARBITRARY_ARGS) FNAME); \
2fdcf8bd 92)\
94a70859 93SCM_SNARF_DOCS(\
3c6d9d71
DH
94SCM_SNARF_DOC_STARTP PRIMNAME #ARGLIST | REQ | OPT | VAR | __FILE__:__LINE__ | \
95 SCM_SNARF_DOCSTRING_START DOCSTRING SCM_SNARF_DOCSTRING_END \
4b4d0898 96)
1bbd0b84 97
c3ee7520 98#define SCM_DEFINE1(FNAME, PRIMNAME, TYPE, ARGLIST, DOCSTRING) \
94a70859 99SCM_SNARF_HERE(\
4b4d0898
GB
100static const char s_ ## FNAME [] = PRIMNAME; \
101SCM FNAME ARGLIST\
2fdcf8bd 102)\
94a70859
MD
103SCM_SNARF_INIT(scm_make_subr (s_ ## FNAME, TYPE, FNAME); ) \
104SCM_SNARF_DOCS(\
3c6d9d71
DH
105SCM_SNARF_DOC_START1 PRIMNAME #ARGLIST | 2 | 0 | 0 | __FILE__:__LINE__ | \
106 SCM_SNARF_DOCSTRING_START DOCSTRING SCM_SNARF_DOCSTRING_END \
4b4d0898 107)
1bbd0b84 108
9b1594fd 109#define SCM_PROC(RANAME, STR, REQ, OPT, VAR, CFN) \
94a70859
MD
110SCM_SNARF_HERE(static const char RANAME[]=STR) \
111SCM_SNARF_INIT(scm_make_gsubr (RANAME, REQ, OPT, VAR, \
112 (SCM_FUNC_CAST_ARBITRARY_ARGS) CFN))
9b1594fd 113
1bbd0b84 114#define SCM_REGISTER_PROC(RANAME, STR, REQ, OPT, VAR, CFN) \
94a70859
MD
115SCM_SNARF_HERE(static const char RANAME[]=STR) \
116SCM_SNARF_INIT(scm_make_gsubr (RANAME, REQ, OPT, VAR, \
117 (SCM_FUNC_CAST_ARBITRARY_ARGS) CFN);) \
118SCM_SNARF_DOCS(\
3c6d9d71
DH
119SCM_SNARF_DOC_STARTR STR | REQ | OPT | VAR | __FILE__:__LINE__ | \
120 SCM_SNARF_DOCSTRING_START CFN SCM_SNARF_DOCSTRING_END \
4b4d0898 121)
3dc81fba 122
9de33deb 123#define SCM_GPROC(RANAME, STR, REQ, OPT, VAR, CFN, GF) \
94a70859 124SCM_SNARF_HERE(\
4b4d0898 125static const char RANAME[]=STR;\
54778cd3 126static SCM GF \
94a70859 127)SCM_SNARF_INIT(\
54778cd3 128GF = SCM_PACK (0); /* Dirk:FIXME:: Can we safely use #f instead of 0? */ \
94a70859
MD
129scm_make_gsubr_with_generic (RANAME, REQ, OPT, VAR, \
130 (SCM_FUNC_CAST_ARBITRARY_ARGS) CFN, &GF) \
4b4d0898 131)
3dc81fba 132
4b4d0898 133#define SCM_PROC1(RANAME, STR, TYPE, CFN) \
94a70859
MD
134SCM_SNARF_HERE(static const char RANAME[]=STR) \
135SCM_SNARF_INIT(\
fd61ba9e 136scm_make_subr (RANAME, TYPE, (SCM_FUNC_CAST_ARBITRARY_ARGS) CFN) \
4b4d0898 137)
9b1594fd 138
9b1594fd 139
4b4d0898 140#define SCM_GPROC1(RANAME, STR, TYPE, CFN, GF) \
94a70859 141SCM_SNARF_HERE(\
4b4d0898 142static const char RANAME[]=STR; \
54778cd3 143static SCM GF \
94a70859 144)SCM_SNARF_INIT(\
54778cd3 145GF = SCM_PACK (0); /* Dirk:FIXME:: Can we safely use #f instead of 0? */ \
94a70859
MD
146scm_make_subr_with_generic (RANAME, TYPE, \
147 (SCM_FUNC_CAST_ARBITRARY_ARGS) CFN, &GF) \
4b4d0898 148)
5b4215a8 149
b8229a3b 150#define SCM_SYNTAX(RANAME, STR, TYPE, CFN) \
94a70859
MD
151SCM_SNARF_HERE(static const char RANAME[]=STR)\
152SCM_SNARF_INIT(scm_make_synt (RANAME, TYPE, CFN))
b8229a3b 153
5b4215a8 154#define SCM_SYMBOL(c_name, scheme_name) \
94a70859 155SCM_SNARF_HERE(static SCM c_name) \
38ae064c 156SCM_SNARF_INIT(c_name = scm_permanent_object (scm_str2symbol (scheme_name)))
5b4215a8 157
78f9f47b 158#define SCM_GLOBAL_SYMBOL(c_name, scheme_name) \
94a70859 159SCM_SNARF_HERE(SCM c_name) \
38ae064c 160SCM_SNARF_INIT(c_name = scm_permanent_object (scm_str2symbol (scheme_name)))
78f9f47b 161
37b83f68 162#define SCM_KEYWORD(c_name, scheme_name) \
94a70859
MD
163SCM_SNARF_HERE(static SCM c_name) \
164SCM_SNARF_INIT(c_name = scm_permanent_object (scm_c_make_keyword (scheme_name)))
37b83f68 165
37b83f68 166#define SCM_GLOBAL_KEYWORD(c_name, scheme_name) \
94a70859
MD
167SCM_SNARF_HERE(SCM c_name) \
168SCM_SNARF_INIT(c_name = scm_permanent_object (scm_c_make_keyword (scheme_name)))
5b4215a8 169
78f9f47b 170#define SCM_VCELL(c_name, scheme_name) \
94a70859 171SCM_SNARF_HERE(static SCM c_name) \
a3fc3be9 172SCM_SNARF_INIT(c_name = scm_permanent_object (scm_sysintern (scheme_name, SCM_BOOL_F));)
78f9f47b 173
78f9f47b 174#define SCM_GLOBAL_VCELL(c_name, scheme_name) \
94a70859 175SCM_SNARF_HERE(SCM c_name) \
a3fc3be9 176SCM_SNARF_INIT(c_name = scm_permanent_object (scm_sysintern (scheme_name, SCM_BOOL_F));)
5b4215a8 177
2e07d033 178#define SCM_VCELL_INIT(c_name, scheme_name, init_val) \
94a70859 179SCM_SNARF_HERE(static SCM c_name) \
a3fc3be9 180SCM_SNARF_INIT(c_name = scm_permanent_object (scm_sysintern (scheme_name, init_val));)
5b4215a8 181
2e07d033 182#define SCM_GLOBAL_VCELL_INIT(c_name, scheme_name, init_val) \
94a70859 183SCM_SNARF_HERE(SCM c_name) \
a3fc3be9 184SCM_SNARF_INIT(c_name = scm_permanent_object (scm_sysintern (scheme_name, init_val));)
5b4215a8 185
4b4d0898
GB
186#define SCM_CONST_LONG(c_name, scheme_name,value) \
187SCM_VCELL_INIT(c_name, scheme_name, scm_long2num(value))
188
189#ifdef SCM_MAGIC_SNARFER
190#undef SCM_ASSERT
191#define SCM_ASSERT(_cond, _arg, _pos, _subr) *&*&*&*SCM_ARG_BETTER_BE_IN_POSITION(_arg,_pos,__LINE__)
192#endif /* SCM_MAGIC_SNARFER */
2e07d033 193
5b4215a8 194#endif /* LIBGUILE_SNARF_H */
4b4d0898 195
89e00824
ML
196
197/*
198 Local Variables:
199 c-file-style: "gnu"
200 End:
201*/