/[cvs]/stack/stack.c
ViewVC logotype

Diff of /stack/stack.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.99 by teddy, Sun Mar 10 10:06:36 2002 UTC revision 1.100 by teddy, Sun Mar 10 12:05:20 2002 UTC
# Line 48  void init_env(environment *env) Line 48  void init_env(environment *env)
48  {  {
49    int i;    int i;
50    
51    env->gc_limit= 200;    env->gc_limit= 400000;
52    env->gc_count= 0;    env->gc_count= 0;
53    env->gc_ref= NULL;    env->gc_ref= NULL;
54    
# Line 80  extern void toss(environment *env) Line 80  extern void toss(environment *env)
80        
81    env->head= env->head->next;   /* Remove the top stack item */    env->head= env->head->next;   /* Remove the top stack item */
82    free(temp);                   /* Free the old top stack item */    free(temp);                   /* Free the old top stack item */
   
   env->gc_limit--;  
83  }  }
84    
85  /* Returns a pointer to a pointer to an element in the hash table. */  /* Returns a pointer to a pointer to an element in the hash table. */
# Line 125  value* new_val(environment *env) Line 123  value* new_val(environment *env)
123    nitem->next= env->gc_ref;    nitem->next= env->gc_ref;
124    env->gc_ref= nitem;    env->gc_ref= nitem;
125    
126    env->gc_count++;    env->gc_count+=sizeof(value);
127    nval->gc.flag.mark= 0;    nval->gc.flag.mark= 0;
128    nval->gc.flag.protect= 0;    nval->gc.flag.protect= 0;
129    
# Line 168  extern void gc_init(environment *env) Line 166  extern void gc_init(environment *env)
166    symbol *tsymb;    symbol *tsymb;
167    int i;    int i;
168    
169      if(env->interactive){
170        printf("Garbage collecting.", env->gc_count, env->gc_limit);
171      }
172    
173    /* Mark values on stack */    /* Mark values on stack */
174    iterator= env->head;    iterator= env->head;
175    while(iterator!=NULL) {    while(iterator!=NULL) {
# Line 175  extern void gc_init(environment *env) Line 177  extern void gc_init(environment *env)
177      iterator= iterator->next;      iterator= iterator->next;
178    }    }
179    
180      if(env->interactive){
181        printf(".");
182      }
183    
184    /* Mark values in hashtable */    /* Mark values in hashtable */
185    for(i= 0; i<HASHTBLSIZE; i++) {    for(i= 0; i<HASHTBLSIZE; i++) {
186      tsymb= env->symbols[i];      tsymb= env->symbols[i];
# Line 185  extern void gc_init(environment *env) Line 191  extern void gc_init(environment *env)
191      }      }
192    }    }
193    
194      if(env->interactive){
195        printf(".");
196      }
197    
198    env->gc_count= 0;    env->gc_count= 0;
199    
200    while(env->gc_ref!=NULL) {    /* Sweep unused values */    while(env->gc_ref!=NULL) {    /* Sweep unused values */
# Line 208  extern void gc_init(environment *env) Line 218  extern void gc_init(environment *env)
218        free(env->gc_ref);        /* Remove value */        free(env->gc_ref);        /* Remove value */
219        env->gc_ref= titem;        env->gc_ref= titem;
220        continue;        continue;
221        } else {
222          env->gc_count += sizeof(value);
223      }      }
224            
225      /* Keep values */      /* Keep values */
# Line 216  extern void gc_init(environment *env) Line 228  extern void gc_init(environment *env)
228      new_head= env->gc_ref;      new_head= env->gc_ref;
229      new_head->item->gc.flag.mark= 0;      new_head->item->gc.flag.mark= 0;
230      env->gc_ref= titem;      env->gc_ref= titem;
     env->gc_count++;  
231    }    }
232    
233    env->gc_limit= env->gc_count*2;    if (env->gc_limit < env->gc_count*2)
234        env->gc_limit= env->gc_count*2;
235    env->gc_ref= new_head;    env->gc_ref= new_head;
236    
237      if(env->interactive){
238        printf("done\n");
239      }
240    
241  }  }
242    
243  /* Protect values from GC */  /* Protect values from GC */
# Line 662  extern void eval(environment *env) Line 679  extern void eval(environment *env)
679        push_val(env, iterator->item);        push_val(env, iterator->item);
680                
681        if(env->head->item->type==symb        if(env->head->item->type==symb
682          && strcmp(";", ((symbol*)(env->head->item->content.ptr))->id)==0) {           && (((symbol*)(env->head->item->content.ptr))->id[0] == ';')) {
683          toss(env);          toss(env);
684          if(env->err) return;          if(env->err) return;
685                    

Legend:
Removed from v.1.99  
changed lines
  Added in v.1.100

root@recompile.se
ViewVC Help
Powered by ViewVC 1.1.26