3 /* Macros for snarfing initialization actions from C source. */
5 #ifndef LIBGUILE_SNARF_H
6 #define LIBGUILE_SNARF_H
8 /* Copyright (C) 1995-2000 Free Software Foundation, Inc.
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)
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.
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
22 * the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
23 * Boston, MA 02111-1307 USA
25 * As a special exception, the Free Software Foundation gives permission
26 * for additional uses of the text contained in its release of GUILE.
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.
34 * This exception does not however invalidate any other reasons why
35 * the executable file might be covered by the GNU General Public License.
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.
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. */
49 /* Software engineering face-lift by Greg J. Badros, 11-Dec-1999,
50 gjb@cs.washington.edu, http://www.cs.washington.edu/homes/gjb */
54 #if defined(__cplusplus) || defined(GUILE_CPLUSPLUS_SNARF)
55 #define SCM_FUNC_CAST_ARBITRARY_ARGS SCM (*)(...)
57 #define SCM_FUNC_CAST_ARBITRARY_ARGS SCM (*)()
60 /* Generic macros to be used in user macro definitions.
62 * For example, in order to define a macro which creates ints and
63 * initializes them to the result of foo (), do:
65 * #define SCM_FOO(NAME) \
66 * SCM_HERE (int NAME) \
67 * SCM_INIT (NAME = foo ())
69 * The SCM_INIT text goes into the corresponding .x file
70 * up through the first occurrence of $$$ on that line, if any.
73 #ifndef SCM_MAGIC_SNARFER
74 # define SCM_HERE(X) X
78 # define SCM_INIT(X) %%% X
81 #define SCM_DEFINE(FNAME, PRIMNAME, REQ, OPT, VAR, ARGLIST, DOCSTRING) \
83 static const char s_ ## FNAME [] = PRIMNAME; \
87 scm_make_gsubr (s_ ## FNAME, REQ, OPT, VAR, (SCM_FUNC_CAST_ARBITRARY_ARGS) FNAME); \
88 $$$P PRIMNAME #ARGLIST | REQ | OPT | VAR | __FILE__:__LINE__ | @@@ DOCSTRING @!!! \
91 #define SCM_DEFINE1(FNAME, PRIMNAME, TYPE, ARGLIST, DOCSTRING) \
93 static const char s_ ## FNAME [] = PRIMNAME; \
96 scm_make_subr (s_ ## FNAME, TYPE, FNAME); \
97 $$$1 PRIMNAME #ARGLIST | 2 | 0 | 0 | __FILE__:__LINE__ | @@@ DOCSTRING @!!! \
100 #define SCM_PROC(RANAME, STR, REQ, OPT, VAR, CFN) \
101 SCM_HERE(static const char RANAME[]=STR) \
103 scm_make_gsubr (RANAME, REQ, OPT, VAR, (SCM_FUNC_CAST_ARBITRARY_ARGS) CFN) \
106 #define SCM_REGISTER_PROC(RANAME, STR, REQ, OPT, VAR, CFN) \
108 static const char RANAME[]=STR \
110 scm_make_gsubr (RANAME, REQ, OPT, VAR, (SCM_FUNC_CAST_ARBITRARY_ARGS) CFN); \
111 $$$R STR | REQ | OPT | VAR | __FILE__:__LINE__ | @@@ CFN @!!! \
114 #define SCM_GPROC(RANAME, STR, REQ, OPT, VAR, CFN, GF) \
116 static const char RANAME[]=STR;\
119 scm_make_gsubr_with_generic (RANAME, REQ, OPT, VAR, (SCM_FUNC_CAST_ARBITRARY_ARGS) CFN, &GF) \
122 #define SCM_PROC1(RANAME, STR, TYPE, CFN) \
123 SCM_HERE(static const char RANAME[]=STR) \
125 scm_make_subr(RANAME, TYPE, (SCM (*)(...))CFN) \
129 #define SCM_GPROC1(RANAME, STR, TYPE, CFN, GF) \
131 static const char RANAME[]=STR; \
134 scm_make_subr_with_generic(RANAME, TYPE, (SCM_FUNC_CAST_ARBITRARY_ARGS) CFN, &GF) \
137 #define SCM_SYNTAX(RANAME, STR, TYPE, CFN) \
138 SCM_HERE(static const char RANAME[]=STR)\
139 SCM_INIT(scm_make_synt (RANAME, TYPE, CFN))
141 #define SCM_SYMBOL(c_name, scheme_name) \
142 SCM_HERE(static SCM c_name = SCM_BOOL_F) \
143 SCM_INIT(c_name = scm_permanent_object (SCM_CAR (scm_intern0 (scheme_name))))
145 #define SCM_GLOBAL_SYMBOL(c_name, scheme_name) \
146 SCM_HERE(SCM c_name = SCM_BOOL_F) \
147 SCM_INIT(c_name = scm_permanent_object (SCM_CAR (scm_intern0 (scheme_name))))
149 #define SCM_KEYWORD(c_name, scheme_name) \
150 SCM_HERE(static SCM c_name = SCM_BOOL_F) \
151 SCM_INIT(c_name = scm_permanent_object (scm_c_make_keyword (scheme_name)))
153 #define SCM_GLOBAL_KEYWORD(c_name, scheme_name) \
154 SCM_HERE(SCM c_name = SCM_BOOL_F) \
155 SCM_INIT(c_name = scm_permanent_object (scm_c_make_keyword (scheme_name)))
157 #define SCM_VCELL(c_name, scheme_name) \
158 SCM_HERE(static SCM c_name = SCM_BOOL_F) \
159 SCM_INIT(c_name = scm_permanent_object (scm_intern0 (scheme_name)); SCM_SETCDR (c_name, SCM_BOOL_F))
161 #define SCM_GLOBAL_VCELL(c_name, scheme_name) \
162 SCM_HERE(SCM c_name = SCM_BOOL_F) \
163 SCM_INIT(c_name = scm_permanent_object (scm_intern0 (scheme_name)); SCM_SETCDR (c_name, SCM_BOOL_F))
165 #define SCM_VCELL_INIT(c_name, scheme_name, init_val) \
166 SCM_HERE(static SCM c_name = SCM_BOOL_F) \
167 SCM_INIT(c_name = scm_permanent_object (scm_intern0 (scheme_name)); SCM_SETCDR (c_name, init_val))
169 #define SCM_GLOBAL_VCELL_INIT(c_name, scheme_name, init_val) \
170 SCM_HERE(SCM c_name = SCM_BOOL_F) \
171 SCM_INIT(c_name = scm_permanent_object (scm_intern0 (scheme_name)); SCM_SETCDR (c_name, init_val))
173 #define SCM_CONST_LONG(c_name, scheme_name,value) \
174 SCM_VCELL_INIT(c_name, scheme_name, scm_long2num(value))
176 #ifdef SCM_MAGIC_SNARFER
178 #define SCM_ASSERT(_cond, _arg, _pos, _subr) *&*&*&*SCM_ARG_BETTER_BE_IN_POSITION(_arg,_pos,__LINE__)
179 #endif /* SCM_MAGIC_SNARFER */
181 #endif /* LIBGUILE_SNARF_H */