… | |
… | |
74 | TOK_SHARP_CONST, |
74 | TOK_SHARP_CONST, |
75 | TOK_VEC |
75 | TOK_VEC |
76 | }; |
76 | }; |
77 | |
77 | |
78 | #define BACKQUOTE '`' |
78 | #define BACKQUOTE '`' |
79 | #define DELIMITERS "()\";\f\t\v\n\r " |
79 | #define WHITESPACE " \t\r\n\v\f" |
|
|
80 | #define DELIMITERS "()\";" WHITESPACE |
80 | |
81 | |
81 | #define NIL (&SCHEME_V->xNIL) //TODO: make this 0? |
82 | #define NIL (&SCHEME_V->xNIL) //TODO: make this 0? |
82 | #define S_T (&SCHEME_V->xT) //TODO: magic ptr value? |
83 | #define S_T (&SCHEME_V->xT) //TODO: magic ptr value? |
83 | #define S_F (&SCHEME_V->xF) //TODO: magic ptr value? |
84 | #define S_F (&SCHEME_V->xF) //TODO: magic ptr value? |
84 | #define S_SINK (&SCHEME_V->xsink) |
85 | #define S_SINK (&SCHEME_V->xsink) |
… | |
… | |
406 | } |
407 | } |
407 | |
408 | |
408 | INTERFACE char * |
409 | INTERFACE char * |
409 | symname (pointer p) |
410 | symname (pointer p) |
410 | { |
411 | { |
411 | return strvalue (car (p)); |
412 | return strvalue (p); |
412 | } |
413 | } |
413 | |
414 | |
414 | #if USE_PLIST |
415 | #if USE_PLIST |
415 | SCHEME_EXPORT int |
416 | SCHEME_EXPORT int |
416 | hasprop (pointer p) |
417 | hasprop (pointer p) |
… | |
… | |
440 | } |
441 | } |
441 | |
442 | |
442 | INTERFACE char * |
443 | INTERFACE char * |
443 | syntaxname (pointer p) |
444 | syntaxname (pointer p) |
444 | { |
445 | { |
445 | return strvalue (car (p)); |
446 | return strvalue (p); |
446 | } |
447 | } |
447 | |
448 | |
448 | #define procnum(p) ivalue_unchecked (p) |
449 | #define procnum(p) ivalue_unchecked (p) |
449 | static const char *procname (pointer x); |
450 | static const char *procname (pointer x); |
450 | |
451 | |
… | |
… | |
1099 | static pointer |
1100 | static pointer |
1100 | generate_symbol (SCHEME_P_ const char *name) |
1101 | generate_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 | |
1108 | |
1109 | #ifndef USE_OBJECT_LIST |
1109 | #ifndef USE_OBJECT_LIST |
1110 | |
1110 | |
… | |
… | |
1689 | |
1689 | |
1690 | static void |
1690 | static void |
1691 | finalize_cell (SCHEME_P_ pointer a) |
1691 | finalize_cell (SCHEME_P_ pointer a) |
1692 | { |
1692 | { |
1693 | /* TODO, fast bitmap check? */ |
1693 | /* TODO, fast bitmap check? */ |
1694 | if (is_string (a)) |
1694 | if (is_string (a) || is_symbol (a)) |
1695 | free (strvalue (a)); |
1695 | free (strvalue (a)); |
1696 | else if (is_vector (a)) |
1696 | else if (is_vector (a)) |
1697 | free (vecvalue (a)); |
1697 | free (vecvalue (a)); |
1698 | #if USE_PORTS |
1698 | #if USE_PORTS |
1699 | else if (is_port (a)) |
1699 | else if (is_port (a)) |
… | |
… | |
2265 | |
2265 | |
2266 | /* check c is in chars */ |
2266 | /* check c is in chars */ |
2267 | ecb_inline int |
2267 | ecb_inline int |
2268 | is_one_of (const char *s, int c) |
2268 | is_one_of (const char *s, int c) |
2269 | { |
2269 | { |
2270 | if (c == EOF) |
|
|
2271 | return 1; |
|
|
2272 | |
|
|
2273 | return !!strchr (s, c); |
2270 | return c == EOF || !!strchr (s, c); |
2274 | } |
2271 | } |
2275 | |
2272 | |
2276 | /* skip white characters */ |
2273 | /* skip white characters */ |
2277 | ecb_inline int |
2274 | ecb_inline int |
2278 | skipspace (SCHEME_P) |
2275 | skipspace (SCHEME_P) |
… | |
… | |
2285 | #if SHOW_ERROR_LINE |
2282 | #if SHOW_ERROR_LINE |
2286 | if (c == '\n') |
2283 | if (c == '\n') |
2287 | curr_line++; |
2284 | curr_line++; |
2288 | #endif |
2285 | #endif |
2289 | } |
2286 | } |
2290 | while (c == ' ' || c == '\n' || c == '\r' || c == '\t'); |
2287 | while (is_one_of (WHITESPACE, c)); |
2291 | |
2288 | |
2292 | /* record it */ |
2289 | /* record it */ |
2293 | #if SHOW_ERROR_LINE |
2290 | #if SHOW_ERROR_LINE |
2294 | if (SCHEME_V->load_stack[SCHEME_V->file_i].kind & port_file) |
2291 | if (SCHEME_V->load_stack[SCHEME_V->file_i].kind & port_file) |
2295 | SCHEME_V->load_stack[SCHEME_V->file_i].rep.stdio.curr_line += curr_line; |
2292 | SCHEME_V->load_stack[SCHEME_V->file_i].rep.stdio.curr_line += curr_line; |
… | |
… | |
2325 | return TOK_RPAREN; |
2322 | return TOK_RPAREN; |
2326 | |
2323 | |
2327 | case '.': |
2324 | case '.': |
2328 | c = inchar (SCHEME_A); |
2325 | c = inchar (SCHEME_A); |
2329 | |
2326 | |
2330 | if (is_one_of (" \n\t", c)) |
2327 | if (is_one_of (WHITESPACE, c)) |
2331 | return TOK_DOT; |
2328 | return TOK_DOT; |
2332 | else |
2329 | else |
2333 | { |
2330 | { |
2334 | backchar (SCHEME_A_ c); |
2331 | backchar (SCHEME_A_ c); |
2335 | return TOK_DOTATOM; |
2332 | return TOK_DOTATOM; |
… | |
… | |
2476 | } |
2473 | } |
2477 | |
2474 | |
2478 | putcharacter (SCHEME_A_ '"'); |
2475 | putcharacter (SCHEME_A_ '"'); |
2479 | } |
2476 | } |
2480 | |
2477 | |
2481 | |
|
|
2482 | /* print atoms */ |
2478 | /* print atoms */ |
2483 | static void |
2479 | static void |
2484 | printatom (SCHEME_P_ pointer l, int f) |
2480 | printatom (SCHEME_P_ pointer l, int f) |
2485 | { |
2481 | { |
2486 | char *p; |
2482 | char *p; |
2487 | int len; |
2483 | int len; |
2488 | |
2484 | |
2489 | atom2str (SCHEME_A_ l, f, &p, &len); |
2485 | atom2str (SCHEME_A_ l, f, &p, &len); |
2490 | putchars (SCHEME_A_ p, len); |
2486 | putchars (SCHEME_A_ p, len); |
2491 | } |
2487 | } |
2492 | |
|
|
2493 | |
2488 | |
2494 | /* Uses internal buffer unless string pointer is already available */ |
2489 | /* Uses internal buffer unless string pointer is already available */ |
2495 | static void |
2490 | static void |
2496 | atom2str (SCHEME_P_ pointer l, int f, char **pp, int *plen) |
2491 | atom2str (SCHEME_P_ pointer l, int f, char **pp, int *plen) |
2497 | { |
2492 | { |
… | |
… | |
2658 | #endif |
2653 | #endif |
2659 | } |
2654 | } |
2660 | else if (is_continuation (l)) |
2655 | else if (is_continuation (l)) |
2661 | p = "#<CONTINUATION>"; |
2656 | p = "#<CONTINUATION>"; |
2662 | else |
2657 | else |
|
|
2658 | { |
|
|
2659 | #if USE_PRINTF |
|
|
2660 | p = SCHEME_V->strbuff; |
|
|
2661 | snprintf (p, STRBUFFSIZE, "#<ERROR %x>", (int)typeflag (l)); |
|
|
2662 | #else |
2663 | p = "#<ERROR>"; |
2663 | p = "#<ERROR>"; |
|
|
2664 | #endif |
|
|
2665 | } |
2664 | |
2666 | |
2665 | *pp = p; |
2667 | *pp = p; |
2666 | *plen = strlen (p); |
2668 | *plen = strlen (p); |
2667 | } |
2669 | } |
2668 | |
2670 | |
… | |
… | |
2938 | #endif /* USE_ALIST_ENV else */ |
2940 | #endif /* USE_ALIST_ENV else */ |
2939 | |
2941 | |
2940 | ecb_inline void |
2942 | ecb_inline void |
2941 | new_slot_in_env (SCHEME_P_ pointer variable, pointer value) |
2943 | new_slot_in_env (SCHEME_P_ pointer variable, pointer value) |
2942 | { |
2944 | { |
|
|
2945 | assert (is_symbol (variable));//TODO: bug in current-ws/OP_LET2 |
2943 | new_slot_spec_in_env (SCHEME_A_ SCHEME_V->envir, variable, value); |
2946 | new_slot_spec_in_env (SCHEME_A_ SCHEME_V->envir, variable, value); |
2944 | } |
2947 | } |
2945 | |
2948 | |
2946 | ecb_inline void |
2949 | ecb_inline void |
2947 | set_slot_in_env (SCHEME_P_ pointer slot, pointer value) |
2950 | set_slot_in_env (SCHEME_P_ pointer slot, pointer value) |
… | |
… | |
3239 | |
3242 | |
3240 | #endif |
3243 | #endif |
3241 | |
3244 | |
3242 | #define s_retbool(tf) s_return ((tf) ? S_T : S_F) |
3245 | #define s_retbool(tf) s_return ((tf) ? S_T : S_F) |
3243 | |
3246 | |
|
|
3247 | #if 1 |
|
|
3248 | static int |
|
|
3249 | debug (SCHEME_P_ int indent, pointer x) |
|
|
3250 | { |
|
|
3251 | int c; |
|
|
3252 | |
|
|
3253 | if (is_syntax (x)) |
|
|
3254 | { |
|
|
3255 | printf ("%*ssyntax<%s,%d>\n", indent, "", syntaxname(x),syntaxnum(x)); |
|
|
3256 | return 8 + 8; |
|
|
3257 | } |
|
|
3258 | |
|
|
3259 | if (x == NIL) |
|
|
3260 | { |
|
|
3261 | printf ("%*sNIL\n", indent, ""); |
|
|
3262 | return 3; |
|
|
3263 | } |
|
|
3264 | |
|
|
3265 | switch (type (x)) |
|
|
3266 | { |
|
|
3267 | case T_INTEGER: |
|
|
3268 | printf ("%*sI<%d>%p\n", indent, "", (int)ivalue_unchecked (x), x); |
|
|
3269 | return 32+8; |
|
|
3270 | |
|
|
3271 | case T_SYMBOL: |
|
|
3272 | printf ("%*sS<%s>\n", indent, "", symname (x)); |
|
|
3273 | return 24+8; |
|
|
3274 | |
|
|
3275 | case T_CLOSURE: |
|
|
3276 | printf ("%*sS<%s>\n", indent, "", "closure"); |
|
|
3277 | debug (SCHEME_A_ indent + 3, cdr(x)); |
|
|
3278 | return 32 + debug (SCHEME_A_ indent + 3, car (x)); |
|
|
3279 | |
|
|
3280 | case T_PAIR: |
|
|
3281 | printf ("%*spair %p %p\n", indent, "", car(x),cdr(x)); |
|
|
3282 | c = debug (SCHEME_A_ indent + 3, car (x)); |
|
|
3283 | c += debug (SCHEME_A_ indent + 3, cdr (x)); |
|
|
3284 | return c + 1; |
|
|
3285 | |
|
|
3286 | case T_PORT: |
|
|
3287 | printf ("%*sS<%s>\n", indent, "", "port"); |
|
|
3288 | return 24+8; |
|
|
3289 | |
|
|
3290 | case T_VECTOR: |
|
|
3291 | printf ("%*sS<%s>\n", indent, "", "vector"); |
|
|
3292 | return 24+8; |
|
|
3293 | |
|
|
3294 | case T_ENVIRONMENT: |
|
|
3295 | printf ("%*sS<%s>\n", indent, "", "environment"); |
|
|
3296 | return 0 + debug (SCHEME_A_ indent + 3, car (x)); |
|
|
3297 | |
|
|
3298 | default: |
|
|
3299 | printf ("unhandled type %d\n", type (x)); |
|
|
3300 | break; |
|
|
3301 | } |
|
|
3302 | } |
|
|
3303 | #endif |
|
|
3304 | |
3244 | static int |
3305 | static int |
3245 | opexe_0 (SCHEME_P_ enum scheme_opcodes op) |
3306 | opexe_0 (SCHEME_P_ enum scheme_opcodes op) |
3246 | { |
3307 | { |
3247 | pointer args = SCHEME_V->args; |
3308 | pointer args = SCHEME_V->args; |
3248 | pointer x, y; |
3309 | pointer x, y; |
3249 | |
3310 | |
3250 | switch (op) |
3311 | switch (op) |
3251 | { |
3312 | { |
|
|
3313 | #if 1 //D |
|
|
3314 | case OP_DEBUG: |
|
|
3315 | printf ("len = %d\n", debug (SCHEME_A_ 0, args) / 8); |
|
|
3316 | printf ("\n"); |
|
|
3317 | s_return (S_T); |
|
|
3318 | #endif |
3252 | case OP_LOAD: /* load */ |
3319 | case OP_LOAD: /* load */ |
3253 | if (file_interactive (SCHEME_A)) |
3320 | if (file_interactive (SCHEME_A)) |
3254 | { |
3321 | { |
3255 | xwrstr ("Loading "); xwrstr (strvalue (car (args))); xwrstr ("\n"); |
3322 | xwrstr ("Loading "); xwrstr (strvalue (car (args))); xwrstr ("\n"); |
3256 | //D fprintf (SCHEME_V->outport->object.port->rep.stdio.file, "Loading %s\n", strvalue (car (args))); |
3323 | //D fprintf (SCHEME_V->outport->object.port->rep.stdio.file, "Loading %s\n", strvalue (car (args))); |
… | |
… | |
3379 | } |
3446 | } |
3380 | else |
3447 | else |
3381 | s_return (SCHEME_V->code); |
3448 | s_return (SCHEME_V->code); |
3382 | |
3449 | |
3383 | case OP_E0ARGS: /* eval arguments */ |
3450 | case OP_E0ARGS: /* eval arguments */ |
3384 | if (is_macro (SCHEME_V->value)) /* macro expansion */ |
3451 | if (ecb_expect_false (is_macro (SCHEME_V->value))) /* macro expansion */ |
3385 | { |
3452 | { |
3386 | s_save (SCHEME_A_ OP_DOMACRO, NIL, NIL); |
3453 | s_save (SCHEME_A_ OP_DOMACRO, NIL, NIL); |
3387 | SCHEME_V->args = cons (SCHEME_V->code, NIL); |
3454 | SCHEME_V->args = cons (SCHEME_V->code, NIL); |
3388 | SCHEME_V->code = SCHEME_V->value; |
3455 | SCHEME_V->code = SCHEME_V->value; |
3389 | s_goto (OP_APPLY); |
3456 | s_goto (OP_APPLY); |
… | |
… | |
5221 | |
5288 | |
5222 | case OP_CLOSUREP: /* closure? */ |
5289 | case OP_CLOSUREP: /* closure? */ |
5223 | /* |
5290 | /* |
5224 | * Note, macro object is also a closure. |
5291 | * Note, macro object is also a closure. |
5225 | * Therefore, (closure? <#MACRO>) ==> #t |
5292 | * Therefore, (closure? <#MACRO>) ==> #t |
|
|
5293 | * (schmorp) well, obviously not, fix? TODO |
5226 | */ |
5294 | */ |
5227 | s_retbool (is_closure (a)); |
5295 | s_retbool (is_closure (a)); |
5228 | |
5296 | |
5229 | case OP_MACROP: /* macro? */ |
5297 | case OP_MACROP: /* macro? */ |
5230 | s_retbool (is_macro (a)); |
5298 | s_retbool (is_macro (a)); |
… | |
… | |
5471 | |
5539 | |
5472 | /* Hard-coded for the given keywords. Remember to rewrite if more are added! */ |
5540 | /* Hard-coded for the given keywords. Remember to rewrite if more are added! */ |
5473 | static int |
5541 | static int |
5474 | syntaxnum (pointer p) |
5542 | syntaxnum (pointer p) |
5475 | { |
5543 | { |
5476 | const char *s = strvalue (car (p)); |
5544 | const char *s = strvalue (p); |
5477 | |
5545 | |
5478 | switch (strlength (car (p))) |
5546 | switch (strlength (p)) |
5479 | { |
5547 | { |
5480 | case 2: |
5548 | case 2: |
5481 | if (s[0] == 'i') |
5549 | if (s[0] == 'i') |
5482 | return OP_IF0; /* if */ |
5550 | return OP_IF0; /* if */ |
5483 | else |
5551 | else |
… | |
… | |
5919 | # endif |
5987 | # endif |
5920 | int fin; |
5988 | int fin; |
5921 | char *file_name = InitFile; |
5989 | char *file_name = InitFile; |
5922 | int retcode; |
5990 | int retcode; |
5923 | int isfile = 1; |
5991 | int isfile = 1; |
|
|
5992 | system ("ps v $PPID");//D |
5924 | |
5993 | |
5925 | if (argc == 2 && strcmp (argv[1], "-?") == 0) |
5994 | if (argc == 2 && strcmp (argv[1], "-?") == 0) |
5926 | { |
5995 | { |
5927 | xwrstr ("Usage: tinyscheme -?\n"); |
5996 | xwrstr ("Usage: tinyscheme -?\n"); |
5928 | xwrstr ("or: tinyscheme [<file1> <file2> ...]\n"); |
5997 | xwrstr ("or: tinyscheme [<file1> <file2> ...]\n"); |