… | |
… | |
16 | * (MINISCM) This is a revised and modified version by Akira KIDA. |
16 | * (MINISCM) This is a revised and modified version by Akira KIDA. |
17 | * (MINISCM) current version is 0.85k4 (15 May 1994) |
17 | * (MINISCM) current version is 0.85k4 (15 May 1994) |
18 | * |
18 | * |
19 | */ |
19 | */ |
20 | |
20 | |
|
|
21 | #define EXPERIMENT 1 |
|
|
22 | |
|
|
23 | #if 1 |
21 | #define PAGE_SIZE 4096 /* does not work on sparc/alpha */ |
24 | #define PAGE_SIZE 4096 /* does not work on sparc/alpha */ |
22 | #include "malloc.c" |
25 | #include "malloc.c" |
|
|
26 | #endif |
23 | |
27 | |
24 | #define SCHEME_SOURCE |
28 | #define SCHEME_SOURCE |
25 | #include "scheme-private.h" |
29 | #include "scheme-private.h" |
26 | #ifndef WIN32 |
30 | #ifndef WIN32 |
27 | # include <unistd.h> |
31 | # include <unistd.h> |
… | |
… | |
74 | TOK_SHARP_CONST, |
78 | TOK_SHARP_CONST, |
75 | TOK_VEC |
79 | TOK_VEC |
76 | }; |
80 | }; |
77 | |
81 | |
78 | #define BACKQUOTE '`' |
82 | #define BACKQUOTE '`' |
79 | #define DELIMITERS "()\";\f\t\v\n\r " |
83 | #define WHITESPACE " \t\r\n\v\f" |
|
|
84 | #define DELIMITERS "()\";" WHITESPACE |
80 | |
85 | |
81 | #define NIL (&SCHEME_V->xNIL) //TODO: make this 0? |
86 | #define NIL POINTER (&SCHEME_V->xNIL) |
82 | #define S_T (&SCHEME_V->xT) //TODO: magic ptr value? |
87 | #define S_T POINTER (&SCHEME_V->xT) |
83 | #define S_F (&SCHEME_V->xF) //TODO: magic ptr value? |
88 | #define S_F POINTER (&SCHEME_V->xF) |
84 | #define S_SINK (&SCHEME_V->xsink) |
89 | #define S_SINK POINTER (&SCHEME_V->xsink) |
85 | #define S_EOF (&SCHEME_V->xEOF_OBJ) |
90 | #define S_EOF POINTER (&SCHEME_V->xEOF_OBJ) |
86 | |
91 | |
87 | #if !USE_MULTIPLICITY |
92 | #if !USE_MULTIPLICITY |
88 | static scheme sc; |
93 | static scheme sc; |
89 | #endif |
94 | #endif |
90 | |
95 | |
… | |
… | |
189 | # define prompt "ts> " |
194 | # define prompt "ts> " |
190 | #endif |
195 | #endif |
191 | |
196 | |
192 | #ifndef InitFile |
197 | #ifndef InitFile |
193 | # define InitFile "init.scm" |
198 | # define InitFile "init.scm" |
194 | #endif |
|
|
195 | |
|
|
196 | #ifndef FIRST_CELLSEGS |
|
|
197 | # define FIRST_CELLSEGS 3 |
|
|
198 | #endif |
199 | #endif |
199 | |
200 | |
200 | enum scheme_types |
201 | enum scheme_types |
201 | { |
202 | { |
202 | T_INTEGER, |
203 | T_INTEGER, |
… | |
… | |
263 | static int is_zero_rvalue (RVALUE x); |
264 | static int is_zero_rvalue (RVALUE x); |
264 | |
265 | |
265 | static num num_zero; |
266 | static num num_zero; |
266 | static num num_one; |
267 | static num num_one; |
267 | |
268 | |
|
|
269 | /* convert "pointer" to cell* / cell* to pointer */ |
|
|
270 | #define CELL(p) ((struct cell *)(p) + 0) |
|
|
271 | #define POINTER(c) ((void *)((c) - 0)) |
|
|
272 | |
268 | /* macros for cell operations */ |
273 | /* macros for cell operations */ |
269 | #define typeflag(p) ((p)->flag + 0) |
274 | #define typeflag(p) (CELL(p)->flag + 0) |
270 | #define set_typeflag(p,v) ((p)->flag = (v)) |
275 | #define set_typeflag(p,v) (CELL(p)->flag = (v)) |
271 | #define type(p) (typeflag (p) & T_MASKTYPE) |
276 | #define type(p) (typeflag (p) & T_MASKTYPE) |
272 | |
277 | |
273 | INTERFACE int |
278 | INTERFACE int |
274 | is_string (pointer p) |
279 | is_string (pointer p) |
275 | { |
280 | { |
276 | return type (p) == T_STRING; |
281 | return type (p) == T_STRING; |
277 | } |
282 | } |
278 | |
283 | |
279 | #define strvalue(p) ((p)->object.string.svalue) |
284 | #define strvalue(p) (CELL(p)->object.string.svalue) |
280 | #define strlength(p) ((p)->object.string.length) |
285 | #define strlength(p) (CELL(p)->object.string.length) |
281 | |
286 | |
282 | INTERFACE int |
287 | INTERFACE int |
283 | is_vector (pointer p) |
288 | is_vector (pointer p) |
284 | { |
289 | { |
285 | return type (p) == T_VECTOR; |
290 | return type (p) == T_VECTOR; |
286 | } |
291 | } |
287 | |
292 | |
288 | #define vecvalue(p) ((p)->object.vector.vvalue) |
293 | #define vecvalue(p) (CELL(p)->object.vector.vvalue) |
289 | #define veclength(p) ((p)->object.vector.length) |
294 | #define veclength(p) (CELL(p)->object.vector.length) |
290 | INTERFACE void fill_vector (pointer vec, uint32_t start, pointer obj); |
295 | INTERFACE void fill_vector (pointer vec, uint32_t start, pointer obj); |
291 | INTERFACE pointer vector_get (pointer vec, uint32_t ielem); |
296 | INTERFACE pointer vector_get (pointer vec, uint32_t ielem); |
292 | INTERFACE void vector_set (pointer vec, uint32_t ielem, pointer a); |
297 | INTERFACE void vector_set (pointer vec, uint32_t ielem, pointer a); |
293 | |
298 | |
294 | INTERFACE int |
299 | INTERFACE int |
… | |
… | |
320 | string_value (pointer p) |
325 | string_value (pointer p) |
321 | { |
326 | { |
322 | return strvalue (p); |
327 | return strvalue (p); |
323 | } |
328 | } |
324 | |
329 | |
325 | #define ivalue_unchecked(p) (p)->object.ivalue |
330 | #define ivalue_unchecked(p) CELL(p)->object.ivalue |
326 | #define set_ivalue(p,v) (p)->object.ivalue = (v) |
331 | #define set_ivalue(p,v) CELL(p)->object.ivalue = (v) |
327 | |
332 | |
328 | #if USE_REAL |
333 | #if USE_REAL |
329 | #define rvalue_unchecked(p) (p)->object.rvalue |
334 | #define rvalue_unchecked(p) CELL(p)->object.rvalue |
330 | #define set_rvalue(p,v) (p)->object.rvalue = (v) |
335 | #define set_rvalue(p,v) CELL(p)->object.rvalue = (v) |
331 | #else |
336 | #else |
332 | #define rvalue_unchecked(p) (p)->object.ivalue |
337 | #define rvalue_unchecked(p) CELL(p)->object.ivalue |
333 | #define set_rvalue(p,v) (p)->object.ivalue = (v) |
338 | #define set_rvalue(p,v) CELL(p)->object.ivalue = (v) |
334 | #endif |
339 | #endif |
335 | |
340 | |
336 | INTERFACE long |
341 | INTERFACE long |
337 | charvalue (pointer p) |
342 | charvalue (pointer p) |
338 | { |
343 | { |
339 | return ivalue_unchecked (p); |
344 | return ivalue_unchecked (p); |
340 | } |
345 | } |
341 | |
346 | |
|
|
347 | #define port(p) CELL(p)->object.port |
|
|
348 | #define set_port(p,v) port(p) = (v) |
342 | INTERFACE int |
349 | INTERFACE int |
343 | is_port (pointer p) |
350 | is_port (pointer p) |
344 | { |
351 | { |
345 | return type (p) == T_PORT; |
352 | return type (p) == T_PORT; |
346 | } |
353 | } |
347 | |
354 | |
348 | INTERFACE int |
355 | INTERFACE int |
349 | is_inport (pointer p) |
356 | is_inport (pointer p) |
350 | { |
357 | { |
351 | return is_port (p) && p->object.port->kind & port_input; |
358 | return is_port (p) && port (p)->kind & port_input; |
352 | } |
359 | } |
353 | |
360 | |
354 | INTERFACE int |
361 | INTERFACE int |
355 | is_outport (pointer p) |
362 | is_outport (pointer p) |
356 | { |
363 | { |
357 | return is_port (p) && p->object.port->kind & port_output; |
364 | return is_port (p) && port (p)->kind & port_output; |
358 | } |
365 | } |
359 | |
366 | |
360 | INTERFACE int |
367 | INTERFACE int |
361 | is_pair (pointer p) |
368 | is_pair (pointer p) |
362 | { |
369 | { |
363 | return type (p) == T_PAIR; |
370 | return type (p) == T_PAIR; |
364 | } |
371 | } |
365 | |
372 | |
366 | #define car(p) ((p)->object.cons.car + 0) |
373 | #define car(p) (POINTER (CELL(p)->object.cons.car)) |
367 | #define cdr(p) ((p)->object.cons.cdr + 0) |
374 | #define cdr(p) (POINTER (CELL(p)->object.cons.cdr)) |
368 | |
375 | |
369 | static pointer caar (pointer p) { return car (car (p)); } |
376 | static pointer caar (pointer p) { return car (car (p)); } |
370 | static pointer cadr (pointer p) { return car (cdr (p)); } |
377 | static pointer cadr (pointer p) { return car (cdr (p)); } |
371 | static pointer cdar (pointer p) { return cdr (car (p)); } |
378 | static pointer cdar (pointer p) { return cdr (car (p)); } |
372 | static pointer cddr (pointer p) { return cdr (cdr (p)); } |
379 | static pointer cddr (pointer p) { return cdr (cdr (p)); } |
… | |
… | |
376 | static pointer cdaar (pointer p) { return cdr (car (car (p))); } |
383 | static pointer cdaar (pointer p) { return cdr (car (car (p))); } |
377 | |
384 | |
378 | INTERFACE void |
385 | INTERFACE void |
379 | set_car (pointer p, pointer q) |
386 | set_car (pointer p, pointer q) |
380 | { |
387 | { |
381 | p->object.cons.car = q; |
388 | CELL(p)->object.cons.car = CELL (q); |
382 | } |
389 | } |
383 | |
390 | |
384 | INTERFACE void |
391 | INTERFACE void |
385 | set_cdr (pointer p, pointer q) |
392 | set_cdr (pointer p, pointer q) |
386 | { |
393 | { |
387 | p->object.cons.cdr = q; |
394 | CELL(p)->object.cons.cdr = CELL (q); |
388 | } |
395 | } |
389 | |
396 | |
390 | INTERFACE pointer |
397 | INTERFACE pointer |
391 | pair_car (pointer p) |
398 | pair_car (pointer p) |
392 | { |
399 | { |
… | |
… | |
406 | } |
413 | } |
407 | |
414 | |
408 | INTERFACE char * |
415 | INTERFACE char * |
409 | symname (pointer p) |
416 | symname (pointer p) |
410 | { |
417 | { |
411 | return strvalue (car (p)); |
418 | return strvalue (p); |
412 | } |
419 | } |
413 | |
420 | |
414 | #if USE_PLIST |
421 | #if USE_PLIST |
|
|
422 | #error plists are broken because symbols are no longer pairs |
|
|
423 | #define symprop(p) cdr(p) |
415 | SCHEME_EXPORT int |
424 | SCHEME_EXPORT int |
416 | hasprop (pointer p) |
425 | hasprop (pointer p) |
417 | { |
426 | { |
418 | return typeflag (p) & T_SYMBOL; |
427 | return typeflag (p) & T_SYMBOL; |
419 | } |
428 | } |
420 | |
|
|
421 | # define symprop(p) cdr(p) |
|
|
422 | #endif |
429 | #endif |
423 | |
430 | |
424 | INTERFACE int |
431 | INTERFACE int |
425 | is_syntax (pointer p) |
432 | is_syntax (pointer p) |
426 | { |
433 | { |
… | |
… | |
440 | } |
447 | } |
441 | |
448 | |
442 | INTERFACE char * |
449 | INTERFACE char * |
443 | syntaxname (pointer p) |
450 | syntaxname (pointer p) |
444 | { |
451 | { |
445 | return strvalue (car (p)); |
452 | return strvalue (p); |
446 | } |
453 | } |
447 | |
454 | |
448 | #define procnum(p) ivalue_unchecked (p) |
455 | #define procnum(p) ivalue_unchecked (p) |
449 | static const char *procname (pointer x); |
456 | static const char *procname (pointer x); |
450 | |
457 | |
… | |
… | |
667 | |
674 | |
668 | static int file_push (SCHEME_P_ const char *fname); |
675 | static int file_push (SCHEME_P_ const char *fname); |
669 | static void file_pop (SCHEME_P); |
676 | static void file_pop (SCHEME_P); |
670 | static int file_interactive (SCHEME_P); |
677 | static int file_interactive (SCHEME_P); |
671 | ecb_inline int is_one_of (const char *s, int c); |
678 | ecb_inline int is_one_of (const char *s, int c); |
672 | static int alloc_cellseg (SCHEME_P_ int n); |
679 | static int alloc_cellseg (SCHEME_P); |
673 | ecb_inline pointer get_cell (SCHEME_P_ pointer a, pointer b); |
680 | ecb_inline pointer get_cell (SCHEME_P_ pointer a, pointer b); |
674 | static void finalize_cell (SCHEME_P_ pointer a); |
681 | static void finalize_cell (SCHEME_P_ pointer a); |
675 | static int count_consecutive_cells (pointer x, int needed); |
682 | static int count_consecutive_cells (pointer x, int needed); |
676 | static pointer find_slot_in_env (SCHEME_P_ pointer env, pointer sym, int all); |
683 | static pointer find_slot_in_env (SCHEME_P_ pointer env, pointer sym, int all); |
677 | static pointer mk_number (SCHEME_P_ const num n); |
684 | static pointer mk_number (SCHEME_P_ const num n); |
… | |
… | |
911 | #endif |
918 | #endif |
912 | } |
919 | } |
913 | |
920 | |
914 | /* allocate new cell segment */ |
921 | /* allocate new cell segment */ |
915 | static int |
922 | static int |
916 | alloc_cellseg (SCHEME_P_ int n) |
923 | alloc_cellseg (SCHEME_P) |
917 | { |
924 | { |
918 | pointer newp; |
925 | struct cell *newp; |
919 | pointer last; |
926 | struct cell *last; |
920 | pointer p; |
927 | struct cell *p; |
921 | char *cp; |
928 | char *cp; |
922 | long i; |
929 | long i; |
923 | int k; |
930 | int k; |
924 | |
931 | |
925 | static int segsize = CELL_SEGSIZE >> 1; |
932 | static int segsize = CELL_SEGSIZE >> 1; |
926 | segsize <<= 1; |
933 | segsize <<= 1; |
927 | |
934 | |
928 | for (k = 0; k < n; k++) |
|
|
929 | { |
|
|
930 | if (SCHEME_V->last_cell_seg >= CELL_NSEGMENT - 1) |
|
|
931 | return k; |
|
|
932 | |
|
|
933 | cp = malloc (segsize * sizeof (struct cell)); |
935 | cp = malloc (segsize * sizeof (struct cell)); |
934 | |
936 | |
935 | if (!cp && USE_ERROR_CHECKING) |
937 | if (!cp && USE_ERROR_CHECKING) |
936 | return k; |
938 | return k; |
937 | |
939 | |
938 | i = ++SCHEME_V->last_cell_seg; |
940 | i = ++SCHEME_V->last_cell_seg; |
939 | SCHEME_V->alloc_seg[i] = cp; |
941 | SCHEME_V->alloc_seg[i] = cp; |
940 | |
942 | |
941 | newp = (pointer)cp; |
943 | newp = (struct cell *)cp; |
942 | SCHEME_V->cell_seg[i] = newp; |
944 | SCHEME_V->cell_seg[i] = newp; |
943 | SCHEME_V->cell_segsize[i] = segsize; |
945 | SCHEME_V->cell_segsize[i] = segsize; |
944 | SCHEME_V->fcells += segsize; |
946 | SCHEME_V->fcells += segsize; |
945 | last = newp + segsize - 1; |
947 | last = newp + segsize - 1; |
946 | |
948 | |
947 | for (p = newp; p <= last; p++) |
949 | for (p = newp; p <= last; p++) |
948 | { |
950 | { |
|
|
951 | pointer cp = POINTER (p); |
949 | set_typeflag (p, T_PAIR); |
952 | set_typeflag (cp, T_PAIR); |
950 | set_car (p, NIL); |
953 | set_car (cp, NIL); |
951 | set_cdr (p, p + 1); |
954 | set_cdr (cp, POINTER (p + 1)); |
952 | } |
955 | } |
953 | |
956 | |
954 | set_cdr (last, SCHEME_V->free_cell); |
957 | set_cdr (POINTER (last), SCHEME_V->free_cell); |
955 | SCHEME_V->free_cell = newp; |
958 | SCHEME_V->free_cell = POINTER (newp); |
956 | } |
|
|
957 | |
959 | |
958 | return n; |
960 | return 1; |
959 | } |
961 | } |
960 | |
962 | |
961 | /* get new cell. parameter a, b is marked by gc. */ |
963 | /* get new cell. parameter a, b is marked by gc. */ |
962 | ecb_inline pointer |
964 | ecb_inline pointer |
963 | get_cell_x (SCHEME_P_ pointer a, pointer b) |
965 | get_cell_x (SCHEME_P_ pointer a, pointer b) |
… | |
… | |
967 | if (SCHEME_V->no_memory && USE_ERROR_CHECKING) |
969 | if (SCHEME_V->no_memory && USE_ERROR_CHECKING) |
968 | return S_SINK; |
970 | return S_SINK; |
969 | |
971 | |
970 | if (SCHEME_V->free_cell == NIL) |
972 | if (SCHEME_V->free_cell == NIL) |
971 | { |
973 | { |
972 | const int min_to_be_recovered = SCHEME_V->last_cell_seg < 128 ? 128 * 8 : SCHEME_V->last_cell_seg * 8; |
974 | const int min_to_be_recovered = SCHEME_V->cell_segsize [SCHEME_V->last_cell_seg] >> 1; |
973 | |
975 | |
974 | gc (SCHEME_A_ a, b); |
976 | gc (SCHEME_A_ a, b); |
975 | |
977 | |
976 | if (SCHEME_V->fcells < min_to_be_recovered || SCHEME_V->free_cell == NIL) |
978 | if (SCHEME_V->fcells < min_to_be_recovered || SCHEME_V->free_cell == NIL) |
977 | { |
979 | { |
978 | /* if only a few recovered, get more to avoid fruitless gc's */ |
980 | /* if only a few recovered, get more to avoid fruitless gc's */ |
979 | if (!alloc_cellseg (SCHEME_A_ 1) && SCHEME_V->free_cell == NIL) |
981 | if (!alloc_cellseg (SCHEME_A) && SCHEME_V->free_cell == NIL) |
980 | { |
982 | { |
981 | #if USE_ERROR_CHECKING |
983 | #if USE_ERROR_CHECKING |
982 | SCHEME_V->no_memory = 1; |
984 | SCHEME_V->no_memory = 1; |
983 | return S_SINK; |
985 | return S_SINK; |
984 | #endif |
986 | #endif |
… | |
… | |
996 | } |
998 | } |
997 | } |
999 | } |
998 | |
1000 | |
999 | /* To retain recent allocs before interpreter knows about them - |
1001 | /* To retain recent allocs before interpreter knows about them - |
1000 | Tehom */ |
1002 | Tehom */ |
1001 | |
|
|
1002 | static void |
1003 | static void |
1003 | push_recent_alloc (SCHEME_P_ pointer recent, pointer extra) |
1004 | push_recent_alloc (SCHEME_P_ pointer recent, pointer extra) |
1004 | { |
1005 | { |
1005 | pointer holder = get_cell_x (SCHEME_A_ recent, extra); |
1006 | pointer holder = get_cell_x (SCHEME_A_ recent, extra); |
1006 | |
1007 | |
… | |
… | |
1028 | } |
1029 | } |
1029 | |
1030 | |
1030 | static pointer |
1031 | static pointer |
1031 | get_vector_object (SCHEME_P_ uint32_t len, pointer init) |
1032 | get_vector_object (SCHEME_P_ uint32_t len, pointer init) |
1032 | { |
1033 | { |
1033 | pointer v = get_cell_x (SCHEME_A_ 0, 0); |
1034 | pointer v = get_cell_x (SCHEME_A_ NIL, NIL); |
1034 | pointer *e = malloc (len * sizeof (pointer)); |
1035 | pointer *e = malloc (len * sizeof (pointer)); |
1035 | |
1036 | |
1036 | if (!e && USE_ERROR_CHECKING) |
1037 | if (!e && USE_ERROR_CHECKING) |
1037 | return S_SINK; |
1038 | return S_SINK; |
1038 | |
1039 | |
1039 | /* Record it as a vector so that gc understands it. */ |
1040 | /* Record it as a vector so that gc understands it. */ |
1040 | set_typeflag (v, T_VECTOR | T_ATOM); |
1041 | set_typeflag (v, T_VECTOR | T_ATOM); |
1041 | |
1042 | |
1042 | v->object.vector.vvalue = e; |
1043 | CELL(v)->object.vector.vvalue = e; |
1043 | v->object.vector.length = len; |
1044 | CELL(v)->object.vector.length = len; |
1044 | fill_vector (v, 0, init); |
1045 | fill_vector (v, 0, init); |
1045 | push_recent_alloc (SCHEME_A_ v, NIL); |
1046 | push_recent_alloc (SCHEME_A_ v, NIL); |
1046 | |
1047 | |
1047 | return v; |
1048 | return v; |
1048 | } |
1049 | } |
… | |
… | |
1092 | set_cdr (x, b); |
1093 | set_cdr (x, b); |
1093 | |
1094 | |
1094 | return x; |
1095 | return x; |
1095 | } |
1096 | } |
1096 | |
1097 | |
1097 | /* ========== oblist implementation ========== */ |
|
|
1098 | |
|
|
1099 | static pointer |
1098 | static pointer |
1100 | generate_symbol (SCHEME_P_ const char *name) |
1099 | generate_symbol (SCHEME_P_ const char *name) |
1101 | { |
1100 | { |
1102 | pointer x = mk_string (SCHEME_A_ name); |
1101 | pointer x = mk_string (SCHEME_A_ name); |
1103 | setimmutable (x); |
1102 | setimmutable (x); |
1104 | x = immutable_cons (x, NIL); |
|
|
1105 | set_typeflag (x, T_SYMBOL); |
1103 | set_typeflag (x, T_SYMBOL | T_ATOM); |
1106 | return x; |
1104 | return x; |
1107 | } |
1105 | } |
|
|
1106 | |
|
|
1107 | /* ========== oblist implementation ========== */ |
1108 | |
1108 | |
1109 | #ifndef USE_OBJECT_LIST |
1109 | #ifndef USE_OBJECT_LIST |
1110 | |
1110 | |
1111 | static int |
1111 | static int |
1112 | hash_fn (const char *key, int table_size) |
1112 | hash_fn (const char *key, int table_size) |
… | |
… | |
1199 | |
1199 | |
1200 | /* returns the new symbol */ |
1200 | /* returns the new symbol */ |
1201 | static pointer |
1201 | static pointer |
1202 | oblist_add_by_name (SCHEME_P_ const char *name) |
1202 | oblist_add_by_name (SCHEME_P_ const char *name) |
1203 | { |
1203 | { |
1204 | pointer x = mk_string (SCHEME_A_ name); |
1204 | pointer x = generate_symbol (SCHEME_A_ name); |
1205 | set_typeflag (x, T_SYMBOL); |
|
|
1206 | setimmutable (x); |
|
|
1207 | SCHEME_V->oblist = immutable_cons (x, SCHEME_V->oblist); |
1205 | SCHEME_V->oblist = immutable_cons (x, SCHEME_V->oblist); |
1208 | return x; |
1206 | return x; |
1209 | } |
1207 | } |
1210 | |
1208 | |
1211 | static pointer |
1209 | static pointer |
… | |
… | |
1221 | mk_port (SCHEME_P_ port *p) |
1219 | mk_port (SCHEME_P_ port *p) |
1222 | { |
1220 | { |
1223 | pointer x = get_cell (SCHEME_A_ NIL, NIL); |
1221 | pointer x = get_cell (SCHEME_A_ NIL, NIL); |
1224 | |
1222 | |
1225 | set_typeflag (x, T_PORT | T_ATOM); |
1223 | set_typeflag (x, T_PORT | T_ATOM); |
1226 | x->object.port = p; |
1224 | set_port (x, p); |
1227 | |
1225 | |
1228 | return x; |
1226 | return x; |
1229 | } |
1227 | } |
1230 | #endif |
1228 | #endif |
1231 | |
1229 | |
1232 | pointer |
1230 | pointer |
1233 | mk_foreign_func (SCHEME_P_ foreign_func f) |
1231 | mk_foreign_func (SCHEME_P_ foreign_func f) |
1234 | { |
1232 | { |
1235 | pointer x = get_cell (SCHEME_A_ NIL, NIL); |
1233 | pointer x = get_cell (SCHEME_A_ NIL, NIL); |
1236 | |
1234 | |
1237 | set_typeflag (x, (T_FOREIGN | T_ATOM)); |
1235 | set_typeflag (x, T_FOREIGN | T_ATOM); |
1238 | x->object.ff = f; |
1236 | CELL(x)->object.ff = f; |
1239 | |
1237 | |
1240 | return x; |
1238 | return x; |
1241 | } |
1239 | } |
1242 | |
1240 | |
1243 | INTERFACE pointer |
1241 | INTERFACE pointer |
1244 | mk_character (SCHEME_P_ int c) |
1242 | mk_character (SCHEME_P_ int c) |
1245 | { |
1243 | { |
1246 | pointer x = get_cell (SCHEME_A_ NIL, NIL); |
1244 | pointer x = get_cell (SCHEME_A_ NIL, NIL); |
1247 | |
1245 | |
1248 | set_typeflag (x, (T_CHARACTER | T_ATOM)); |
1246 | set_typeflag (x, T_CHARACTER | T_ATOM); |
1249 | set_ivalue (x, c & 0xff); |
1247 | set_ivalue (x, c & 0xff); |
1250 | |
1248 | |
1251 | return x; |
1249 | return x; |
1252 | } |
1250 | } |
1253 | |
1251 | |
1254 | /* get number atom (integer) */ |
1252 | /* get number atom (integer) */ |
1255 | INTERFACE pointer |
1253 | INTERFACE pointer |
1256 | mk_integer (SCHEME_P_ long n) |
1254 | mk_integer (SCHEME_P_ long n) |
1257 | { |
1255 | { |
|
|
1256 | pointer p = 0; |
|
|
1257 | pointer *pp = &p; |
|
|
1258 | |
|
|
1259 | #if USE_INTCACHE |
|
|
1260 | if (n >= INTCACHE_MIN && n <= INTCACHE_MAX) |
|
|
1261 | pp = &SCHEME_V->intcache[n - INTCACHE_MIN]; |
|
|
1262 | #endif |
|
|
1263 | |
|
|
1264 | if (!*pp) |
|
|
1265 | { |
1258 | pointer x = get_cell (SCHEME_A_ NIL, NIL); |
1266 | pointer x = get_cell (SCHEME_A_ NIL, NIL); |
1259 | |
1267 | |
1260 | set_typeflag (x, (T_INTEGER | T_ATOM)); |
1268 | set_typeflag (x, T_INTEGER | T_ATOM); |
|
|
1269 | setimmutable (x); /* shouldn't do anythi9ng, doesn't cost anything */ |
1261 | set_ivalue (x, n); |
1270 | set_ivalue (x, n); |
1262 | |
1271 | |
|
|
1272 | *pp = x; |
|
|
1273 | } |
|
|
1274 | |
1263 | return x; |
1275 | return *pp; |
1264 | } |
1276 | } |
1265 | |
1277 | |
1266 | INTERFACE pointer |
1278 | INTERFACE pointer |
1267 | mk_real (SCHEME_P_ RVALUE n) |
1279 | mk_real (SCHEME_P_ RVALUE n) |
1268 | { |
1280 | { |
1269 | #if USE_REAL |
1281 | #if USE_REAL |
1270 | pointer x = get_cell (SCHEME_A_ NIL, NIL); |
1282 | pointer x = get_cell (SCHEME_A_ NIL, NIL); |
1271 | |
1283 | |
1272 | set_typeflag (x, (T_REAL | T_ATOM)); |
1284 | set_typeflag (x, T_REAL | T_ATOM); |
1273 | set_rvalue (x, n); |
1285 | set_rvalue (x, n); |
1274 | |
1286 | |
1275 | return x; |
1287 | return x; |
1276 | #else |
1288 | #else |
1277 | return mk_integer (SCHEME_A_ n); |
1289 | return mk_integer (SCHEME_A_ n); |
… | |
… | |
1354 | |
1366 | |
1355 | for (i = start; i < veclength (vec); i++) |
1367 | for (i = start; i < veclength (vec); i++) |
1356 | vecvalue (vec)[i] = obj; |
1368 | vecvalue (vec)[i] = obj; |
1357 | } |
1369 | } |
1358 | |
1370 | |
|
|
1371 | INTERFACE void |
|
|
1372 | vector_resize (pointer vec, uint32_t newsize, pointer fill) |
|
|
1373 | { |
|
|
1374 | uint32_t oldsize = veclength (vec); |
|
|
1375 | vecvalue (vec) = realloc (vecvalue (vec), newsize * sizeof (pointer)); |
|
|
1376 | veclength (vec) = newsize; |
|
|
1377 | fill_vector (vec, oldsize, fill); |
|
|
1378 | } |
|
|
1379 | |
1359 | INTERFACE pointer |
1380 | INTERFACE pointer |
1360 | vector_get (pointer vec, uint32_t ielem) |
1381 | vector_get (pointer vec, uint32_t ielem) |
1361 | { |
1382 | { |
1362 | return vecvalue(vec)[ielem]; |
1383 | return vecvalue(vec)[ielem]; |
1363 | } |
1384 | } |
… | |
… | |
1384 | INTERFACE pointer |
1405 | INTERFACE pointer |
1385 | gensym (SCHEME_P) |
1406 | gensym (SCHEME_P) |
1386 | { |
1407 | { |
1387 | pointer x; |
1408 | pointer x; |
1388 | char name[40] = "gensym-"; |
1409 | char name[40] = "gensym-"; |
1389 | xnum (name + 7, SCHEME_V->gensym_cnt); |
1410 | xnum (name + 7, ++SCHEME_V->gensym_cnt); |
1390 | |
1411 | |
1391 | return generate_symbol (SCHEME_A_ name); |
1412 | return generate_symbol (SCHEME_A_ name); |
|
|
1413 | } |
|
|
1414 | |
|
|
1415 | static int |
|
|
1416 | is_gensym (SCHEME_P_ pointer x) |
|
|
1417 | { |
|
|
1418 | return is_symbol (x) && oblist_find_by_name (SCHEME_A_ strvalue (x)) != x; |
1392 | } |
1419 | } |
1393 | |
1420 | |
1394 | /* make symbol or number atom from string */ |
1421 | /* make symbol or number atom from string */ |
1395 | static pointer |
1422 | static pointer |
1396 | mk_atom (SCHEME_P_ char *q) |
1423 | mk_atom (SCHEME_P_ char *q) |
… | |
… | |
1605 | |
1632 | |
1606 | /* garbage collection. parameter a, b is marked. */ |
1633 | /* garbage collection. parameter a, b is marked. */ |
1607 | static void |
1634 | static void |
1608 | gc (SCHEME_P_ pointer a, pointer b) |
1635 | gc (SCHEME_P_ pointer a, pointer b) |
1609 | { |
1636 | { |
1610 | pointer p; |
|
|
1611 | int i; |
1637 | int i; |
1612 | |
1638 | |
1613 | if (SCHEME_V->gc_verbose) |
1639 | if (SCHEME_V->gc_verbose) |
1614 | putstr (SCHEME_A_ "gc..."); |
1640 | putstr (SCHEME_A_ "gc..."); |
1615 | |
1641 | |
… | |
… | |
1631 | /* Mark recent objects the interpreter doesn't know about yet. */ |
1657 | /* Mark recent objects the interpreter doesn't know about yet. */ |
1632 | mark (car (S_SINK)); |
1658 | mark (car (S_SINK)); |
1633 | /* Mark any older stuff above nested C calls */ |
1659 | /* Mark any older stuff above nested C calls */ |
1634 | mark (SCHEME_V->c_nest); |
1660 | mark (SCHEME_V->c_nest); |
1635 | |
1661 | |
|
|
1662 | #if USE_INTCACHE |
|
|
1663 | /* mark intcache */ |
|
|
1664 | for (i = INTCACHE_MIN; i <= INTCACHE_MAX; ++i) |
|
|
1665 | if (SCHEME_V->intcache[i - INTCACHE_MIN]) |
|
|
1666 | mark (SCHEME_V->intcache[i - INTCACHE_MIN]); |
|
|
1667 | #endif |
|
|
1668 | |
1636 | /* mark variables a, b */ |
1669 | /* mark variables a, b */ |
1637 | mark (a); |
1670 | mark (a); |
1638 | mark (b); |
1671 | mark (b); |
1639 | |
1672 | |
1640 | /* garbage collect */ |
1673 | /* garbage collect */ |
1641 | clrmark (NIL); |
1674 | clrmark (NIL); |
1642 | SCHEME_V->fcells = 0; |
1675 | SCHEME_V->fcells = 0; |
1643 | SCHEME_V->free_cell = NIL; |
1676 | SCHEME_V->free_cell = NIL; |
1644 | |
1677 | |
1645 | /* free-list is kept sorted by address so as to maintain consecutive |
1678 | if (SCHEME_V->gc_verbose) |
1646 | ranges, if possible, for use with vectors. Here we scan the cells |
1679 | xwrstr ("freeing..."); |
1647 | (which are also kept sorted by address) downwards to build the |
1680 | |
1648 | free-list in sorted order. |
1681 | uint32_t total = 0; |
1649 | */ |
1682 | |
|
|
1683 | /* Here we scan the cells to build the free-list. */ |
1650 | for (i = SCHEME_V->last_cell_seg; i >= 0; i--) |
1684 | for (i = SCHEME_V->last_cell_seg; i >= 0; i--) |
1651 | { |
1685 | { |
1652 | p = SCHEME_V->cell_seg[i] + SCHEME_V->cell_segsize [i]; |
1686 | struct cell *end = SCHEME_V->cell_seg[i] + SCHEME_V->cell_segsize [i]; |
|
|
1687 | struct cell *p; |
|
|
1688 | total += SCHEME_V->cell_segsize [i]; |
1653 | |
1689 | |
1654 | while (--p >= SCHEME_V->cell_seg[i]) |
1690 | for (p = SCHEME_V->cell_seg[i]; p < end; ++p) |
1655 | { |
1691 | { |
|
|
1692 | pointer c = POINTER (p); |
|
|
1693 | |
1656 | if (is_mark (p)) |
1694 | if (is_mark (c)) |
1657 | clrmark (p); |
1695 | clrmark (c); |
1658 | else |
1696 | else |
1659 | { |
1697 | { |
1660 | /* reclaim cell */ |
1698 | /* reclaim cell */ |
1661 | if (typeflag (p) != T_PAIR) |
1699 | if (typeflag (c) != T_PAIR) |
1662 | { |
1700 | { |
1663 | finalize_cell (SCHEME_A_ p); |
1701 | finalize_cell (SCHEME_A_ c); |
1664 | set_typeflag (p, T_PAIR); |
1702 | set_typeflag (c, T_PAIR); |
1665 | set_car (p, NIL); |
1703 | set_car (c, NIL); |
1666 | } |
1704 | } |
1667 | |
1705 | |
1668 | ++SCHEME_V->fcells; |
1706 | ++SCHEME_V->fcells; |
1669 | set_cdr (p, SCHEME_V->free_cell); |
1707 | set_cdr (c, SCHEME_V->free_cell); |
1670 | SCHEME_V->free_cell = p; |
1708 | SCHEME_V->free_cell = c; |
1671 | } |
1709 | } |
1672 | } |
1710 | } |
1673 | } |
1711 | } |
1674 | |
1712 | |
1675 | if (SCHEME_V->gc_verbose) |
1713 | if (SCHEME_V->gc_verbose) |
1676 | { |
1714 | { |
1677 | xwrstr ("done: "); xwrnum (SCHEME_V->fcells); xwrstr (" cells were recovered.\n"); |
1715 | xwrstr ("done: "); xwrnum (SCHEME_V->fcells); xwrstr (" out of "); xwrnum (total); xwrstr (" cells were recovered.\n"); |
1678 | } |
1716 | } |
1679 | } |
1717 | } |
1680 | |
1718 | |
1681 | static void |
1719 | static void |
1682 | finalize_cell (SCHEME_P_ pointer a) |
1720 | finalize_cell (SCHEME_P_ pointer a) |
1683 | { |
1721 | { |
1684 | /* TODO, fast bitmap check? */ |
1722 | /* TODO, fast bitmap check? */ |
1685 | if (is_string (a)) |
1723 | if (is_string (a) || is_symbol (a)) |
1686 | free (strvalue (a)); |
1724 | free (strvalue (a)); |
1687 | else if (is_vector (a)) |
1725 | else if (is_vector (a)) |
1688 | free (vecvalue (a)); |
1726 | free (vecvalue (a)); |
1689 | #if USE_PORTS |
1727 | #if USE_PORTS |
1690 | else if (is_port (a)) |
1728 | else if (is_port (a)) |
1691 | { |
1729 | { |
1692 | if (a->object.port->kind & port_file && a->object.port->rep.stdio.closeit) |
1730 | if (port(a)->kind & port_file && port (a)->rep.stdio.closeit) |
1693 | port_close (SCHEME_A_ a, port_input | port_output); |
1731 | port_close (SCHEME_A_ a, port_input | port_output); |
1694 | |
1732 | |
1695 | free (a->object.port); |
1733 | free (port (a)); |
1696 | } |
1734 | } |
1697 | #endif |
1735 | #endif |
1698 | } |
1736 | } |
1699 | |
1737 | |
1700 | /* ========== Routines for Reading ========== */ |
1738 | /* ========== Routines for Reading ========== */ |
… | |
… | |
1716 | SCHEME_V->load_stack[SCHEME_V->file_i].unget = -1; |
1754 | SCHEME_V->load_stack[SCHEME_V->file_i].unget = -1; |
1717 | SCHEME_V->load_stack[SCHEME_V->file_i].kind = port_file | port_input; |
1755 | SCHEME_V->load_stack[SCHEME_V->file_i].kind = port_file | port_input; |
1718 | SCHEME_V->load_stack[SCHEME_V->file_i].rep.stdio.file = fin; |
1756 | SCHEME_V->load_stack[SCHEME_V->file_i].rep.stdio.file = fin; |
1719 | SCHEME_V->load_stack[SCHEME_V->file_i].rep.stdio.closeit = 1; |
1757 | SCHEME_V->load_stack[SCHEME_V->file_i].rep.stdio.closeit = 1; |
1720 | SCHEME_V->nesting_stack[SCHEME_V->file_i] = 0; |
1758 | SCHEME_V->nesting_stack[SCHEME_V->file_i] = 0; |
1721 | SCHEME_V->loadport->object.port = SCHEME_V->load_stack + SCHEME_V->file_i; |
1759 | set_port (SCHEME_V->loadport, SCHEME_V->load_stack + SCHEME_V->file_i); |
1722 | |
1760 | |
1723 | #if SHOW_ERROR_LINE |
1761 | #if SHOW_ERROR_LINE |
1724 | SCHEME_V->load_stack[SCHEME_V->file_i].rep.stdio.curr_line = 0; |
1762 | SCHEME_V->load_stack[SCHEME_V->file_i].rep.stdio.curr_line = 0; |
1725 | |
1763 | |
1726 | if (fname) |
1764 | if (fname) |
… | |
… | |
1743 | SCHEME_V->nesting = SCHEME_V->nesting_stack[SCHEME_V->file_i]; |
1781 | SCHEME_V->nesting = SCHEME_V->nesting_stack[SCHEME_V->file_i]; |
1744 | #if USE_PORTS |
1782 | #if USE_PORTS |
1745 | port_close (SCHEME_A_ SCHEME_V->loadport, port_input); |
1783 | port_close (SCHEME_A_ SCHEME_V->loadport, port_input); |
1746 | #endif |
1784 | #endif |
1747 | SCHEME_V->file_i--; |
1785 | SCHEME_V->file_i--; |
1748 | SCHEME_V->loadport->object.port = SCHEME_V->load_stack + SCHEME_V->file_i; |
1786 | set_port (SCHEME_V->loadport, SCHEME_V->load_stack + SCHEME_V->file_i); |
1749 | } |
1787 | } |
1750 | } |
1788 | } |
1751 | |
1789 | |
1752 | static int |
1790 | static int |
1753 | file_interactive (SCHEME_P) |
1791 | file_interactive (SCHEME_P) |
1754 | { |
1792 | { |
1755 | #if USE_PORTS |
1793 | #if USE_PORTS |
1756 | return SCHEME_V->file_i == 0 |
1794 | return SCHEME_V->file_i == 0 |
1757 | && SCHEME_V->load_stack[0].rep.stdio.file == STDIN_FILENO |
1795 | && SCHEME_V->load_stack[0].rep.stdio.file == STDIN_FILENO |
1758 | && (SCHEME_V->inport->object.port->kind & port_file); |
1796 | && (port (SCHEME_V->inport)->kind & port_file); |
1759 | #else |
1797 | #else |
1760 | return 0; |
1798 | return 0; |
1761 | #endif |
1799 | #endif |
1762 | } |
1800 | } |
1763 | |
1801 | |
… | |
… | |
1897 | } |
1935 | } |
1898 | |
1936 | |
1899 | static void |
1937 | static void |
1900 | port_close (SCHEME_P_ pointer p, int flag) |
1938 | port_close (SCHEME_P_ pointer p, int flag) |
1901 | { |
1939 | { |
1902 | port *pt = p->object.port; |
1940 | port *pt = port (p); |
1903 | |
1941 | |
1904 | pt->kind &= ~flag; |
1942 | pt->kind &= ~flag; |
1905 | |
1943 | |
1906 | if ((pt->kind & (port_input | port_output)) == 0) |
1944 | if ((pt->kind & (port_input | port_output)) == 0) |
1907 | { |
1945 | { |
… | |
… | |
1928 | /* get new character from input file */ |
1966 | /* get new character from input file */ |
1929 | static int |
1967 | static int |
1930 | inchar (SCHEME_P) |
1968 | inchar (SCHEME_P) |
1931 | { |
1969 | { |
1932 | int c; |
1970 | int c; |
1933 | port *pt; |
1971 | port *pt = port (SCHEME_V->inport); |
1934 | |
|
|
1935 | pt = SCHEME_V->inport->object.port; |
|
|
1936 | |
1972 | |
1937 | if (pt->kind & port_saw_EOF) |
1973 | if (pt->kind & port_saw_EOF) |
1938 | return EOF; |
1974 | return EOF; |
1939 | |
1975 | |
1940 | c = basic_inchar (pt); |
1976 | c = basic_inchar (pt); |
… | |
… | |
2007 | port *pt; |
2043 | port *pt; |
2008 | |
2044 | |
2009 | if (c == EOF) |
2045 | if (c == EOF) |
2010 | return; |
2046 | return; |
2011 | |
2047 | |
2012 | pt = SCHEME_V->inport->object.port; |
2048 | pt = port (SCHEME_V->inport); |
2013 | pt->unget = c; |
2049 | pt->unget = c; |
2014 | #else |
2050 | #else |
2015 | if (c == EOF) |
2051 | if (c == EOF) |
2016 | return; |
2052 | return; |
2017 | |
2053 | |
… | |
… | |
2045 | |
2081 | |
2046 | INTERFACE void |
2082 | INTERFACE void |
2047 | putstr (SCHEME_P_ const char *s) |
2083 | putstr (SCHEME_P_ const char *s) |
2048 | { |
2084 | { |
2049 | #if USE_PORTS |
2085 | #if USE_PORTS |
2050 | port *pt = SCHEME_V->outport->object.port; |
2086 | port *pt = port (SCHEME_V->outport); |
2051 | |
2087 | |
2052 | if (pt->kind & port_file) |
2088 | if (pt->kind & port_file) |
2053 | write (pt->rep.stdio.file, s, strlen (s)); |
2089 | write (pt->rep.stdio.file, s, strlen (s)); |
2054 | else |
2090 | else |
2055 | for (; *s; s++) |
2091 | for (; *s; s++) |
… | |
… | |
2065 | |
2101 | |
2066 | static void |
2102 | static void |
2067 | putchars (SCHEME_P_ const char *s, int len) |
2103 | putchars (SCHEME_P_ const char *s, int len) |
2068 | { |
2104 | { |
2069 | #if USE_PORTS |
2105 | #if USE_PORTS |
2070 | port *pt = SCHEME_V->outport->object.port; |
2106 | port *pt = port (SCHEME_V->outport); |
2071 | |
2107 | |
2072 | if (pt->kind & port_file) |
2108 | if (pt->kind & port_file) |
2073 | write (pt->rep.stdio.file, s, len); |
2109 | write (pt->rep.stdio.file, s, len); |
2074 | else |
2110 | else |
2075 | { |
2111 | { |
… | |
… | |
2089 | |
2125 | |
2090 | INTERFACE void |
2126 | INTERFACE void |
2091 | putcharacter (SCHEME_P_ int c) |
2127 | putcharacter (SCHEME_P_ int c) |
2092 | { |
2128 | { |
2093 | #if USE_PORTS |
2129 | #if USE_PORTS |
2094 | port *pt = SCHEME_V->outport->object.port; |
2130 | port *pt = port (SCHEME_V->outport); |
2095 | |
2131 | |
2096 | if (pt->kind & port_file) |
2132 | if (pt->kind & port_file) |
2097 | { |
2133 | { |
2098 | char cc = c; |
2134 | char cc = c; |
2099 | write (pt->rep.stdio.file, &cc, 1); |
2135 | write (pt->rep.stdio.file, &cc, 1); |
… | |
… | |
2256 | |
2292 | |
2257 | /* check c is in chars */ |
2293 | /* check c is in chars */ |
2258 | ecb_inline int |
2294 | ecb_inline int |
2259 | is_one_of (const char *s, int c) |
2295 | is_one_of (const char *s, int c) |
2260 | { |
2296 | { |
2261 | if (c == EOF) |
|
|
2262 | return 1; |
|
|
2263 | |
|
|
2264 | return !!strchr (s, c); |
2297 | return c == EOF || !!strchr (s, c); |
2265 | } |
2298 | } |
2266 | |
2299 | |
2267 | /* skip white characters */ |
2300 | /* skip white characters */ |
2268 | ecb_inline int |
2301 | ecb_inline int |
2269 | skipspace (SCHEME_P) |
2302 | skipspace (SCHEME_P) |
… | |
… | |
2271 | int c, curr_line = 0; |
2304 | int c, curr_line = 0; |
2272 | |
2305 | |
2273 | do |
2306 | do |
2274 | { |
2307 | { |
2275 | c = inchar (SCHEME_A); |
2308 | c = inchar (SCHEME_A); |
|
|
2309 | |
2276 | #if SHOW_ERROR_LINE |
2310 | #if SHOW_ERROR_LINE |
2277 | if (c == '\n') |
2311 | if (ecb_expect_false (c == '\n')) |
2278 | curr_line++; |
2312 | curr_line++; |
2279 | #endif |
2313 | #endif |
|
|
2314 | |
|
|
2315 | if (ecb_expect_false (c == EOF)) |
|
|
2316 | return c; |
2280 | } |
2317 | } |
2281 | while (c == ' ' || c == '\n' || c == '\r' || c == '\t'); |
2318 | while (is_one_of (WHITESPACE, c)); |
2282 | |
2319 | |
2283 | /* record it */ |
2320 | /* record it */ |
2284 | #if SHOW_ERROR_LINE |
2321 | #if SHOW_ERROR_LINE |
2285 | if (SCHEME_V->load_stack[SCHEME_V->file_i].kind & port_file) |
2322 | if (SCHEME_V->load_stack[SCHEME_V->file_i].kind & port_file) |
2286 | SCHEME_V->load_stack[SCHEME_V->file_i].rep.stdio.curr_line += curr_line; |
2323 | SCHEME_V->load_stack[SCHEME_V->file_i].rep.stdio.curr_line += curr_line; |
2287 | #endif |
2324 | #endif |
2288 | |
2325 | |
2289 | if (c != EOF) |
|
|
2290 | { |
|
|
2291 | backchar (SCHEME_A_ c); |
2326 | backchar (SCHEME_A_ c); |
2292 | return 1; |
2327 | return 1; |
2293 | } |
|
|
2294 | else |
|
|
2295 | return EOF; |
|
|
2296 | } |
2328 | } |
2297 | |
2329 | |
2298 | /* get token */ |
2330 | /* get token */ |
2299 | static int |
2331 | static int |
2300 | token (SCHEME_P) |
2332 | token (SCHEME_P) |
… | |
… | |
2316 | return TOK_RPAREN; |
2348 | return TOK_RPAREN; |
2317 | |
2349 | |
2318 | case '.': |
2350 | case '.': |
2319 | c = inchar (SCHEME_A); |
2351 | c = inchar (SCHEME_A); |
2320 | |
2352 | |
2321 | if (is_one_of (" \n\t", c)) |
2353 | if (is_one_of (WHITESPACE, c)) |
2322 | return TOK_DOT; |
2354 | return TOK_DOT; |
2323 | else |
2355 | else |
2324 | { |
2356 | { |
2325 | backchar (SCHEME_A_ c); |
2357 | backchar (SCHEME_A_ c); |
2326 | return TOK_DOTATOM; |
2358 | return TOK_DOTATOM; |
… | |
… | |
2467 | } |
2499 | } |
2468 | |
2500 | |
2469 | putcharacter (SCHEME_A_ '"'); |
2501 | putcharacter (SCHEME_A_ '"'); |
2470 | } |
2502 | } |
2471 | |
2503 | |
2472 | |
|
|
2473 | /* print atoms */ |
2504 | /* print atoms */ |
2474 | static void |
2505 | static void |
2475 | printatom (SCHEME_P_ pointer l, int f) |
2506 | printatom (SCHEME_P_ pointer l, int f) |
2476 | { |
2507 | { |
2477 | char *p; |
2508 | char *p; |
2478 | int len; |
2509 | int len; |
2479 | |
2510 | |
2480 | atom2str (SCHEME_A_ l, f, &p, &len); |
2511 | atom2str (SCHEME_A_ l, f, &p, &len); |
2481 | putchars (SCHEME_A_ p, len); |
2512 | putchars (SCHEME_A_ p, len); |
2482 | } |
2513 | } |
2483 | |
|
|
2484 | |
2514 | |
2485 | /* Uses internal buffer unless string pointer is already available */ |
2515 | /* Uses internal buffer unless string pointer is already available */ |
2486 | static void |
2516 | static void |
2487 | atom2str (SCHEME_P_ pointer l, int f, char **pp, int *plen) |
2517 | atom2str (SCHEME_P_ pointer l, int f, char **pp, int *plen) |
2488 | { |
2518 | { |
… | |
… | |
2649 | #endif |
2679 | #endif |
2650 | } |
2680 | } |
2651 | else if (is_continuation (l)) |
2681 | else if (is_continuation (l)) |
2652 | p = "#<CONTINUATION>"; |
2682 | p = "#<CONTINUATION>"; |
2653 | else |
2683 | else |
|
|
2684 | { |
|
|
2685 | #if USE_PRINTF |
|
|
2686 | p = SCHEME_V->strbuff; |
|
|
2687 | snprintf (p, STRBUFFSIZE, "#<ERROR %x>", (int)typeflag (l)); |
|
|
2688 | #else |
2654 | p = "#<ERROR>"; |
2689 | p = "#<ERROR>"; |
|
|
2690 | #endif |
|
|
2691 | } |
2655 | |
2692 | |
2656 | *pp = p; |
2693 | *pp = p; |
2657 | *plen = strlen (p); |
2694 | *plen = strlen (p); |
2658 | } |
2695 | } |
2659 | |
2696 | |
… | |
… | |
2929 | #endif /* USE_ALIST_ENV else */ |
2966 | #endif /* USE_ALIST_ENV else */ |
2930 | |
2967 | |
2931 | ecb_inline void |
2968 | ecb_inline void |
2932 | new_slot_in_env (SCHEME_P_ pointer variable, pointer value) |
2969 | new_slot_in_env (SCHEME_P_ pointer variable, pointer value) |
2933 | { |
2970 | { |
|
|
2971 | assert (is_symbol (variable));//TODO: bug in current-ws/OP_LET2 |
2934 | new_slot_spec_in_env (SCHEME_A_ SCHEME_V->envir, variable, value); |
2972 | new_slot_spec_in_env (SCHEME_A_ SCHEME_V->envir, variable, value); |
2935 | } |
2973 | } |
2936 | |
2974 | |
2937 | ecb_inline void |
2975 | ecb_inline void |
2938 | set_slot_in_env (SCHEME_P_ pointer slot, pointer value) |
2976 | set_slot_in_env (SCHEME_P_ pointer slot, pointer value) |
… | |
… | |
3039 | { |
3077 | { |
3040 | int nframes = (uintptr_t)SCHEME_V->dump; |
3078 | int nframes = (uintptr_t)SCHEME_V->dump; |
3041 | struct dump_stack_frame *next_frame; |
3079 | struct dump_stack_frame *next_frame; |
3042 | |
3080 | |
3043 | /* enough room for the next frame? */ |
3081 | /* enough room for the next frame? */ |
3044 | if (nframes >= SCHEME_V->dump_size) |
3082 | if (ecb_expect_false (nframes >= SCHEME_V->dump_size)) |
3045 | { |
3083 | { |
3046 | SCHEME_V->dump_size += STACK_GROWTH; |
3084 | SCHEME_V->dump_size += STACK_GROWTH; |
3047 | SCHEME_V->dump_base = realloc (SCHEME_V->dump_base, sizeof (struct dump_stack_frame) * SCHEME_V->dump_size); |
3085 | SCHEME_V->dump_base = realloc (SCHEME_V->dump_base, sizeof (struct dump_stack_frame) * SCHEME_V->dump_size); |
3048 | } |
3086 | } |
3049 | |
3087 | |
… | |
… | |
3230 | |
3268 | |
3231 | #endif |
3269 | #endif |
3232 | |
3270 | |
3233 | #define s_retbool(tf) s_return ((tf) ? S_T : S_F) |
3271 | #define s_retbool(tf) s_return ((tf) ? S_T : S_F) |
3234 | |
3272 | |
|
|
3273 | #if EXPERIMENT |
|
|
3274 | static int |
|
|
3275 | debug (SCHEME_P_ int indent, pointer x) |
|
|
3276 | { |
|
|
3277 | int c; |
|
|
3278 | |
|
|
3279 | if (is_syntax (x)) |
|
|
3280 | { |
|
|
3281 | printf ("%*ssyntax<%s,%d>\n", indent, "", syntaxname(x),syntaxnum(x)); |
|
|
3282 | return 8 + 8; |
|
|
3283 | } |
|
|
3284 | |
|
|
3285 | if (x == NIL) |
|
|
3286 | { |
|
|
3287 | printf ("%*sNIL\n", indent, ""); |
|
|
3288 | return 3; |
|
|
3289 | } |
|
|
3290 | |
|
|
3291 | switch (type (x)) |
|
|
3292 | { |
|
|
3293 | case T_INTEGER: |
|
|
3294 | printf ("%*sI<%d>%p\n", indent, "", (int)ivalue_unchecked (x), x); |
|
|
3295 | return 32+8; |
|
|
3296 | |
|
|
3297 | case T_SYMBOL: |
|
|
3298 | printf ("%*sS<%s>\n", indent, "", symname (x)); |
|
|
3299 | return 24+8; |
|
|
3300 | |
|
|
3301 | case T_CLOSURE: |
|
|
3302 | printf ("%*sS<%s>\n", indent, "", "closure"); |
|
|
3303 | debug (SCHEME_A_ indent + 3, cdr(x)); |
|
|
3304 | return 32 + debug (SCHEME_A_ indent + 3, car (x)); |
|
|
3305 | |
|
|
3306 | case T_PAIR: |
|
|
3307 | printf ("%*spair %p %p\n", indent, "", car(x),cdr(x)); |
|
|
3308 | c = debug (SCHEME_A_ indent + 3, car (x)); |
|
|
3309 | c += debug (SCHEME_A_ indent + 3, cdr (x)); |
|
|
3310 | return c + 1; |
|
|
3311 | |
|
|
3312 | case T_PORT: |
|
|
3313 | printf ("%*sS<%s>\n", indent, "", "port"); |
|
|
3314 | return 24+8; |
|
|
3315 | |
|
|
3316 | case T_VECTOR: |
|
|
3317 | printf ("%*sS<%s>\n", indent, "", "vector"); |
|
|
3318 | return 24+8; |
|
|
3319 | |
|
|
3320 | case T_ENVIRONMENT: |
|
|
3321 | printf ("%*sS<%s>\n", indent, "", "environment"); |
|
|
3322 | return 0 + debug (SCHEME_A_ indent + 3, car (x)); |
|
|
3323 | |
|
|
3324 | default: |
|
|
3325 | printf ("unhandled type %d\n", type (x)); |
|
|
3326 | break; |
|
|
3327 | } |
|
|
3328 | } |
|
|
3329 | #endif |
|
|
3330 | |
3235 | static int |
3331 | static int |
3236 | opexe_0 (SCHEME_P_ enum scheme_opcodes op) |
3332 | opexe_0 (SCHEME_P_ enum scheme_opcodes op) |
3237 | { |
3333 | { |
3238 | pointer args = SCHEME_V->args; |
3334 | pointer args = SCHEME_V->args; |
3239 | pointer x, y; |
3335 | pointer x, y; |
3240 | |
3336 | |
3241 | switch (op) |
3337 | switch (op) |
3242 | { |
3338 | { |
|
|
3339 | #if EXPERIMENT //D |
|
|
3340 | case OP_DEBUG: |
|
|
3341 | printf ("len = %d\n", debug (SCHEME_A_ 0, args) / 8); |
|
|
3342 | printf ("\n"); |
|
|
3343 | s_return (S_T); |
|
|
3344 | #endif |
3243 | case OP_LOAD: /* load */ |
3345 | case OP_LOAD: /* load */ |
3244 | if (file_interactive (SCHEME_A)) |
3346 | if (file_interactive (SCHEME_A)) |
3245 | { |
3347 | { |
3246 | xwrstr ("Loading "); xwrstr (strvalue (car (args))); xwrstr ("\n"); |
3348 | xwrstr ("Loading "); xwrstr (strvalue (car (args))); xwrstr ("\n"); |
3247 | //D fprintf (SCHEME_V->outport->object.port->rep.stdio.file, "Loading %s\n", strvalue (car (args))); |
3349 | //D fprintf (port (SCHEME_V->outport)->rep.stdio.file, "Loading %s\n", strvalue (car (args))); |
3248 | } |
3350 | } |
3249 | |
3351 | |
3250 | if (!file_push (SCHEME_A_ strvalue (car (args)))) |
3352 | if (!file_push (SCHEME_A_ strvalue (car (args)))) |
3251 | Error_1 ("unable to open", car (args)); |
3353 | Error_1 ("unable to open", car (args)); |
3252 | else |
3354 | else |
… | |
… | |
3256 | } |
3358 | } |
3257 | |
3359 | |
3258 | case OP_T0LVL: /* top level */ |
3360 | case OP_T0LVL: /* top level */ |
3259 | |
3361 | |
3260 | /* If we reached the end of file, this loop is done. */ |
3362 | /* If we reached the end of file, this loop is done. */ |
3261 | if (SCHEME_V->loadport->object.port->kind & port_saw_EOF) |
3363 | if (port (SCHEME_V->loadport)->kind & port_saw_EOF) |
3262 | { |
3364 | { |
3263 | if (SCHEME_V->file_i == 0) |
3365 | if (SCHEME_V->file_i == 0) |
3264 | { |
3366 | { |
3265 | SCHEME_V->args = NIL; |
3367 | SCHEME_V->args = NIL; |
3266 | s_goto (OP_QUIT); |
3368 | s_goto (OP_QUIT); |
… | |
… | |
3344 | #endif |
3446 | #endif |
3345 | if (is_symbol (SCHEME_V->code)) /* symbol */ |
3447 | if (is_symbol (SCHEME_V->code)) /* symbol */ |
3346 | { |
3448 | { |
3347 | x = find_slot_in_env (SCHEME_A_ SCHEME_V->envir, SCHEME_V->code, 1); |
3449 | x = find_slot_in_env (SCHEME_A_ SCHEME_V->envir, SCHEME_V->code, 1); |
3348 | |
3450 | |
3349 | if (x != NIL) |
3451 | if (x == NIL) |
3350 | s_return (slot_value_in_env (x)); |
|
|
3351 | else |
|
|
3352 | Error_1 ("eval: unbound variable:", SCHEME_V->code); |
3452 | Error_1 ("eval: unbound variable:", SCHEME_V->code); |
|
|
3453 | |
|
|
3454 | s_return (slot_value_in_env (x)); |
3353 | } |
3455 | } |
3354 | else if (is_pair (SCHEME_V->code)) |
3456 | else if (is_pair (SCHEME_V->code)) |
3355 | { |
3457 | { |
3356 | x = car (SCHEME_V->code); |
3458 | x = car (SCHEME_V->code); |
3357 | |
3459 | |
… | |
… | |
3370 | } |
3472 | } |
3371 | else |
3473 | else |
3372 | s_return (SCHEME_V->code); |
3474 | s_return (SCHEME_V->code); |
3373 | |
3475 | |
3374 | case OP_E0ARGS: /* eval arguments */ |
3476 | case OP_E0ARGS: /* eval arguments */ |
3375 | if (is_macro (SCHEME_V->value)) /* macro expansion */ |
3477 | if (ecb_expect_false (is_macro (SCHEME_V->value))) /* macro expansion */ |
3376 | { |
3478 | { |
3377 | s_save (SCHEME_A_ OP_DOMACRO, NIL, NIL); |
3479 | s_save (SCHEME_A_ OP_DOMACRO, NIL, NIL); |
3378 | SCHEME_V->args = cons (SCHEME_V->code, NIL); |
3480 | SCHEME_V->args = cons (SCHEME_V->code, NIL); |
3379 | SCHEME_V->code = SCHEME_V->value; |
3481 | SCHEME_V->code = SCHEME_V->value; |
3380 | s_goto (OP_APPLY); |
3482 | s_goto (OP_APPLY); |
… | |
… | |
3434 | s_goto (procnum (SCHEME_V->code)); /* PROCEDURE */ |
3536 | s_goto (procnum (SCHEME_V->code)); /* PROCEDURE */ |
3435 | else if (is_foreign (SCHEME_V->code)) |
3537 | else if (is_foreign (SCHEME_V->code)) |
3436 | { |
3538 | { |
3437 | /* Keep nested calls from GC'ing the arglist */ |
3539 | /* Keep nested calls from GC'ing the arglist */ |
3438 | push_recent_alloc (SCHEME_A_ args, NIL); |
3540 | push_recent_alloc (SCHEME_A_ args, NIL); |
3439 | x = SCHEME_V->code->object.ff (SCHEME_A_ args); |
3541 | x = CELL(SCHEME_V->code)->object.ff (SCHEME_A_ args); |
3440 | |
3542 | |
3441 | s_return (x); |
3543 | s_return (x); |
3442 | } |
3544 | } |
3443 | else if (is_closure (SCHEME_V->code) || is_macro (SCHEME_V->code) || is_promise (SCHEME_V->code)) /* CLOSURE */ |
3545 | else if (is_closure (SCHEME_V->code) || is_macro (SCHEME_V->code) || is_promise (SCHEME_V->code)) /* CLOSURE */ |
3444 | { |
3546 | { |
… | |
… | |
3481 | |
3583 | |
3482 | case OP_DOMACRO: /* do macro */ |
3584 | case OP_DOMACRO: /* do macro */ |
3483 | SCHEME_V->code = SCHEME_V->value; |
3585 | SCHEME_V->code = SCHEME_V->value; |
3484 | s_goto (OP_EVAL); |
3586 | s_goto (OP_EVAL); |
3485 | |
3587 | |
3486 | #if 1 |
|
|
3487 | |
|
|
3488 | case OP_LAMBDA: /* lambda */ |
3588 | case OP_LAMBDA: /* lambda */ |
3489 | /* If the hook is defined, apply it to SCHEME_V->code, otherwise |
3589 | /* If the hook is defined, apply it to SCHEME_V->code, otherwise |
3490 | set SCHEME_V->value fall thru */ |
3590 | set SCHEME_V->value fall thru */ |
3491 | { |
3591 | { |
3492 | pointer f = find_slot_in_env (SCHEME_A_ SCHEME_V->envir, SCHEME_V->COMPILE_HOOK, 1); |
3592 | pointer f = find_slot_in_env (SCHEME_A_ SCHEME_V->envir, SCHEME_V->COMPILE_HOOK, 1); |
… | |
… | |
3498 | SCHEME_V->code = slot_value_in_env (f); |
3598 | SCHEME_V->code = slot_value_in_env (f); |
3499 | s_goto (OP_APPLY); |
3599 | s_goto (OP_APPLY); |
3500 | } |
3600 | } |
3501 | |
3601 | |
3502 | SCHEME_V->value = SCHEME_V->code; |
3602 | SCHEME_V->value = SCHEME_V->code; |
3503 | /* Fallthru */ |
|
|
3504 | } |
3603 | } |
|
|
3604 | /* Fallthru */ |
3505 | |
3605 | |
3506 | case OP_LAMBDA1: |
3606 | case OP_LAMBDA1: |
3507 | s_return (mk_closure (SCHEME_A_ SCHEME_V->value, SCHEME_V->envir)); |
3607 | s_return (mk_closure (SCHEME_A_ SCHEME_V->value, SCHEME_V->envir)); |
3508 | |
|
|
3509 | #else |
|
|
3510 | |
|
|
3511 | case OP_LAMBDA: /* lambda */ |
|
|
3512 | s_return (mk_closure (SCHEME_A_ SCHEME_V->code, SCHEME_V->envir)); |
|
|
3513 | |
|
|
3514 | #endif |
|
|
3515 | |
3608 | |
3516 | case OP_MKCLOSURE: /* make-closure */ |
3609 | case OP_MKCLOSURE: /* make-closure */ |
3517 | x = car (args); |
3610 | x = car (args); |
3518 | |
3611 | |
3519 | if (car (x) == SCHEME_V->LAMBDA) |
3612 | if (car (x) == SCHEME_V->LAMBDA) |
… | |
… | |
4115 | else |
4208 | else |
4116 | Error_0 ("modulo: division by zero"); |
4209 | Error_0 ("modulo: division by zero"); |
4117 | |
4210 | |
4118 | s_return (mk_number (SCHEME_A_ v)); |
4211 | s_return (mk_number (SCHEME_A_ v)); |
4119 | |
4212 | |
4120 | case OP_CAR: /* car */ |
4213 | /* the compiler will optimize this mess... */ |
4121 | s_return (caar (args)); |
4214 | case OP_CAR: op_car: s_return (car (x)); |
4122 | |
4215 | case OP_CDR: op_cdr: s_return (cdr (x)); |
4123 | case OP_CDR: /* cdr */ |
4216 | case OP_CAAR: op_caar: x = car (x); goto op_car; |
4124 | s_return (cdar (args)); |
4217 | case OP_CADR: op_cadr: x = cdr (x); goto op_car; |
|
|
4218 | case OP_CDAR: op_cdar: x = car (x); goto op_cdr; |
|
|
4219 | case OP_CDDR: op_cddr: x = cdr (x); goto op_cdr; |
|
|
4220 | case OP_CAAAR: op_caaar: x = car (x); goto op_caar; |
|
|
4221 | case OP_CAADR: op_caadr: x = cdr (x); goto op_caar; |
|
|
4222 | case OP_CADAR: op_cadar: x = car (x); goto op_cadr; |
|
|
4223 | case OP_CADDR: op_caddr: x = cdr (x); goto op_cadr; |
|
|
4224 | case OP_CDAAR: op_cdaar: x = car (x); goto op_cdar; |
|
|
4225 | case OP_CDADR: op_cdadr: x = cdr (x); goto op_cdar; |
|
|
4226 | case OP_CDDAR: op_cddar: x = car (x); goto op_cddr; |
|
|
4227 | case OP_CDDDR: op_cdddr: x = cdr (x); goto op_cddr; |
|
|
4228 | case OP_CAAAAR: x = car (x); goto op_caaar; |
|
|
4229 | case OP_CAAADR: x = cdr (x); goto op_caaar; |
|
|
4230 | case OP_CAADAR: x = car (x); goto op_caadr; |
|
|
4231 | case OP_CAADDR: x = cdr (x); goto op_caadr; |
|
|
4232 | case OP_CADAAR: x = car (x); goto op_cadar; |
|
|
4233 | case OP_CADADR: x = cdr (x); goto op_cadar; |
|
|
4234 | case OP_CADDAR: x = car (x); goto op_caddr; |
|
|
4235 | case OP_CADDDR: x = cdr (x); goto op_caddr; |
|
|
4236 | case OP_CDAAAR: x = car (x); goto op_cdaar; |
|
|
4237 | case OP_CDAADR: x = cdr (x); goto op_cdaar; |
|
|
4238 | case OP_CDADAR: x = car (x); goto op_cdadr; |
|
|
4239 | case OP_CDADDR: x = cdr (x); goto op_cdadr; |
|
|
4240 | case OP_CDDAAR: x = car (x); goto op_cddar; |
|
|
4241 | case OP_CDDADR: x = cdr (x); goto op_cddar; |
|
|
4242 | case OP_CDDDAR: x = car (x); goto op_cdddr; |
|
|
4243 | case OP_CDDDDR: x = cdr (x); goto op_cdddr; |
4125 | |
4244 | |
4126 | case OP_CONS: /* cons */ |
4245 | case OP_CONS: /* cons */ |
4127 | set_cdr (args, cadr (args)); |
4246 | set_cdr (args, cadr (args)); |
4128 | s_return (args); |
4247 | s_return (args); |
4129 | |
4248 | |
… | |
… | |
4378 | } |
4497 | } |
4379 | |
4498 | |
4380 | case OP_VECLEN: /* vector-length */ |
4499 | case OP_VECLEN: /* vector-length */ |
4381 | s_return (mk_integer (SCHEME_A_ veclength (x))); |
4500 | s_return (mk_integer (SCHEME_A_ veclength (x))); |
4382 | |
4501 | |
|
|
4502 | case OP_VECRESIZE: |
|
|
4503 | vector_resize (x, ivalue_unchecked (cadr (args)), caddr (args)); |
|
|
4504 | s_return (x); |
|
|
4505 | |
4383 | case OP_VECREF: /* vector-ref */ |
4506 | case OP_VECREF: /* vector-ref */ |
4384 | { |
4507 | { |
4385 | int index = ivalue_unchecked (cadr (args)); |
4508 | int index = ivalue_unchecked (cadr (args)); |
4386 | |
4509 | |
4387 | if (index >= veclength (car (args)) && USE_ERROR_CHECKING) |
4510 | if (index >= veclength (car (args)) && USE_ERROR_CHECKING) |
… | |
… | |
4447 | pointer d = cdr (args); |
4570 | pointer d = cdr (args); |
4448 | int r; |
4571 | int r; |
4449 | |
4572 | |
4450 | switch (op) |
4573 | switch (op) |
4451 | { |
4574 | { |
4452 | case OP_NOT: /* not */ r = is_false (a) ; break; |
4575 | case OP_NOT: /* not */ r = is_false (a) ; break; |
4453 | case OP_BOOLP: /* boolean? */ r = a == S_F || a == S_T; break; |
4576 | case OP_BOOLP: /* boolean? */ r = a == S_F || a == S_T ; break; |
4454 | case OP_EOFOBJP: /* eof-object? */ r = a == S_EOF ; break; |
4577 | case OP_EOFOBJP: /* eof-object? */ r = a == S_EOF ; break; |
4455 | case OP_NULLP: /* null? */ r = a == NIL ; break; |
4578 | case OP_NULLP: /* null? */ r = a == NIL ; break; |
4456 | case OP_SYMBOLP: /* symbol? */ r = is_symbol (a) ; break; |
4579 | case OP_SYMBOLP: /* symbol? */ r = is_symbol (a) ; break; |
|
|
4580 | case OP_GENSYMP: /* gensym? */ r = is_gensym (SCHEME_A_ a); break; |
4457 | case OP_NUMBERP: /* number? */ r = is_number (a) ; break; |
4581 | case OP_NUMBERP: /* number? */ r = is_number (a) ; break; |
4458 | case OP_STRINGP: /* string? */ r = is_string (a) ; break; |
4582 | case OP_STRINGP: /* string? */ r = is_string (a) ; break; |
4459 | case OP_INTEGERP: /* integer? */ r = is_integer (a) ; break; |
4583 | case OP_INTEGERP: /* integer? */ r = is_integer (a) ; break; |
4460 | case OP_REALP: /* real? */ r = is_number (a) ; break; /* all numbers are real */ |
4584 | case OP_REALP: /* real? */ r = is_number (a) ; break; /* all numbers are real */ |
4461 | case OP_CHARP: /* char? */ r = is_character (a) ; break; |
4585 | case OP_CHARP: /* char? */ r = is_character (a) ; break; |
4462 | |
4586 | |
4463 | #if USE_CHAR_CLASSIFIERS |
4587 | #if USE_CHAR_CLASSIFIERS |
4464 | case OP_CHARAP: /* char-alphabetic? */ r = Cisalpha (ivalue_unchecked (a)); break; |
4588 | case OP_CHARAP: /* char-alphabetic? */ r = Cisalpha (ivalue_unchecked (a)); break; |
4465 | case OP_CHARNP: /* char-numeric? */ r = Cisdigit (ivalue_unchecked (a)); break; |
4589 | case OP_CHARNP: /* char-numeric? */ r = Cisdigit (ivalue_unchecked (a)); break; |
4466 | case OP_CHARWP: /* char-whitespace? */ r = Cisspace (ivalue_unchecked (a)); break; |
4590 | case OP_CHARWP: /* char-whitespace? */ r = Cisspace (ivalue_unchecked (a)); break; |
… | |
… | |
4516 | } |
4640 | } |
4517 | else |
4641 | else |
4518 | s_return (SCHEME_V->code); |
4642 | s_return (SCHEME_V->code); |
4519 | |
4643 | |
4520 | case OP_SAVE_FORCED: /* Save forced value replacing promise */ |
4644 | case OP_SAVE_FORCED: /* Save forced value replacing promise */ |
4521 | memcpy (SCHEME_V->code, SCHEME_V->value, sizeof (struct cell)); |
4645 | *CELL (SCHEME_V->code) = *CELL (SCHEME_V->value); |
4522 | s_return (SCHEME_V->value); |
4646 | s_return (SCHEME_V->value); |
4523 | |
4647 | |
4524 | #if USE_PORTS |
4648 | #if USE_PORTS |
4525 | |
4649 | |
4526 | case OP_WRITE: /* write */ |
4650 | case OP_WRITE: /* write */ |
… | |
… | |
4671 | SCHEME_V->gc_verbose = (a != S_F); |
4795 | SCHEME_V->gc_verbose = (a != S_F); |
4672 | s_retbool (was); |
4796 | s_retbool (was); |
4673 | } |
4797 | } |
4674 | |
4798 | |
4675 | case OP_NEWSEGMENT: /* new-segment */ |
4799 | case OP_NEWSEGMENT: /* new-segment */ |
|
|
4800 | #if 0 |
4676 | if (!is_pair (args) || !is_number (a)) |
4801 | if (!is_pair (args) || !is_number (a)) |
4677 | Error_0 ("new-segment: argument must be a number"); |
4802 | Error_0 ("new-segment: argument must be a number"); |
4678 | |
4803 | #endif |
4679 | alloc_cellseg (SCHEME_A_ ivalue (a)); |
4804 | s_retbool (alloc_cellseg (SCHEME_A)); |
4680 | |
|
|
4681 | s_return (S_T); |
|
|
4682 | |
4805 | |
4683 | case OP_OBLIST: /* oblist */ |
4806 | case OP_OBLIST: /* oblist */ |
4684 | s_return (oblist_all_symbols (SCHEME_A)); |
4807 | s_return (oblist_all_symbols (SCHEME_A)); |
4685 | |
4808 | |
4686 | #if USE_PORTS |
4809 | #if USE_PORTS |
… | |
… | |
4756 | s_return (p == NIL ? S_F : p); |
4879 | s_return (p == NIL ? S_F : p); |
4757 | } |
4880 | } |
4758 | |
4881 | |
4759 | case OP_GET_OUTSTRING: /* get-output-string */ |
4882 | case OP_GET_OUTSTRING: /* get-output-string */ |
4760 | { |
4883 | { |
4761 | port *p; |
4884 | port *p = port (a); |
4762 | |
4885 | |
4763 | if ((p = a->object.port)->kind & port_string) |
4886 | if (p->kind & port_string) |
4764 | { |
4887 | { |
4765 | off_t size; |
4888 | off_t size; |
4766 | char *str; |
4889 | char *str; |
4767 | |
4890 | |
4768 | size = p->rep.string.curr - p->rep.string.start + 1; |
4891 | size = p->rep.string.curr - p->rep.string.start + 1; |
… | |
… | |
4873 | int res; |
4996 | int res; |
4874 | |
4997 | |
4875 | if (is_pair (args)) |
4998 | if (is_pair (args)) |
4876 | p = car (args); |
4999 | p = car (args); |
4877 | |
5000 | |
4878 | res = p->object.port->kind & port_string; |
5001 | res = port (p)->kind & port_string; |
4879 | |
5002 | |
4880 | s_retbool (res); |
5003 | s_retbool (res); |
4881 | } |
5004 | } |
4882 | |
5005 | |
4883 | case OP_SET_INPORT: /* set-input-port */ |
5006 | case OP_SET_INPORT: /* set-input-port */ |
… | |
… | |
4947 | s_return (mk_atom (SCHEME_A_ readstr_upto (SCHEME_A_ 0, DELIMITERS))); |
5070 | s_return (mk_atom (SCHEME_A_ readstr_upto (SCHEME_A_ 0, DELIMITERS))); |
4948 | |
5071 | |
4949 | case TOK_DOTATOM: |
5072 | case TOK_DOTATOM: |
4950 | SCHEME_V->strbuff[0] = '.'; |
5073 | SCHEME_V->strbuff[0] = '.'; |
4951 | s_return (mk_atom (SCHEME_A_ readstr_upto (SCHEME_A_ 1, DELIMITERS))); |
5074 | s_return (mk_atom (SCHEME_A_ readstr_upto (SCHEME_A_ 1, DELIMITERS))); |
|
|
5075 | |
|
|
5076 | case TOK_STRATOM: |
|
|
5077 | x = readstrexp (SCHEME_A_ '|'); |
|
|
5078 | //TODO: haven't checked whether the garbage collector could interfere |
|
|
5079 | s_return (mk_atom (SCHEME_A_ strvalue (x))); |
4952 | |
5080 | |
4953 | case TOK_DQUOTE: |
5081 | case TOK_DQUOTE: |
4954 | x = readstrexp (SCHEME_A_ '"'); |
5082 | x = readstrexp (SCHEME_A_ '"'); |
4955 | |
5083 | |
4956 | if (x == S_F) |
5084 | if (x == S_F) |
… | |
… | |
5203 | |
5331 | |
5204 | case OP_CLOSUREP: /* closure? */ |
5332 | case OP_CLOSUREP: /* closure? */ |
5205 | /* |
5333 | /* |
5206 | * Note, macro object is also a closure. |
5334 | * Note, macro object is also a closure. |
5207 | * Therefore, (closure? <#MACRO>) ==> #t |
5335 | * Therefore, (closure? <#MACRO>) ==> #t |
|
|
5336 | * (schmorp) well, obviously not, fix? TODO |
5208 | */ |
5337 | */ |
5209 | s_retbool (is_closure (a)); |
5338 | s_retbool (is_closure (a)); |
5210 | |
5339 | |
5211 | case OP_MACROP: /* macro? */ |
5340 | case OP_MACROP: /* macro? */ |
5212 | s_retbool (is_macro (a)); |
5341 | s_retbool (is_macro (a)); |
… | |
… | |
5453 | |
5582 | |
5454 | /* Hard-coded for the given keywords. Remember to rewrite if more are added! */ |
5583 | /* Hard-coded for the given keywords. Remember to rewrite if more are added! */ |
5455 | static int |
5584 | static int |
5456 | syntaxnum (pointer p) |
5585 | syntaxnum (pointer p) |
5457 | { |
5586 | { |
5458 | const char *s = strvalue (car (p)); |
5587 | const char *s = strvalue (p); |
5459 | |
5588 | |
5460 | switch (strlength (car (p))) |
5589 | switch (strlength (p)) |
5461 | { |
5590 | { |
5462 | case 2: |
5591 | case 2: |
5463 | if (s[0] == 'i') |
5592 | if (s[0] == 'i') |
5464 | return OP_IF0; /* if */ |
5593 | return OP_IF0; /* if */ |
5465 | else |
5594 | else |
… | |
… | |
5540 | ecb_cold int |
5669 | ecb_cold int |
5541 | scheme_init (SCHEME_P) |
5670 | scheme_init (SCHEME_P) |
5542 | { |
5671 | { |
5543 | int i, n = sizeof (dispatch_table) / sizeof (dispatch_table[0]); |
5672 | int i, n = sizeof (dispatch_table) / sizeof (dispatch_table[0]); |
5544 | pointer x; |
5673 | pointer x; |
|
|
5674 | |
|
|
5675 | /* this memset is not strictly correct, as we assume (intcache) |
|
|
5676 | * that memset 0 will also set pointers to 0, but memset does |
|
|
5677 | * of course not guarantee that. screw such systems. |
|
|
5678 | */ |
|
|
5679 | memset (SCHEME_V, 0, sizeof (*SCHEME_V)); |
5545 | |
5680 | |
5546 | num_set_fixnum (num_zero, 1); |
5681 | num_set_fixnum (num_zero, 1); |
5547 | num_set_ivalue (num_zero, 0); |
5682 | num_set_ivalue (num_zero, 0); |
5548 | num_set_fixnum (num_one, 1); |
5683 | num_set_fixnum (num_one, 1); |
5549 | num_set_ivalue (num_one, 1); |
5684 | num_set_ivalue (num_one, 1); |
… | |
… | |
5561 | SCHEME_V->save_inport = NIL; |
5696 | SCHEME_V->save_inport = NIL; |
5562 | SCHEME_V->loadport = NIL; |
5697 | SCHEME_V->loadport = NIL; |
5563 | SCHEME_V->nesting = 0; |
5698 | SCHEME_V->nesting = 0; |
5564 | SCHEME_V->interactive_repl = 0; |
5699 | SCHEME_V->interactive_repl = 0; |
5565 | |
5700 | |
5566 | if (alloc_cellseg (SCHEME_A_ FIRST_CELLSEGS) != FIRST_CELLSEGS) |
5701 | if (!alloc_cellseg (SCHEME_A)) |
5567 | { |
5702 | { |
5568 | #if USE_ERROR_CHECKING |
5703 | #if USE_ERROR_CHECKING |
5569 | SCHEME_V->no_memory = 1; |
5704 | SCHEME_V->no_memory = 1; |
5570 | return 0; |
5705 | return 0; |
5571 | #endif |
5706 | #endif |
… | |
… | |
5901 | # endif |
6036 | # endif |
5902 | int fin; |
6037 | int fin; |
5903 | char *file_name = InitFile; |
6038 | char *file_name = InitFile; |
5904 | int retcode; |
6039 | int retcode; |
5905 | int isfile = 1; |
6040 | int isfile = 1; |
|
|
6041 | system ("ps v $PPID");//D |
5906 | |
6042 | |
5907 | if (argc == 2 && strcmp (argv[1], "-?") == 0) |
6043 | if (argc == 2 && strcmp (argv[1], "-?") == 0) |
5908 | { |
6044 | { |
5909 | xwrstr ("Usage: tinyscheme -?\n"); |
6045 | xwrstr ("Usage: tinyscheme -?\n"); |
5910 | xwrstr ("or: tinyscheme [<file1> <file2> ...]\n"); |
6046 | xwrstr ("or: tinyscheme [<file1> <file2> ...]\n"); |