1 /* Copyright (C) 1995,1996,1997,1998,2000,2001 Free Software Foundation, Inc.
2  *
3  * This program is free software; you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License as published by
5  * the Free Software Foundation; either version 2, or (at your option)
6  * any later version.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this software; see the file COPYING.  If not, write to
15  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16  * Boston, MA 02110-1301 USA.
17  *
18  * As a special exception, the Free Software Foundation gives permission
19  * for additional uses of the text contained in its release of GUILE.
20  *
21  * The exception is that, if you link the GUILE library with other files
22  * to produce an executable, this does not by itself cause the
23  * resulting executable to be covered by the GNU General Public License.
24  * Your use of that executable is in no way restricted on account of
25  * linking the GUILE library code into it.
26  *
27  * This exception does not however invalidate any other reasons why
28  * the executable file might be covered by the GNU General Public License.
29  *
30  * This exception applies only to the code released by the
31  * Free Software Foundation under the name GUILE.  If you copy
32  * code from other Free Software Foundation releases into a copy of
33  * GUILE, as the General Public License permits, the exception does
34  * not apply to the code that you add in this way.  To avoid misleading
35  * anyone as to the status of such modified files, you must delete
36  * this exception notice from them.
37  *
38  * If you write modifications of your own for GUILE, it is your choice
39  * whether to permit this exception to apply to your modifications.
40  * If you do not wish that, delete this exception notice.  */
41 
42 
43 #ifndef REP_GH_H
44 #define REP_GH_H
45 
46 #ifdef __cplusplus
47 extern "C" {
48 #endif
49 
50 #include <rep.h>
51 
52 /* gcc has extern inline functions that are basically as fast as macros */
53 #ifdef __GNUC__
54 # define INL inline
55 # define EXTINL extern inline
56 #else
57 # define INL
58 #define EXTINL
59 #endif /* __GNUC__ */
60 
61 typedef repv SCM;
62 
63 #define SCM_EOL Qnil
64 #define SCM_BOOL_F Qnil
65 #define SCM_BOOL_T Qt
66 #define SCM_UNDEFINED rep_undefined_value
67 #define SCM_UNSPECIFIED rep_undefined_value
68 
69 typedef SCM (*scm_t_catch_body) (void *data);
70 typedef SCM (*scm_t_catch_handler) (void *data,
71                                     SCM tag, SCM throw_args);
72 
73 void gh_enter(int argc, char *argv[], void (*c_main_prog)(int, char **));
74 #define gh_init () scm_init_guile ()
75 void gh_repl(int argc, char *argv[]);
76 SCM gh_catch(SCM tag, scm_t_catch_body body, void *body_data,
77 	     scm_t_catch_handler handler, void *handler_data);
78 
79 SCM gh_standard_handler(void *data, SCM tag, SCM throw_args);
80 
81 SCM gh_eval_str(const char *scheme_code);
82 SCM gh_eval_str_with_catch(const char *scheme_code, scm_t_catch_handler handler);
83 SCM gh_eval_str_with_standard_handler(const char *scheme_code);
84 SCM gh_eval_str_with_stack_saving_handler(const char *scheme_code);
85 
86 SCM gh_eval_file(const char *fname);
87 #define gh_load(fname) gh_eval_file(fname)
88 SCM gh_eval_file_with_catch(const char *scheme_code, scm_t_catch_handler handler);
89 SCM gh_eval_file_with_standard_handler(const char *scheme_code);
90 
91 #define gh_defer_ints() do{}while(0)
92 #define gh_allow_ints() do{}while(0)
93 
94 SCM gh_new_procedure(const char *proc_name, SCM (*fn)(),
95 		     int n_required_args, int n_optional_args, int varp);
96 SCM gh_new_procedure0_0(const char *proc_name, SCM (*fn)(void));
97 SCM gh_new_procedure0_1(const char *proc_name, SCM (*fn)(SCM));
98 SCM gh_new_procedure0_2(const char *proc_name, SCM (*fn)(SCM, SCM));
99 SCM gh_new_procedure1_0(const char *proc_name, SCM (*fn)(SCM));
100 SCM gh_new_procedure1_1(const char *proc_name, SCM (*fn)(SCM, SCM));
101 SCM gh_new_procedure1_2(const char *proc_name, SCM (*fn)(SCM, SCM, SCM));
102 SCM gh_new_procedure2_0(const char *proc_name, SCM (*fn)(SCM, SCM));
103 SCM gh_new_procedure2_1(const char *proc_name, SCM (*fn)(SCM, SCM, SCM));
104 SCM gh_new_procedure2_2(const char *proc_name, SCM (*fn)(SCM, SCM, SCM, SCM));
105 SCM gh_new_procedure3_0(const char *proc_name, SCM (*fn)(SCM, SCM, SCM));
106 SCM gh_new_procedure4_0(const char *proc_name, SCM (*fn)(SCM, SCM, SCM, SCM));
107 SCM gh_new_procedure5_0(const char *proc_name, SCM (*fn)(SCM, SCM, SCM, SCM, SCM));
108 
109 /* C to Scheme conversion */
110 SCM gh_bool2scm(int x);
111 SCM gh_int2scm(int x);
112 SCM gh_ulong2scm(unsigned long x);
113 SCM gh_long2scm(long x);
114 SCM gh_double2scm(double x);
115 SCM gh_char2scm(char c);
116 SCM gh_str2scm(const char *s, size_t len);
117 SCM gh_str02scm(const char *s);
118 void gh_set_substr(char *src, SCM dst, long start, size_t len);
119 SCM gh_symbol2scm(const char *symbol_str);
120 SCM gh_ints2scm(const int *d, long n);
121 SCM gh_doubles2scm(const double *d, long n);
122 
123 /* Scheme to C conversion */
124 int gh_scm2bool(SCM obj);
125 int gh_scm2int(SCM obj);
126 unsigned long gh_scm2ulong(SCM obj);
127 long gh_scm2long(SCM obj);
128 char gh_scm2char(SCM obj);
129 double gh_scm2double(SCM obj);
130 char *gh_scm2newstr(SCM str, size_t *lenp);
131 void gh_get_substr(SCM src, char *dst, long start, size_t len);
132 char *gh_symbol2newstr(SCM sym, size_t *lenp);
133 char *gh_scm2chars(SCM vector, char *result);
134 short *gh_scm2shorts(SCM vector, short *result);
135 long *gh_scm2longs(SCM vector, long *result);
136 float *gh_scm2floats(SCM vector, float *result);
137 double *gh_scm2doubles(SCM vector, double *result);
138 
139 /* type predicates: tell you if an SCM object has a given type */
140 int gh_boolean_p(SCM val);
141 int gh_symbol_p(SCM val);
142 int gh_char_p(SCM val);
143 int gh_vector_p(SCM val);
144 int gh_pair_p(SCM val);
145 int gh_number_p(SCM val);
146 int gh_string_p(SCM val);
147 int gh_procedure_p(SCM val);
148 int gh_list_p(SCM val);
149 int gh_inexact_p(SCM val);
150 int gh_exact_p(SCM val);
151 
152 /* more predicates */
153 int gh_eq_p(SCM x, SCM y);
154 int gh_eqv_p(SCM x, SCM y);
155 int gh_equal_p(SCM x, SCM y);
156 int gh_string_equal_p(SCM s1, SCM s2);
157 int gh_null_p(SCM l);
158 
159 /* standard Scheme procedures available from C */
160 
161 SCM gh_not(SCM val);
162 
163 SCM gh_define(const char *name, SCM val);
164 
165 /* string manipulation routines */
166 SCM gh_make_string(SCM k, SCM chr);
167 SCM gh_string_length(SCM str);
168 SCM gh_string_ref(SCM str, SCM k);
169 SCM gh_string_set_x(SCM str, SCM k, SCM chr);
170 SCM gh_substring(SCM str, SCM start, SCM end);
171 SCM gh_string_append(SCM args);
172 
173 
174 /* vector manipulation routines */
175 /* note that gh_vector() does not behave quite like the Scheme (vector
176    obj1 obj2 ...), because the interpreter engine does not pass the
177    data element by element, but rather as a list.  thus, gh_vector()
178    ends up being identical to gh_list_to_vector() */
179 SCM gh_vector(SCM ls);
180 SCM gh_make_vector(SCM length, SCM val);
181 SCM gh_vector_set_x(SCM vec, SCM pos, SCM val);
182 SCM gh_vector_ref(SCM vec, SCM pos);
183 unsigned long gh_vector_length (SCM v);
184 unsigned long gh_uniform_vector_length (SCM v);
185 SCM gh_uniform_vector_ref (SCM v, SCM ilist);
186 #define gh_list_to_vector(ls) gh_vector(ls)
187 SCM gh_vector_to_list(SCM v);
188 
189 SCM gh_lookup (const char *sname);
190 SCM gh_module_lookup (SCM module, const char *sname);
191 
192 SCM gh_cons(SCM x, SCM y);
193 SCM gh_list(SCM elt, ...);
194 unsigned long gh_length(SCM l);
195 SCM gh_append(SCM args);
196 SCM gh_append2(SCM l1, SCM l2);
197 SCM gh_append3(SCM l1, SCM l2, SCM l3);
198 SCM gh_append4(SCM l1, SCM l2, SCM l3, SCM l4);
199 SCM gh_reverse(SCM ls);
200 SCM gh_list_tail(SCM ls, SCM k);
201 SCM gh_list_ref(SCM ls, SCM k);
202 SCM gh_memq(SCM x, SCM ls);
203 SCM gh_memv(SCM x, SCM ls);
204 SCM gh_member(SCM x, SCM ls);
205 SCM gh_assq(SCM x, SCM alist);
206 SCM gh_assv(SCM x, SCM alist);
207 SCM gh_assoc(SCM x, SCM alist);
208 
209 SCM gh_car(SCM x);
210 SCM gh_cdr(SCM x);
211 
212 SCM gh_caar(SCM x);
213 SCM gh_cadr(SCM x);
214 SCM gh_cdar(SCM x);
215 SCM gh_cddr(SCM x);
216 
217 SCM gh_caaar(SCM x);
218 SCM gh_caadr(SCM x);
219 SCM gh_cadar(SCM x);
220 SCM gh_caddr(SCM x);
221 SCM gh_cdaar(SCM x);
222 SCM gh_cdadr(SCM x);
223 SCM gh_cddar(SCM x);
224 SCM gh_cdddr(SCM x);
225 
226 SCM gh_set_car_x(SCM pair, SCM value);
227 SCM gh_set_cdr_x(SCM pair, SCM value);
228 
229 
230 /* Calling Scheme functions from C.  */
231 SCM gh_apply (SCM proc, SCM ls);
232 SCM gh_call0 (SCM proc);
233 SCM gh_call1 (SCM proc, SCM arg);
234 SCM gh_call2 (SCM proc, SCM arg1, SCM arg2);
235 SCM gh_call3 (SCM proc, SCM arg1, SCM arg2, SCM arg3);
236 
237 /* reading and writing Scheme objects.  */
238 void gh_display (SCM x);
239 void gh_write (SCM x);
240 void gh_newline (void);
241 
242 /* void  gh_gc_mark(SCM)              : mark an SCM as in use. */
243 /* void  gh_defer_ints()              : don't interrupt code section. */
244 /* void  gh_allow_ints()              : see gh_defer_ints(). */
245 /* void  gh_new_cell(SCM, int tag)    : initialize SCM to be of type 'tag' */
246 /* int   gh_type_p(SCM, tag)          : test if SCM is of type 'tag' */
247 /* SCM   gh_intern(char*)             : get symbol corresponding to c-string.*/
248 /* void  gh_set_ext_data(SCM, void*)  : set extension data on SCM */
249 /* void *gh_get_ext_data(SCM)         : return extension data from SCM. */
250 
251 /* void  gh_assert(int cond, char *msg, SCM obj); */
252 
253 #ifdef __cplusplus
254 }
255 #endif
256 
257 #endif /* REP_GH_H */
258 
259 /*
260   Local Variables:
261   c-file-style: "gnu"
262   End:
263 */
264