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