Commit | Line | Data |
---|---|---|
2b829bbb | 1 | /* Copyright (C) 1995,1996,1997,1998,2000,2001, 2005, 2006 Free Software Foundation, Inc. |
ee2a8b9b | 2 | * |
73be1d9e MV |
3 | * This library is free software; you can redistribute it and/or |
4 | * modify it under the terms of the GNU Lesser General Public | |
5 | * License as published by the Free Software Foundation; either | |
6 | * version 2.1 of the License, or (at your option) any later version. | |
ee2a8b9b | 7 | * |
73be1d9e MV |
8 | * This library 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 GNU | |
11 | * Lesser General Public License for more details. | |
ee2a8b9b | 12 | * |
73be1d9e MV |
13 | * You should have received a copy of the GNU Lesser General Public |
14 | * License along with this library; if not, write to the Free Software | |
92205699 | 15 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
73be1d9e | 16 | */ |
ee2a8b9b JB |
17 | \f |
18 | ||
19 | #ifndef __GH_H | |
20 | #define __GH_H | |
21 | ||
73a90115 MD |
22 | /* This needs to be included outside of the extern "C" block. |
23 | */ | |
24 | #include <libguile.h> | |
25 | ||
5c56ebe1 MV |
26 | #if SCM_ENABLE_DEPRECATED |
27 | ||
18daf95b AG |
28 | #ifdef __cplusplus |
29 | extern "C" { | |
30 | #endif | |
31 | ||
ee2a8b9b JB |
32 | /* gcc has extern inline functions that are basically as fast as macros */ |
33 | #ifdef __GNUC__ | |
34 | # define INL inline | |
35 | # define EXTINL extern inline | |
36 | #else | |
37 | # define INL | |
38 | #define EXTINL | |
39 | #endif /* __GNUC__ */ | |
40 | ||
33b001fd MV |
41 | SCM_API void gh_enter(int argc, char *argv[], |
42 | void (*c_main_prog)(int, char **)); | |
1464aae0 | 43 | #define gh_init () scm_init_guile () |
33b001fd MV |
44 | SCM_API void gh_repl(int argc, char *argv[]); |
45 | SCM_API SCM gh_catch(SCM tag, scm_t_catch_body body, void *body_data, | |
46 | scm_t_catch_handler handler, void *handler_data); | |
ee2a8b9b | 47 | |
33b001fd | 48 | SCM_API SCM gh_standard_handler(void *data, SCM tag, SCM throw_args); |
ee2a8b9b | 49 | |
33b001fd MV |
50 | SCM_API SCM gh_eval_str(const char *scheme_code); |
51 | SCM_API SCM gh_eval_str_with_catch(const char *scheme_code, scm_t_catch_handler handler); | |
52 | SCM_API SCM gh_eval_str_with_standard_handler(const char *scheme_code); | |
53 | SCM_API SCM gh_eval_str_with_stack_saving_handler(const char *scheme_code); | |
ee2a8b9b | 54 | |
33b001fd | 55 | SCM_API SCM gh_eval_file(const char *fname); |
e5eece74 | 56 | #define gh_load(fname) gh_eval_file(fname) |
33b001fd MV |
57 | SCM_API SCM gh_eval_file_with_catch(const char *scheme_code, scm_t_catch_handler handler); |
58 | SCM_API SCM gh_eval_file_with_standard_handler(const char *scheme_code); | |
ee2a8b9b | 59 | |
9de87eea MV |
60 | #define gh_defer_ints() SCM_CRITICAL_SECTION_START |
61 | #define gh_allow_ints() SCM_CRITICAL_SECTION_END | |
ee2a8b9b | 62 | |
33b001fd MV |
63 | SCM_API SCM gh_new_procedure(const char *proc_name, SCM (*fn)(), |
64 | int n_required_args, int n_optional_args, | |
65 | int varp); | |
66 | SCM_API SCM gh_new_procedure0_0(const char *proc_name, SCM (*fn)(void)); | |
67 | SCM_API SCM gh_new_procedure0_1(const char *proc_name, SCM (*fn)(SCM)); | |
68 | SCM_API SCM gh_new_procedure0_2(const char *proc_name, SCM (*fn)(SCM, SCM)); | |
69 | SCM_API SCM gh_new_procedure1_0(const char *proc_name, SCM (*fn)(SCM)); | |
70 | SCM_API SCM gh_new_procedure1_1(const char *proc_name, SCM (*fn)(SCM, SCM)); | |
71 | SCM_API SCM gh_new_procedure1_2(const char *proc_name, SCM (*fn)(SCM, SCM, SCM)); | |
72 | SCM_API SCM gh_new_procedure2_0(const char *proc_name, SCM (*fn)(SCM, SCM)); | |
73 | SCM_API SCM gh_new_procedure2_1(const char *proc_name, SCM (*fn)(SCM, SCM, SCM)); | |
74 | SCM_API SCM gh_new_procedure2_2(const char *proc_name, SCM (*fn)(SCM, SCM, SCM, SCM)); | |
75 | SCM_API SCM gh_new_procedure3_0(const char *proc_name, SCM (*fn)(SCM, SCM, SCM)); | |
76 | SCM_API SCM gh_new_procedure4_0(const char *proc_name, SCM (*fn)(SCM, SCM, SCM, SCM)); | |
77 | SCM_API SCM gh_new_procedure5_0(const char *proc_name, SCM (*fn)(SCM, SCM, SCM, SCM, SCM)); | |
ee2a8b9b JB |
78 | |
79 | /* C to Scheme conversion */ | |
33b001fd MV |
80 | SCM_API SCM gh_bool2scm(int x); |
81 | SCM_API SCM gh_int2scm(int x); | |
82 | SCM_API SCM gh_ulong2scm(unsigned long x); | |
83 | SCM_API SCM gh_long2scm(long x); | |
84 | SCM_API SCM gh_double2scm(double x); | |
85 | SCM_API SCM gh_char2scm(char c); | |
86 | SCM_API SCM gh_str2scm(const char *s, size_t len); | |
87 | SCM_API SCM gh_str02scm(const char *s); | |
f76c6bb2 | 88 | SCM_API void gh_set_substr(const char *src, SCM dst, long start, size_t len); |
33b001fd MV |
89 | SCM_API SCM gh_symbol2scm(const char *symbol_str); |
90 | SCM_API SCM gh_ints2scm(const int *d, long n); | |
afe5177e | 91 | |
33b001fd MV |
92 | SCM_API SCM gh_chars2byvect(const char *d, long n); |
93 | SCM_API SCM gh_shorts2svect(const short *d, long n); | |
94 | SCM_API SCM gh_longs2ivect(const long *d, long n); | |
95 | SCM_API SCM gh_ulongs2uvect(const unsigned long *d, long n); | |
96 | SCM_API SCM gh_floats2fvect(const float *d, long n); | |
97 | SCM_API SCM gh_doubles2dvect(const double *d, long n); | |
ee2a8b9b | 98 | |
33b001fd | 99 | SCM_API SCM gh_doubles2scm(const double *d, long n); |
ee2a8b9b JB |
100 | |
101 | /* Scheme to C conversion */ | |
33b001fd MV |
102 | SCM_API int gh_scm2bool(SCM obj); |
103 | SCM_API int gh_scm2int(SCM obj); | |
104 | SCM_API unsigned long gh_scm2ulong(SCM obj); | |
105 | SCM_API long gh_scm2long(SCM obj); | |
106 | SCM_API char gh_scm2char(SCM obj); | |
107 | SCM_API double gh_scm2double(SCM obj); | |
108 | SCM_API char *gh_scm2newstr(SCM str, size_t *lenp); | |
109 | SCM_API void gh_get_substr(SCM src, char *dst, long start, size_t len); | |
110 | SCM_API char *gh_symbol2newstr(SCM sym, size_t *lenp); | |
111 | SCM_API char *gh_scm2chars(SCM vector, char *result); | |
112 | SCM_API short *gh_scm2shorts(SCM vector, short *result); | |
113 | SCM_API long *gh_scm2longs(SCM vector, long *result); | |
114 | SCM_API float *gh_scm2floats(SCM vector, float *result); | |
115 | SCM_API double *gh_scm2doubles(SCM vector, double *result); | |
ee2a8b9b JB |
116 | |
117 | /* type predicates: tell you if an SCM object has a given type */ | |
33b001fd MV |
118 | SCM_API int gh_boolean_p(SCM val); |
119 | SCM_API int gh_symbol_p(SCM val); | |
120 | SCM_API int gh_char_p(SCM val); | |
121 | SCM_API int gh_vector_p(SCM val); | |
122 | SCM_API int gh_pair_p(SCM val); | |
123 | SCM_API int gh_number_p(SCM val); | |
124 | SCM_API int gh_string_p(SCM val); | |
125 | SCM_API int gh_procedure_p(SCM val); | |
126 | SCM_API int gh_list_p(SCM val); | |
127 | SCM_API int gh_inexact_p(SCM val); | |
128 | SCM_API int gh_exact_p(SCM val); | |
ee2a8b9b JB |
129 | |
130 | /* more predicates */ | |
33b001fd MV |
131 | SCM_API int gh_eq_p(SCM x, SCM y); |
132 | SCM_API int gh_eqv_p(SCM x, SCM y); | |
133 | SCM_API int gh_equal_p(SCM x, SCM y); | |
134 | SCM_API int gh_string_equal_p(SCM s1, SCM s2); | |
135 | SCM_API int gh_null_p(SCM l); | |
ee2a8b9b JB |
136 | |
137 | /* standard Scheme procedures available from C */ | |
138 | ||
7fee59bd MG |
139 | #define gh_not(x) scm_not(x) |
140 | ||
33b001fd | 141 | SCM_API SCM gh_define(const char *name, SCM val); |
ee2a8b9b | 142 | |
1464aae0 MV |
143 | /* string manipulation routines */ |
144 | #define gh_make_string(k, chr) scm_make_string(k, chr) | |
145 | #define gh_string_length(str) scm_string_length(str) | |
146 | #define gh_string_ref(str, k) scm_string_ref(str, k) | |
147 | #define gh_string_set_x(str, k, chr) scm_string_set_x(str, k, chr) | |
34d19ef6 | 148 | #define gh_substring(str, start, end) scm_substring(str, start, end) |
1464aae0 MV |
149 | #define gh_string_append(args) scm_string_append(args) |
150 | ||
151 | ||
e5eece74 MG |
152 | /* vector manipulation routines */ |
153 | /* note that gh_vector() does not behave quite like the Scheme (vector | |
154 | obj1 obj2 ...), because the interpreter engine does not pass the | |
155 | data element by element, but rather as a list. thus, gh_vector() | |
156 | ends up being identical to gh_list_to_vector() */ | |
157 | #define gh_vector(ls) scm_vector(ls) | |
33b001fd MV |
158 | SCM_API SCM gh_make_vector(SCM length, SCM val); |
159 | SCM_API SCM gh_vector_set_x(SCM vec, SCM pos, SCM val); | |
160 | SCM_API SCM gh_vector_ref(SCM vec, SCM pos); | |
161 | SCM_API unsigned long gh_vector_length (SCM v); | |
162 | SCM_API unsigned long gh_uniform_vector_length (SCM v); | |
163 | SCM_API SCM gh_uniform_vector_ref (SCM v, SCM ilist); | |
e5eece74 | 164 | #define gh_list_to_vector(ls) scm_vector(ls) |
c56f8119 | 165 | #define gh_vector_to_list(v) scm_vector_to_list(v) |
ee2a8b9b | 166 | |
33b001fd MV |
167 | SCM_API SCM gh_lookup (const char *sname); |
168 | SCM_API SCM gh_module_lookup (SCM module, const char *sname); | |
35379308 | 169 | |
33b001fd | 170 | SCM_API SCM gh_cons(SCM x, SCM y); |
1afff620 | 171 | #define gh_list scm_list_n |
33b001fd MV |
172 | SCM_API unsigned long gh_length(SCM l); |
173 | SCM_API SCM gh_append(SCM args); | |
174 | SCM_API SCM gh_append2(SCM l1, SCM l2); | |
175 | SCM_API SCM gh_append3(SCM l1, SCM l2, SCM l3); | |
176 | SCM_API SCM gh_append4(SCM l1, SCM l2, SCM l3, SCM l4); | |
7fee59bd MG |
177 | #define gh_reverse(ls) scm_reverse(ls) |
178 | #define gh_list_tail(ls, k) scm_list_tail(ls, k) | |
179 | #define gh_list_ref(ls, k) scm_list_ref(ls, k) | |
180 | #define gh_memq(x, ls) scm_memq(x, ls) | |
38d0f691 MD |
181 | #define gh_memv(x, ls) scm_memv(x, ls) |
182 | #define gh_member(x, ls) scm_member(x, ls) | |
7fee59bd MG |
183 | #define gh_assq(x, alist) scm_assq(x, alist) |
184 | #define gh_assv(x, alist) scm_assv(x, alist) | |
185 | #define gh_assoc(x, alist) scm_assoc(x, alist) | |
ee2a8b9b | 186 | |
33b001fd MV |
187 | SCM_API SCM gh_car(SCM x); |
188 | SCM_API SCM gh_cdr(SCM x); | |
ee2a8b9b | 189 | |
33b001fd MV |
190 | SCM_API SCM gh_caar(SCM x); |
191 | SCM_API SCM gh_cadr(SCM x); | |
192 | SCM_API SCM gh_cdar(SCM x); | |
193 | SCM_API SCM gh_cddr(SCM x); | |
ee2a8b9b | 194 | |
33b001fd MV |
195 | SCM_API SCM gh_caaar(SCM x); |
196 | SCM_API SCM gh_caadr(SCM x); | |
197 | SCM_API SCM gh_cadar(SCM x); | |
198 | SCM_API SCM gh_caddr(SCM x); | |
199 | SCM_API SCM gh_cdaar(SCM x); | |
200 | SCM_API SCM gh_cdadr(SCM x); | |
201 | SCM_API SCM gh_cddar(SCM x); | |
202 | SCM_API SCM gh_cdddr(SCM x); | |
ee2a8b9b | 203 | |
33b001fd MV |
204 | SCM_API SCM gh_set_car_x(SCM pair, SCM value); |
205 | SCM_API SCM gh_set_cdr_x(SCM pair, SCM value); | |
7fee59bd MG |
206 | |
207 | ||
ee2a8b9b | 208 | /* Calling Scheme functions from C. */ |
33b001fd MV |
209 | SCM_API SCM gh_apply (SCM proc, SCM ls); |
210 | SCM_API SCM gh_call0 (SCM proc); | |
211 | SCM_API SCM gh_call1 (SCM proc, SCM arg); | |
212 | SCM_API SCM gh_call2 (SCM proc, SCM arg1, SCM arg2); | |
213 | SCM_API SCM gh_call3 (SCM proc, SCM arg1, SCM arg2, SCM arg3); | |
ee2a8b9b JB |
214 | |
215 | /* reading and writing Scheme objects. */ | |
33b001fd MV |
216 | SCM_API void gh_display (SCM x); |
217 | SCM_API void gh_write (SCM x); | |
218 | SCM_API void gh_newline (void); | |
ee2a8b9b JB |
219 | |
220 | /* void gh_gc_mark(SCM) : mark an SCM as in use. */ | |
221 | /* void gh_defer_ints() : don't interrupt code section. */ | |
222 | /* void gh_allow_ints() : see gh_defer_ints(). */ | |
223 | /* void gh_new_cell(SCM, int tag) : initialize SCM to be of type 'tag' */ | |
224 | /* int gh_type_p(SCM, tag) : test if SCM is of type 'tag' */ | |
225 | /* SCM gh_intern(char*) : get symbol corresponding to c-string.*/ | |
226 | /* void gh_set_ext_data(SCM, void*) : set extension data on SCM */ | |
227 | /* void *gh_get_ext_data(SCM) : return extension data from SCM. */ | |
228 | ||
229 | /* void gh_assert(int cond, char *msg, SCM obj); */ | |
230 | ||
18daf95b AG |
231 | #ifdef __cplusplus |
232 | } | |
233 | #endif | |
ee2a8b9b | 234 | |
5c56ebe1 MV |
235 | #endif |
236 | ||
ee2a8b9b | 237 | #endif /* __GH_H */ |
a61b2054 | 238 | |
89e00824 ML |
239 | /* |
240 | Local Variables: | |
241 | c-file-style: "gnu" | |
242 | End: | |
243 | */ |