1 |
root |
1.1 |
|
2 |
|
|
/* scheme-private.h */ |
3 |
|
|
|
4 |
|
|
#ifndef SCHEME_PRIVATE_H |
5 |
root |
1.2 |
#define SCHEME_PRIVATE_H |
6 |
root |
1.1 |
|
7 |
root |
1.2 |
#include "scheme.h" |
8 |
|
|
|
9 |
|
|
#include <inttypes.h> |
10 |
root |
1.1 |
|
11 |
|
|
/*------------------ Ugly internals -----------------------------------*/ |
12 |
|
|
|
13 |
|
|
/*------------------ Of interest only to FFI users --------------------*/ |
14 |
|
|
|
15 |
|
|
# ifdef __cplusplus |
16 |
|
|
extern "C" |
17 |
|
|
{ |
18 |
|
|
# endif |
19 |
|
|
|
20 |
|
|
enum scheme_port_kind |
21 |
|
|
{ |
22 |
|
|
port_free = 0, |
23 |
|
|
port_file = 1, |
24 |
|
|
port_string = 2, |
25 |
|
|
port_srfi6 = 4, |
26 |
|
|
port_input = 16, |
27 |
|
|
port_output = 32, |
28 |
|
|
port_saw_EOF = 64 |
29 |
|
|
}; |
30 |
|
|
|
31 |
|
|
typedef struct port |
32 |
|
|
{ |
33 |
|
|
unsigned char kind; |
34 |
|
|
int16_t unget; |
35 |
|
|
union |
36 |
|
|
{ |
37 |
|
|
struct |
38 |
|
|
{ |
39 |
|
|
int file; |
40 |
|
|
int closeit; |
41 |
|
|
# if SHOW_ERROR_LINE |
42 |
|
|
int curr_line; |
43 |
|
|
char *filename; |
44 |
|
|
# endif |
45 |
|
|
} stdio; |
46 |
|
|
struct |
47 |
|
|
{ |
48 |
|
|
char *start; |
49 |
|
|
char *past_the_end; |
50 |
|
|
char *curr; |
51 |
|
|
} string; |
52 |
|
|
} rep; |
53 |
|
|
} port; |
54 |
|
|
|
55 |
|
|
/* cell structure */ |
56 |
|
|
struct cell |
57 |
|
|
{ |
58 |
|
|
union |
59 |
|
|
{ |
60 |
|
|
struct |
61 |
|
|
{ |
62 |
|
|
char *svalue; |
63 |
|
|
int length; |
64 |
|
|
} string; |
65 |
|
|
|
66 |
|
|
num number; |
67 |
|
|
|
68 |
|
|
port *port; |
69 |
|
|
|
70 |
|
|
foreign_func ff; |
71 |
|
|
|
72 |
|
|
struct |
73 |
|
|
{ |
74 |
|
|
struct cell *car; |
75 |
|
|
struct cell *cdr; |
76 |
|
|
} cons; |
77 |
|
|
|
78 |
|
|
} object; |
79 |
|
|
|
80 |
root |
1.2 |
unsigned int flag; /* need 11 bits */ |
81 |
root |
1.1 |
}; |
82 |
|
|
|
83 |
|
|
/* frequently accessed members are near the beginning, reducing codesize esp. on CISC */ |
84 |
|
|
struct scheme |
85 |
|
|
{ |
86 |
|
|
/* NIL is the most commonly accessed value */ |
87 |
|
|
struct cell xNIL; /* special cell representing empty cell */ |
88 |
|
|
|
89 |
|
|
/* We use 4 registers. */ |
90 |
|
|
pointer args; /* register for arguments of function */ |
91 |
|
|
pointer envir; /* stack register for current environment */ |
92 |
|
|
pointer code; /* register for current code */ |
93 |
|
|
pointer dump; /* stack register for next evaluation */ |
94 |
|
|
|
95 |
|
|
struct cell xT; /* special cell representing #t */ |
96 |
|
|
struct cell xF; /* special cell representing #f */ |
97 |
|
|
struct cell xEOF_OBJ; /* special cell representing end-of-file object */ |
98 |
|
|
struct cell xsink; /* when mem. alloc. fails */ |
99 |
|
|
|
100 |
|
|
/* arrays for segments */ |
101 |
|
|
#ifndef CELL_SEGSIZE |
102 |
|
|
# define CELL_SEGSIZE 128 /* # of cells in one segment */ |
103 |
|
|
#endif |
104 |
|
|
#ifndef CELL_NSEGMENT |
105 |
|
|
# define CELL_NSEGMENT 10 /* # of segments for cells */ |
106 |
|
|
#endif |
107 |
|
|
char *alloc_seg[CELL_NSEGMENT]; |
108 |
|
|
pointer cell_seg[CELL_NSEGMENT]; |
109 |
|
|
int cell_segsize[CELL_NSEGMENT]; |
110 |
|
|
int last_cell_seg; |
111 |
|
|
|
112 |
|
|
int interactive_repl; /* are we in an interactive REPL? */ |
113 |
|
|
|
114 |
|
|
pointer oblist; /* pointer to symbol table */ |
115 |
|
|
pointer global_env; /* pointer to global environment */ |
116 |
|
|
pointer c_nest; /* stack for nested calls from C */ |
117 |
|
|
|
118 |
|
|
/* global pointers to special symbols */ |
119 |
|
|
pointer LAMBDA; /* pointer to syntax lambda */ |
120 |
|
|
pointer QUOTE; /* pointer to syntax quote */ |
121 |
|
|
|
122 |
|
|
pointer QQUOTE; /* pointer to symbol quasiquote */ |
123 |
|
|
pointer UNQUOTE; /* pointer to symbol unquote */ |
124 |
|
|
pointer UNQUOTESP; /* pointer to symbol unquote-splicing */ |
125 |
|
|
pointer FEED_TO; /* => */ |
126 |
|
|
pointer COLON_HOOK; /* *colon-hook* */ |
127 |
|
|
pointer ERROR_HOOK; /* *error-hook* */ |
128 |
|
|
pointer SHARP_HOOK; /* *sharp-hook* */ |
129 |
|
|
pointer COMPILE_HOOK; /* *compile-hook* */ |
130 |
|
|
|
131 |
|
|
pointer free_cell; /* pointer to top of free cells */ |
132 |
|
|
long fcells; /* # of free cells */ |
133 |
|
|
|
134 |
|
|
/* return code */ |
135 |
|
|
int retcode; |
136 |
|
|
int tracing; |
137 |
|
|
|
138 |
|
|
pointer inport; |
139 |
|
|
pointer outport; |
140 |
|
|
pointer save_inport; |
141 |
|
|
pointer loadport; |
142 |
|
|
|
143 |
|
|
# define MAXFIL 64 |
144 |
|
|
port load_stack[MAXFIL]; /* Stack of open files for port -1 (LOADing) */ |
145 |
|
|
int nesting_stack[MAXFIL]; |
146 |
|
|
int file_i; |
147 |
|
|
int nesting; |
148 |
|
|
|
149 |
|
|
char gc_verbose; /* if gc_verbose is not zero, print gc status */ |
150 |
|
|
char no_memory; /* Whether mem. alloc. has failed */ |
151 |
|
|
|
152 |
|
|
# define LINESIZE 1024 |
153 |
|
|
char linebuff[LINESIZE]; |
154 |
|
|
# define STRBUFFSIZE 256 |
155 |
|
|
char strbuff[STRBUFFSIZE]; |
156 |
|
|
|
157 |
|
|
int tmpfp; |
158 |
|
|
int tok; |
159 |
|
|
int print_flag; |
160 |
|
|
pointer value; |
161 |
|
|
int op; |
162 |
|
|
|
163 |
|
|
void *ext_data; /* For the benefit of foreign functions */ |
164 |
|
|
long gensym_cnt; |
165 |
|
|
|
166 |
|
|
struct scheme_interface *vptr; |
167 |
|
|
struct dump_stack_frame *dump_base; /* pointer to base of allocated dump stack */ |
168 |
|
|
int dump_size; /* number of frames allocated for dump stack */ |
169 |
|
|
}; |
170 |
|
|
|
171 |
|
|
/* operator code */ |
172 |
|
|
enum scheme_opcodes |
173 |
|
|
{ |
174 |
|
|
# define OP_DEF(A,B,C,D,E,OP) OP, |
175 |
|
|
# include "opdefines.h" |
176 |
|
|
OP_MAXDEFINED |
177 |
|
|
}; |
178 |
|
|
|
179 |
|
|
# define cons(a,b) xcons(SCHEME_A_ a,b,0) |
180 |
|
|
# define immutable_cons(a,b) xcons(SCHEME_A_ a,b,1) |
181 |
|
|
|
182 |
|
|
INTERFACE int is_string (pointer p); |
183 |
|
|
INTERFACE char *string_value (pointer p); |
184 |
|
|
INTERFACE int is_number (pointer p); |
185 |
|
|
INTERFACE num nvalue (pointer p); |
186 |
|
|
INTERFACE IVALUE ivalue (pointer p); |
187 |
|
|
INTERFACE RVALUE rvalue (pointer p); |
188 |
|
|
INTERFACE int is_integer (pointer p); |
189 |
|
|
INTERFACE int is_real (pointer p); |
190 |
|
|
INTERFACE int is_character (pointer p); |
191 |
|
|
INTERFACE long charvalue (pointer p); |
192 |
|
|
INTERFACE int is_vector (pointer p); |
193 |
|
|
|
194 |
|
|
INTERFACE int is_port (pointer p); |
195 |
|
|
|
196 |
|
|
INTERFACE int is_pair (pointer p); |
197 |
|
|
INTERFACE pointer pair_car (pointer p); |
198 |
|
|
INTERFACE pointer pair_cdr (pointer p); |
199 |
|
|
INTERFACE void set_car (pointer p, pointer q); |
200 |
|
|
INTERFACE void set_cdr (pointer p, pointer q); |
201 |
|
|
|
202 |
|
|
INTERFACE int is_symbol (pointer p); |
203 |
|
|
INTERFACE char *symname (pointer p); |
204 |
|
|
INTERFACE int hasprop (pointer p); |
205 |
|
|
|
206 |
|
|
INTERFACE int is_syntax (pointer p); |
207 |
|
|
INTERFACE int is_proc (pointer p); |
208 |
|
|
INTERFACE int is_foreign (pointer p); |
209 |
|
|
INTERFACE char *syntaxname (pointer p); |
210 |
|
|
INTERFACE int is_closure (pointer p); |
211 |
|
|
# ifdef USE_MACRO |
212 |
|
|
INTERFACE int is_macro (pointer p); |
213 |
|
|
# endif |
214 |
|
|
INTERFACE pointer closure_code (pointer p); |
215 |
|
|
INTERFACE pointer closure_env (pointer p); |
216 |
|
|
|
217 |
|
|
INTERFACE int is_continuation (pointer p); |
218 |
|
|
INTERFACE int is_promise (pointer p); |
219 |
|
|
INTERFACE int is_environment (pointer p); |
220 |
|
|
INTERFACE int is_immutable (pointer p); |
221 |
|
|
INTERFACE void setimmutable (pointer p); |
222 |
|
|
|
223 |
root |
1.2 |
#ifdef __cplusplus |
224 |
root |
1.1 |
} |
225 |
root |
1.2 |
#endif |
226 |
root |
1.1 |
|
227 |
|
|
#endif |
228 |
|
|
|
229 |
|
|
/* |
230 |
|
|
Local variables: |
231 |
|
|
c-file-style: "k&r" |
232 |
|
|
End: |
233 |
|
|
*/ |