* Added comments.
[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) \
1e76143f 66 * SCM_HERE (int NAME) \
73d8385e 67 * SCM_INIT (NAME = foo ())
1e76143f
GB
68 *
69 * The SCM_INIT text goes into the corresponding .x file
70 * up through the first occurrence of $$$ on that line, if any.
73d8385e
MD
71 */
72
1e76143f
GB
73#ifndef SCM_MAGIC_SNARFER
74# define SCM_HERE(X) X
75# define SCM_INIT(X)
2fdcf8bd 76# define SCM_DOCS(X)
1e76143f
GB
77#else
78# define SCM_HERE(X)
79# define SCM_INIT(X) %%% X
2fdcf8bd 80# define SCM_DOCS(X) X
1e76143f 81#endif
73d8385e 82
a1ec6916 83#define SCM_DEFINE(FNAME, PRIMNAME, REQ, OPT, VAR, ARGLIST, DOCSTRING) \
1e76143f 84SCM_HERE(\
4b4d0898
GB
85static const char s_ ## FNAME [] = PRIMNAME; \
86SCM FNAME ARGLIST\
87)\
1e76143f
GB
88SCM_INIT(\
89scm_make_gsubr (s_ ## FNAME, REQ, OPT, VAR, (SCM_FUNC_CAST_ARBITRARY_ARGS) FNAME); \
2fdcf8bd
GB
90)\
91SCM_DOCS(\
4b4d0898
GB
92$$$P PRIMNAME #ARGLIST | REQ | OPT | VAR | __FILE__:__LINE__ | @@@ DOCSTRING @!!! \
93)
1bbd0b84 94
c3ee7520 95#define SCM_DEFINE1(FNAME, PRIMNAME, TYPE, ARGLIST, DOCSTRING) \
1e76143f 96SCM_HERE(\
4b4d0898
GB
97static const char s_ ## FNAME [] = PRIMNAME; \
98SCM FNAME ARGLIST\
2fdcf8bd
GB
99)\
100SCM_INIT(scm_make_subr (s_ ## FNAME, TYPE, FNAME); ) \
101SCM_DOCS(\
4b4d0898
GB
102$$$1 PRIMNAME #ARGLIST | 2 | 0 | 0 | __FILE__:__LINE__ | @@@ DOCSTRING @!!! \
103)
1bbd0b84 104
9b1594fd 105#define SCM_PROC(RANAME, STR, REQ, OPT, VAR, CFN) \
1e76143f 106SCM_HERE(static const char RANAME[]=STR) \
2fdcf8bd 107SCM_INIT(scm_make_gsubr (RANAME, REQ, OPT, VAR, (SCM_FUNC_CAST_ARBITRARY_ARGS) CFN))
9b1594fd 108
1bbd0b84 109#define SCM_REGISTER_PROC(RANAME, STR, REQ, OPT, VAR, CFN) \
2fdcf8bd
GB
110SCM_HERE(static const char RANAME[]=STR) \
111SCM_INIT(scm_make_gsubr (RANAME, REQ, OPT, VAR, (SCM_FUNC_CAST_ARBITRARY_ARGS) CFN);) \
112SCM_DOCS(\
4b4d0898
GB
113$$$R STR | REQ | OPT | VAR | __FILE__:__LINE__ | @@@ CFN @!!! \
114)
3dc81fba 115
9de33deb 116#define SCM_GPROC(RANAME, STR, REQ, OPT, VAR, CFN, GF) \
1e76143f 117SCM_HERE(\
4b4d0898 118static const char RANAME[]=STR;\
54778cd3 119static SCM GF \
1e76143f 120)SCM_INIT(\
54778cd3 121GF = SCM_PACK (0); /* Dirk:FIXME:: Can we safely use #f instead of 0? */ \
1e76143f 122scm_make_gsubr_with_generic (RANAME, REQ, OPT, VAR, (SCM_FUNC_CAST_ARBITRARY_ARGS) CFN, &GF) \
4b4d0898 123)
3dc81fba 124
4b4d0898 125#define SCM_PROC1(RANAME, STR, TYPE, CFN) \
1e76143f
GB
126SCM_HERE(static const char RANAME[]=STR) \
127SCM_INIT(\
fd61ba9e 128scm_make_subr (RANAME, TYPE, (SCM_FUNC_CAST_ARBITRARY_ARGS) CFN) \
4b4d0898 129)
9b1594fd 130
9b1594fd 131
4b4d0898 132#define SCM_GPROC1(RANAME, STR, TYPE, CFN, GF) \
1e76143f 133SCM_HERE(\
4b4d0898 134static const char RANAME[]=STR; \
54778cd3 135static SCM GF \
1e76143f 136)SCM_INIT(\
54778cd3 137GF = SCM_PACK (0); /* Dirk:FIXME:: Can we safely use #f instead of 0? */ \
fd61ba9e 138scm_make_subr_with_generic (RANAME, TYPE, (SCM_FUNC_CAST_ARBITRARY_ARGS) CFN, &GF) \
4b4d0898 139)
5b4215a8 140
b8229a3b 141#define SCM_SYNTAX(RANAME, STR, TYPE, CFN) \
1e76143f
GB
142SCM_HERE(static const char RANAME[]=STR)\
143SCM_INIT(scm_make_synt (RANAME, TYPE, CFN))
b8229a3b 144
5b4215a8 145#define SCM_SYMBOL(c_name, scheme_name) \
54778cd3 146SCM_HERE(static SCM c_name) \
1e76143f 147SCM_INIT(c_name = scm_permanent_object (SCM_CAR (scm_intern0 (scheme_name))))
5b4215a8 148
78f9f47b 149#define SCM_GLOBAL_SYMBOL(c_name, scheme_name) \
54778cd3 150SCM_HERE(SCM c_name) \
1e76143f 151SCM_INIT(c_name = scm_permanent_object (SCM_CAR (scm_intern0 (scheme_name))))
78f9f47b 152
37b83f68 153#define SCM_KEYWORD(c_name, scheme_name) \
54778cd3 154SCM_HERE(static SCM c_name) \
1e76143f 155SCM_INIT(c_name = scm_permanent_object (scm_c_make_keyword (scheme_name)))
37b83f68 156
37b83f68 157#define SCM_GLOBAL_KEYWORD(c_name, scheme_name) \
54778cd3 158SCM_HERE(SCM c_name) \
1e76143f 159SCM_INIT(c_name = scm_permanent_object (scm_c_make_keyword (scheme_name)))
5b4215a8 160
78f9f47b 161#define SCM_VCELL(c_name, scheme_name) \
54778cd3 162SCM_HERE(static SCM c_name) \
1e76143f 163SCM_INIT(c_name = scm_permanent_object (scm_intern0 (scheme_name)); SCM_SETCDR (c_name, SCM_BOOL_F))
78f9f47b 164
78f9f47b 165#define SCM_GLOBAL_VCELL(c_name, scheme_name) \
54778cd3 166SCM_HERE(SCM c_name) \
1e76143f 167SCM_INIT(c_name = scm_permanent_object (scm_intern0 (scheme_name)); SCM_SETCDR (c_name, SCM_BOOL_F))
5b4215a8 168
2e07d033 169#define SCM_VCELL_INIT(c_name, scheme_name, init_val) \
54778cd3 170SCM_HERE(static SCM c_name) \
1e76143f 171SCM_INIT(c_name = scm_permanent_object (scm_intern0 (scheme_name)); SCM_SETCDR (c_name, init_val))
5b4215a8 172
2e07d033 173#define SCM_GLOBAL_VCELL_INIT(c_name, scheme_name, init_val) \
54778cd3 174SCM_HERE(SCM c_name) \
1e76143f 175SCM_INIT(c_name = scm_permanent_object (scm_intern0 (scheme_name)); SCM_SETCDR (c_name, init_val))
5b4215a8 176
4b4d0898
GB
177#define SCM_CONST_LONG(c_name, scheme_name,value) \
178SCM_VCELL_INIT(c_name, scheme_name, scm_long2num(value))
179
180#ifdef SCM_MAGIC_SNARFER
181#undef SCM_ASSERT
182#define SCM_ASSERT(_cond, _arg, _pos, _subr) *&*&*&*SCM_ARG_BETTER_BE_IN_POSITION(_arg,_pos,__LINE__)
183#endif /* SCM_MAGIC_SNARFER */
2e07d033 184
5b4215a8 185#endif /* LIBGUILE_SNARF_H */
4b4d0898 186
89e00824
ML
187
188/*
189 Local Variables:
190 c-file-style: "gnu"
191 End:
192*/