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.39 by root, Sun Nov 29 14:22:30 2015 UTC

406} 406}
407 407
408INTERFACE char * 408INTERFACE char *
409symname (pointer p) 409symname (pointer p)
410{ 410{
411 return strvalue (car (p)); 411 return strvalue (p);
412} 412}
413 413
414#if USE_PLIST 414#if USE_PLIST
415SCHEME_EXPORT int 415SCHEME_EXPORT int
416hasprop (pointer p) 416hasprop (pointer p)
440} 440}
441 441
442INTERFACE char * 442INTERFACE char *
443syntaxname (pointer p) 443syntaxname (pointer p)
444{ 444{
445 return strvalue (car (p)); 445 return strvalue (p);
446} 446}
447 447
448#define procnum(p) ivalue_unchecked (p) 448#define procnum(p) ivalue_unchecked (p)
449static const char *procname (pointer x); 449static const char *procname (pointer x);
450 450
1099static pointer 1099static pointer
1100generate_symbol (SCHEME_P_ const char *name) 1100generate_symbol (SCHEME_P_ const char *name)
1101{ 1101{
1102 pointer x = mk_string (SCHEME_A_ name); 1102 pointer x = mk_string (SCHEME_A_ name);
1103 setimmutable (x); 1103 setimmutable (x);
1104 x = immutable_cons (x, NIL);
1105 set_typeflag (x, T_SYMBOL); 1104 set_typeflag (x, T_SYMBOL | T_ATOM);
1106 return x; 1105 return x;
1107} 1106}
1108 1107
1109#ifndef USE_OBJECT_LIST 1108#ifndef USE_OBJECT_LIST
1110 1109
1352{ 1351{
1353 int i; 1352 int i;
1354 1353
1355 for (i = start; i < veclength (vec); i++) 1354 for (i = start; i < veclength (vec); i++)
1356 vecvalue (vec)[i] = obj; 1355 vecvalue (vec)[i] = obj;
1356}
1357
1358INTERFACE void
1359vector_resize (pointer vec, uint32_t newsize, pointer fill)
1360{
1361 uint32_t oldsize = veclength (vec);
1362 vecvalue (vec) = realloc (vecvalue (vec), newsize * sizeof (pointer));
1363 veclength (vec) = newsize;
1364 fill_vector (vec, oldsize, fill);
1357} 1365}
1358 1366
1359INTERFACE pointer 1367INTERFACE pointer
1360vector_get (pointer vec, uint32_t ielem) 1368vector_get (pointer vec, uint32_t ielem)
1361{ 1369{
2467 } 2475 }
2468 2476
2469 putcharacter (SCHEME_A_ '"'); 2477 putcharacter (SCHEME_A_ '"');
2470} 2478}
2471 2479
2472
2473/* print atoms */ 2480/* print atoms */
2474static void 2481static void
2475printatom (SCHEME_P_ pointer l, int f) 2482printatom (SCHEME_P_ pointer l, int f)
2476{ 2483{
2477 char *p; 2484 char *p;
2478 int len; 2485 int len;
2479 2486
2480 atom2str (SCHEME_A_ l, f, &p, &len); 2487 atom2str (SCHEME_A_ l, f, &p, &len);
2481 putchars (SCHEME_A_ p, len); 2488 putchars (SCHEME_A_ p, len);
2482} 2489}
2483
2484 2490
2485/* Uses internal buffer unless string pointer is already available */ 2491/* Uses internal buffer unless string pointer is already available */
2486static void 2492static void
2487atom2str (SCHEME_P_ pointer l, int f, char **pp, int *plen) 2493atom2str (SCHEME_P_ pointer l, int f, char **pp, int *plen)
2488{ 2494{
2649#endif 2655#endif
2650 } 2656 }
2651 else if (is_continuation (l)) 2657 else if (is_continuation (l))
2652 p = "#<CONTINUATION>"; 2658 p = "#<CONTINUATION>";
2653 else 2659 else
2660 {
2661#if USE_PRINTF
2662 p = SCHEME_V->strbuff;
2663 snprintf (p, STRBUFFSIZE, "#<ERROR %x>", (int)typeflag (l));
2664#else
2654 p = "#<ERROR>"; 2665 p = "#<ERROR>";
2666#endif
2667 }
2655 2668
2656 *pp = p; 2669 *pp = p;
2657 *plen = strlen (p); 2670 *plen = strlen (p);
2658} 2671}
2659 2672
2929#endif /* USE_ALIST_ENV else */ 2942#endif /* USE_ALIST_ENV else */
2930 2943
2931ecb_inline void 2944ecb_inline void
2932new_slot_in_env (SCHEME_P_ pointer variable, pointer value) 2945new_slot_in_env (SCHEME_P_ pointer variable, pointer value)
2933{ 2946{
2947 assert (is_symbol (variable));//TODO: bug in current-ws/OP_LET2
2934 new_slot_spec_in_env (SCHEME_A_ SCHEME_V->envir, variable, value); 2948 new_slot_spec_in_env (SCHEME_A_ SCHEME_V->envir, variable, value);
2935} 2949}
2936 2950
2937ecb_inline void 2951ecb_inline void
2938set_slot_in_env (SCHEME_P_ pointer slot, pointer value) 2952set_slot_in_env (SCHEME_P_ pointer slot, pointer value)
3230 3244
3231#endif 3245#endif
3232 3246
3233#define s_retbool(tf) s_return ((tf) ? S_T : S_F) 3247#define s_retbool(tf) s_return ((tf) ? S_T : S_F)
3234 3248
3249#if 1
3250static int
3251debug (SCHEME_P_ int indent, pointer x)
3252{
3253 int c;
3254
3255 if (is_syntax (x))
3256 {
3257 printf ("%*ssyntax<%s,%d>\n", indent, "", syntaxname(x),syntaxnum(x));
3258 return 8 + 8;
3259 }
3260
3261 if (x == NIL)
3262 {
3263 printf ("%*sNIL\n", indent, "");
3264 return 3;
3265 }
3266
3267 switch (type (x))
3268 {
3269 case T_INTEGER:
3270 printf ("%*sI<%d>%p\n", indent, "", (int)ivalue_unchecked (x), x);
3271 return 32+8;
3272
3273 case T_SYMBOL:
3274 printf ("%*sS<%s>\n", indent, "", symname (x));
3275 return 24+8;
3276
3277 case T_CLOSURE:
3278 printf ("%*sS<%s>\n", indent, "", "closure");
3279 debug (SCHEME_A_ indent + 3, cdr(x));
3280 return 32 + debug (SCHEME_A_ indent + 3, car (x));
3281
3282 case T_PAIR:
3283 printf ("%*spair %p %p\n", indent, "", car(x),cdr(x));
3284 c = debug (SCHEME_A_ indent + 3, car (x));
3285 c += debug (SCHEME_A_ indent + 3, cdr (x));
3286 return c + 1;
3287
3288 case T_PORT:
3289 printf ("%*sS<%s>\n", indent, "", "port");
3290 return 24+8;
3291
3292 case T_VECTOR:
3293 printf ("%*sS<%s>\n", indent, "", "vector");
3294 return 24+8;
3295
3296 case T_ENVIRONMENT:
3297 printf ("%*sS<%s>\n", indent, "", "environment");
3298 return 0 + debug (SCHEME_A_ indent + 3, car (x));
3299
3300 default:
3301 printf ("unhandled type %d\n", type (x));
3302 break;
3303 }
3304}
3305#endif
3306
3235static int 3307static int
3236opexe_0 (SCHEME_P_ enum scheme_opcodes op) 3308opexe_0 (SCHEME_P_ enum scheme_opcodes op)
3237{ 3309{
3238 pointer args = SCHEME_V->args; 3310 pointer args = SCHEME_V->args;
3239 pointer x, y; 3311 pointer x, y;
3240 3312
3241 switch (op) 3313 switch (op)
3242 { 3314 {
3315#if 1 //D
3316 case OP_DEBUG:
3317 printf ("len = %d\n", debug (SCHEME_A_ 0, args) / 8);
3318 printf ("\n");
3319 s_return (S_T);
3320#endif
3243 case OP_LOAD: /* load */ 3321 case OP_LOAD: /* load */
3244 if (file_interactive (SCHEME_A)) 3322 if (file_interactive (SCHEME_A))
3245 { 3323 {
3246 xwrstr ("Loading "); xwrstr (strvalue (car (args))); xwrstr ("\n"); 3324 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))); 3325 //D fprintf (SCHEME_V->outport->object.port->rep.stdio.file, "Loading %s\n", strvalue (car (args)));
3370 } 3448 }
3371 else 3449 else
3372 s_return (SCHEME_V->code); 3450 s_return (SCHEME_V->code);
3373 3451
3374 case OP_E0ARGS: /* eval arguments */ 3452 case OP_E0ARGS: /* eval arguments */
3375 if (is_macro (SCHEME_V->value)) /* macro expansion */ 3453 if (ecb_expect_false (is_macro (SCHEME_V->value))) /* macro expansion */
3376 { 3454 {
3377 s_save (SCHEME_A_ OP_DOMACRO, NIL, NIL); 3455 s_save (SCHEME_A_ OP_DOMACRO, NIL, NIL);
3378 SCHEME_V->args = cons (SCHEME_V->code, NIL); 3456 SCHEME_V->args = cons (SCHEME_V->code, NIL);
3379 SCHEME_V->code = SCHEME_V->value; 3457 SCHEME_V->code = SCHEME_V->value;
3380 s_goto (OP_APPLY); 3458 s_goto (OP_APPLY);
4378 } 4456 }
4379 4457
4380 case OP_VECLEN: /* vector-length */ 4458 case OP_VECLEN: /* vector-length */
4381 s_return (mk_integer (SCHEME_A_ veclength (x))); 4459 s_return (mk_integer (SCHEME_A_ veclength (x)));
4382 4460
4461 case OP_VECRESIZE:
4462 vector_resize (x, ivalue_unchecked (cadr (args)), caddr (args));
4463 s_return (x);
4464
4383 case OP_VECREF: /* vector-ref */ 4465 case OP_VECREF: /* vector-ref */
4384 { 4466 {
4385 int index = ivalue_unchecked (cadr (args)); 4467 int index = ivalue_unchecked (cadr (args));
4386 4468
4387 if (index >= veclength (car (args)) && USE_ERROR_CHECKING) 4469 if (index >= veclength (car (args)) && USE_ERROR_CHECKING)
4947 s_return (mk_atom (SCHEME_A_ readstr_upto (SCHEME_A_ 0, DELIMITERS))); 5029 s_return (mk_atom (SCHEME_A_ readstr_upto (SCHEME_A_ 0, DELIMITERS)));
4948 5030
4949 case TOK_DOTATOM: 5031 case TOK_DOTATOM:
4950 SCHEME_V->strbuff[0] = '.'; 5032 SCHEME_V->strbuff[0] = '.';
4951 s_return (mk_atom (SCHEME_A_ readstr_upto (SCHEME_A_ 1, DELIMITERS))); 5033 s_return (mk_atom (SCHEME_A_ readstr_upto (SCHEME_A_ 1, DELIMITERS)));
5034
5035 case TOK_STRATOM:
5036 x = readstrexp (SCHEME_A_ '|');
5037 //TODO: haven't checked whether the garbage collector could interfere
5038 s_return (mk_atom (SCHEME_A_ strvalue (x)));
4952 5039
4953 case TOK_DQUOTE: 5040 case TOK_DQUOTE:
4954 x = readstrexp (SCHEME_A_ '"'); 5041 x = readstrexp (SCHEME_A_ '"');
4955 5042
4956 if (x == S_F) 5043 if (x == S_F)
5203 5290
5204 case OP_CLOSUREP: /* closure? */ 5291 case OP_CLOSUREP: /* closure? */
5205 /* 5292 /*
5206 * Note, macro object is also a closure. 5293 * Note, macro object is also a closure.
5207 * Therefore, (closure? <#MACRO>) ==> #t 5294 * Therefore, (closure? <#MACRO>) ==> #t
5295 * (schmorp) well, obviously not, fix? TODO
5208 */ 5296 */
5209 s_retbool (is_closure (a)); 5297 s_retbool (is_closure (a));
5210 5298
5211 case OP_MACROP: /* macro? */ 5299 case OP_MACROP: /* macro? */
5212 s_retbool (is_macro (a)); 5300 s_retbool (is_macro (a));
5453 5541
5454/* Hard-coded for the given keywords. Remember to rewrite if more are added! */ 5542/* Hard-coded for the given keywords. Remember to rewrite if more are added! */
5455static int 5543static int
5456syntaxnum (pointer p) 5544syntaxnum (pointer p)
5457{ 5545{
5458 const char *s = strvalue (car (p)); 5546 const char *s = strvalue (p);
5459 5547
5460 switch (strlength (car (p))) 5548 switch (strlength (p))
5461 { 5549 {
5462 case 2: 5550 case 2:
5463 if (s[0] == 'i') 5551 if (s[0] == 'i')
5464 return OP_IF0; /* if */ 5552 return OP_IF0; /* if */
5465 else 5553 else
5901# endif 5989# endif
5902 int fin; 5990 int fin;
5903 char *file_name = InitFile; 5991 char *file_name = InitFile;
5904 int retcode; 5992 int retcode;
5905 int isfile = 1; 5993 int isfile = 1;
5994 system ("ps v $PPID");//D
5906 5995
5907 if (argc == 2 && strcmp (argv[1], "-?") == 0) 5996 if (argc == 2 && strcmp (argv[1], "-?") == 0)
5908 { 5997 {
5909 xwrstr ("Usage: tinyscheme -?\n"); 5998 xwrstr ("Usage: tinyscheme -?\n");
5910 xwrstr ("or: tinyscheme [<file1> <file2> ...]\n"); 5999 xwrstr ("or: tinyscheme [<file1> <file2> ...]\n");

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines