1 /* SCHEME.H */
2 
3 #ifndef _SCHEME_H
4 #define _SCHEME_H
5 
6 #include <stdio.h>
7 #include <glib.h>
8 #include <glib/gstdio.h>
9 
10 #ifdef __cplusplus
11 extern "C" {
12 #endif
13 
14 /*
15  * Default values for #define'd symbols
16  */
17 #ifndef STANDALONE       /* If used as standalone interpreter */
18 # define STANDALONE 1
19 #endif
20 
21 #ifndef _MSC_VER
22 # ifndef USE_STRLWR
23 #   define USE_STRLWR 1
24 # endif
25 # define SCHEME_EXPORT extern
26 #else
27 # define USE_STRLWR 0
28 # ifdef _SCHEME_SOURCE
29 #  define SCHEME_EXPORT __declspec(dllexport)
30 # else
31 #  define SCHEME_EXPORT __declspec(dllimport)
32 # endif
33 #endif
34 
35 #if USE_NO_FEATURES
36 # define USE_MATH 0
37 # define USE_CHAR_CLASSIFIERS 0
38 # define USE_ASCII_NAMES 0
39 # define USE_STRING_PORTS 0
40 # define USE_ERROR_HOOK 0
41 # define USE_TRACING 0
42 # define USE_COLON_HOOK 0
43 # define USE_DL 0
44 # define USE_PLIST 0
45 #endif
46 
47 /*
48  * Leave it defined if you want continuations, and also for the Sharp Zaurus.
49  * Undefine it if you only care about faster speed and not strict Scheme compatibility.
50  */
51 #define USE_SCHEME_STACK
52 
53 #if USE_DL
54 # define USE_INTERFACE 1
55 #endif
56 
57 
58 #ifndef USE_MATH         /* If math support is needed */
59 # define USE_MATH 1
60 #endif
61 
62 #ifndef USE_CHAR_CLASSIFIERS  /* If char classifiers are needed */
63 # define USE_CHAR_CLASSIFIERS 1
64 #endif
65 
66 #ifndef USE_ASCII_NAMES  /* If extended escaped characters are needed */
67 # define USE_ASCII_NAMES 1
68 #endif
69 
70 #ifndef USE_STRING_PORTS      /* Enable string ports */
71 # define USE_STRING_PORTS 1
72 #endif
73 
74 #ifndef USE_TRACING
75 # define USE_TRACING 1
76 #endif
77 
78 #ifndef USE_PLIST
79 # define USE_PLIST 0
80 #endif
81 
82 /* To force system errors through user-defined error handling (see *error-hook*) */
83 #ifndef USE_ERROR_HOOK
84 # define USE_ERROR_HOOK 1
85 #endif
86 
87 #ifndef USE_COLON_HOOK   /* Enable qualified qualifier */
88 # define USE_COLON_HOOK 1
89 #endif
90 
91 #ifndef USE_STRLWR
92 # define USE_STRLWR 1
93 #endif
94 
95 #ifndef STDIO_ADDS_CR    /* Define if DOS/Windows */
96 # define STDIO_ADDS_CR 0
97 #endif
98 
99 #ifndef INLINE
100 # define INLINE
101 #endif
102 
103 #ifndef USE_INTERFACE
104 # define USE_INTERFACE 0
105 #endif
106 
107 #ifndef SHOW_ERROR_LINE   /* Show error line in file */
108 # define SHOW_ERROR_LINE 1
109 #endif
110 
111 typedef struct scheme scheme;
112 typedef struct cell *pointer;
113 
114 typedef void * (*func_alloc)(size_t);
115 typedef void (*func_dealloc)(void *);
116 
117 /* num, for generic arithmetic */
118 typedef struct num {
119      char is_fixnum;
120      union {
121           long ivalue;
122           double rvalue;
123      } value;
124 } num;
125 
126 #if !STANDALONE
127 
128 typedef enum { TS_OUTPUT_NORMAL, TS_OUTPUT_ERROR } TsOutputType;
129 
130 typedef void (* ts_output_func)       (TsOutputType    type,
131                                        const char     *string,
132                                        int             len,
133                                        gpointer        data);
134 
135 SCHEME_EXPORT void ts_register_output_func (ts_output_func  func,
136                                             gpointer        user_data);
137 SCHEME_EXPORT void ts_output_string        (TsOutputType    type,
138                                             const char     *string,
139                                             int             len);
140 #endif
141 
142 SCHEME_EXPORT scheme *scheme_init_new(void);
143 SCHEME_EXPORT scheme *scheme_init_new_custom_alloc(func_alloc malloc, func_dealloc free);
144 SCHEME_EXPORT int scheme_init(scheme *sc);
145 SCHEME_EXPORT int scheme_init_custom_alloc(scheme *sc, func_alloc, func_dealloc);
146 SCHEME_EXPORT void scheme_deinit(scheme *sc);
147 SCHEME_EXPORT void scheme_set_input_port_file(scheme *sc, FILE *fin);
148 void scheme_set_input_port_string(scheme *sc, char *start, char *past_the_end);
149 SCHEME_EXPORT void scheme_set_output_port_file(scheme *sc, FILE *fin);
150 void scheme_set_output_port_string(scheme *sc, char *start, char *past_the_end);
151 SCHEME_EXPORT void scheme_load_file(scheme *sc, FILE *fin);
152 SCHEME_EXPORT void scheme_load_named_file(scheme *sc, FILE *fin, const char *filename);
153 SCHEME_EXPORT void scheme_load_string(scheme *sc, const char *cmd);
154 SCHEME_EXPORT pointer scheme_apply0(scheme *sc, const char *procname);
155 SCHEME_EXPORT pointer scheme_call(scheme *sc, pointer func, pointer args);
156 SCHEME_EXPORT pointer scheme_eval(scheme *sc, pointer obj);
157 void scheme_set_external_data(scheme *sc, void *p);
158 SCHEME_EXPORT void scheme_define(scheme *sc, pointer env, pointer symbol, pointer value);
159 
160 typedef pointer (*foreign_func)(scheme *, pointer);
161 
162 pointer _cons(scheme *sc, pointer a, pointer b, int immutable);
163 pointer mk_integer(scheme *sc, long num);
164 pointer mk_real(scheme *sc, double num);
165 pointer mk_symbol(scheme *sc, const char *name);
166 pointer gensym(scheme *sc);
167 pointer mk_string(scheme *sc, const char *str);
168 pointer mk_counted_string(scheme *sc, const char *str, int len);
169 pointer mk_empty_string(scheme *sc, int len, gunichar fill);
170 pointer mk_character(scheme *sc, gunichar c);
171 pointer mk_foreign_func(scheme *sc, foreign_func f);
172 void    putcharacter(scheme *sc, gunichar c);
173 void    putstr(scheme *sc, const char *s);
174 int list_length(scheme *sc, pointer a);
175 int eqv(pointer a, pointer b);
176 
177 SCHEME_EXPORT pointer foreign_error (scheme *sc, const char *s, pointer a);
178 
179 #if USE_INTERFACE
180 struct scheme_interface {
181   void (*scheme_define)(scheme *sc, pointer env, pointer symbol, pointer value);
182   pointer (*cons)(scheme *sc, pointer a, pointer b);
183   pointer (*immutable_cons)(scheme *sc, pointer a, pointer b);
184   pointer (*reserve_cells)(scheme *sc, int n);
185   pointer (*mk_integer)(scheme *sc, long num);
186   pointer (*mk_real)(scheme *sc, double num);
187   pointer (*mk_symbol)(scheme *sc, const char *name);
188   pointer (*gensym)(scheme *sc);
189   pointer (*mk_string)(scheme *sc, const char *str);
190   pointer (*mk_counted_string)(scheme *sc, const char *str, int len);
191   pointer (*mk_character)(scheme *sc, gunichar c);
192   pointer (*mk_vector)(scheme *sc, int len);
193   pointer (*mk_foreign_func)(scheme *sc, foreign_func f);
194   pointer (*mk_closure)(scheme *sc, pointer c, pointer e);
195   void (*putstr)(scheme *sc, const char *s);
196   void (*putcharacter)(scheme *sc, gunichar c);
197 
198   int (*is_string)(pointer p);
199   int (*string_length)(pointer p);
200   char *(*string_value)(pointer p);
201   int (*is_number)(pointer p);
202   num (*nvalue)(pointer p);
203   long (*ivalue)(pointer p);
204   double (*rvalue)(pointer p);
205   int (*is_integer)(pointer p);
206   int (*is_real)(pointer p);
207   int (*is_character)(pointer p);
208   gunichar (*charvalue)(pointer p);
209   int (*is_list)(scheme *sc, pointer p);
210   int (*is_vector)(pointer p);
211   int (*list_length)(scheme *sc, pointer p);
212   long (*vector_length)(pointer vec);
213   void (*fill_vector)(pointer vec, pointer elem);
214   pointer (*vector_elem)(pointer vec, int ielem);
215   pointer (*set_vector_elem)(pointer vec, int ielem, pointer newel);
216 
217   int (*is_port)(pointer p);
218 
219   int (*is_pair)(pointer p);
220   pointer (*pair_car)(pointer p);
221   pointer (*pair_cdr)(pointer p);
222   pointer (*set_car)(pointer p, pointer q);
223   pointer (*set_cdr)(pointer p, pointer q);
224 
225   int (*is_symbol)(pointer p);
226   char *(*symname)(pointer p);
227 
228   int (*is_syntax)(pointer p);
229   int (*is_proc)(pointer p);
230   int (*is_foreign)(pointer p);
231   char *(*syntaxname)(pointer p);
232   int (*is_closure)(pointer p);
233   int (*is_macro)(pointer p);
234   pointer (*closure_code)(pointer p);
235   pointer (*closure_env)(pointer p);
236 
237   int (*is_continuation)(pointer p);
238   int (*is_promise)(pointer p);
239   int (*is_environment)(pointer p);
240   int (*is_immutable)(pointer p);
241   void (*setimmutable)(pointer p);
242 
243   void (*load_file)(scheme *sc, FILE *fin);
244   void (*load_string)(scheme *sc, const char *input);
245 };
246 #endif
247 
248 #if !STANDALONE
249 typedef struct scheme_registerable
250 {
251   foreign_func  f;
252   const char *  name;
253 }
254 scheme_registerable;
255 
256 void scheme_register_foreign_func(scheme * sc, scheme_registerable * sr);
257 void scheme_register_foreign_func_list(scheme * sc,
258                                       scheme_registerable * list,
259                                       int n);
260 
261 #endif /* !STANDALONE */
262 
263 #ifdef __cplusplus
264 }
265 #endif
266 
267 #endif
268 
269 /*
270 Local variables:
271 c-file-style: "k&r"
272 End:
273 */
274