1 |
root |
1.5 |
/* |
2 |
|
|
* µscheme |
3 |
|
|
* |
4 |
|
|
* Copyright (C) 2015 Marc Alexander Lehmann <uscheme@schmorp.de> |
5 |
|
|
* do as you want with this, attribution appreciated. |
6 |
|
|
*/ |
7 |
root |
1.1 |
|
8 |
|
|
/* SCHEME.H */ |
9 |
|
|
|
10 |
|
|
#ifndef SCHEME_H |
11 |
root |
1.2 |
#define SCHEME_H |
12 |
root |
1.1 |
|
13 |
root |
1.3 |
#include <inttypes.h> |
14 |
root |
1.2 |
#include <stdio.h> |
15 |
root |
1.1 |
|
16 |
root |
1.2 |
#ifdef __cplusplus |
17 |
root |
1.1 |
extern "C" |
18 |
|
|
{ |
19 |
root |
1.2 |
#endif |
20 |
root |
1.1 |
|
21 |
|
|
/* |
22 |
|
|
* Default values for #define'd symbols |
23 |
|
|
*/ |
24 |
root |
1.2 |
#ifndef STANDALONE /* If used as standalone interpreter */ |
25 |
|
|
# define STANDALONE 1 |
26 |
|
|
#endif |
27 |
|
|
|
28 |
|
|
#define SCHEME_EXPORT static |
29 |
|
|
|
30 |
|
|
#if USE_NO_FEATURES |
31 |
|
|
# define USE_MULTIPLICITY 0 |
32 |
|
|
# define USE_MATH 0 |
33 |
|
|
# define USE_CHAR_CLASSIFIERS 0 |
34 |
|
|
# define USE_ASCII_NAMES 0 |
35 |
|
|
# define USE_PORTS 1 |
36 |
|
|
# define USE_STRING_PORTS 0 |
37 |
|
|
# define USE_ERROR_HOOK 0 |
38 |
|
|
# define USE_TRACING 0 |
39 |
|
|
# define USE_COLON_HOOK 0 |
40 |
|
|
# define USE_DL 0 |
41 |
|
|
# define USE_PLIST 0 |
42 |
root |
1.5 |
# define USE_REAL 0 |
43 |
root |
1.2 |
# define USE_ERROR_CHECKING 0 |
44 |
|
|
# define USE_PRINTF 0 |
45 |
root |
1.9 |
# define USE_INTCACHE 0 |
46 |
root |
1.2 |
#endif |
47 |
root |
1.1 |
|
48 |
|
|
/* |
49 |
root |
1.4 |
* Define: much slower, but somewhat smaller evaluation stack implemention, use more memory |
50 |
|
|
* Undefined: faster, somewhat bigger implementation, uses less memory at runtime |
51 |
root |
1.1 |
*/ |
52 |
root |
1.4 |
/*#define USE_SCHEME_STACK*/ |
53 |
root |
1.2 |
|
54 |
|
|
#ifndef USE_MULTIPLICITY |
55 |
|
|
# define USE_MULTIPLICITY 1 |
56 |
|
|
#endif |
57 |
|
|
|
58 |
root |
1.5 |
#ifndef USE_REAL |
59 |
|
|
# define USE_REAL 1 |
60 |
root |
1.2 |
#endif |
61 |
root |
1.1 |
|
62 |
root |
1.2 |
#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 |
root |
1.8 |
# define USE_PLIST 1 |
88 |
root |
1.2 |
#endif |
89 |
root |
1.1 |
|
90 |
|
|
/* To force system errors through user-defined error handling (see *error-hook*) */ |
91 |
root |
1.2 |
#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 |
root |
1.6 |
#ifndef USE_IGNORECASE |
108 |
|
|
# define USE_IGNORECASE 1 |
109 |
root |
1.2 |
#endif |
110 |
|
|
|
111 |
root |
1.9 |
#ifndef USE_INTCACHE |
112 |
|
|
# define USE_INTCACHE 1 |
113 |
|
|
#endif |
114 |
|
|
|
115 |
root |
1.12 |
#ifndef USE_SYSTEM_MALLOC |
116 |
|
|
# define USE_SYSTEM_MALLOC 1 |
117 |
|
|
#endif |
118 |
|
|
|
119 |
root |
1.6 |
#ifndef SHOW_ERROR_LINE /* Show error line in file */ |
120 |
|
|
# define SHOW_ERROR_LINE 1 |
121 |
root |
1.2 |
#endif |
122 |
|
|
|
123 |
root |
1.6 |
#if !USE_REAL |
124 |
|
|
# undef USE_MATH |
125 |
|
|
# define USE_MATH 0 |
126 |
root |
1.2 |
#endif |
127 |
|
|
|
128 |
root |
1.8 |
/* property lists currently broken to to symbol change*/ |
129 |
|
|
#undef USE_PLIST |
130 |
|
|
#define USE_PLIST 0 |
131 |
|
|
|
132 |
root |
1.2 |
#if USE_MULTIPLICITY |
133 |
|
|
# define SCHEME_V sc |
134 |
|
|
# define SCHEME_P scheme *SCHEME_V |
135 |
|
|
# define SCHEME_P_ SCHEME_P, |
136 |
|
|
# define SCHEME_A SCHEME_V |
137 |
|
|
# define SCHEME_A_ SCHEME_A, |
138 |
|
|
#else |
139 |
|
|
# define SCHEME_V (&sc) |
140 |
|
|
# define SCHEME_P |
141 |
|
|
# define SCHEME_P_ |
142 |
|
|
# define SCHEME_A |
143 |
|
|
# define SCHEME_A_ |
144 |
|
|
#endif |
145 |
root |
1.1 |
|
146 |
root |
1.5 |
typedef struct scheme scheme; |
147 |
root |
1.11 |
//typedef void *pointer; |
148 |
|
|
typedef struct cell *pointer; // for debugging, slightly worse code, surprisingly |
149 |
root |
1.1 |
|
150 |
root |
1.5 |
typedef long IVALUE; /* this is not used consistently yet */ |
151 |
|
|
#if USE_REAL |
152 |
|
|
typedef double RVALUE; |
153 |
root |
1.2 |
#else |
154 |
root |
1.11 |
typedef IVALUE RVALUE; |
155 |
root |
1.2 |
#endif |
156 |
root |
1.1 |
|
157 |
|
|
/* Used for documentation purposes, to signal functions in 'interface' */ |
158 |
root |
1.2 |
#define INTERFACE static |
159 |
root |
1.1 |
|
160 |
root |
1.5 |
SCHEME_EXPORT scheme *scheme_init_new (); |
161 |
|
|
SCHEME_EXPORT int scheme_init (SCHEME_P); |
162 |
|
|
SCHEME_EXPORT void scheme_deinit (SCHEME_P); |
163 |
|
|
void scheme_set_input_port_file (SCHEME_P_ int fin); |
164 |
|
|
void scheme_set_input_port_string (SCHEME_P_ char *start, char *past_the_end); |
165 |
|
|
SCHEME_EXPORT void scheme_set_output_port_file (SCHEME_P_ int fin); |
166 |
|
|
void scheme_set_output_port_string (SCHEME_P_ char *start, char *past_the_end); |
167 |
|
|
SCHEME_EXPORT void scheme_load_file (SCHEME_P_ int fin); |
168 |
|
|
SCHEME_EXPORT void scheme_load_named_file (SCHEME_P_ int fin, const char *filename); |
169 |
|
|
SCHEME_EXPORT void scheme_load_string (SCHEME_P_ const char *cmd); |
170 |
|
|
SCHEME_EXPORT pointer scheme_apply0 (SCHEME_P_ const char *procname); |
171 |
|
|
SCHEME_EXPORT pointer scheme_call (SCHEME_P_ pointer func, pointer args); |
172 |
|
|
SCHEME_EXPORT pointer scheme_eval (SCHEME_P_ pointer obj); |
173 |
|
|
void scheme_set_external_data (SCHEME_P_ void *p); |
174 |
|
|
SCHEME_EXPORT void scheme_define (SCHEME_P_ pointer env, pointer symbol, pointer value); |
175 |
|
|
|
176 |
|
|
typedef pointer (*foreign_func) (SCHEME_P_ pointer); |
177 |
|
|
|
178 |
root |
1.12 |
//pointer xcons (SCHEME_P_ pointer a, pointer b); |
179 |
root |
1.7 |
INTERFACE pointer mk_integer (SCHEME_P_ IVALUE n); |
180 |
|
|
INTERFACE pointer mk_real (SCHEME_P_ RVALUE n); |
181 |
root |
1.5 |
INTERFACE pointer mk_symbol (SCHEME_P_ const char *name); |
182 |
|
|
INTERFACE pointer gensym (SCHEME_P); |
183 |
|
|
INTERFACE pointer mk_string (SCHEME_P_ const char *str); |
184 |
|
|
INTERFACE pointer mk_counted_string (SCHEME_P_ const char *str, uint32_t len); |
185 |
|
|
INTERFACE pointer mk_empty_string (SCHEME_P_ uint32_t len, char fill); |
186 |
|
|
INTERFACE pointer mk_character (SCHEME_P_ int c); |
187 |
|
|
INTERFACE pointer mk_foreign_func (SCHEME_P_ foreign_func f); |
188 |
|
|
INTERFACE void putstr (SCHEME_P_ const char *s); |
189 |
|
|
INTERFACE int list_length (SCHEME_P_ pointer a); |
190 |
|
|
INTERFACE int eqv (pointer a, pointer b); |
191 |
root |
1.1 |
|
192 |
root |
1.2 |
#if !STANDALONE |
193 |
root |
1.5 |
typedef struct scheme_registerable |
194 |
|
|
{ |
195 |
|
|
foreign_func f; |
196 |
|
|
const char *name; |
197 |
|
|
} scheme_registerable; |
198 |
root |
1.1 |
|
199 |
root |
1.5 |
void scheme_register_foreign_func_list (SCHEME_P_ scheme_registerable * list, int n); |
200 |
root |
1.2 |
#endif /* !STANDALONE */ |
201 |
root |
1.1 |
|
202 |
root |
1.2 |
#ifdef __cplusplus |
203 |
root |
1.1 |
} |
204 |
root |
1.2 |
#endif |
205 |
root |
1.1 |
|
206 |
|
|
#endif |
207 |
|
|
|
208 |
|
|
/* |
209 |
|
|
Local variables: |
210 |
|
|
c-file-style: "k&r" |
211 |
|
|
End: |
212 |
|
|
*/ |