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

Diff of /stack/stack.c

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

revision 1.95 by masse, Sun Mar 10 06:34:01 2002 UTC revision 1.96 by teddy, Sun Mar 10 07:55:13 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= 20;    env->gc_limit= 200;
52    env->gc_count= 0;    env->gc_count= 0;
53    env->gc_ref= NULL;    env->gc_ref= NULL;
54    env->gc_protect= NULL;    env->gc_protect= NULL;
# Line 83  extern void toss(environment *env) Line 83  extern void toss(environment *env)
83    free(temp);                   /* Free the old top stack item */    free(temp);                   /* Free the old top stack item */
84    
85    env->gc_limit--;    env->gc_limit--;
   gc_init(env);  
86  }  }
87    
88  /* 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 129  value* new_val(environment *env) Line 128  value* new_val(environment *env)
128    
129    env->gc_count++;    env->gc_count++;
130    
   protect(env, nval);  
   gc_init(env);  
   unprotect(env);  
   
131    return nval;    return nval;
132  }  }
133    
134  /* Mark values recursively.  /* Mark values recursively.
135     Marked values are not collected by the GC. */     Marked values are not collected by the GC. */
136  void gc_mark(value *val)  inline void gc_mark(value *val)
137  {  {
138    stackitem *iterator;    stackitem *iterator;
139    
# Line 157  void gc_mark(value *val) Line 152  void gc_mark(value *val)
152    }    }
153  }  }
154    
155    inline void gc_maybe(environment *env)
156    {
157      if(env->gc_count < env->gc_limit)
158        return;
159      else
160        return gc_init(env);
161    }
162    
163  /* Start GC */  /* Start GC */
164  extern void gc_init(environment *env)  extern void gc_init(environment *env)
165  {  {
# Line 164  extern void gc_init(environment *env) Line 167  extern void gc_init(environment *env)
167    symbol *tsymb;    symbol *tsymb;
168    int i;    int i;
169    
   if(env->gc_count < env->gc_limit)  
     return;  
   
170    /* Garb by default */    /* Garb by default */
171    iterator= env->gc_ref;    iterator= env->gc_ref;
172    while(iterator!=NULL) {    while(iterator!=NULL) {
# Line 613  extern void eval(environment *env) Line 613  extern void eval(environment *env)
613    
614   eval_start:   eval_start:
615    
616      gc_maybe(env);
617    
618    if(env->head==NULL) {    if(env->head==NULL) {
619      printerr("Too Few Arguments");      printerr("Too Few Arguments");
620      env->err=1;      env->err=1;
# Line 869  extern void quit(environment *env) Line 871  extern void quit(environment *env)
871    }    }
872    
873    env->gc_limit= 0;    env->gc_limit= 0;
874    gc_init(env);    gc_maybe(env);
875    
876    if(env->free_string!=NULL)    if(env->free_string!=NULL)
877      free(env->free_string);      free(env->free_string);
# Line 1008  under certain conditions; type `copying; Line 1010  under certain conditions; type `copying;
1010        toss(&myenv);             /* No error check in main */        toss(&myenv);             /* No error check in main */
1011        eval(&myenv);        eval(&myenv);
1012      }      }
1013      gc_init(&myenv);      gc_maybe(&myenv);
1014    }    }
1015    quit(&myenv);    quit(&myenv);
1016    return EXIT_FAILURE;    return EXIT_FAILURE;

Legend:
Removed from v.1.95  
changed lines
  Added in v.1.96

root@recompile.se
ViewVC Help
Powered by ViewVC 1.1.26