ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/microscheme/scheme.c
(Generate patch)

Comparing cvsroot/microscheme/scheme.c (file contents):
Revision 1.35 by root, Sun Nov 29 00:02:21 2015 UTC vs.
Revision 1.47 by root, Mon Nov 30 09:25:19 2015 UTC

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
21#define PAGE_SIZE 4096 /* does not work on sparc/alpha */ 23#define PAGE_SIZE 4096 /* does not work on sparc/alpha */
22#include "malloc.c" 24#include "malloc.c"
23 25
24#define SCHEME_SOURCE 26#define SCHEME_SOURCE
25#include "scheme-private.h" 27#include "scheme-private.h"
74 TOK_SHARP_CONST, 76 TOK_SHARP_CONST,
75 TOK_VEC 77 TOK_VEC
76}; 78};
77 79
78#define BACKQUOTE '`' 80#define BACKQUOTE '`'
79#define DELIMITERS "()\";\f\t\v\n\r " 81#define WHITESPACE " \t\r\n\v\f"
82#define DELIMITERS "()\";" WHITESPACE
80 83
81#define NIL (&SCHEME_V->xNIL) //TODO: make this 0? 84#define NIL (&SCHEME_V->xNIL) //TODO: make this 0?
82#define S_T (&SCHEME_V->xT) //TODO: magic ptr value? 85#define S_T (&SCHEME_V->xT) //TODO: magic ptr value?
83#define S_F (&SCHEME_V->xF) //TODO: magic ptr value? 86#define S_F (&SCHEME_V->xF) //TODO: magic ptr value?
84#define S_SINK (&SCHEME_V->xsink) 87#define S_SINK (&SCHEME_V->xsink)
406} 409}
407 410
408INTERFACE char * 411INTERFACE char *
409symname (pointer p) 412symname (pointer p)
410{ 413{
411 return strvalue (car (p)); 414 return strvalue (p);
412} 415}
413 416
414#if USE_PLIST 417#if USE_PLIST
418#error plists are broken because symbols are no longer pairs
419#define symprop(p) cdr(p)
415SCHEME_EXPORT int 420SCHEME_EXPORT int
416hasprop (pointer p) 421hasprop (pointer p)
417{ 422{
418 return typeflag (p) & T_SYMBOL; 423 return typeflag (p) & T_SYMBOL;
419} 424}
420
421# define symprop(p) cdr(p)
422#endif 425#endif
423 426
424INTERFACE int 427INTERFACE int
425is_syntax (pointer p) 428is_syntax (pointer p)
426{ 429{
440} 443}
441 444
442INTERFACE char * 445INTERFACE char *
443syntaxname (pointer p) 446syntaxname (pointer p)
444{ 447{
445 return strvalue (car (p)); 448 return strvalue (p);
446} 449}
447 450
448#define procnum(p) ivalue_unchecked (p) 451#define procnum(p) ivalue_unchecked (p)
449static const char *procname (pointer x); 452static const char *procname (pointer x);
450 453
967 if (SCHEME_V->no_memory && USE_ERROR_CHECKING) 970 if (SCHEME_V->no_memory && USE_ERROR_CHECKING)
968 return S_SINK; 971 return S_SINK;
969 972
970 if (SCHEME_V->free_cell == NIL) 973 if (SCHEME_V->free_cell == NIL)
971 { 974 {
972 const int min_to_be_recovered = SCHEME_V->last_cell_seg < 128 ? 128 * 8 : SCHEME_V->last_cell_seg * 8; 975 const int min_to_be_recovered = SCHEME_V->cell_segsize [SCHEME_V->last_cell_seg] >> 1;
973 976
974 gc (SCHEME_A_ a, b); 977 gc (SCHEME_A_ a, b);
975 978
976 if (SCHEME_V->fcells < min_to_be_recovered || SCHEME_V->free_cell == NIL) 979 if (SCHEME_V->fcells < min_to_be_recovered || SCHEME_V->free_cell == NIL)
977 { 980 {
1028} 1031}
1029 1032
1030static pointer 1033static pointer
1031get_vector_object (SCHEME_P_ uint32_t len, pointer init) 1034get_vector_object (SCHEME_P_ uint32_t len, pointer init)
1032{ 1035{
1033 pointer v = get_cell_x (SCHEME_A_ 0, 0); 1036 pointer v = get_cell_x (SCHEME_A_ NIL, NIL);
1034 pointer *e = malloc (len * sizeof (pointer)); 1037 pointer *e = malloc (len * sizeof (pointer));
1035 1038
1036 if (!e && USE_ERROR_CHECKING) 1039 if (!e && USE_ERROR_CHECKING)
1037 return S_SINK; 1040 return S_SINK;
1038 1041
1092 set_cdr (x, b); 1095 set_cdr (x, b);
1093 1096
1094 return x; 1097 return x;
1095} 1098}
1096 1099
1097/* ========== oblist implementation ========== */
1098
1099static pointer 1100static pointer
1100generate_symbol (SCHEME_P_ const char *name) 1101generate_symbol (SCHEME_P_ const char *name)
1101{ 1102{
1102 pointer x = mk_string (SCHEME_A_ name); 1103 pointer x = mk_string (SCHEME_A_ name);
1103 setimmutable (x); 1104 setimmutable (x);
1104 x = immutable_cons (x, NIL);
1105 set_typeflag (x, T_SYMBOL); 1105 set_typeflag (x, T_SYMBOL | T_ATOM);
1106 return x; 1106 return x;
1107} 1107}
1108
1109/* ========== oblist implementation ========== */
1108 1110
1109#ifndef USE_OBJECT_LIST 1111#ifndef USE_OBJECT_LIST
1110 1112
1111static int 1113static int
1112hash_fn (const char *key, int table_size) 1114hash_fn (const char *key, int table_size)
1354 1356
1355 for (i = start; i < veclength (vec); i++) 1357 for (i = start; i < veclength (vec); i++)
1356 vecvalue (vec)[i] = obj; 1358 vecvalue (vec)[i] = obj;
1357} 1359}
1358 1360
1361INTERFACE void
1362vector_resize (pointer vec, uint32_t newsize, pointer fill)
1363{
1364 uint32_t oldsize = veclength (vec);
1365 vecvalue (vec) = realloc (vecvalue (vec), newsize * sizeof (pointer));
1366 veclength (vec) = newsize;
1367 fill_vector (vec, oldsize, fill);
1368}
1369
1359INTERFACE pointer 1370INTERFACE pointer
1360vector_get (pointer vec, uint32_t ielem) 1371vector_get (pointer vec, uint32_t ielem)
1361{ 1372{
1362 return vecvalue(vec)[ielem]; 1373 return vecvalue(vec)[ielem];
1363} 1374}
1384INTERFACE pointer 1395INTERFACE pointer
1385gensym (SCHEME_P) 1396gensym (SCHEME_P)
1386{ 1397{
1387 pointer x; 1398 pointer x;
1388 char name[40] = "gensym-"; 1399 char name[40] = "gensym-";
1389 xnum (name + 7, SCHEME_V->gensym_cnt); 1400 xnum (name + 7, ++SCHEME_V->gensym_cnt);
1390 1401
1391 return generate_symbol (SCHEME_A_ name); 1402 return generate_symbol (SCHEME_A_ name);
1403}
1404
1405static int
1406is_gensym (SCHEME_P_ pointer x)
1407{
1408 return is_symbol (x) && oblist_find_by_name (SCHEME_A_ strvalue (x)) != x;
1392} 1409}
1393 1410
1394/* make symbol or number atom from string */ 1411/* make symbol or number atom from string */
1395static pointer 1412static pointer
1396mk_atom (SCHEME_P_ char *q) 1413mk_atom (SCHEME_P_ char *q)
1640 /* garbage collect */ 1657 /* garbage collect */
1641 clrmark (NIL); 1658 clrmark (NIL);
1642 SCHEME_V->fcells = 0; 1659 SCHEME_V->fcells = 0;
1643 SCHEME_V->free_cell = NIL; 1660 SCHEME_V->free_cell = NIL;
1644 1661
1645 /* free-list is kept sorted by address so as to maintain consecutive 1662 if (SCHEME_V->gc_verbose)
1646 ranges, if possible, for use with vectors. Here we scan the cells 1663 xwrstr ("freeing...");
1647 (which are also kept sorted by address) downwards to build the 1664
1648 free-list in sorted order. 1665 uint32_t total = 0;
1649 */ 1666
1667 /* Here we scan the cells to build the free-list. */
1650 for (i = SCHEME_V->last_cell_seg; i >= 0; i--) 1668 for (i = SCHEME_V->last_cell_seg; i >= 0; i--)
1651 { 1669 {
1652 p = SCHEME_V->cell_seg[i] + SCHEME_V->cell_segsize [i]; 1670 pointer end = SCHEME_V->cell_seg[i] + SCHEME_V->cell_segsize [i];
1671 total += SCHEME_V->cell_segsize [i];
1653 1672
1654 while (--p >= SCHEME_V->cell_seg[i]) 1673 for (p = SCHEME_V->cell_seg[i]; p < end; ++p)
1655 { 1674 {
1656 if (is_mark (p)) 1675 if (is_mark (p))
1657 clrmark (p); 1676 clrmark (p);
1658 else 1677 else
1659 { 1678 {
1672 } 1691 }
1673 } 1692 }
1674 1693
1675 if (SCHEME_V->gc_verbose) 1694 if (SCHEME_V->gc_verbose)
1676 { 1695 {
1677 xwrstr ("done: "); xwrnum (SCHEME_V->fcells); xwrstr (" cells were recovered.\n"); 1696 xwrstr ("done: "); xwrnum (SCHEME_V->fcells); xwrstr (" out of "); xwrnum (total); xwrstr (" cells were recovered.\n");
1678 } 1697 }
1679} 1698}
1680 1699
1681static void 1700static void
1682finalize_cell (SCHEME_P_ pointer a) 1701finalize_cell (SCHEME_P_ pointer a)
1683{ 1702{
1684 /* TODO, fast bitmap check? */ 1703 /* TODO, fast bitmap check? */
1685 if (is_string (a)) 1704 if (is_string (a) || is_symbol (a))
1686 free (strvalue (a)); 1705 free (strvalue (a));
1687 else if (is_vector (a)) 1706 else if (is_vector (a))
1688 free (vecvalue (a)); 1707 free (vecvalue (a));
1689#if USE_PORTS 1708#if USE_PORTS
1690 else if (is_port (a)) 1709 else if (is_port (a))
2256 2275
2257/* check c is in chars */ 2276/* check c is in chars */
2258ecb_inline int 2277ecb_inline int
2259is_one_of (const char *s, int c) 2278is_one_of (const char *s, int c)
2260{ 2279{
2261 if (c == EOF)
2262 return 1;
2263
2264 return !!strchr (s, c); 2280 return c == EOF || !!strchr (s, c);
2265} 2281}
2266 2282
2267/* skip white characters */ 2283/* skip white characters */
2268ecb_inline int 2284ecb_inline int
2269skipspace (SCHEME_P) 2285skipspace (SCHEME_P)
2271 int c, curr_line = 0; 2287 int c, curr_line = 0;
2272 2288
2273 do 2289 do
2274 { 2290 {
2275 c = inchar (SCHEME_A); 2291 c = inchar (SCHEME_A);
2292
2276#if SHOW_ERROR_LINE 2293#if SHOW_ERROR_LINE
2277 if (c == '\n') 2294 if (ecb_expect_false (c == '\n'))
2278 curr_line++; 2295 curr_line++;
2279#endif 2296#endif
2297
2298 if (ecb_expect_false (c == EOF))
2299 return c;
2280 } 2300 }
2281 while (c == ' ' || c == '\n' || c == '\r' || c == '\t'); 2301 while (is_one_of (WHITESPACE, c));
2282 2302
2283 /* record it */ 2303 /* record it */
2284#if SHOW_ERROR_LINE 2304#if SHOW_ERROR_LINE
2285 if (SCHEME_V->load_stack[SCHEME_V->file_i].kind & port_file) 2305 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; 2306 SCHEME_V->load_stack[SCHEME_V->file_i].rep.stdio.curr_line += curr_line;
2287#endif 2307#endif
2288 2308
2289 if (c != EOF)
2290 {
2291 backchar (SCHEME_A_ c); 2309 backchar (SCHEME_A_ c);
2292 return 1; 2310 return 1;
2293 }
2294 else
2295 return EOF;
2296} 2311}
2297 2312
2298/* get token */ 2313/* get token */
2299static int 2314static int
2300token (SCHEME_P) 2315token (SCHEME_P)
2316 return TOK_RPAREN; 2331 return TOK_RPAREN;
2317 2332
2318 case '.': 2333 case '.':
2319 c = inchar (SCHEME_A); 2334 c = inchar (SCHEME_A);
2320 2335
2321 if (is_one_of (" \n\t", c)) 2336 if (is_one_of (WHITESPACE, c))
2322 return TOK_DOT; 2337 return TOK_DOT;
2323 else 2338 else
2324 { 2339 {
2325 backchar (SCHEME_A_ c); 2340 backchar (SCHEME_A_ c);
2326 return TOK_DOTATOM; 2341 return TOK_DOTATOM;
2467 } 2482 }
2468 2483
2469 putcharacter (SCHEME_A_ '"'); 2484 putcharacter (SCHEME_A_ '"');
2470} 2485}
2471 2486
2472
2473/* print atoms */ 2487/* print atoms */
2474static void 2488static void
2475printatom (SCHEME_P_ pointer l, int f) 2489printatom (SCHEME_P_ pointer l, int f)
2476{ 2490{
2477 char *p; 2491 char *p;
2478 int len; 2492 int len;
2479 2493
2480 atom2str (SCHEME_A_ l, f, &p, &len); 2494 atom2str (SCHEME_A_ l, f, &p, &len);
2481 putchars (SCHEME_A_ p, len); 2495 putchars (SCHEME_A_ p, len);
2482} 2496}
2483
2484 2497
2485/* Uses internal buffer unless string pointer is already available */ 2498/* Uses internal buffer unless string pointer is already available */
2486static void 2499static void
2487atom2str (SCHEME_P_ pointer l, int f, char **pp, int *plen) 2500atom2str (SCHEME_P_ pointer l, int f, char **pp, int *plen)
2488{ 2501{
2649#endif 2662#endif
2650 } 2663 }
2651 else if (is_continuation (l)) 2664 else if (is_continuation (l))
2652 p = "#<CONTINUATION>"; 2665 p = "#<CONTINUATION>";
2653 else 2666 else
2667 {
2668#if USE_PRINTF
2669 p = SCHEME_V->strbuff;
2670 snprintf (p, STRBUFFSIZE, "#<ERROR %x>", (int)typeflag (l));
2671#else
2654 p = "#<ERROR>"; 2672 p = "#<ERROR>";
2673#endif
2674 }
2655 2675
2656 *pp = p; 2676 *pp = p;
2657 *plen = strlen (p); 2677 *plen = strlen (p);
2658} 2678}
2659 2679
2929#endif /* USE_ALIST_ENV else */ 2949#endif /* USE_ALIST_ENV else */
2930 2950
2931ecb_inline void 2951ecb_inline void
2932new_slot_in_env (SCHEME_P_ pointer variable, pointer value) 2952new_slot_in_env (SCHEME_P_ pointer variable, pointer value)
2933{ 2953{
2954 assert (is_symbol (variable));//TODO: bug in current-ws/OP_LET2
2934 new_slot_spec_in_env (SCHEME_A_ SCHEME_V->envir, variable, value); 2955 new_slot_spec_in_env (SCHEME_A_ SCHEME_V->envir, variable, value);
2935} 2956}
2936 2957
2937ecb_inline void 2958ecb_inline void
2938set_slot_in_env (SCHEME_P_ pointer slot, pointer value) 2959set_slot_in_env (SCHEME_P_ pointer slot, pointer value)
3230 3251
3231#endif 3252#endif
3232 3253
3233#define s_retbool(tf) s_return ((tf) ? S_T : S_F) 3254#define s_retbool(tf) s_return ((tf) ? S_T : S_F)
3234 3255
3256#if EXPERIMENT
3257static int
3258debug (SCHEME_P_ int indent, pointer x)
3259{
3260 int c;
3261
3262 if (is_syntax (x))
3263 {
3264 printf ("%*ssyntax<%s,%d>\n", indent, "", syntaxname(x),syntaxnum(x));
3265 return 8 + 8;
3266 }
3267
3268 if (x == NIL)
3269 {
3270 printf ("%*sNIL\n", indent, "");
3271 return 3;
3272 }
3273
3274 switch (type (x))
3275 {
3276 case T_INTEGER:
3277 printf ("%*sI<%d>%p\n", indent, "", (int)ivalue_unchecked (x), x);
3278 return 32+8;
3279
3280 case T_SYMBOL:
3281 printf ("%*sS<%s>\n", indent, "", symname (x));
3282 return 24+8;
3283
3284 case T_CLOSURE:
3285 printf ("%*sS<%s>\n", indent, "", "closure");
3286 debug (SCHEME_A_ indent + 3, cdr(x));
3287 return 32 + debug (SCHEME_A_ indent + 3, car (x));
3288
3289 case T_PAIR:
3290 printf ("%*spair %p %p\n", indent, "", car(x),cdr(x));
3291 c = debug (SCHEME_A_ indent + 3, car (x));
3292 c += debug (SCHEME_A_ indent + 3, cdr (x));
3293 return c + 1;
3294
3295 case T_PORT:
3296 printf ("%*sS<%s>\n", indent, "", "port");
3297 return 24+8;
3298
3299 case T_VECTOR:
3300 printf ("%*sS<%s>\n", indent, "", "vector");
3301 return 24+8;
3302
3303 case T_ENVIRONMENT:
3304 printf ("%*sS<%s>\n", indent, "", "environment");
3305 return 0 + debug (SCHEME_A_ indent + 3, car (x));
3306
3307 default:
3308 printf ("unhandled type %d\n", type (x));
3309 break;
3310 }
3311}
3312#endif
3313
3235static int 3314static int
3236opexe_0 (SCHEME_P_ enum scheme_opcodes op) 3315opexe_0 (SCHEME_P_ enum scheme_opcodes op)
3237{ 3316{
3238 pointer args = SCHEME_V->args; 3317 pointer args = SCHEME_V->args;
3239 pointer x, y; 3318 pointer x, y;
3240 3319
3241 switch (op) 3320 switch (op)
3242 { 3321 {
3322#if EXPERIMENT //D
3323 case OP_DEBUG:
3324 printf ("len = %d\n", debug (SCHEME_A_ 0, args) / 8);
3325 printf ("\n");
3326 s_return (S_T);
3327#endif
3243 case OP_LOAD: /* load */ 3328 case OP_LOAD: /* load */
3244 if (file_interactive (SCHEME_A)) 3329 if (file_interactive (SCHEME_A))
3245 { 3330 {
3246 xwrstr ("Loading "); xwrstr (strvalue (car (args))); xwrstr ("\n"); 3331 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))); 3332 //D fprintf (SCHEME_V->outport->object.port->rep.stdio.file, "Loading %s\n", strvalue (car (args)));
3370 } 3455 }
3371 else 3456 else
3372 s_return (SCHEME_V->code); 3457 s_return (SCHEME_V->code);
3373 3458
3374 case OP_E0ARGS: /* eval arguments */ 3459 case OP_E0ARGS: /* eval arguments */
3375 if (is_macro (SCHEME_V->value)) /* macro expansion */ 3460 if (ecb_expect_false (is_macro (SCHEME_V->value))) /* macro expansion */
3376 { 3461 {
3377 s_save (SCHEME_A_ OP_DOMACRO, NIL, NIL); 3462 s_save (SCHEME_A_ OP_DOMACRO, NIL, NIL);
3378 SCHEME_V->args = cons (SCHEME_V->code, NIL); 3463 SCHEME_V->args = cons (SCHEME_V->code, NIL);
3379 SCHEME_V->code = SCHEME_V->value; 3464 SCHEME_V->code = SCHEME_V->value;
3380 s_goto (OP_APPLY); 3465 s_goto (OP_APPLY);
4115 else 4200 else
4116 Error_0 ("modulo: division by zero"); 4201 Error_0 ("modulo: division by zero");
4117 4202
4118 s_return (mk_number (SCHEME_A_ v)); 4203 s_return (mk_number (SCHEME_A_ v));
4119 4204
4120 case OP_CAR: /* car */ 4205 /* the compiler will optimize this mess... */
4121 s_return (caar (args)); 4206 case OP_CAR: op_car: s_return (car (x));
4122 4207 case OP_CDR: op_cdr: s_return (cdr (x));
4123 case OP_CDR: /* cdr */ 4208 case OP_CAAR: op_caar: x = car (x); goto op_car;
4124 s_return (cdar (args)); 4209 case OP_CADR: op_cadr: x = cdr (x); goto op_car;
4210 case OP_CDAR: op_cdar: x = car (x); goto op_cdr;
4211 case OP_CDDR: op_cddr: x = cdr (x); goto op_cdr;
4212 case OP_CAAAR: op_caaar: x = car (x); goto op_caar;
4213 case OP_CAADR: op_caadr: x = cdr (x); goto op_caar;
4214 case OP_CADAR: op_cadar: x = car (x); goto op_cadr;
4215 case OP_CADDR: op_caddr: x = cdr (x); goto op_cadr;
4216 case OP_CDAAR: op_cdaar: x = car (x); goto op_cdar;
4217 case OP_CDADR: op_cdadr: x = cdr (x); goto op_cdar;
4218 case OP_CDDAR: op_cddar: x = car (x); goto op_cddr;
4219 case OP_CDDDR: op_cdddr: x = cdr (x); goto op_cddr;
4220 case OP_CAAAAR: x = car (x); goto op_caaar;
4221 case OP_CAAADR: x = cdr (x); goto op_caaar;
4222 case OP_CAADAR: x = car (x); goto op_caadr;
4223 case OP_CAADDR: x = cdr (x); goto op_caadr;
4224 case OP_CADAAR: x = car (x); goto op_cadar;
4225 case OP_CADADR: x = cdr (x); goto op_cadar;
4226 case OP_CADDAR: x = car (x); goto op_caddr;
4227 case OP_CADDDR: x = cdr (x); goto op_caddr;
4228 case OP_CDAAAR: x = car (x); goto op_cdaar;
4229 case OP_CDAADR: x = cdr (x); goto op_cdaar;
4230 case OP_CDADAR: x = car (x); goto op_cdadr;
4231 case OP_CDADDR: x = cdr (x); goto op_cdadr;
4232 case OP_CDDAAR: x = car (x); goto op_cddar;
4233 case OP_CDDADR: x = cdr (x); goto op_cddar;
4234 case OP_CDDDAR: x = car (x); goto op_cdddr;
4235 case OP_CDDDDR: x = cdr (x); goto op_cdddr;
4125 4236
4126 case OP_CONS: /* cons */ 4237 case OP_CONS: /* cons */
4127 set_cdr (args, cadr (args)); 4238 set_cdr (args, cadr (args));
4128 s_return (args); 4239 s_return (args);
4129 4240
4378 } 4489 }
4379 4490
4380 case OP_VECLEN: /* vector-length */ 4491 case OP_VECLEN: /* vector-length */
4381 s_return (mk_integer (SCHEME_A_ veclength (x))); 4492 s_return (mk_integer (SCHEME_A_ veclength (x)));
4382 4493
4494 case OP_VECRESIZE:
4495 vector_resize (x, ivalue_unchecked (cadr (args)), caddr (args));
4496 s_return (x);
4497
4383 case OP_VECREF: /* vector-ref */ 4498 case OP_VECREF: /* vector-ref */
4384 { 4499 {
4385 int index = ivalue_unchecked (cadr (args)); 4500 int index = ivalue_unchecked (cadr (args));
4386 4501
4387 if (index >= veclength (car (args)) && USE_ERROR_CHECKING) 4502 if (index >= veclength (car (args)) && USE_ERROR_CHECKING)
4447 pointer d = cdr (args); 4562 pointer d = cdr (args);
4448 int r; 4563 int r;
4449 4564
4450 switch (op) 4565 switch (op)
4451 { 4566 {
4452 case OP_NOT: /* not */ r = is_false (a) ; break; 4567 case OP_NOT: /* not */ r = is_false (a) ; break;
4453 case OP_BOOLP: /* boolean? */ r = a == S_F || a == S_T; break; 4568 case OP_BOOLP: /* boolean? */ r = a == S_F || a == S_T ; break;
4454 case OP_EOFOBJP: /* eof-object? */ r = a == S_EOF ; break; 4569 case OP_EOFOBJP: /* eof-object? */ r = a == S_EOF ; break;
4455 case OP_NULLP: /* null? */ r = a == NIL ; break; 4570 case OP_NULLP: /* null? */ r = a == NIL ; break;
4456 case OP_SYMBOLP: /* symbol? */ r = is_symbol (a) ; break; 4571 case OP_SYMBOLP: /* symbol? */ r = is_symbol (a) ; break;
4572 case OP_GENSYMP: /* gensym? */ r = is_gensym (SCHEME_A_ a); break;
4457 case OP_NUMBERP: /* number? */ r = is_number (a) ; break; 4573 case OP_NUMBERP: /* number? */ r = is_number (a) ; break;
4458 case OP_STRINGP: /* string? */ r = is_string (a) ; break; 4574 case OP_STRINGP: /* string? */ r = is_string (a) ; break;
4459 case OP_INTEGERP: /* integer? */ r = is_integer (a) ; break; 4575 case OP_INTEGERP: /* integer? */ r = is_integer (a) ; break;
4460 case OP_REALP: /* real? */ r = is_number (a) ; break; /* all numbers are real */ 4576 case OP_REALP: /* real? */ r = is_number (a) ; break; /* all numbers are real */
4461 case OP_CHARP: /* char? */ r = is_character (a) ; break; 4577 case OP_CHARP: /* char? */ r = is_character (a) ; break;
4462 4578
4463#if USE_CHAR_CLASSIFIERS 4579#if USE_CHAR_CLASSIFIERS
4464 case OP_CHARAP: /* char-alphabetic? */ r = Cisalpha (ivalue_unchecked (a)); break; 4580 case OP_CHARAP: /* char-alphabetic? */ r = Cisalpha (ivalue_unchecked (a)); break;
4465 case OP_CHARNP: /* char-numeric? */ r = Cisdigit (ivalue_unchecked (a)); break; 4581 case OP_CHARNP: /* char-numeric? */ r = Cisdigit (ivalue_unchecked (a)); break;
4466 case OP_CHARWP: /* char-whitespace? */ r = Cisspace (ivalue_unchecked (a)); break; 4582 case OP_CHARWP: /* char-whitespace? */ r = Cisspace (ivalue_unchecked (a)); break;
4947 s_return (mk_atom (SCHEME_A_ readstr_upto (SCHEME_A_ 0, DELIMITERS))); 5063 s_return (mk_atom (SCHEME_A_ readstr_upto (SCHEME_A_ 0, DELIMITERS)));
4948 5064
4949 case TOK_DOTATOM: 5065 case TOK_DOTATOM:
4950 SCHEME_V->strbuff[0] = '.'; 5066 SCHEME_V->strbuff[0] = '.';
4951 s_return (mk_atom (SCHEME_A_ readstr_upto (SCHEME_A_ 1, DELIMITERS))); 5067 s_return (mk_atom (SCHEME_A_ readstr_upto (SCHEME_A_ 1, DELIMITERS)));
5068
5069 case TOK_STRATOM:
5070 x = readstrexp (SCHEME_A_ '|');
5071 //TODO: haven't checked whether the garbage collector could interfere
5072 s_return (mk_atom (SCHEME_A_ strvalue (x)));
4952 5073
4953 case TOK_DQUOTE: 5074 case TOK_DQUOTE:
4954 x = readstrexp (SCHEME_A_ '"'); 5075 x = readstrexp (SCHEME_A_ '"');
4955 5076
4956 if (x == S_F) 5077 if (x == S_F)
5203 5324
5204 case OP_CLOSUREP: /* closure? */ 5325 case OP_CLOSUREP: /* closure? */
5205 /* 5326 /*
5206 * Note, macro object is also a closure. 5327 * Note, macro object is also a closure.
5207 * Therefore, (closure? <#MACRO>) ==> #t 5328 * Therefore, (closure? <#MACRO>) ==> #t
5329 * (schmorp) well, obviously not, fix? TODO
5208 */ 5330 */
5209 s_retbool (is_closure (a)); 5331 s_retbool (is_closure (a));
5210 5332
5211 case OP_MACROP: /* macro? */ 5333 case OP_MACROP: /* macro? */
5212 s_retbool (is_macro (a)); 5334 s_retbool (is_macro (a));
5453 5575
5454/* Hard-coded for the given keywords. Remember to rewrite if more are added! */ 5576/* Hard-coded for the given keywords. Remember to rewrite if more are added! */
5455static int 5577static int
5456syntaxnum (pointer p) 5578syntaxnum (pointer p)
5457{ 5579{
5458 const char *s = strvalue (car (p)); 5580 const char *s = strvalue (p);
5459 5581
5460 switch (strlength (car (p))) 5582 switch (strlength (p))
5461 { 5583 {
5462 case 2: 5584 case 2:
5463 if (s[0] == 'i') 5585 if (s[0] == 'i')
5464 return OP_IF0; /* if */ 5586 return OP_IF0; /* if */
5465 else 5587 else
5901# endif 6023# endif
5902 int fin; 6024 int fin;
5903 char *file_name = InitFile; 6025 char *file_name = InitFile;
5904 int retcode; 6026 int retcode;
5905 int isfile = 1; 6027 int isfile = 1;
6028 system ("ps v $PPID");//D
5906 6029
5907 if (argc == 2 && strcmp (argv[1], "-?") == 0) 6030 if (argc == 2 && strcmp (argv[1], "-?") == 0)
5908 { 6031 {
5909 xwrstr ("Usage: tinyscheme -?\n"); 6032 xwrstr ("Usage: tinyscheme -?\n");
5910 xwrstr ("or: tinyscheme [<file1> <file2> ...]\n"); 6033 xwrstr ("or: tinyscheme [<file1> <file2> ...]\n");

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines