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.38 by root, Sun Nov 29 13:47:15 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
3370 } 3383 }
3371 else 3384 else
3372 s_return (SCHEME_V->code); 3385 s_return (SCHEME_V->code);
3373 3386
3374 case OP_E0ARGS: /* eval arguments */ 3387 case OP_E0ARGS: /* eval arguments */
3375 if (is_macro (SCHEME_V->value)) /* macro expansion */ 3388 if (ecb_expect_false (is_macro (SCHEME_V->value))) /* macro expansion */
3376 { 3389 {
3377 s_save (SCHEME_A_ OP_DOMACRO, NIL, NIL); 3390 s_save (SCHEME_A_ OP_DOMACRO, NIL, NIL);
3378 SCHEME_V->args = cons (SCHEME_V->code, NIL); 3391 SCHEME_V->args = cons (SCHEME_V->code, NIL);
3379 SCHEME_V->code = SCHEME_V->value; 3392 SCHEME_V->code = SCHEME_V->value;
3380 s_goto (OP_APPLY); 3393 s_goto (OP_APPLY);
3641 case OP_LET2: /* let */ 3654 case OP_LET2: /* let */
3642 new_frame_in_env (SCHEME_A_ SCHEME_V->envir); 3655 new_frame_in_env (SCHEME_A_ SCHEME_V->envir);
3643 3656
3644 for (x = is_symbol (car (SCHEME_V->code)) ? cadr (SCHEME_V->code) : car (SCHEME_V->code), y = args; 3657 for (x = is_symbol (car (SCHEME_V->code)) ? cadr (SCHEME_V->code) : car (SCHEME_V->code), y = args;
3645 y != NIL; x = cdr (x), y = cdr (y)) 3658 y != NIL; x = cdr (x), y = cdr (y))
3659 { if (is_pair(caar(x))){debug(SCHEME_A_ 0, SCHEME_V->code);};//D
3660 pointer z = caar (x);
3661 if(is_pair(z)) z = car(z);//D
3662 new_slot_in_env (SCHEME_A_ z, car (y));
3663 }
3646 new_slot_in_env (SCHEME_A_ caar (x), car (y)); 3664 //new_slot_in_env (SCHEME_A_ caar (x), car (y));
3647 3665
3648 if (is_symbol (car (SCHEME_V->code))) /* named let */ 3666 if (is_symbol (car (SCHEME_V->code))) /* named let */
3649 { 3667 {
3650 for (x = cadr (SCHEME_V->code), args = NIL; x != NIL; x = cdr (x)) 3668 for (x = cadr (SCHEME_V->code), args = NIL; x != NIL; x = cdr (x))
3651 { 3669 {
4378 } 4396 }
4379 4397
4380 case OP_VECLEN: /* vector-length */ 4398 case OP_VECLEN: /* vector-length */
4381 s_return (mk_integer (SCHEME_A_ veclength (x))); 4399 s_return (mk_integer (SCHEME_A_ veclength (x)));
4382 4400
4401 case OP_VECRESIZE:
4402 vector_resize (x, ivalue_unchecked (cadr (args)), caddr (args));
4403 s_return (x);
4404
4383 case OP_VECREF: /* vector-ref */ 4405 case OP_VECREF: /* vector-ref */
4384 { 4406 {
4385 int index = ivalue_unchecked (cadr (args)); 4407 int index = ivalue_unchecked (cadr (args));
4386 4408
4387 if (index >= veclength (car (args)) && USE_ERROR_CHECKING) 4409 if (index >= veclength (car (args)) && USE_ERROR_CHECKING)
4947 s_return (mk_atom (SCHEME_A_ readstr_upto (SCHEME_A_ 0, DELIMITERS))); 4969 s_return (mk_atom (SCHEME_A_ readstr_upto (SCHEME_A_ 0, DELIMITERS)));
4948 4970
4949 case TOK_DOTATOM: 4971 case TOK_DOTATOM:
4950 SCHEME_V->strbuff[0] = '.'; 4972 SCHEME_V->strbuff[0] = '.';
4951 s_return (mk_atom (SCHEME_A_ readstr_upto (SCHEME_A_ 1, DELIMITERS))); 4973 s_return (mk_atom (SCHEME_A_ readstr_upto (SCHEME_A_ 1, DELIMITERS)));
4974
4975 case TOK_STRATOM:
4976 x = readstrexp (SCHEME_A_ '|');
4977 //TODO: haven't checked whether the garbage collector could interfere
4978 s_return (mk_atom (SCHEME_A_ strvalue (x)));
4952 4979
4953 case TOK_DQUOTE: 4980 case TOK_DQUOTE:
4954 x = readstrexp (SCHEME_A_ '"'); 4981 x = readstrexp (SCHEME_A_ '"');
4955 4982
4956 if (x == S_F) 4983 if (x == S_F)
5203 5230
5204 case OP_CLOSUREP: /* closure? */ 5231 case OP_CLOSUREP: /* closure? */
5205 /* 5232 /*
5206 * Note, macro object is also a closure. 5233 * Note, macro object is also a closure.
5207 * Therefore, (closure? <#MACRO>) ==> #t 5234 * Therefore, (closure? <#MACRO>) ==> #t
5235 * (schmorp) well, obviously not, fix? TODO
5208 */ 5236 */
5209 s_retbool (is_closure (a)); 5237 s_retbool (is_closure (a));
5210 5238
5211 case OP_MACROP: /* macro? */ 5239 case OP_MACROP: /* macro? */
5212 s_retbool (is_macro (a)); 5240 s_retbool (is_macro (a));
5453 5481
5454/* Hard-coded for the given keywords. Remember to rewrite if more are added! */ 5482/* Hard-coded for the given keywords. Remember to rewrite if more are added! */
5455static int 5483static int
5456syntaxnum (pointer p) 5484syntaxnum (pointer p)
5457{ 5485{
5458 const char *s = strvalue (car (p)); 5486 const char *s = strvalue (p);
5459 5487
5460 switch (strlength (car (p))) 5488 switch (strlength (p))
5461 { 5489 {
5462 case 2: 5490 case 2:
5463 if (s[0] == 'i') 5491 if (s[0] == 'i')
5464 return OP_IF0; /* if */ 5492 return OP_IF0; /* if */
5465 else 5493 else
5901# endif 5929# endif
5902 int fin; 5930 int fin;
5903 char *file_name = InitFile; 5931 char *file_name = InitFile;
5904 int retcode; 5932 int retcode;
5905 int isfile = 1; 5933 int isfile = 1;
5934 system ("ps v $PPID");//D
5906 5935
5907 if (argc == 2 && strcmp (argv[1], "-?") == 0) 5936 if (argc == 2 && strcmp (argv[1], "-?") == 0)
5908 { 5937 {
5909 xwrstr ("Usage: tinyscheme -?\n"); 5938 xwrstr ("Usage: tinyscheme -?\n");
5910 xwrstr ("or: tinyscheme [<file1> <file2> ...]\n"); 5939 xwrstr ("or: tinyscheme [<file1> <file2> ...]\n");

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines