999ffe3d7c1e8de063a68299fd62b266bcb965cd
[bpt/guile.git] / libguile / snarf.h
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
8 /* Copyright (C) 1995,1996,1997,1998, 1999 Free Software Foundation, Inc.
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
22 * the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
23 * Boston, MA 02111-1307 USA
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. */
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
52 \f
53
54 #ifndef SCM_MAGIC_SNARFER
55
56 #define GUILE_PROC(FNAME, PRIMNAME, REQ, OPT, VAR, ARGLIST, DOCSTRING) \
57 static const char s_ ## FNAME [] = PRIMNAME; \
58 SCM FNAME ARGLIST
59 #define GUILE_PROC1(FNAME, PRIMNAME, TYPE, ARGLIST, DOCSTRING) \
60 static const char s_ ## FNAME [] = PRIMNAME; \
61 SCM FNAME ARGLIST
62
63 #define SCM_REGISTER_PROC(RANAME, STR, REQ, OPT, VAR, CFN) \
64 static const char RANAME[]=STR
65 #define SCM_GPROC(RANAME, STR, REQ, OPT, VAR, CFN, GF) \
66 static const char RANAME[]=STR; \
67 static SCM GF = 0
68 #define SCM_PROC1(RANAME, STR, TYPE, CFN) \
69 static const char RANAME[]=STR
70 #define SCM_GPROC1(RANAME, STR, TYPE, CFN, GF) \
71 static const char RANAME[]=STR; \
72 static SCM GF = 0
73 #else
74 #if defined(__cplusplus) || defined(GUILE_CPLUSPLUS_SNARF)
75
76 #define GUILE_PROC(FNAME, PRIMNAME, REQ, OPT, VAR, ARGLIST, DOCSTRING) \
77 %%% scm_make_gsubr (s_ ## FNAME, REQ, OPT, VAR, (SCM (*)(...)) FNAME); \
78 $$$ primname #ARGLIST req opt var @@@ docstring @!!!
79
80 #define GUILE_PROC1(FNAME, PRIMNAME, TYPE, ARGLIST, DOCSTRING) \
81 %%% scm_make_subr (s_ ## FNAME, TYPE, FNAME); \
82 $$1 primname #ARGLIST type @@@ docstring @!!!
83
84 #define SCM_REGISTER_PROC(RANAME, STR, REQ, OPT, VAR, CFN) \
85 %%% scm_make_gsubr (RANAME, REQ, OPT, VAR, (SCM (*)(...)) CFN) \
86 $$R RANAMEprimname #ARGLIST type @@@ docstring @!!!
87
88 #define SCM_GPROC(RANAME, STR, REQ, OPT, VAR, CFN, GF) \
89 %%% scm_make_gsubr_with_generic (RANAME, REQ, OPT, VAR, (SCM (*)(...))CFN, &GF)
90 #define SCM_PROC1(RANAME, STR, TYPE, CFN) \
91 %%% scm_make_subr(RANAME, TYPE, (SCM (*)(...))CFN)
92 #define SCM_GPROC1(RANAME, STR, TYPE, CFN, GF) \
93 %%% scm_make_subr_with_generic(RANAME, TYPE, (SCM (*)(...))CFN, &GF)
94 #else
95
96 #define GUILE_PROC(FNAME, PRIMNAME, REQ, OPT, VAR, ARGLIST, DOCSTRING) \
97 %%% scm_make_gsubr (s_ ## FNAME, REQ, OPT, VAR, (SCM (*)()) FNAME);
98 #define GUILE_PROC1(FNAME, PRIMNAME, TYPE, ARGLIST, DOCSTRING) \
99 %%% scm_make_subr (s_ ## FNAME, TYPE, FNAME);
100
101
102 #define SCM_PROC(RANAME, STR, REQ, OPT, VAR, CFN) \
103 %%% scm_make_gsubr (RANAME, REQ, OPT, VAR, (SCM (*)()) CFN)
104 #define SCM_REGISTER_PROC(RANAME, STR, REQ, OPT, VAR, CFN) \
105 %%% scm_make_gsubr (RANAME, REQ, OPT, VAR, (SCM (*)()) CFN)
106 #define SCM_GPROC(RANAME, STR, REQ, OPT, VAR, CFN, GF) \
107 %%% scm_make_gsubr_with_generic (RANAME, REQ, OPT, VAR, (SCM (*)()) CFN, &GF)
108 #define SCM_PROC1(RANAME, STR, TYPE, CFN) \
109 %%% scm_make_subr(RANAME, TYPE, CFN)
110 #define SCM_GPROC1(RANAME, STR, TYPE, CFN, GF) \
111 %%% scm_make_subr_with_generic(RANAME, TYPE, CFN, &GF)
112 #endif
113 #endif
114
115 #ifndef SCM_MAGIC_SNARFER
116 #define SCM_SYNTAX(RANAME, STR, TYPE, CFN) \
117 static const char RANAME[]=STR
118 #else
119 #define SCM_SYNTAX(RANAME, STR, TYPE, CFN) \
120 %%% scm_make_synt (RANAME, TYPE, CFN)
121 #endif
122
123 #ifndef SCM_MAGIC_SNARFER
124 #define SCM_SYMBOL(c_name, scheme_name) \
125 static SCM c_name = SCM_BOOL_F
126 #else
127 #define SCM_SYMBOL(C_NAME, SCHEME_NAME) \
128 %%% C_NAME = scm_permanent_object (SCM_CAR (scm_intern0 (SCHEME_NAME)))
129 #endif
130
131 #ifndef SCM_MAGIC_SNARFER
132 #define SCM_GLOBAL_SYMBOL(c_name, scheme_name) \
133 SCM c_name = SCM_BOOL_F
134 #else
135 #define SCM_GLOBAL_SYMBOL(C_NAME, SCHEME_NAME) \
136 %%% C_NAME = scm_permanent_object (SCM_CAR (scm_intern0 (SCHEME_NAME)))
137 #endif
138
139 #ifndef SCM_MAGIC_SNARFER
140 #define SCM_KEYWORD(c_name, scheme_name) \
141 static SCM c_name = SCM_BOOL_F
142 #else
143 #define SCM_KEYWORD(C_NAME, SCHEME_NAME) \
144 %%% C_NAME = scm_permanent_object (scm_c_make_keyword (SCHEME_NAME))
145 #endif
146
147 #ifndef SCM_MAGIC_SNARFER
148 #define SCM_GLOBAL_KEYWORD(c_name, scheme_name) \
149 SCM c_name = SCM_BOOL_F
150 #else
151 #define SCM_GLOBAL_KEYWORD(C_NAME, SCHEME_NAME) \
152 %%% C_NAME = scm_permanent_object (scm_c_make_keyword (SCHEME_NAME))
153 #endif
154
155 #ifndef SCM_MAGIC_SNARFER
156 #define SCM_VCELL(c_name, scheme_name) \
157 static SCM c_name = SCM_BOOL_F
158 #else
159 #define SCM_VCELL(C_NAME, SCHEME_NAME) \
160 %%% C_NAME = scm_permanent_object (scm_intern0 (SCHEME_NAME)); SCM_SETCDR (C_NAME, SCM_BOOL_F)
161 #endif
162
163 #ifndef SCM_MAGIC_SNARFER
164 #define SCM_GLOBAL_VCELL(c_name, scheme_name) \
165 SCM c_name = SCM_BOOL_F
166 #else
167 #define SCM_GLOBAL_VCELL(C_NAME, SCHEME_NAME) \
168 %%% C_NAME = scm_permanent_object (scm_intern0 (SCHEME_NAME)); SCM_SETCDR (C_NAME, SCM_BOOL_F)
169 #endif
170
171 #ifndef SCM_MAGIC_SNARFER
172 #define SCM_VCELL_INIT(c_name, scheme_name, init_val) \
173 static SCM c_name = SCM_BOOL_F
174 #else
175 #define SCM_VCELL_INIT(C_NAME, SCHEME_NAME, init_val) \
176 %%% C_NAME = scm_permanent_object (scm_intern0 (SCHEME_NAME)); SCM_SETCDR (C_NAME, init_val)
177 #endif
178
179 #ifndef SCM_MAGIC_SNARFER
180 #define SCM_GLOBAL_VCELL_INIT(c_name, scheme_name, init_val) \
181 SCM c_name = SCM_BOOL_F
182 #else
183 #define SCM_GLOBAL_VCELL_INIT(C_NAME, SCHEME_NAME, init_val) \
184 %%% C_NAME = scm_permanent_object (scm_intern0 (SCHEME_NAME)); SCM_SETCDR (C_NAME, init_val)
185 #endif
186
187 #define SCM_CONST_LONG(C_NAME, SCHEME_NAME,VALUE) SCM_VCELL_INIT(C_NAME, SCHEME_NAME, scm_long2num(VALUE))
188
189 #endif /* LIBGUILE_SNARF_H */