--- stack/stack.c 2002/03/14 10:39:11 1.109 +++ stack/stack.c 2002/03/16 09:12:39 1.110 @@ -188,7 +188,6 @@ if(env->interactive) printf("."); - env->gc_count= 0; while(env->gc_ref!=NULL) { /* Sweep unused values */ @@ -203,7 +202,32 @@ free(env->gc_ref); /* Remove value */ env->gc_ref= titem; continue; - } + } +#ifdef DEBUG + printf("Kept value (%p)", env->gc_ref->item); + if(env->gc_ref->item->gc.flag.mark) + printf(" (marked)"); + if(env->gc_ref->item->gc.flag.protect) + printf(" (protected)"); + switch(env->gc_ref->item->type){ + case integer: + printf(" integer: %d", env->gc_ref->item->content.i); + break; + case func: + printf(" func: %p", env->gc_ref->item->content.ptr); + break; + case symb: + printf(" symb: %s", env->gc_ref->item->content.sym->id); + break; + case tcons: + printf(" tcons: %p\t%p", env->gc_ref->item->content.c->car, + env->gc_ref->item->content.c->cdr); + break; + default: + printf(" ", (env->gc_ref->item->type)); + } + printf("\n"); +#endif /* DEBUG */ /* Keep values */ env->gc_count += sizeof(value); @@ -223,7 +247,7 @@ env->gc_ref= new_head; if(env->interactive) - printf("done\n"); + printf("done (%d bytes still allocated)\n", env->gc_count); } @@ -607,11 +631,11 @@ env->err= 3; return; } - protect(val); - toss(env); /* toss the symbol */ + push_val(env, val); /* Return the symbol's bound value */ + swap(env); + if(env->err) return; + toss(env); /* toss the symbol */ if(env->err) return; - push_val(env, val); /* Return its bound value */ - unprotect(val); } /* If the top element is a symbol, determine if it's bound to a @@ -672,7 +696,7 @@ eval(env); if(env->err) return; } - if (CDR(iterator)->type == tcons) + if (CDR(iterator)==NULL || CDR(iterator)->type == tcons) iterator= CDR(iterator); else { printerr("Bad Argument Type"); /* Improper list */ @@ -887,6 +911,8 @@ env->gc_limit= 0; gc_maybe(env); + words(env); + if(env->free_string!=NULL) free(env->free_string); @@ -913,6 +939,10 @@ for(i= 0; isymbols[i]; while(temp!=NULL) { +#ifdef DEBUG + if (temp->val != NULL && temp->val->gc.flag.protect) + printf("(protected) "); +#endif /* DEBUG */ printf("%s\n", temp->id); temp= temp->next; } @@ -983,7 +1013,7 @@ break; case '?': fprintf (stderr, - "Unknown option character `\\x%x'.\n", + "Unknown option character '\\x%x'.\n", optopt); return EX_USAGE; default: @@ -1000,11 +1030,11 @@ } if(myenv.interactive) { - printf("Stack version $Revision: 1.109 $\n\ + printf("Stack version $Revision: 1.110 $\n\ Copyright (C) 2002 Mats Alritzson and Teddy Hogeborn\n\ -Stack comes with ABSOLUTELY NO WARRANTY; for details type `warranty;'.\n\ +Stack comes with ABSOLUTELY NO WARRANTY; for details type 'warranty;'.\n\ This is free software, and you are welcome to redistribute it\n\ -under certain conditions; type `copying;' for details.\n"); +under certain conditions; type 'copying;' for details.\n"); } while(1) { @@ -1019,9 +1049,10 @@ } myenv.err=0; } - sx_72656164(&myenv); - if (myenv.err==4) { - return EXIT_SUCCESS; /* EOF */ + sx_72656164(&myenv); /* "read" */ + if (myenv.err==4) { /* EOF */ + myenv.err=0; + quit(&myenv); } else if(myenv.head!=NULL && CAR(myenv.head)->type==symb && CAR(myenv.head)->content.sym->id[0]