|
|
1 | /* |
|
|
2 | * µscheme |
|
|
3 | * |
|
|
4 | * Copyright (C) 2015 Marc Alexander Lehmann <uscheme@schmorp.de> |
|
|
5 | * do as you want with this, attribution appreciated. |
|
|
6 | */ |
1 | |
7 | |
2 | /* SCHEME.H */ |
8 | /* SCHEME.H */ |
3 | |
9 | |
4 | #ifndef SCHEME_H |
10 | #ifndef SCHEME_H |
5 | #define SCHEME_H |
11 | #define SCHEME_H |
… | |
… | |
35 | # define USE_ERROR_HOOK 0 |
41 | # define USE_ERROR_HOOK 0 |
36 | # define USE_TRACING 0 |
42 | # define USE_TRACING 0 |
37 | # define USE_COLON_HOOK 0 |
43 | # define USE_COLON_HOOK 0 |
38 | # define USE_DL 0 |
44 | # define USE_DL 0 |
39 | # define USE_PLIST 0 |
45 | # define USE_PLIST 0 |
40 | # define USE_FLOAT 0 |
46 | # define USE_REAL 0 |
41 | # define USE_ERROR_CHECKING 0 |
47 | # define USE_ERROR_CHECKING 0 |
42 | # define USE_PRINTF 0 |
48 | # define USE_PRINTF 0 |
43 | #endif |
49 | #endif |
44 | |
50 | |
45 | /* |
51 | /* |
… | |
… | |
50 | |
56 | |
51 | #ifndef USE_MULTIPLICITY |
57 | #ifndef USE_MULTIPLICITY |
52 | # define USE_MULTIPLICITY 1 |
58 | # define USE_MULTIPLICITY 1 |
53 | #endif |
59 | #endif |
54 | |
60 | |
55 | #ifndef USE_FLOAT |
61 | #ifndef USE_REAL |
56 | # define USE_FLOAT 1 |
62 | # define USE_REAL 1 |
57 | #endif |
63 | #endif |
58 | |
64 | |
59 | #ifndef USE_MATH /* If math support is needed */ |
65 | #ifndef USE_MATH /* If math support is needed */ |
60 | # define USE_MATH 1 |
66 | # define USE_MATH 1 |
61 | #endif |
67 | #endif |
… | |
… | |
125 | # define SCHEME_P_ |
131 | # define SCHEME_P_ |
126 | # define SCHEME_A |
132 | # define SCHEME_A |
127 | # define SCHEME_A_ |
133 | # define SCHEME_A_ |
128 | #endif |
134 | #endif |
129 | |
135 | |
130 | typedef struct scheme scheme; |
136 | typedef struct scheme scheme; |
131 | typedef struct cell *pointer; |
137 | typedef struct cell *pointer; |
132 | |
138 | |
133 | typedef void *(*func_alloc) (size_t); |
139 | typedef void *(*func_alloc) (size_t); |
134 | typedef void (*func_dealloc) (void *); |
140 | typedef void (*func_dealloc) (void *); |
135 | |
141 | |
136 | typedef long IVALUE; /* this is not used consistently yet */ |
142 | typedef long IVALUE; /* this is not used consistently yet */ |
137 | |
143 | |
138 | #if USE_FLOAT |
144 | #if USE_REAL |
139 | typedef double RVALUE; |
145 | typedef double RVALUE; |
140 | # define num_is_fixnum(n) (n).is_fixnum |
146 | # define num_is_fixnum(n) (n).is_fixnum |
141 | # define num_set_fixnum(n,f) (n).is_fixnum = (f) |
147 | # define num_set_fixnum(n,f) (n).is_fixnum = (f) |
142 | # define num_ivalue(n) (n).value.ivalue |
148 | # define num_ivalue(n) (n).value.ivalue |
143 | # define num_rvalue(n) (n).value.rvalue |
149 | # define num_rvalue(n) (n).value.rvalue |
144 | # define num_set_ivalue(n,i) (n).value.ivalue = (i) |
150 | # define num_set_ivalue(n,i) (n).value.ivalue = (i) |
145 | # define num_set_rvalue(n,r) (n).value.rvalue = (r) |
151 | # define num_set_rvalue(n,r) (n).value.rvalue = (r) |
146 | #else |
152 | #else |
147 | typedef long RVALUE; |
153 | typedef long RVALUE; |
148 | # define num_is_fixnum(n) 1 |
154 | # define num_is_fixnum(n) 1 |
149 | # define num_set_fixnum(n,f) 0 |
155 | # define num_set_fixnum(n,f) 0 |
150 | # define num_ivalue(n) (n).value.ivalue |
156 | # define num_ivalue(n) (n).value.ivalue |
151 | # define num_rvalue(n) (n).value.ivalue |
157 | # define num_rvalue(n) (n).value.ivalue |
152 | # define num_set_ivalue(n,i) (n).value.ivalue = (i) |
158 | # define num_set_ivalue(n,i) (n).value.ivalue = (i) |
153 | # define num_set_rvalue(n,r) (n).value.ivalue = (r) |
159 | # define num_set_rvalue(n,r) (n).value.ivalue = (r) |
154 | #endif |
160 | #endif |
155 | |
161 | |
156 | /* num, for generic arithmetic */ |
162 | /* num, for generic arithmetic */ |
157 | typedef struct num |
163 | typedef struct num |
|
|
164 | { |
|
|
165 | union |
158 | { |
166 | { |
159 | union |
167 | IVALUE ivalue; |
160 | { |
168 | #if USE_REAL |
161 | long ivalue; |
|
|
162 | #if USE_FLOAT |
|
|
163 | RVALUE rvalue; |
169 | RVALUE rvalue; |
164 | #endif |
170 | #endif |
165 | } value; |
171 | } value; |
166 | #if USE_FLOAT |
172 | #if USE_REAL |
167 | char is_fixnum; |
173 | char is_fixnum; |
168 | #endif |
174 | #endif |
169 | } num; |
175 | } num; |
170 | |
176 | |
171 | /* Used for documentation purposes, to signal functions in 'interface' */ |
177 | /* Used for documentation purposes, to signal functions in 'interface' */ |
172 | #define INTERFACE static |
178 | #define INTERFACE static |
173 | |
179 | |
174 | SCHEME_EXPORT scheme *scheme_init_new (); |
180 | SCHEME_EXPORT scheme *scheme_init_new (); |
175 | SCHEME_EXPORT int scheme_init (SCHEME_P); |
181 | SCHEME_EXPORT int scheme_init (SCHEME_P); |
176 | SCHEME_EXPORT void scheme_deinit (SCHEME_P); |
182 | SCHEME_EXPORT void scheme_deinit (SCHEME_P); |
177 | void scheme_set_input_port_file (SCHEME_P_ int fin); |
183 | 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); |
184 | 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); |
185 | 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); |
186 | 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); |
187 | 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); |
188 | 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); |
189 | SCHEME_EXPORT void scheme_load_string (SCHEME_P_ const char *cmd); |
184 | SCHEME_EXPORT pointer scheme_apply0 (SCHEME_P_ const char *procname); |
190 | SCHEME_EXPORT pointer scheme_apply0 (SCHEME_P_ const char *procname); |
185 | SCHEME_EXPORT pointer scheme_call (SCHEME_P_ pointer func, pointer args); |
191 | SCHEME_EXPORT pointer scheme_call (SCHEME_P_ pointer func, pointer args); |
186 | SCHEME_EXPORT pointer scheme_eval (SCHEME_P_ pointer obj); |
192 | SCHEME_EXPORT pointer scheme_eval (SCHEME_P_ pointer obj); |
187 | void scheme_set_external_data (SCHEME_P_ void *p); |
193 | void scheme_set_external_data (SCHEME_P_ void *p); |
188 | SCHEME_EXPORT void scheme_define (SCHEME_P_ pointer env, pointer symbol, pointer value); |
194 | SCHEME_EXPORT void scheme_define (SCHEME_P_ pointer env, pointer symbol, pointer value); |
189 | |
195 | |
190 | typedef pointer (*foreign_func) (SCHEME_P_ pointer); |
196 | typedef pointer (*foreign_func) (SCHEME_P_ pointer); |
191 | |
197 | |
192 | pointer xcons (SCHEME_P_ pointer a, pointer b, int immutable); |
198 | pointer xcons (SCHEME_P_ pointer a, pointer b, int immutable); |
193 | INTERFACE pointer mk_integer (SCHEME_P_ long num); |
199 | INTERFACE pointer mk_integer (SCHEME_P_ long num); |
194 | INTERFACE pointer mk_real (SCHEME_P_ RVALUE num); |
200 | INTERFACE pointer mk_real (SCHEME_P_ RVALUE num); |
195 | INTERFACE pointer mk_symbol (SCHEME_P_ const char *name); |
201 | INTERFACE pointer mk_symbol (SCHEME_P_ const char *name); |
196 | INTERFACE pointer gensym (SCHEME_P); |
202 | INTERFACE pointer gensym (SCHEME_P); |
197 | INTERFACE pointer mk_string (SCHEME_P_ const char *str); |
203 | INTERFACE pointer mk_string (SCHEME_P_ const char *str); |
198 | INTERFACE pointer mk_counted_string (SCHEME_P_ const char *str, uint32_t len); |
204 | 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); |
205 | INTERFACE pointer mk_empty_string (SCHEME_P_ uint32_t len, char fill); |
200 | INTERFACE pointer mk_character (SCHEME_P_ int c); |
206 | INTERFACE pointer mk_character (SCHEME_P_ int c); |
201 | INTERFACE pointer mk_foreign_func (SCHEME_P_ foreign_func f); |
207 | INTERFACE pointer mk_foreign_func (SCHEME_P_ foreign_func f); |
202 | INTERFACE void putstr (SCHEME_P_ const char *s); |
208 | INTERFACE void putstr (SCHEME_P_ const char *s); |
203 | INTERFACE int list_length (SCHEME_P_ pointer a); |
209 | INTERFACE int list_length (SCHEME_P_ pointer a); |
204 | INTERFACE int eqv (pointer a, pointer b); |
210 | INTERFACE int eqv (pointer a, pointer b); |
205 | |
211 | |
206 | #if !STANDALONE |
212 | #if !STANDALONE |
207 | typedef struct scheme_registerable |
213 | typedef struct scheme_registerable |
208 | { |
214 | { |
209 | foreign_func f; |
215 | foreign_func f; |
210 | const char *name; |
216 | const char *name; |
211 | } |
|
|
212 | scheme_registerable; |
217 | } scheme_registerable; |
213 | |
218 | |
214 | void scheme_register_foreign_func_list (SCHEME_P_ scheme_registerable * list, int n); |
219 | void scheme_register_foreign_func_list (SCHEME_P_ scheme_registerable * list, int n); |
215 | |
|
|
216 | #endif /* !STANDALONE */ |
220 | #endif /* !STANDALONE */ |
217 | |
221 | |
218 | #ifdef __cplusplus |
222 | #ifdef __cplusplus |
219 | } |
223 | } |
220 | #endif |
224 | #endif |