* scheme-io.texi: Removed obsolete section Binary IO. Added
[bpt/guile.git] / libguile / gh.h
CommitLineData
80dee77b 1/* Copyright (C) 1995,1996,1997,1998,2000,2001 Free Software Foundation, Inc.
ee2a8b9b
JB
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
82892bed
JB
15 * the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
16 * Boston, MA 02111-1307 USA
ee2a8b9b
JB
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.
82892bed 40 * If you do not wish that, delete this exception notice. */
ee2a8b9b
JB
41\f
42
43#ifndef __GH_H
44#define __GH_H
45
18daf95b
AG
46#ifdef __cplusplus
47extern "C" {
48#endif
49
ee2a8b9b
JB
50#include <libguile.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
47d0411b 61void gh_enter(int argc, char *argv[], void (*c_main_prog)(int, char **));
5aadf8c1 62void gh_repl(int argc, char *argv[]);
ee2a8b9b
JB
63SCM gh_catch(SCM tag, scm_catch_body_t body, void *body_data,
64 scm_catch_handler_t handler, void *handler_data);
65
ee2a8b9b 66SCM gh_standard_handler(void *data, SCM tag, SCM throw_args);
ee2a8b9b 67
6e706938
GB
68SCM gh_eval_str(const char *scheme_code);
69SCM gh_eval_str_with_catch(const char *scheme_code, scm_catch_handler_t handler);
70SCM gh_eval_str_with_standard_handler(const char *scheme_code);
71SCM gh_eval_str_with_stack_saving_handler(const char *scheme_code);
ee2a8b9b 72
6e706938 73SCM gh_eval_file(const char *fname);
e5eece74 74#define gh_load(fname) gh_eval_file(fname)
6e706938
GB
75SCM gh_eval_file_with_catch(const char *scheme_code, scm_catch_handler_t handler);
76SCM gh_eval_file_with_standard_handler(const char *scheme_code);
ee2a8b9b
JB
77
78#define gh_defer_ints() SCM_DEFER_INTS
79#define gh_allow_ints() SCM_ALLOW_INTS
80
bcee10dd 81SCM gh_new_procedure(const char *proc_name, SCM (*fn)(),
ee2a8b9b 82 int n_required_args, int n_optional_args, int varp);
bcee10dd
DH
83SCM gh_new_procedure0_0(const char *proc_name, SCM (*fn)(void));
84SCM gh_new_procedure0_1(const char *proc_name, SCM (*fn)(SCM));
85SCM gh_new_procedure0_2(const char *proc_name, SCM (*fn)(SCM, SCM));
86SCM gh_new_procedure1_0(const char *proc_name, SCM (*fn)(SCM));
87SCM gh_new_procedure1_1(const char *proc_name, SCM (*fn)(SCM, SCM));
88SCM gh_new_procedure1_2(const char *proc_name, SCM (*fn)(SCM, SCM, SCM));
89SCM gh_new_procedure2_0(const char *proc_name, SCM (*fn)(SCM, SCM));
90SCM gh_new_procedure2_1(const char *proc_name, SCM (*fn)(SCM, SCM, SCM));
91SCM gh_new_procedure2_2(const char *proc_name, SCM (*fn)(SCM, SCM, SCM, SCM));
92SCM gh_new_procedure3_0(const char *proc_name, SCM (*fn)(SCM, SCM, SCM));
93SCM gh_new_procedure4_0(const char *proc_name, SCM (*fn)(SCM, SCM, SCM, SCM));
94SCM gh_new_procedure5_0(const char *proc_name, SCM (*fn)(SCM, SCM, SCM, SCM, SCM));
ee2a8b9b
JB
95
96/* C to Scheme conversion */
97SCM gh_bool2scm(int x);
98SCM gh_int2scm(int x);
99SCM gh_ulong2scm(unsigned long x);
100SCM gh_long2scm(long x);
101SCM gh_double2scm(double x);
102SCM gh_char2scm(char c);
70d63753 103SCM gh_str2scm(const char *s, int len);
6e706938 104SCM gh_str02scm(const char *s);
ee2a8b9b 105void gh_set_substr(char *src, SCM dst, int start, int len);
4921140c 106SCM gh_symbol2scm(const char *symbol_str);
80dee77b 107SCM gh_ints2scm(const int *d, int n);
afe5177e
GH
108
109#ifdef HAVE_ARRAYS
bcee10dd
DH
110SCM gh_chars2byvect(const char *d, int n);
111SCM gh_shorts2svect(const short *d, int n);
112SCM gh_longs2ivect(const long *d, int n);
113SCM gh_ulongs2uvect(const unsigned long *d, int n);
114SCM gh_floats2fvect(const float *d, int n);
115SCM gh_doubles2dvect(const double *d, int n);
f3a2c4cf 116#endif
ee2a8b9b 117
bcee10dd 118SCM gh_doubles2scm(const double *d, int n);
ee2a8b9b
JB
119
120/* Scheme to C conversion */
121int gh_scm2bool(SCM obj);
122int gh_scm2int(SCM obj);
123unsigned long gh_scm2ulong(SCM obj);
124long gh_scm2long(SCM obj);
125char gh_scm2char(SCM obj);
126double gh_scm2double(SCM obj);
127char *gh_scm2newstr(SCM str, int *lenp);
128void gh_get_substr(SCM src, char *dst, int start, int len);
129char *gh_symbol2newstr(SCM sym, int *lenp);
3ffc7a36
MD
130char *gh_scm2chars(SCM vector, char *result);
131short *gh_scm2shorts(SCM vector, short *result);
132long *gh_scm2longs(SCM vector, long *result);
133float *gh_scm2floats(SCM vector, float *result);
134double *gh_scm2doubles(SCM vector, double *result);
ee2a8b9b
JB
135
136/* type predicates: tell you if an SCM object has a given type */
137int gh_boolean_p(SCM val);
138int gh_symbol_p(SCM val);
139int gh_char_p(SCM val);
140int gh_vector_p(SCM val);
141int gh_pair_p(SCM val);
142int gh_number_p(SCM val);
143int gh_string_p(SCM val);
144int gh_procedure_p(SCM val);
145int gh_list_p(SCM val);
146int gh_inexact_p(SCM val);
147int gh_exact_p(SCM val);
148
149/* more predicates */
150int gh_eq_p(SCM x, SCM y);
151int gh_eqv_p(SCM x, SCM y);
152int gh_equal_p(SCM x, SCM y);
7fee59bd
MG
153int gh_string_equal_p(SCM s1, SCM s2);
154int gh_null_p(SCM l);
ee2a8b9b
JB
155
156/* standard Scheme procedures available from C */
157
7fee59bd
MG
158#define gh_not(x) scm_not(x)
159
bcee10dd 160SCM gh_define(const char *name, SCM val);
ee2a8b9b 161
e5eece74
MG
162/* vector manipulation routines */
163/* note that gh_vector() does not behave quite like the Scheme (vector
164 obj1 obj2 ...), because the interpreter engine does not pass the
165 data element by element, but rather as a list. thus, gh_vector()
166 ends up being identical to gh_list_to_vector() */
167#define gh_vector(ls) scm_vector(ls)
168SCM gh_make_vector(SCM length, SCM val);
956328d2 169SCM gh_vector_set_x(SCM vec, SCM pos, SCM val);
e5eece74 170SCM gh_vector_ref(SCM vec, SCM pos);
88040021
JB
171unsigned long gh_vector_length (SCM v);
172unsigned long gh_uniform_vector_length (SCM v);
173SCM gh_uniform_vector_ref (SCM v, SCM ilist);
e5eece74 174#define gh_list_to_vector(ls) scm_vector(ls)
c56f8119 175#define gh_vector_to_list(v) scm_vector_to_list(v)
ee2a8b9b 176
bcee10dd
DH
177SCM gh_lookup (const char *sname);
178SCM gh_module_lookup (SCM vector, const char *sname);
35379308 179
ee2a8b9b
JB
180SCM gh_cons(SCM x, SCM y);
181#define gh_list scm_listify
92396c0a 182unsigned long gh_length(SCM l);
7fee59bd
MG
183SCM gh_append(SCM args);
184SCM gh_append2(SCM l1, SCM l2);
185SCM gh_append3(SCM l1, SCM l2, SCM l3);
186SCM gh_append4(SCM l1, SCM l2, SCM l3, SCM l4);
187#define gh_reverse(ls) scm_reverse(ls)
188#define gh_list_tail(ls, k) scm_list_tail(ls, k)
189#define gh_list_ref(ls, k) scm_list_ref(ls, k)
190#define gh_memq(x, ls) scm_memq(x, ls)
38d0f691
MD
191#define gh_memv(x, ls) scm_memv(x, ls)
192#define gh_member(x, ls) scm_member(x, ls)
7fee59bd
MG
193#define gh_assq(x, alist) scm_assq(x, alist)
194#define gh_assv(x, alist) scm_assv(x, alist)
195#define gh_assoc(x, alist) scm_assoc(x, alist)
ee2a8b9b
JB
196
197SCM gh_car(SCM x);
198SCM gh_cdr(SCM x);
199
200SCM gh_caar(SCM x);
201SCM gh_cadr(SCM x);
202SCM gh_cdar(SCM x);
203SCM gh_cddr(SCM x);
204
205SCM gh_caaar(SCM x);
206SCM gh_caadr(SCM x);
207SCM gh_cadar(SCM x);
208SCM gh_caddr(SCM x);
209SCM gh_cdaar(SCM x);
210SCM gh_cdadr(SCM x);
211SCM gh_cddar(SCM x);
212SCM gh_cdddr(SCM x);
213
7fee59bd
MG
214SCM gh_set_car_x(SCM pair, SCM value);
215SCM gh_set_cdr_x(SCM pair, SCM value);
216
217
ee2a8b9b
JB
218/* Calling Scheme functions from C. */
219SCM gh_apply (SCM proc, SCM ls);
220SCM gh_call0 (SCM proc);
221SCM gh_call1 (SCM proc, SCM arg);
222SCM gh_call2 (SCM proc, SCM arg1, SCM arg2);
223SCM gh_call3 (SCM proc, SCM arg1, SCM arg2, SCM arg3);
224
225/* reading and writing Scheme objects. */
226void gh_display (SCM x);
38d0f691 227void gh_write (SCM x);
ee2a8b9b
JB
228void gh_newline (void);
229
230/* void gh_gc_mark(SCM) : mark an SCM as in use. */
231/* void gh_defer_ints() : don't interrupt code section. */
232/* void gh_allow_ints() : see gh_defer_ints(). */
233/* void gh_new_cell(SCM, int tag) : initialize SCM to be of type 'tag' */
234/* int gh_type_p(SCM, tag) : test if SCM is of type 'tag' */
235/* SCM gh_intern(char*) : get symbol corresponding to c-string.*/
236/* void gh_set_ext_data(SCM, void*) : set extension data on SCM */
237/* void *gh_get_ext_data(SCM) : return extension data from SCM. */
238
239/* void gh_assert(int cond, char *msg, SCM obj); */
240
18daf95b
AG
241#ifdef __cplusplus
242}
243#endif
ee2a8b9b
JB
244
245#endif /* __GH_H */
89e00824
ML
246
247/*
248 Local Variables:
249 c-file-style: "gnu"
250 End:
251*/