… | |
… | |
18 | * |
18 | * |
19 | */ |
19 | */ |
20 | |
20 | |
21 | #define EXPERIMENT 1 |
21 | #define EXPERIMENT 1 |
22 | |
22 | |
|
|
23 | #if 1 |
23 | #define PAGE_SIZE 4096 /* does not work on sparc/alpha */ |
24 | #define PAGE_SIZE 4096 /* does not work on sparc/alpha */ |
24 | #include "malloc.c" |
25 | #include "malloc.c" |
|
|
26 | #endif |
25 | |
27 | |
26 | #define SCHEME_SOURCE |
28 | #define SCHEME_SOURCE |
27 | #include "scheme-private.h" |
29 | #include "scheme-private.h" |
28 | #ifndef WIN32 |
30 | #ifndef WIN32 |
29 | # include <unistd.h> |
31 | # include <unistd.h> |
… | |
… | |
79 | |
81 | |
80 | #define BACKQUOTE '`' |
82 | #define BACKQUOTE '`' |
81 | #define WHITESPACE " \t\r\n\v\f" |
83 | #define WHITESPACE " \t\r\n\v\f" |
82 | #define DELIMITERS "()\";" WHITESPACE |
84 | #define DELIMITERS "()\";" WHITESPACE |
83 | |
85 | |
84 | #define NIL (&SCHEME_V->xNIL) //TODO: make this 0? |
86 | #define NIL POINTER (&SCHEME_V->xNIL) |
85 | #define S_T (&SCHEME_V->xT) //TODO: magic ptr value? |
87 | #define S_T POINTER (&SCHEME_V->xT) |
86 | #define S_F (&SCHEME_V->xF) //TODO: magic ptr value? |
88 | #define S_F POINTER (&SCHEME_V->xF) |
87 | #define S_SINK (&SCHEME_V->xsink) |
89 | #define S_SINK POINTER (&SCHEME_V->xsink) |
88 | #define S_EOF (&SCHEME_V->xEOF_OBJ) |
90 | #define S_EOF POINTER (&SCHEME_V->xEOF_OBJ) |
89 | |
91 | |
90 | #if !USE_MULTIPLICITY |
92 | #if !USE_MULTIPLICITY |
91 | static scheme sc; |
93 | static scheme sc; |
92 | #endif |
94 | #endif |
93 | |
95 | |
… | |
… | |
101 | } |
103 | } |
102 | |
104 | |
103 | char *p = s; |
105 | char *p = s; |
104 | |
106 | |
105 | do { |
107 | do { |
106 | *p++ = '0' + n % base; |
108 | *p++ = "0123456789abcdef"[n % base]; |
107 | n /= base; |
109 | n /= base; |
108 | } while (n); |
110 | } while (n); |
109 | |
111 | |
110 | *p-- = 0; |
112 | *p-- = 0; |
111 | |
113 | |
… | |
… | |
121 | { |
123 | { |
122 | xbase (s, n, 10); |
124 | xbase (s, n, 10); |
123 | } |
125 | } |
124 | |
126 | |
125 | static void |
127 | static void |
126 | xwrstr (const char *s) |
128 | putnum (SCHEME_P_ long n) |
127 | { |
|
|
128 | write (1, s, strlen (s)); |
|
|
129 | } |
|
|
130 | |
|
|
131 | static void |
|
|
132 | xwrnum (long n) |
|
|
133 | { |
129 | { |
134 | char buf[64]; |
130 | char buf[64]; |
135 | |
131 | |
136 | xnum (buf, n); |
132 | xnum (buf, n); |
137 | xwrstr (buf); |
133 | putstr (SCHEME_A_ buf); |
138 | } |
134 | } |
139 | |
135 | |
140 | static char |
136 | static char |
141 | xtoupper (char c) |
137 | xtoupper (char c) |
142 | { |
138 | { |
… | |
… | |
192 | # define prompt "ts> " |
188 | # define prompt "ts> " |
193 | #endif |
189 | #endif |
194 | |
190 | |
195 | #ifndef InitFile |
191 | #ifndef InitFile |
196 | # define InitFile "init.scm" |
192 | # define InitFile "init.scm" |
197 | #endif |
|
|
198 | |
|
|
199 | #ifndef FIRST_CELLSEGS |
|
|
200 | # define FIRST_CELLSEGS 3 |
|
|
201 | #endif |
193 | #endif |
202 | |
194 | |
203 | enum scheme_types |
195 | enum scheme_types |
204 | { |
196 | { |
205 | T_INTEGER, |
197 | T_INTEGER, |
… | |
… | |
266 | static int is_zero_rvalue (RVALUE x); |
258 | static int is_zero_rvalue (RVALUE x); |
267 | |
259 | |
268 | static num num_zero; |
260 | static num num_zero; |
269 | static num num_one; |
261 | static num num_one; |
270 | |
262 | |
|
|
263 | /* convert "pointer" to cell* / cell* to pointer */ |
|
|
264 | #define CELL(p) ((struct cell *)(p) + 0) |
|
|
265 | #define POINTER(c) ((void *)((c) - 0)) |
|
|
266 | |
271 | /* macros for cell operations */ |
267 | /* macros for cell operations */ |
272 | #define typeflag(p) ((p)->flag + 0) |
268 | #define typeflag(p) (CELL(p)->flag + 0) |
273 | #define set_typeflag(p,v) ((p)->flag = (v)) |
269 | #define set_typeflag(p,v) (CELL(p)->flag = (v)) |
274 | #define type(p) (typeflag (p) & T_MASKTYPE) |
270 | #define type(p) (typeflag (p) & T_MASKTYPE) |
275 | |
271 | |
276 | INTERFACE int |
272 | INTERFACE int |
277 | is_string (pointer p) |
273 | is_string (pointer p) |
278 | { |
274 | { |
279 | return type (p) == T_STRING; |
275 | return type (p) == T_STRING; |
280 | } |
276 | } |
281 | |
277 | |
282 | #define strvalue(p) ((p)->object.string.svalue) |
278 | #define strvalue(p) (CELL(p)->object.string.svalue) |
283 | #define strlength(p) ((p)->object.string.length) |
279 | #define strlength(p) (CELL(p)->object.string.length) |
284 | |
280 | |
285 | INTERFACE int |
281 | INTERFACE int |
286 | is_vector (pointer p) |
282 | is_vector (pointer p) |
287 | { |
283 | { |
288 | return type (p) == T_VECTOR; |
284 | return type (p) == T_VECTOR; |
289 | } |
285 | } |
290 | |
286 | |
291 | #define vecvalue(p) ((p)->object.vector.vvalue) |
287 | #define vecvalue(p) (CELL(p)->object.vector.vvalue) |
292 | #define veclength(p) ((p)->object.vector.length) |
288 | #define veclength(p) (CELL(p)->object.vector.length) |
293 | INTERFACE void fill_vector (pointer vec, uint32_t start, pointer obj); |
289 | INTERFACE void fill_vector (pointer vec, uint32_t start, pointer obj); |
294 | INTERFACE pointer vector_get (pointer vec, uint32_t ielem); |
290 | INTERFACE pointer vector_get (pointer vec, uint32_t ielem); |
295 | INTERFACE void vector_set (pointer vec, uint32_t ielem, pointer a); |
291 | INTERFACE void vector_set (pointer vec, uint32_t ielem, pointer a); |
296 | |
292 | |
297 | INTERFACE int |
293 | INTERFACE int |
… | |
… | |
323 | string_value (pointer p) |
319 | string_value (pointer p) |
324 | { |
320 | { |
325 | return strvalue (p); |
321 | return strvalue (p); |
326 | } |
322 | } |
327 | |
323 | |
328 | #define ivalue_unchecked(p) (p)->object.ivalue |
324 | #define ivalue_unchecked(p) CELL(p)->object.ivalue |
329 | #define set_ivalue(p,v) (p)->object.ivalue = (v) |
325 | #define set_ivalue(p,v) CELL(p)->object.ivalue = (v) |
330 | |
326 | |
331 | #if USE_REAL |
327 | #if USE_REAL |
332 | #define rvalue_unchecked(p) (p)->object.rvalue |
328 | #define rvalue_unchecked(p) CELL(p)->object.rvalue |
333 | #define set_rvalue(p,v) (p)->object.rvalue = (v) |
329 | #define set_rvalue(p,v) CELL(p)->object.rvalue = (v) |
334 | #else |
330 | #else |
335 | #define rvalue_unchecked(p) (p)->object.ivalue |
331 | #define rvalue_unchecked(p) CELL(p)->object.ivalue |
336 | #define set_rvalue(p,v) (p)->object.ivalue = (v) |
332 | #define set_rvalue(p,v) CELL(p)->object.ivalue = (v) |
337 | #endif |
333 | #endif |
338 | |
334 | |
339 | INTERFACE long |
335 | INTERFACE long |
340 | charvalue (pointer p) |
336 | charvalue (pointer p) |
341 | { |
337 | { |
342 | return ivalue_unchecked (p); |
338 | return ivalue_unchecked (p); |
343 | } |
339 | } |
344 | |
340 | |
|
|
341 | #define port(p) CELL(p)->object.port |
|
|
342 | #define set_port(p,v) port(p) = (v) |
345 | INTERFACE int |
343 | INTERFACE int |
346 | is_port (pointer p) |
344 | is_port (pointer p) |
347 | { |
345 | { |
348 | return type (p) == T_PORT; |
346 | return type (p) == T_PORT; |
349 | } |
347 | } |
350 | |
348 | |
351 | INTERFACE int |
349 | INTERFACE int |
352 | is_inport (pointer p) |
350 | is_inport (pointer p) |
353 | { |
351 | { |
354 | return is_port (p) && p->object.port->kind & port_input; |
352 | return is_port (p) && port (p)->kind & port_input; |
355 | } |
353 | } |
356 | |
354 | |
357 | INTERFACE int |
355 | INTERFACE int |
358 | is_outport (pointer p) |
356 | is_outport (pointer p) |
359 | { |
357 | { |
360 | return is_port (p) && p->object.port->kind & port_output; |
358 | return is_port (p) && port (p)->kind & port_output; |
361 | } |
359 | } |
362 | |
360 | |
363 | INTERFACE int |
361 | INTERFACE int |
364 | is_pair (pointer p) |
362 | is_pair (pointer p) |
365 | { |
363 | { |
366 | return type (p) == T_PAIR; |
364 | return type (p) == T_PAIR; |
367 | } |
365 | } |
368 | |
366 | |
369 | #define car(p) ((p)->object.cons.car + 0) |
367 | #define car(p) (POINTER (CELL(p)->object.cons.car)) |
370 | #define cdr(p) ((p)->object.cons.cdr + 0) |
368 | #define cdr(p) (POINTER (CELL(p)->object.cons.cdr)) |
371 | |
369 | |
372 | static pointer caar (pointer p) { return car (car (p)); } |
370 | static pointer caar (pointer p) { return car (car (p)); } |
373 | static pointer cadr (pointer p) { return car (cdr (p)); } |
371 | static pointer cadr (pointer p) { return car (cdr (p)); } |
374 | static pointer cdar (pointer p) { return cdr (car (p)); } |
372 | static pointer cdar (pointer p) { return cdr (car (p)); } |
375 | static pointer cddr (pointer p) { return cdr (cdr (p)); } |
373 | static pointer cddr (pointer p) { return cdr (cdr (p)); } |
… | |
… | |
379 | static pointer cdaar (pointer p) { return cdr (car (car (p))); } |
377 | static pointer cdaar (pointer p) { return cdr (car (car (p))); } |
380 | |
378 | |
381 | INTERFACE void |
379 | INTERFACE void |
382 | set_car (pointer p, pointer q) |
380 | set_car (pointer p, pointer q) |
383 | { |
381 | { |
384 | p->object.cons.car = q; |
382 | CELL(p)->object.cons.car = CELL (q); |
385 | } |
383 | } |
386 | |
384 | |
387 | INTERFACE void |
385 | INTERFACE void |
388 | set_cdr (pointer p, pointer q) |
386 | set_cdr (pointer p, pointer q) |
389 | { |
387 | { |
390 | p->object.cons.cdr = q; |
388 | CELL(p)->object.cons.cdr = CELL (q); |
391 | } |
389 | } |
392 | |
390 | |
393 | INTERFACE pointer |
391 | INTERFACE pointer |
394 | pair_car (pointer p) |
392 | pair_car (pointer p) |
395 | { |
393 | { |
… | |
… | |
413 | { |
411 | { |
414 | return strvalue (p); |
412 | return strvalue (p); |
415 | } |
413 | } |
416 | |
414 | |
417 | #if USE_PLIST |
415 | #if USE_PLIST |
|
|
416 | #error plists are broken because symbols are no longer pairs |
418 | #define symprop(p) cdr(p) |
417 | #define symprop(p) cdr(p) |
419 | SCHEME_EXPORT int |
418 | SCHEME_EXPORT int |
420 | hasprop (pointer p) |
419 | hasprop (pointer p) |
421 | { |
420 | { |
422 | return typeflag (p) & T_SYMBOL; |
421 | return typeflag (p) & T_SYMBOL; |
… | |
… | |
669 | |
668 | |
670 | static int file_push (SCHEME_P_ const char *fname); |
669 | static int file_push (SCHEME_P_ const char *fname); |
671 | static void file_pop (SCHEME_P); |
670 | static void file_pop (SCHEME_P); |
672 | static int file_interactive (SCHEME_P); |
671 | static int file_interactive (SCHEME_P); |
673 | ecb_inline int is_one_of (const char *s, int c); |
672 | ecb_inline int is_one_of (const char *s, int c); |
674 | static int alloc_cellseg (SCHEME_P_ int n); |
673 | static int alloc_cellseg (SCHEME_P); |
675 | ecb_inline pointer get_cell (SCHEME_P_ pointer a, pointer b); |
674 | ecb_inline pointer get_cell (SCHEME_P_ pointer a, pointer b); |
676 | static void finalize_cell (SCHEME_P_ pointer a); |
675 | static void finalize_cell (SCHEME_P_ pointer a); |
677 | static int count_consecutive_cells (pointer x, int needed); |
676 | static int count_consecutive_cells (pointer x, int needed); |
678 | static pointer find_slot_in_env (SCHEME_P_ pointer env, pointer sym, int all); |
677 | static pointer find_slot_in_env (SCHEME_P_ pointer env, pointer sym, int all); |
679 | static pointer mk_number (SCHEME_P_ const num n); |
678 | static pointer mk_number (SCHEME_P_ const num n); |
… | |
… | |
913 | #endif |
912 | #endif |
914 | } |
913 | } |
915 | |
914 | |
916 | /* allocate new cell segment */ |
915 | /* allocate new cell segment */ |
917 | static int |
916 | static int |
918 | alloc_cellseg (SCHEME_P_ int n) |
917 | alloc_cellseg (SCHEME_P) |
919 | { |
918 | { |
920 | pointer newp; |
919 | struct cell *newp; |
921 | pointer last; |
920 | struct cell *last; |
922 | pointer p; |
921 | struct cell *p; |
923 | char *cp; |
922 | char *cp; |
924 | long i; |
923 | long i; |
925 | int k; |
924 | int k; |
926 | |
925 | |
927 | static int segsize = CELL_SEGSIZE >> 1; |
926 | static int segsize = CELL_SEGSIZE >> 1; |
928 | segsize <<= 1; |
927 | segsize <<= 1; |
929 | |
928 | |
930 | for (k = 0; k < n; k++) |
|
|
931 | { |
|
|
932 | if (SCHEME_V->last_cell_seg >= CELL_NSEGMENT - 1) |
|
|
933 | return k; |
|
|
934 | |
|
|
935 | cp = malloc (segsize * sizeof (struct cell)); |
929 | cp = malloc (segsize * sizeof (struct cell)); |
936 | |
930 | |
937 | if (!cp && USE_ERROR_CHECKING) |
931 | if (!cp && USE_ERROR_CHECKING) |
938 | return k; |
932 | return k; |
939 | |
933 | |
940 | i = ++SCHEME_V->last_cell_seg; |
934 | i = ++SCHEME_V->last_cell_seg; |
941 | SCHEME_V->alloc_seg[i] = cp; |
935 | SCHEME_V->alloc_seg[i] = cp; |
942 | |
936 | |
943 | newp = (pointer)cp; |
937 | newp = (struct cell *)cp; |
944 | SCHEME_V->cell_seg[i] = newp; |
938 | SCHEME_V->cell_seg[i] = newp; |
945 | SCHEME_V->cell_segsize[i] = segsize; |
939 | SCHEME_V->cell_segsize[i] = segsize; |
946 | SCHEME_V->fcells += segsize; |
940 | SCHEME_V->fcells += segsize; |
947 | last = newp + segsize - 1; |
941 | last = newp + segsize - 1; |
948 | |
942 | |
949 | for (p = newp; p <= last; p++) |
943 | for (p = newp; p <= last; p++) |
950 | { |
944 | { |
|
|
945 | pointer cp = POINTER (p); |
951 | set_typeflag (p, T_PAIR); |
946 | set_typeflag (cp, T_PAIR); |
952 | set_car (p, NIL); |
947 | set_car (cp, NIL); |
953 | set_cdr (p, p + 1); |
948 | set_cdr (cp, POINTER (p + 1)); |
954 | } |
949 | } |
955 | |
950 | |
956 | set_cdr (last, SCHEME_V->free_cell); |
951 | set_cdr (POINTER (last), SCHEME_V->free_cell); |
957 | SCHEME_V->free_cell = newp; |
952 | SCHEME_V->free_cell = POINTER (newp); |
958 | } |
|
|
959 | |
953 | |
960 | return n; |
954 | return 1; |
961 | } |
955 | } |
962 | |
956 | |
963 | /* get new cell. parameter a, b is marked by gc. */ |
957 | /* get new cell. parameter a, b is marked by gc. */ |
964 | ecb_inline pointer |
958 | ecb_inline pointer |
965 | get_cell_x (SCHEME_P_ pointer a, pointer b) |
959 | get_cell_x (SCHEME_P_ pointer a, pointer b) |
… | |
… | |
976 | gc (SCHEME_A_ a, b); |
970 | gc (SCHEME_A_ a, b); |
977 | |
971 | |
978 | if (SCHEME_V->fcells < min_to_be_recovered || SCHEME_V->free_cell == NIL) |
972 | if (SCHEME_V->fcells < min_to_be_recovered || SCHEME_V->free_cell == NIL) |
979 | { |
973 | { |
980 | /* if only a few recovered, get more to avoid fruitless gc's */ |
974 | /* if only a few recovered, get more to avoid fruitless gc's */ |
981 | if (!alloc_cellseg (SCHEME_A_ 1) && SCHEME_V->free_cell == NIL) |
975 | if (!alloc_cellseg (SCHEME_A) && SCHEME_V->free_cell == NIL) |
982 | { |
976 | { |
983 | #if USE_ERROR_CHECKING |
977 | #if USE_ERROR_CHECKING |
984 | SCHEME_V->no_memory = 1; |
978 | SCHEME_V->no_memory = 1; |
985 | return S_SINK; |
979 | return S_SINK; |
986 | #endif |
980 | #endif |
… | |
… | |
998 | } |
992 | } |
999 | } |
993 | } |
1000 | |
994 | |
1001 | /* To retain recent allocs before interpreter knows about them - |
995 | /* To retain recent allocs before interpreter knows about them - |
1002 | Tehom */ |
996 | Tehom */ |
1003 | |
|
|
1004 | static void |
997 | static void |
1005 | push_recent_alloc (SCHEME_P_ pointer recent, pointer extra) |
998 | push_recent_alloc (SCHEME_P_ pointer recent, pointer extra) |
1006 | { |
999 | { |
1007 | pointer holder = get_cell_x (SCHEME_A_ recent, extra); |
1000 | pointer holder = get_cell_x (SCHEME_A_ recent, extra); |
1008 | |
1001 | |
… | |
… | |
1039 | return S_SINK; |
1032 | return S_SINK; |
1040 | |
1033 | |
1041 | /* Record it as a vector so that gc understands it. */ |
1034 | /* Record it as a vector so that gc understands it. */ |
1042 | set_typeflag (v, T_VECTOR | T_ATOM); |
1035 | set_typeflag (v, T_VECTOR | T_ATOM); |
1043 | |
1036 | |
1044 | v->object.vector.vvalue = e; |
1037 | CELL(v)->object.vector.vvalue = e; |
1045 | v->object.vector.length = len; |
1038 | CELL(v)->object.vector.length = len; |
1046 | fill_vector (v, 0, init); |
1039 | fill_vector (v, 0, init); |
1047 | push_recent_alloc (SCHEME_A_ v, NIL); |
1040 | push_recent_alloc (SCHEME_A_ v, NIL); |
1048 | |
1041 | |
1049 | return v; |
1042 | return v; |
1050 | } |
1043 | } |
… | |
… | |
1059 | static void |
1052 | static void |
1060 | check_cell_alloced (pointer p, int expect_alloced) |
1053 | check_cell_alloced (pointer p, int expect_alloced) |
1061 | { |
1054 | { |
1062 | /* Can't use putstr(SCHEME_A_ str) because callers have no access to sc. */ |
1055 | /* Can't use putstr(SCHEME_A_ str) because callers have no access to sc. */ |
1063 | if (typeflag (p) & !expect_alloced) |
1056 | if (typeflag (p) & !expect_alloced) |
1064 | xwrstr ("Cell is already allocated!\n"); |
1057 | putstr (SCHEME_A_ "Cell is already allocated!\n"); |
1065 | |
1058 | |
1066 | if (!(typeflag (p)) & expect_alloced) |
1059 | if (!(typeflag (p)) & expect_alloced) |
1067 | xwrstr ("Cell is not allocated!\n"); |
1060 | putstr (SCHEME_A_ "Cell is not allocated!\n"); |
1068 | } |
1061 | } |
1069 | |
1062 | |
1070 | static void |
1063 | static void |
1071 | check_range_alloced (pointer p, int n, int expect_alloced) |
1064 | check_range_alloced (pointer p, int n, int expect_alloced) |
1072 | { |
1065 | { |
… | |
… | |
1200 | |
1193 | |
1201 | /* returns the new symbol */ |
1194 | /* returns the new symbol */ |
1202 | static pointer |
1195 | static pointer |
1203 | oblist_add_by_name (SCHEME_P_ const char *name) |
1196 | oblist_add_by_name (SCHEME_P_ const char *name) |
1204 | { |
1197 | { |
1205 | pointer x = mk_string (SCHEME_A_ name); |
1198 | pointer x = generate_symbol (SCHEME_A_ name); |
1206 | set_typeflag (x, T_SYMBOL); |
|
|
1207 | setimmutable (x); |
|
|
1208 | SCHEME_V->oblist = immutable_cons (x, SCHEME_V->oblist); |
1199 | SCHEME_V->oblist = immutable_cons (x, SCHEME_V->oblist); |
1209 | return x; |
1200 | return x; |
1210 | } |
1201 | } |
1211 | |
1202 | |
1212 | static pointer |
1203 | static pointer |
… | |
… | |
1222 | mk_port (SCHEME_P_ port *p) |
1213 | mk_port (SCHEME_P_ port *p) |
1223 | { |
1214 | { |
1224 | pointer x = get_cell (SCHEME_A_ NIL, NIL); |
1215 | pointer x = get_cell (SCHEME_A_ NIL, NIL); |
1225 | |
1216 | |
1226 | set_typeflag (x, T_PORT | T_ATOM); |
1217 | set_typeflag (x, T_PORT | T_ATOM); |
1227 | x->object.port = p; |
1218 | set_port (x, p); |
1228 | |
1219 | |
1229 | return x; |
1220 | return x; |
1230 | } |
1221 | } |
1231 | #endif |
1222 | #endif |
1232 | |
1223 | |
1233 | pointer |
1224 | pointer |
1234 | mk_foreign_func (SCHEME_P_ foreign_func f) |
1225 | mk_foreign_func (SCHEME_P_ foreign_func f) |
1235 | { |
1226 | { |
1236 | pointer x = get_cell (SCHEME_A_ NIL, NIL); |
1227 | pointer x = get_cell (SCHEME_A_ NIL, NIL); |
1237 | |
1228 | |
1238 | set_typeflag (x, (T_FOREIGN | T_ATOM)); |
1229 | set_typeflag (x, T_FOREIGN | T_ATOM); |
1239 | x->object.ff = f; |
1230 | CELL(x)->object.ff = f; |
1240 | |
1231 | |
1241 | return x; |
1232 | return x; |
1242 | } |
1233 | } |
1243 | |
1234 | |
1244 | INTERFACE pointer |
1235 | INTERFACE pointer |
1245 | mk_character (SCHEME_P_ int c) |
1236 | mk_character (SCHEME_P_ int c) |
1246 | { |
1237 | { |
1247 | pointer x = get_cell (SCHEME_A_ NIL, NIL); |
1238 | pointer x = get_cell (SCHEME_A_ NIL, NIL); |
1248 | |
1239 | |
1249 | set_typeflag (x, (T_CHARACTER | T_ATOM)); |
1240 | set_typeflag (x, T_CHARACTER | T_ATOM); |
1250 | set_ivalue (x, c & 0xff); |
1241 | set_ivalue (x, c & 0xff); |
1251 | |
1242 | |
1252 | return x; |
1243 | return x; |
1253 | } |
1244 | } |
1254 | |
1245 | |
1255 | /* get number atom (integer) */ |
1246 | /* get number atom (integer) */ |
1256 | INTERFACE pointer |
1247 | INTERFACE pointer |
1257 | mk_integer (SCHEME_P_ long n) |
1248 | mk_integer (SCHEME_P_ long n) |
1258 | { |
1249 | { |
|
|
1250 | pointer p = 0; |
|
|
1251 | pointer *pp = &p; |
|
|
1252 | |
|
|
1253 | #if USE_INTCACHE |
|
|
1254 | if (n >= INTCACHE_MIN && n <= INTCACHE_MAX) |
|
|
1255 | pp = &SCHEME_V->intcache[n - INTCACHE_MIN]; |
|
|
1256 | #endif |
|
|
1257 | |
|
|
1258 | if (!*pp) |
|
|
1259 | { |
1259 | pointer x = get_cell (SCHEME_A_ NIL, NIL); |
1260 | pointer x = get_cell (SCHEME_A_ NIL, NIL); |
1260 | |
1261 | |
1261 | set_typeflag (x, (T_INTEGER | T_ATOM)); |
1262 | set_typeflag (x, T_INTEGER | T_ATOM); |
|
|
1263 | setimmutable (x); /* shouldn't do anythi9ng, doesn't cost anything */ |
1262 | set_ivalue (x, n); |
1264 | set_ivalue (x, n); |
1263 | |
1265 | |
|
|
1266 | *pp = x; |
|
|
1267 | } |
|
|
1268 | |
1264 | return x; |
1269 | return *pp; |
1265 | } |
1270 | } |
1266 | |
1271 | |
1267 | INTERFACE pointer |
1272 | INTERFACE pointer |
1268 | mk_real (SCHEME_P_ RVALUE n) |
1273 | mk_real (SCHEME_P_ RVALUE n) |
1269 | { |
1274 | { |
1270 | #if USE_REAL |
1275 | #if USE_REAL |
1271 | pointer x = get_cell (SCHEME_A_ NIL, NIL); |
1276 | pointer x = get_cell (SCHEME_A_ NIL, NIL); |
1272 | |
1277 | |
1273 | set_typeflag (x, (T_REAL | T_ATOM)); |
1278 | set_typeflag (x, T_REAL | T_ATOM); |
1274 | set_rvalue (x, n); |
1279 | set_rvalue (x, n); |
1275 | |
1280 | |
1276 | return x; |
1281 | return x; |
1277 | #else |
1282 | #else |
1278 | return mk_integer (SCHEME_A_ n); |
1283 | return mk_integer (SCHEME_A_ n); |
… | |
… | |
1621 | |
1626 | |
1622 | /* garbage collection. parameter a, b is marked. */ |
1627 | /* garbage collection. parameter a, b is marked. */ |
1623 | static void |
1628 | static void |
1624 | gc (SCHEME_P_ pointer a, pointer b) |
1629 | gc (SCHEME_P_ pointer a, pointer b) |
1625 | { |
1630 | { |
1626 | pointer p; |
|
|
1627 | int i; |
1631 | int i; |
1628 | |
1632 | |
1629 | if (SCHEME_V->gc_verbose) |
1633 | if (SCHEME_V->gc_verbose) |
1630 | putstr (SCHEME_A_ "gc..."); |
1634 | putstr (SCHEME_A_ "gc..."); |
1631 | |
1635 | |
… | |
… | |
1647 | /* Mark recent objects the interpreter doesn't know about yet. */ |
1651 | /* Mark recent objects the interpreter doesn't know about yet. */ |
1648 | mark (car (S_SINK)); |
1652 | mark (car (S_SINK)); |
1649 | /* Mark any older stuff above nested C calls */ |
1653 | /* Mark any older stuff above nested C calls */ |
1650 | mark (SCHEME_V->c_nest); |
1654 | mark (SCHEME_V->c_nest); |
1651 | |
1655 | |
|
|
1656 | #if USE_INTCACHE |
|
|
1657 | /* mark intcache */ |
|
|
1658 | for (i = INTCACHE_MIN; i <= INTCACHE_MAX; ++i) |
|
|
1659 | if (SCHEME_V->intcache[i - INTCACHE_MIN]) |
|
|
1660 | mark (SCHEME_V->intcache[i - INTCACHE_MIN]); |
|
|
1661 | #endif |
|
|
1662 | |
1652 | /* mark variables a, b */ |
1663 | /* mark variables a, b */ |
1653 | mark (a); |
1664 | mark (a); |
1654 | mark (b); |
1665 | mark (b); |
1655 | |
1666 | |
1656 | /* garbage collect */ |
1667 | /* garbage collect */ |
1657 | clrmark (NIL); |
1668 | clrmark (NIL); |
1658 | SCHEME_V->fcells = 0; |
1669 | SCHEME_V->fcells = 0; |
1659 | SCHEME_V->free_cell = NIL; |
1670 | SCHEME_V->free_cell = NIL; |
1660 | |
1671 | |
1661 | if (SCHEME_V->gc_verbose) |
1672 | if (SCHEME_V->gc_verbose) |
1662 | xwrstr ("freeing..."); |
1673 | putstr (SCHEME_A_ "freeing..."); |
1663 | |
1674 | |
1664 | uint32_t total = 0; |
1675 | uint32_t total = 0; |
1665 | |
1676 | |
1666 | /* Here we scan the cells to build the free-list. */ |
1677 | /* Here we scan the cells to build the free-list. */ |
1667 | for (i = SCHEME_V->last_cell_seg; i >= 0; i--) |
1678 | for (i = SCHEME_V->last_cell_seg; i >= 0; i--) |
1668 | { |
1679 | { |
1669 | pointer end = SCHEME_V->cell_seg[i] + SCHEME_V->cell_segsize [i]; |
1680 | struct cell *end = SCHEME_V->cell_seg[i] + SCHEME_V->cell_segsize [i]; |
|
|
1681 | struct cell *p; |
1670 | total += SCHEME_V->cell_segsize [i]; |
1682 | total += SCHEME_V->cell_segsize [i]; |
1671 | |
1683 | |
1672 | for (p = SCHEME_V->cell_seg[i]; p < end; ++p) |
1684 | for (p = SCHEME_V->cell_seg[i]; p < end; ++p) |
1673 | { |
1685 | { |
|
|
1686 | pointer c = POINTER (p); |
|
|
1687 | |
1674 | if (is_mark (p)) |
1688 | if (is_mark (c)) |
1675 | clrmark (p); |
1689 | clrmark (c); |
1676 | else |
1690 | else |
1677 | { |
1691 | { |
1678 | /* reclaim cell */ |
1692 | /* reclaim cell */ |
1679 | if (typeflag (p) != T_PAIR) |
1693 | if (typeflag (c) != T_PAIR) |
1680 | { |
1694 | { |
1681 | finalize_cell (SCHEME_A_ p); |
1695 | finalize_cell (SCHEME_A_ c); |
1682 | set_typeflag (p, T_PAIR); |
1696 | set_typeflag (c, T_PAIR); |
1683 | set_car (p, NIL); |
1697 | set_car (c, NIL); |
1684 | } |
1698 | } |
1685 | |
1699 | |
1686 | ++SCHEME_V->fcells; |
1700 | ++SCHEME_V->fcells; |
1687 | set_cdr (p, SCHEME_V->free_cell); |
1701 | set_cdr (c, SCHEME_V->free_cell); |
1688 | SCHEME_V->free_cell = p; |
1702 | SCHEME_V->free_cell = c; |
1689 | } |
1703 | } |
1690 | } |
1704 | } |
1691 | } |
1705 | } |
1692 | |
1706 | |
1693 | if (SCHEME_V->gc_verbose) |
1707 | if (SCHEME_V->gc_verbose) |
1694 | { |
1708 | { |
1695 | xwrstr ("done: "); xwrnum (SCHEME_V->fcells); xwrstr (" out of "); xwrnum (total); xwrstr (" cells were recovered.\n"); |
1709 | putstr (SCHEME_A_ "done: "); putnum (SCHEME_A_ SCHEME_V->fcells); putstr (SCHEME_A_ " out of "); putnum (SCHEME_A_ total); putstr (SCHEME_A_ " cells were recovered.\n"); |
1696 | } |
1710 | } |
1697 | } |
1711 | } |
1698 | |
1712 | |
1699 | static void |
1713 | static void |
1700 | finalize_cell (SCHEME_P_ pointer a) |
1714 | finalize_cell (SCHEME_P_ pointer a) |
… | |
… | |
1705 | else if (is_vector (a)) |
1719 | else if (is_vector (a)) |
1706 | free (vecvalue (a)); |
1720 | free (vecvalue (a)); |
1707 | #if USE_PORTS |
1721 | #if USE_PORTS |
1708 | else if (is_port (a)) |
1722 | else if (is_port (a)) |
1709 | { |
1723 | { |
1710 | if (a->object.port->kind & port_file && a->object.port->rep.stdio.closeit) |
1724 | if (port(a)->kind & port_file && port (a)->rep.stdio.closeit) |
1711 | port_close (SCHEME_A_ a, port_input | port_output); |
1725 | port_close (SCHEME_A_ a, port_input | port_output); |
1712 | |
1726 | |
1713 | free (a->object.port); |
1727 | free (port (a)); |
1714 | } |
1728 | } |
1715 | #endif |
1729 | #endif |
1716 | } |
1730 | } |
1717 | |
1731 | |
1718 | /* ========== Routines for Reading ========== */ |
1732 | /* ========== Routines for Reading ========== */ |
… | |
… | |
1734 | SCHEME_V->load_stack[SCHEME_V->file_i].unget = -1; |
1748 | SCHEME_V->load_stack[SCHEME_V->file_i].unget = -1; |
1735 | SCHEME_V->load_stack[SCHEME_V->file_i].kind = port_file | port_input; |
1749 | SCHEME_V->load_stack[SCHEME_V->file_i].kind = port_file | port_input; |
1736 | SCHEME_V->load_stack[SCHEME_V->file_i].rep.stdio.file = fin; |
1750 | SCHEME_V->load_stack[SCHEME_V->file_i].rep.stdio.file = fin; |
1737 | SCHEME_V->load_stack[SCHEME_V->file_i].rep.stdio.closeit = 1; |
1751 | SCHEME_V->load_stack[SCHEME_V->file_i].rep.stdio.closeit = 1; |
1738 | SCHEME_V->nesting_stack[SCHEME_V->file_i] = 0; |
1752 | SCHEME_V->nesting_stack[SCHEME_V->file_i] = 0; |
1739 | SCHEME_V->loadport->object.port = SCHEME_V->load_stack + SCHEME_V->file_i; |
1753 | set_port (SCHEME_V->loadport, SCHEME_V->load_stack + SCHEME_V->file_i); |
1740 | |
1754 | |
1741 | #if SHOW_ERROR_LINE |
1755 | #if SHOW_ERROR_LINE |
1742 | SCHEME_V->load_stack[SCHEME_V->file_i].rep.stdio.curr_line = 0; |
1756 | SCHEME_V->load_stack[SCHEME_V->file_i].rep.stdio.curr_line = 0; |
1743 | |
1757 | |
1744 | if (fname) |
1758 | if (fname) |
… | |
… | |
1761 | SCHEME_V->nesting = SCHEME_V->nesting_stack[SCHEME_V->file_i]; |
1775 | SCHEME_V->nesting = SCHEME_V->nesting_stack[SCHEME_V->file_i]; |
1762 | #if USE_PORTS |
1776 | #if USE_PORTS |
1763 | port_close (SCHEME_A_ SCHEME_V->loadport, port_input); |
1777 | port_close (SCHEME_A_ SCHEME_V->loadport, port_input); |
1764 | #endif |
1778 | #endif |
1765 | SCHEME_V->file_i--; |
1779 | SCHEME_V->file_i--; |
1766 | SCHEME_V->loadport->object.port = SCHEME_V->load_stack + SCHEME_V->file_i; |
1780 | set_port (SCHEME_V->loadport, SCHEME_V->load_stack + SCHEME_V->file_i); |
1767 | } |
1781 | } |
1768 | } |
1782 | } |
1769 | |
1783 | |
1770 | static int |
1784 | static int |
1771 | file_interactive (SCHEME_P) |
1785 | file_interactive (SCHEME_P) |
1772 | { |
1786 | { |
1773 | #if USE_PORTS |
1787 | #if USE_PORTS |
1774 | return SCHEME_V->file_i == 0 |
1788 | return SCHEME_V->file_i == 0 |
1775 | && SCHEME_V->load_stack[0].rep.stdio.file == STDIN_FILENO |
1789 | && SCHEME_V->load_stack[0].rep.stdio.file == STDIN_FILENO |
1776 | && (SCHEME_V->inport->object.port->kind & port_file); |
1790 | && (port (SCHEME_V->inport)->kind & port_file); |
1777 | #else |
1791 | #else |
1778 | return 0; |
1792 | return 0; |
1779 | #endif |
1793 | #endif |
1780 | } |
1794 | } |
1781 | |
1795 | |
… | |
… | |
1915 | } |
1929 | } |
1916 | |
1930 | |
1917 | static void |
1931 | static void |
1918 | port_close (SCHEME_P_ pointer p, int flag) |
1932 | port_close (SCHEME_P_ pointer p, int flag) |
1919 | { |
1933 | { |
1920 | port *pt = p->object.port; |
1934 | port *pt = port (p); |
1921 | |
1935 | |
1922 | pt->kind &= ~flag; |
1936 | pt->kind &= ~flag; |
1923 | |
1937 | |
1924 | if ((pt->kind & (port_input | port_output)) == 0) |
1938 | if ((pt->kind & (port_input | port_output)) == 0) |
1925 | { |
1939 | { |
… | |
… | |
1946 | /* get new character from input file */ |
1960 | /* get new character from input file */ |
1947 | static int |
1961 | static int |
1948 | inchar (SCHEME_P) |
1962 | inchar (SCHEME_P) |
1949 | { |
1963 | { |
1950 | int c; |
1964 | int c; |
1951 | port *pt; |
1965 | port *pt = port (SCHEME_V->inport); |
1952 | |
|
|
1953 | pt = SCHEME_V->inport->object.port; |
|
|
1954 | |
1966 | |
1955 | if (pt->kind & port_saw_EOF) |
1967 | if (pt->kind & port_saw_EOF) |
1956 | return EOF; |
1968 | return EOF; |
1957 | |
1969 | |
1958 | c = basic_inchar (pt); |
1970 | c = basic_inchar (pt); |
… | |
… | |
2025 | port *pt; |
2037 | port *pt; |
2026 | |
2038 | |
2027 | if (c == EOF) |
2039 | if (c == EOF) |
2028 | return; |
2040 | return; |
2029 | |
2041 | |
2030 | pt = SCHEME_V->inport->object.port; |
2042 | pt = port (SCHEME_V->inport); |
2031 | pt->unget = c; |
2043 | pt->unget = c; |
2032 | #else |
2044 | #else |
2033 | if (c == EOF) |
2045 | if (c == EOF) |
2034 | return; |
2046 | return; |
2035 | |
2047 | |
… | |
… | |
2063 | |
2075 | |
2064 | INTERFACE void |
2076 | INTERFACE void |
2065 | putstr (SCHEME_P_ const char *s) |
2077 | putstr (SCHEME_P_ const char *s) |
2066 | { |
2078 | { |
2067 | #if USE_PORTS |
2079 | #if USE_PORTS |
2068 | port *pt = SCHEME_V->outport->object.port; |
2080 | port *pt = port (SCHEME_V->outport); |
2069 | |
2081 | |
2070 | if (pt->kind & port_file) |
2082 | if (pt->kind & port_file) |
2071 | write (pt->rep.stdio.file, s, strlen (s)); |
2083 | write (pt->rep.stdio.file, s, strlen (s)); |
2072 | else |
2084 | else |
2073 | for (; *s; s++) |
2085 | for (; *s; s++) |
… | |
… | |
2075 | *pt->rep.string.curr++ = *s; |
2087 | *pt->rep.string.curr++ = *s; |
2076 | else if (pt->kind & port_srfi6 && realloc_port_string (SCHEME_A_ pt)) |
2088 | else if (pt->kind & port_srfi6 && realloc_port_string (SCHEME_A_ pt)) |
2077 | *pt->rep.string.curr++ = *s; |
2089 | *pt->rep.string.curr++ = *s; |
2078 | |
2090 | |
2079 | #else |
2091 | #else |
2080 | xwrstr (s); |
2092 | write (pt->rep.stdio.file, s, strlen (s)); |
2081 | #endif |
2093 | #endif |
2082 | } |
2094 | } |
2083 | |
2095 | |
2084 | static void |
2096 | static void |
2085 | putchars (SCHEME_P_ const char *s, int len) |
2097 | putchars (SCHEME_P_ const char *s, int len) |
2086 | { |
2098 | { |
2087 | #if USE_PORTS |
2099 | #if USE_PORTS |
2088 | port *pt = SCHEME_V->outport->object.port; |
2100 | port *pt = port (SCHEME_V->outport); |
2089 | |
2101 | |
2090 | if (pt->kind & port_file) |
2102 | if (pt->kind & port_file) |
2091 | write (pt->rep.stdio.file, s, len); |
2103 | write (pt->rep.stdio.file, s, len); |
2092 | else |
2104 | else |
2093 | { |
2105 | { |
… | |
… | |
2107 | |
2119 | |
2108 | INTERFACE void |
2120 | INTERFACE void |
2109 | putcharacter (SCHEME_P_ int c) |
2121 | putcharacter (SCHEME_P_ int c) |
2110 | { |
2122 | { |
2111 | #if USE_PORTS |
2123 | #if USE_PORTS |
2112 | port *pt = SCHEME_V->outport->object.port; |
2124 | port *pt = port (SCHEME_V->outport); |
2113 | |
2125 | |
2114 | if (pt->kind & port_file) |
2126 | if (pt->kind & port_file) |
2115 | { |
2127 | { |
2116 | char cc = c; |
2128 | char cc = c; |
2117 | write (pt->rep.stdio.file, &cc, 1); |
2129 | write (pt->rep.stdio.file, &cc, 1); |
… | |
… | |
3059 | { |
3071 | { |
3060 | int nframes = (uintptr_t)SCHEME_V->dump; |
3072 | int nframes = (uintptr_t)SCHEME_V->dump; |
3061 | struct dump_stack_frame *next_frame; |
3073 | struct dump_stack_frame *next_frame; |
3062 | |
3074 | |
3063 | /* enough room for the next frame? */ |
3075 | /* enough room for the next frame? */ |
3064 | if (nframes >= SCHEME_V->dump_size) |
3076 | if (ecb_expect_false (nframes >= SCHEME_V->dump_size)) |
3065 | { |
3077 | { |
3066 | SCHEME_V->dump_size += STACK_GROWTH; |
3078 | SCHEME_V->dump_size += STACK_GROWTH; |
3067 | SCHEME_V->dump_base = realloc (SCHEME_V->dump_base, sizeof (struct dump_stack_frame) * SCHEME_V->dump_size); |
3079 | SCHEME_V->dump_base = realloc (SCHEME_V->dump_base, sizeof (struct dump_stack_frame) * SCHEME_V->dump_size); |
3068 | } |
3080 | } |
3069 | |
3081 | |
… | |
… | |
3325 | s_return (S_T); |
3337 | s_return (S_T); |
3326 | #endif |
3338 | #endif |
3327 | case OP_LOAD: /* load */ |
3339 | case OP_LOAD: /* load */ |
3328 | if (file_interactive (SCHEME_A)) |
3340 | if (file_interactive (SCHEME_A)) |
3329 | { |
3341 | { |
3330 | xwrstr ("Loading "); xwrstr (strvalue (car (args))); xwrstr ("\n"); |
3342 | putstr (SCHEME_A_ "Loading "); putstr (SCHEME_A_ strvalue (car (args))); putstr (SCHEME_A_ "\n"); |
3331 | //D fprintf (SCHEME_V->outport->object.port->rep.stdio.file, "Loading %s\n", strvalue (car (args))); |
3343 | //D fprintf (port (SCHEME_V->outport)->rep.stdio.file, "Loading %s\n", strvalue (car (args))); |
3332 | } |
3344 | } |
3333 | |
3345 | |
3334 | if (!file_push (SCHEME_A_ strvalue (car (args)))) |
3346 | if (!file_push (SCHEME_A_ strvalue (car (args)))) |
3335 | Error_1 ("unable to open", car (args)); |
3347 | Error_1 ("unable to open", car (args)); |
3336 | else |
3348 | else |
… | |
… | |
3340 | } |
3352 | } |
3341 | |
3353 | |
3342 | case OP_T0LVL: /* top level */ |
3354 | case OP_T0LVL: /* top level */ |
3343 | |
3355 | |
3344 | /* If we reached the end of file, this loop is done. */ |
3356 | /* If we reached the end of file, this loop is done. */ |
3345 | if (SCHEME_V->loadport->object.port->kind & port_saw_EOF) |
3357 | if (port (SCHEME_V->loadport)->kind & port_saw_EOF) |
3346 | { |
3358 | { |
3347 | if (SCHEME_V->file_i == 0) |
3359 | if (SCHEME_V->file_i == 0) |
3348 | { |
3360 | { |
3349 | SCHEME_V->args = NIL; |
3361 | SCHEME_V->args = NIL; |
3350 | s_goto (OP_QUIT); |
3362 | s_goto (OP_QUIT); |
… | |
… | |
3428 | #endif |
3440 | #endif |
3429 | if (is_symbol (SCHEME_V->code)) /* symbol */ |
3441 | if (is_symbol (SCHEME_V->code)) /* symbol */ |
3430 | { |
3442 | { |
3431 | x = find_slot_in_env (SCHEME_A_ SCHEME_V->envir, SCHEME_V->code, 1); |
3443 | x = find_slot_in_env (SCHEME_A_ SCHEME_V->envir, SCHEME_V->code, 1); |
3432 | |
3444 | |
3433 | if (x != NIL) |
3445 | if (x == NIL) |
3434 | s_return (slot_value_in_env (x)); |
|
|
3435 | else |
|
|
3436 | Error_1 ("eval: unbound variable:", SCHEME_V->code); |
3446 | Error_1 ("eval: unbound variable:", SCHEME_V->code); |
|
|
3447 | |
|
|
3448 | s_return (slot_value_in_env (x)); |
3437 | } |
3449 | } |
3438 | else if (is_pair (SCHEME_V->code)) |
3450 | else if (is_pair (SCHEME_V->code)) |
3439 | { |
3451 | { |
3440 | x = car (SCHEME_V->code); |
3452 | x = car (SCHEME_V->code); |
3441 | |
3453 | |
… | |
… | |
3518 | s_goto (procnum (SCHEME_V->code)); /* PROCEDURE */ |
3530 | s_goto (procnum (SCHEME_V->code)); /* PROCEDURE */ |
3519 | else if (is_foreign (SCHEME_V->code)) |
3531 | else if (is_foreign (SCHEME_V->code)) |
3520 | { |
3532 | { |
3521 | /* Keep nested calls from GC'ing the arglist */ |
3533 | /* Keep nested calls from GC'ing the arglist */ |
3522 | push_recent_alloc (SCHEME_A_ args, NIL); |
3534 | push_recent_alloc (SCHEME_A_ args, NIL); |
3523 | x = SCHEME_V->code->object.ff (SCHEME_A_ args); |
3535 | x = CELL(SCHEME_V->code)->object.ff (SCHEME_A_ args); |
3524 | |
3536 | |
3525 | s_return (x); |
3537 | s_return (x); |
3526 | } |
3538 | } |
3527 | else if (is_closure (SCHEME_V->code) || is_macro (SCHEME_V->code) || is_promise (SCHEME_V->code)) /* CLOSURE */ |
3539 | else if (is_closure (SCHEME_V->code) || is_macro (SCHEME_V->code) || is_promise (SCHEME_V->code)) /* CLOSURE */ |
3528 | { |
3540 | { |
… | |
… | |
3565 | |
3577 | |
3566 | case OP_DOMACRO: /* do macro */ |
3578 | case OP_DOMACRO: /* do macro */ |
3567 | SCHEME_V->code = SCHEME_V->value; |
3579 | SCHEME_V->code = SCHEME_V->value; |
3568 | s_goto (OP_EVAL); |
3580 | s_goto (OP_EVAL); |
3569 | |
3581 | |
3570 | #if 1 |
|
|
3571 | |
|
|
3572 | case OP_LAMBDA: /* lambda */ |
3582 | case OP_LAMBDA: /* lambda */ |
3573 | /* If the hook is defined, apply it to SCHEME_V->code, otherwise |
3583 | /* If the hook is defined, apply it to SCHEME_V->code, otherwise |
3574 | set SCHEME_V->value fall thru */ |
3584 | set SCHEME_V->value fall thru */ |
3575 | { |
3585 | { |
3576 | pointer f = find_slot_in_env (SCHEME_A_ SCHEME_V->envir, SCHEME_V->COMPILE_HOOK, 1); |
3586 | pointer f = find_slot_in_env (SCHEME_A_ SCHEME_V->envir, SCHEME_V->COMPILE_HOOK, 1); |
… | |
… | |
3582 | SCHEME_V->code = slot_value_in_env (f); |
3592 | SCHEME_V->code = slot_value_in_env (f); |
3583 | s_goto (OP_APPLY); |
3593 | s_goto (OP_APPLY); |
3584 | } |
3594 | } |
3585 | |
3595 | |
3586 | SCHEME_V->value = SCHEME_V->code; |
3596 | SCHEME_V->value = SCHEME_V->code; |
3587 | /* Fallthru */ |
|
|
3588 | } |
3597 | } |
|
|
3598 | /* Fallthru */ |
3589 | |
3599 | |
3590 | case OP_LAMBDA1: |
3600 | case OP_LAMBDA1: |
3591 | s_return (mk_closure (SCHEME_A_ SCHEME_V->value, SCHEME_V->envir)); |
3601 | s_return (mk_closure (SCHEME_A_ SCHEME_V->value, SCHEME_V->envir)); |
3592 | |
|
|
3593 | #else |
|
|
3594 | |
|
|
3595 | case OP_LAMBDA: /* lambda */ |
|
|
3596 | s_return (mk_closure (SCHEME_A_ SCHEME_V->code, SCHEME_V->envir)); |
|
|
3597 | |
|
|
3598 | #endif |
|
|
3599 | |
3602 | |
3600 | case OP_MKCLOSURE: /* make-closure */ |
3603 | case OP_MKCLOSURE: /* make-closure */ |
3601 | x = car (args); |
3604 | x = car (args); |
3602 | |
3605 | |
3603 | if (car (x) == SCHEME_V->LAMBDA) |
3606 | if (car (x) == SCHEME_V->LAMBDA) |
… | |
… | |
4631 | } |
4634 | } |
4632 | else |
4635 | else |
4633 | s_return (SCHEME_V->code); |
4636 | s_return (SCHEME_V->code); |
4634 | |
4637 | |
4635 | case OP_SAVE_FORCED: /* Save forced value replacing promise */ |
4638 | case OP_SAVE_FORCED: /* Save forced value replacing promise */ |
4636 | memcpy (SCHEME_V->code, SCHEME_V->value, sizeof (struct cell)); |
4639 | *CELL (SCHEME_V->code) = *CELL (SCHEME_V->value); |
4637 | s_return (SCHEME_V->value); |
4640 | s_return (SCHEME_V->value); |
4638 | |
4641 | |
4639 | #if USE_PORTS |
4642 | #if USE_PORTS |
4640 | |
4643 | |
4641 | case OP_WRITE: /* write */ |
4644 | case OP_WRITE: /* write */ |
… | |
… | |
4786 | SCHEME_V->gc_verbose = (a != S_F); |
4789 | SCHEME_V->gc_verbose = (a != S_F); |
4787 | s_retbool (was); |
4790 | s_retbool (was); |
4788 | } |
4791 | } |
4789 | |
4792 | |
4790 | case OP_NEWSEGMENT: /* new-segment */ |
4793 | case OP_NEWSEGMENT: /* new-segment */ |
|
|
4794 | #if 0 |
4791 | if (!is_pair (args) || !is_number (a)) |
4795 | if (!is_pair (args) || !is_number (a)) |
4792 | Error_0 ("new-segment: argument must be a number"); |
4796 | Error_0 ("new-segment: argument must be a number"); |
4793 | |
4797 | #endif |
4794 | alloc_cellseg (SCHEME_A_ ivalue (a)); |
4798 | s_retbool (alloc_cellseg (SCHEME_A)); |
4795 | |
|
|
4796 | s_return (S_T); |
|
|
4797 | |
4799 | |
4798 | case OP_OBLIST: /* oblist */ |
4800 | case OP_OBLIST: /* oblist */ |
4799 | s_return (oblist_all_symbols (SCHEME_A)); |
4801 | s_return (oblist_all_symbols (SCHEME_A)); |
4800 | |
4802 | |
4801 | #if USE_PORTS |
4803 | #if USE_PORTS |
… | |
… | |
4871 | s_return (p == NIL ? S_F : p); |
4873 | s_return (p == NIL ? S_F : p); |
4872 | } |
4874 | } |
4873 | |
4875 | |
4874 | case OP_GET_OUTSTRING: /* get-output-string */ |
4876 | case OP_GET_OUTSTRING: /* get-output-string */ |
4875 | { |
4877 | { |
4876 | port *p; |
4878 | port *p = port (a); |
4877 | |
4879 | |
4878 | if ((p = a->object.port)->kind & port_string) |
4880 | if (p->kind & port_string) |
4879 | { |
4881 | { |
4880 | off_t size; |
4882 | off_t size; |
4881 | char *str; |
4883 | char *str; |
4882 | |
4884 | |
4883 | size = p->rep.string.curr - p->rep.string.start + 1; |
4885 | size = p->rep.string.curr - p->rep.string.start + 1; |
… | |
… | |
4988 | int res; |
4990 | int res; |
4989 | |
4991 | |
4990 | if (is_pair (args)) |
4992 | if (is_pair (args)) |
4991 | p = car (args); |
4993 | p = car (args); |
4992 | |
4994 | |
4993 | res = p->object.port->kind & port_string; |
4995 | res = port (p)->kind & port_string; |
4994 | |
4996 | |
4995 | s_retbool (res); |
4997 | s_retbool (res); |
4996 | } |
4998 | } |
4997 | |
4999 | |
4998 | case OP_SET_INPORT: /* set-input-port */ |
5000 | case OP_SET_INPORT: /* set-input-port */ |
… | |
… | |
5538 | if (ecb_expect_false (dispatch_funcs [pcd->func] (SCHEME_A_ SCHEME_V->op) != 0)) |
5540 | if (ecb_expect_false (dispatch_funcs [pcd->func] (SCHEME_A_ SCHEME_V->op) != 0)) |
5539 | return; |
5541 | return; |
5540 | |
5542 | |
5541 | if (SCHEME_V->no_memory && USE_ERROR_CHECKING) |
5543 | if (SCHEME_V->no_memory && USE_ERROR_CHECKING) |
5542 | { |
5544 | { |
5543 | xwrstr ("No memory!\n"); |
5545 | putstr (SCHEME_A_ "No memory!\n"); |
5544 | return; |
5546 | return; |
5545 | } |
5547 | } |
5546 | } |
5548 | } |
5547 | } |
5549 | } |
5548 | |
5550 | |
… | |
… | |
5661 | ecb_cold int |
5663 | ecb_cold int |
5662 | scheme_init (SCHEME_P) |
5664 | scheme_init (SCHEME_P) |
5663 | { |
5665 | { |
5664 | int i, n = sizeof (dispatch_table) / sizeof (dispatch_table[0]); |
5666 | int i, n = sizeof (dispatch_table) / sizeof (dispatch_table[0]); |
5665 | pointer x; |
5667 | pointer x; |
|
|
5668 | |
|
|
5669 | /* this memset is not strictly correct, as we assume (intcache) |
|
|
5670 | * that memset 0 will also set pointers to 0, but memset does |
|
|
5671 | * of course not guarantee that. screw such systems. |
|
|
5672 | */ |
|
|
5673 | memset (SCHEME_V, 0, sizeof (*SCHEME_V)); |
5666 | |
5674 | |
5667 | num_set_fixnum (num_zero, 1); |
5675 | num_set_fixnum (num_zero, 1); |
5668 | num_set_ivalue (num_zero, 0); |
5676 | num_set_ivalue (num_zero, 0); |
5669 | num_set_fixnum (num_one, 1); |
5677 | num_set_fixnum (num_one, 1); |
5670 | num_set_ivalue (num_one, 1); |
5678 | num_set_ivalue (num_one, 1); |
… | |
… | |
5682 | SCHEME_V->save_inport = NIL; |
5690 | SCHEME_V->save_inport = NIL; |
5683 | SCHEME_V->loadport = NIL; |
5691 | SCHEME_V->loadport = NIL; |
5684 | SCHEME_V->nesting = 0; |
5692 | SCHEME_V->nesting = 0; |
5685 | SCHEME_V->interactive_repl = 0; |
5693 | SCHEME_V->interactive_repl = 0; |
5686 | |
5694 | |
5687 | if (alloc_cellseg (SCHEME_A_ FIRST_CELLSEGS) != FIRST_CELLSEGS) |
5695 | if (!alloc_cellseg (SCHEME_A)) |
5688 | { |
5696 | { |
5689 | #if USE_ERROR_CHECKING |
5697 | #if USE_ERROR_CHECKING |
5690 | SCHEME_V->no_memory = 1; |
5698 | SCHEME_V->no_memory = 1; |
5691 | return 0; |
5699 | return 0; |
5692 | #endif |
5700 | #endif |
… | |
… | |
6026 | int isfile = 1; |
6034 | int isfile = 1; |
6027 | system ("ps v $PPID");//D |
6035 | system ("ps v $PPID");//D |
6028 | |
6036 | |
6029 | if (argc == 2 && strcmp (argv[1], "-?") == 0) |
6037 | if (argc == 2 && strcmp (argv[1], "-?") == 0) |
6030 | { |
6038 | { |
6031 | xwrstr ("Usage: tinyscheme -?\n"); |
6039 | putstr (SCHEME_A_ "Usage: tinyscheme -?\n"); |
6032 | xwrstr ("or: tinyscheme [<file1> <file2> ...]\n"); |
6040 | putstr (SCHEME_A_ "or: tinyscheme [<file1> <file2> ...]\n"); |
6033 | xwrstr ("followed by\n"); |
6041 | putstr (SCHEME_A_ "followed by\n"); |
6034 | xwrstr (" -1 <file> [<arg1> <arg2> ...]\n"); |
6042 | putstr (SCHEME_A_ " -1 <file> [<arg1> <arg2> ...]\n"); |
6035 | xwrstr (" -c <Scheme commands> [<arg1> <arg2> ...]\n"); |
6043 | putstr (SCHEME_A_ " -c <Scheme commands> [<arg1> <arg2> ...]\n"); |
6036 | xwrstr ("assuming that the executable is named tinyscheme.\n"); |
6044 | putstr (SCHEME_A_ "assuming that the executable is named tinyscheme.\n"); |
6037 | xwrstr ("Use - as filename for stdin.\n"); |
6045 | putstr (SCHEME_A_ "Use - as filename for stdin.\n"); |
6038 | return 1; |
6046 | return 1; |
6039 | } |
6047 | } |
6040 | |
6048 | |
6041 | if (!scheme_init (SCHEME_A)) |
6049 | if (!scheme_init (SCHEME_A)) |
6042 | { |
6050 | { |
6043 | xwrstr ("Could not initialize!\n"); |
6051 | putstr (SCHEME_A_ "Could not initialize!\n"); |
6044 | return 2; |
6052 | return 2; |
6045 | } |
6053 | } |
6046 | |
6054 | |
6047 | # if USE_PORTS |
6055 | # if USE_PORTS |
6048 | scheme_set_input_port_file (SCHEME_A_ STDIN_FILENO); |
6056 | scheme_set_input_port_file (SCHEME_A_ STDIN_FILENO); |
… | |
… | |
6093 | fin = open (file_name, O_RDONLY); |
6101 | fin = open (file_name, O_RDONLY); |
6094 | #endif |
6102 | #endif |
6095 | |
6103 | |
6096 | if (isfile && fin < 0) |
6104 | if (isfile && fin < 0) |
6097 | { |
6105 | { |
6098 | xwrstr ("Could not open file "); xwrstr (file_name); xwrstr ("\n"); |
6106 | putstr (SCHEME_A_ "Could not open file "); putstr (SCHEME_A_ file_name); putstr (SCHEME_A_ "\n"); |
6099 | } |
6107 | } |
6100 | else |
6108 | else |
6101 | { |
6109 | { |
6102 | if (isfile) |
6110 | if (isfile) |
6103 | scheme_load_named_file (SCHEME_A_ fin, file_name); |
6111 | scheme_load_named_file (SCHEME_A_ fin, file_name); |
… | |
… | |
6107 | #if USE_PORTS |
6115 | #if USE_PORTS |
6108 | if (!isfile || fin != STDIN_FILENO) |
6116 | if (!isfile || fin != STDIN_FILENO) |
6109 | { |
6117 | { |
6110 | if (SCHEME_V->retcode != 0) |
6118 | if (SCHEME_V->retcode != 0) |
6111 | { |
6119 | { |
6112 | xwrstr ("Errors encountered reading "); xwrstr (file_name); xwrstr ("\n"); |
6120 | putstr (SCHEME_A_ "Errors encountered reading "); putstr (SCHEME_A_ file_name); putstr (SCHEME_A_ "\n"); |
6113 | } |
6121 | } |
6114 | |
6122 | |
6115 | if (isfile) |
6123 | if (isfile) |
6116 | close (fin); |
6124 | close (fin); |
6117 | } |
6125 | } |