diff --git a/stage2/High_level_prototypes/lisp_cell.c b/stage2/High_level_prototypes/lisp_cell.c index 1c7a002..a255839 100644 --- a/stage2/High_level_prototypes/lisp_cell.c +++ b/stage2/High_level_prototypes/lisp_cell.c @@ -134,14 +134,27 @@ void mark_all_cells() } } -void unmark_cells(struct cell* list) +void unmark_cells(struct cell* list, struct cell* stop, int count) { + if(count > 1) return; + for(; NULL != list; list = list->cdr) { + if(list == stop) count = count + 1; list->type = list->type & ~MARKED; - if((list->type & CONS)|| list->type & PROC ) + + if(list->type & PROC) { - unmark_cells(list->car); + unmark_cells(list->car, stop, count); + if(NULL != list->env) + { + unmark_cells(list->env, stop, count); + } + } + + if(list->type & CONS) + { + unmark_cells(list->car, stop, count); } } } @@ -149,8 +162,8 @@ void unmark_cells(struct cell* list) void garbage_collect() { mark_all_cells(); - unmark_cells(all_symbols); - unmark_cells(top_env); + unmark_cells(all_symbols, all_symbols, 0); + unmark_cells(top_env, top_env, 0); reclaim_marked(); update_remaining(); compact(all_symbols);