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