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; |
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. */ |
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 |
|
|
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 |
{ |
{ |
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) { |
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; |
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); |
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; |