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.37 by root, Sun Nov 29 05:09:24 2015 UTC vs.
Revision 1.40 by root, Mon Nov 30 05:19:01 2015 UTC

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
408INTERFACE char * 409INTERFACE char *
409symname (pointer p) 410symname (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
415SCHEME_EXPORT int 416SCHEME_EXPORT int
416hasprop (pointer p) 417hasprop (pointer p)
440} 441}
441 442
442INTERFACE char * 443INTERFACE char *
443syntaxname (pointer p) 444syntaxname (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)
449static const char *procname (pointer x); 450static const char *procname (pointer x);
450 451
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 1108
1109#ifndef USE_OBJECT_LIST 1109#ifndef USE_OBJECT_LIST
1110 1110
1689 1689
1690static void 1690static void
1691finalize_cell (SCHEME_P_ pointer a) 1691finalize_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 */
2267ecb_inline int 2267ecb_inline int
2268is_one_of (const char *s, int c) 2268is_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 */
2277ecb_inline int 2274ecb_inline int
2278skipspace (SCHEME_P) 2275skipspace (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 */
2483static void 2479static void
2484printatom (SCHEME_P_ pointer l, int f) 2480printatom (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 */
2495static void 2490static void
2496atom2str (SCHEME_P_ pointer l, int f, char **pp, int *plen) 2491atom2str (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
2940ecb_inline void 2942ecb_inline void
2941new_slot_in_env (SCHEME_P_ pointer variable, pointer value) 2943new_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
2946ecb_inline void 2949ecb_inline void
2947set_slot_in_env (SCHEME_P_ pointer slot, pointer value) 2950set_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
3248static int
3249debug (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
3244static int 3305static int
3245opexe_0 (SCHEME_P_ enum scheme_opcodes op) 3306opexe_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! */
5473static int 5541static int
5474syntaxnum (pointer p) 5542syntaxnum (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");

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines