1 |
|
2 |
/* SCHEME.H */ |
3 |
|
4 |
#ifndef SCHEME_H |
5 |
# define SCHEME_H |
6 |
|
7 |
# include <stdio.h> |
8 |
|
9 |
# ifdef __cplusplus |
10 |
extern "C" |
11 |
{ |
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 |
# define USE_STRCASECMP 1 |
22 |
# ifndef USE_STRLWR |
23 |
# define USE_STRLWR 1 |
24 |
# endif |
25 |
# define SCHEME_EXPORT static |
26 |
|
27 |
# if USE_NO_FEATURES |
28 |
# define USE_MULTIPLICITY 0 |
29 |
# define USE_MATH 0 |
30 |
# define USE_CHAR_CLASSIFIERS 0 |
31 |
# define USE_ASCII_NAMES 0 |
32 |
# define USE_PORTS 1 |
33 |
# define USE_STRING_PORTS 0 |
34 |
# define USE_ERROR_HOOK 0 |
35 |
# define USE_TRACING 0 |
36 |
# define USE_COLON_HOOK 0 |
37 |
# define USE_DL 0 |
38 |
# define USE_PLIST 0 |
39 |
# define USE_FLOAT 0 |
40 |
# define USE_ERROR_CHECKING 0 |
41 |
# define USE_PRINTF 0 |
42 |
# endif |
43 |
|
44 |
/* |
45 |
* Leave it defined if you want continuations, and also for the Sharp Zaurus. |
46 |
* Undefine it if you only care about faster speed and not strict Scheme compatibility. |
47 |
*/ |
48 |
//# define USE_SCHEME_STACK |
49 |
|
50 |
# if USE_DL |
51 |
# define USE_INTERFACE 1 |
52 |
# endif |
53 |
|
54 |
# ifndef USE_MULTIPLICITY |
55 |
# define USE_MULTIPLICITY 1 |
56 |
# endif |
57 |
|
58 |
# ifndef USE_FLOAT |
59 |
# define USE_FLOAT 1 |
60 |
# endif |
61 |
|
62 |
# ifndef USE_MATH /* If math support is needed */ |
63 |
# define USE_MATH 1 |
64 |
# endif |
65 |
|
66 |
# ifndef USE_CHAR_CLASSIFIERS /* If char classifiers are needed */ |
67 |
# define USE_CHAR_CLASSIFIERS 1 |
68 |
# endif |
69 |
|
70 |
# ifndef USE_ASCII_NAMES /* If extended escaped characters are needed */ |
71 |
# define USE_ASCII_NAMES 1 |
72 |
# endif |
73 |
|
74 |
# ifndef USE_PORTS /* Enable ports */ |
75 |
# define USE_PORTS 1 |
76 |
# endif |
77 |
|
78 |
# ifndef USE_STRING_PORTS /* Enable string ports */ |
79 |
# define USE_STRING_PORTS USE_PORTS |
80 |
# endif |
81 |
|
82 |
# ifndef USE_TRACING |
83 |
# define USE_TRACING 1 |
84 |
# endif |
85 |
|
86 |
# ifndef USE_PLIST |
87 |
# define USE_PLIST 0 |
88 |
# endif |
89 |
|
90 |
/* To force system errors through user-defined error handling (see *error-hook*) */ |
91 |
# ifndef USE_ERROR_HOOK |
92 |
# define USE_ERROR_HOOK 1 |
93 |
# endif |
94 |
|
95 |
# ifndef USE_COLON_HOOK /* Enable qualified qualifier */ |
96 |
# define USE_COLON_HOOK 1 |
97 |
# endif |
98 |
|
99 |
# ifndef USE_ERROR_CHECKING |
100 |
# define USE_ERROR_CHECKING 1 |
101 |
# endif |
102 |
|
103 |
# ifndef USE_PRINTF |
104 |
# define USE_PRINTF 1 |
105 |
# endif |
106 |
|
107 |
# ifndef USE_STRLWR |
108 |
# define USE_STRLWR 1 |
109 |
# endif |
110 |
|
111 |
# ifndef INLINE |
112 |
# define INLINE inline |
113 |
# endif |
114 |
|
115 |
# ifndef SHOW_ERROR_LINE /* Show error line in file */ |
116 |
# define SHOW_ERROR_LINE 1 |
117 |
# endif |
118 |
|
119 |
# if USE_MULTIPLICITY |
120 |
# define SCHEME_V sc |
121 |
# define SCHEME_P scheme *SCHEME_V |
122 |
# define SCHEME_P_ SCHEME_P, |
123 |
# define SCHEME_A SCHEME_V |
124 |
# define SCHEME_A_ SCHEME_A, |
125 |
# else |
126 |
# define SCHEME_V (&sc) |
127 |
# define SCHEME_P |
128 |
# define SCHEME_P_ |
129 |
# define SCHEME_A |
130 |
# define SCHEME_A_ |
131 |
# endif |
132 |
|
133 |
typedef struct scheme scheme; |
134 |
typedef struct cell *pointer; |
135 |
|
136 |
typedef void *(*func_alloc) (size_t); |
137 |
typedef void (*func_dealloc) (void *); |
138 |
|
139 |
typedef long IVALUE; /* this is not used consistently yet */ |
140 |
|
141 |
# if USE_FLOAT |
142 |
typedef double RVALUE; |
143 |
# define num_is_fixnum(n) (n).is_fixnum |
144 |
# define num_set_fixnum(n,f) (n).is_fixnum = (f) |
145 |
# define num_ivalue(n) (n.is_fixnum?(n).value.ivalue:(IVALUE)(n).value.rvalue) |
146 |
# define num_rvalue(n) (!n.is_fixnum?(n).value.rvalue:(RVALUE)(n).value.ivalue) |
147 |
# define num_set_ivalue(n,i) (n).value.ivalue = (i) |
148 |
# define num_set_rvalue(n,r) (n).value.rvalue = (r) |
149 |
# else |
150 |
typedef long RVALUE; |
151 |
# define num_is_fixnum(n) 1 |
152 |
# define num_set_fixnum(n,f) 0 |
153 |
# define num_ivalue(n) (n).value.ivalue |
154 |
# define num_rvalue(n) (n).value.ivalue |
155 |
# define num_set_ivalue(n,i) (n).value.ivalue = (i) |
156 |
# define num_set_rvalue(n,r) (n).value.ivalue = (r) |
157 |
# endif |
158 |
|
159 |
/* num, for generic arithmetic */ |
160 |
typedef struct num |
161 |
{ |
162 |
union |
163 |
{ |
164 |
long ivalue; |
165 |
# if USE_FLOAT |
166 |
RVALUE rvalue; |
167 |
# endif |
168 |
} value; |
169 |
# if USE_FLOAT |
170 |
char is_fixnum; |
171 |
# endif |
172 |
} num; |
173 |
|
174 |
/* Used for documentation purposes, to signal functions in 'interface' */ |
175 |
# define INTERFACE static |
176 |
|
177 |
SCHEME_EXPORT scheme *scheme_init_new (); |
178 |
SCHEME_EXPORT int scheme_init (SCHEME_P); |
179 |
SCHEME_EXPORT void scheme_deinit (SCHEME_P); |
180 |
void scheme_set_input_port_file (SCHEME_P_ int fin); |
181 |
void scheme_set_input_port_string (SCHEME_P_ char *start, char *past_the_end); |
182 |
SCHEME_EXPORT void scheme_set_output_port_file (SCHEME_P_ int fin); |
183 |
void scheme_set_output_port_string (SCHEME_P_ char *start, char *past_the_end); |
184 |
SCHEME_EXPORT void scheme_load_file (SCHEME_P_ int fin); |
185 |
SCHEME_EXPORT void scheme_load_named_file (SCHEME_P_ int fin, const char *filename); |
186 |
SCHEME_EXPORT void scheme_load_string (SCHEME_P_ const char *cmd); |
187 |
SCHEME_EXPORT pointer scheme_apply0 (SCHEME_P_ const char *procname); |
188 |
SCHEME_EXPORT pointer scheme_call (SCHEME_P_ pointer func, pointer args); |
189 |
SCHEME_EXPORT pointer scheme_eval (SCHEME_P_ pointer obj); |
190 |
void scheme_set_external_data (SCHEME_P_ void *p); |
191 |
SCHEME_EXPORT void scheme_define (SCHEME_P_ pointer env, pointer symbol, pointer value); |
192 |
|
193 |
typedef pointer (*foreign_func) (SCHEME_P_ pointer); |
194 |
|
195 |
pointer xcons (SCHEME_P_ pointer a, pointer b, int immutable); |
196 |
INTERFACE pointer mk_integer (SCHEME_P_ long num); |
197 |
INTERFACE pointer mk_real (SCHEME_P_ RVALUE num); |
198 |
INTERFACE pointer mk_symbol (SCHEME_P_ const char *name); |
199 |
INTERFACE pointer gensym (SCHEME_P); |
200 |
INTERFACE pointer mk_string (SCHEME_P_ const char *str); |
201 |
INTERFACE pointer mk_counted_string (SCHEME_P_ const char *str, int len); |
202 |
INTERFACE pointer mk_empty_string (SCHEME_P_ int len, char fill); |
203 |
INTERFACE pointer mk_character (SCHEME_P_ int c); |
204 |
INTERFACE pointer mk_foreign_func (SCHEME_P_ foreign_func f); |
205 |
INTERFACE void putstr (SCHEME_P_ const char *s); |
206 |
INTERFACE int list_length (SCHEME_P_ pointer a); |
207 |
INTERFACE int eqv (pointer a, pointer b); |
208 |
|
209 |
# if !STANDALONE |
210 |
typedef struct scheme_registerable |
211 |
{ |
212 |
foreign_func f; |
213 |
const char *name; |
214 |
} |
215 |
scheme_registerable; |
216 |
|
217 |
void scheme_register_foreign_func_list (SCHEME_P_ scheme_registerable * list, int n); |
218 |
|
219 |
# endif /* !STANDALONE */ |
220 |
|
221 |
# ifdef __cplusplus |
222 |
} |
223 |
# endif |
224 |
|
225 |
#endif |
226 |
|
227 |
|
228 |
/* |
229 |
Local variables: |
230 |
c-file-style: "k&r" |
231 |
End: |
232 |
*/ |