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