--- stack/stack.c 2002/03/10 09:13:36 1.98 +++ stack/stack.c 2002/03/10 12:05:20 1.100 @@ -48,7 +48,7 @@ { int i; - env->gc_limit= 200; + env->gc_limit= 400000; env->gc_count= 0; env->gc_ref= NULL; @@ -80,8 +80,6 @@ env->head= env->head->next; /* Remove the top stack item */ free(temp); /* Free the old top stack item */ - - env->gc_limit--; } /* Returns a pointer to a pointer to an element in the hash table. */ @@ -125,8 +123,9 @@ nitem->next= env->gc_ref; env->gc_ref= nitem; - env->gc_count++; - nval->gc_garb= 1; + env->gc_count+=sizeof(value); + nval->gc.flag.mark= 0; + nval->gc.flag.protect= 0; return nval; } @@ -137,10 +136,10 @@ { stackitem *iterator; - if(val->gc_garb==0) + if(val->gc.flag.mark) return; - val->gc_garb= 0; + val->gc.flag.mark= 1; if(val->type==list) { iterator= val->content.ptr; @@ -167,6 +166,10 @@ symbol *tsymb; int i; + if(env->interactive){ + printf("Garbage collecting.", env->gc_count, env->gc_limit); + } + /* Mark values on stack */ iterator= env->head; while(iterator!=NULL) { @@ -174,6 +177,10 @@ iterator= iterator->next; } + if(env->interactive){ + printf("."); + } + /* Mark values in hashtable */ for(i= 0; isymbols[i]; @@ -184,12 +191,15 @@ } } + if(env->interactive){ + printf("."); + } + env->gc_count= 0; while(env->gc_ref!=NULL) { /* Sweep unused values */ - if(env->gc_ref->item->gc_garb - && !(env->gc_ref->item->gc_protect)) { + if(!(env->gc_ref->item->gc.no_gc)){ /* neither mark nor protect */ switch(env->gc_ref->item->type) { /* Remove content */ case string: @@ -208,19 +218,26 @@ free(env->gc_ref); /* Remove value */ env->gc_ref= titem; continue; + } else { + env->gc_count += sizeof(value); } /* Keep values */ titem= env->gc_ref->next; env->gc_ref->next= new_head; new_head= env->gc_ref; - new_head->item->gc_garb= 1; + new_head->item->gc.flag.mark= 0; env->gc_ref= titem; - env->gc_count++; } - env->gc_limit= env->gc_count*2; + if (env->gc_limit < env->gc_count*2) + env->gc_limit= env->gc_count*2; env->gc_ref= new_head; + + if(env->interactive){ + printf("done\n"); + } + } /* Protect values from GC */ @@ -228,10 +245,10 @@ { stackitem *iterator; - if(val->gc_protect) + if(val->gc.flag.protect) return; - val->gc_protect= 1; + val->gc.flag.protect= 1; if(val->type==list) { iterator= val->content.ptr; @@ -248,10 +265,10 @@ { stackitem *iterator; - if(!(val->gc_protect)) + if(!(val->gc.flag.protect)) return; - val->gc_protect= 0; + val->gc.flag.protect= 0; if(val->type==list) { iterator= val->content.ptr; @@ -662,7 +679,7 @@ push_val(env, iterator->item); if(env->head->item->type==symb - && strcmp(";", ((symbol*)(env->head->item->content.ptr))->id)==0) { + && (((symbol*)(env->head->item->content.ptr))->id[0] == ';')) { toss(env); if(env->err) return; @@ -994,7 +1011,7 @@ } if(myenv.interactive) { - printf("Stack version $Revision: 1.98 $\n\ + printf("Stack version $Revision: 1.100 $\n\ Copyright (C) 2002 Mats Alritzson and Teddy Hogeborn\n\ Stack comes with ABSOLUTELY NO WARRANTY; for details type `warranty;'.\n\ This is free software, and you are welcome to redistribute it\n\