ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/microscheme/scheme.h
Revision: 1.5
Committed: Wed Nov 25 22:12:59 2015 UTC (8 years, 6 months ago) by root
Content type: text/plain
Branch: MAIN
Changes since 1.4: +65 -61 lines
Log Message:
*** empty log message ***

File Contents

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