ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/microscheme/scheme-private.h
Revision: 1.5
Committed: Thu Nov 26 21:32:16 2015 UTC (8 years, 7 months ago) by root
Content type: text/plain
Branch: MAIN
Changes since 1.4: +10 -9 lines
Log Message:
*** empty log message ***

File Contents

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