pSlipObject slip_evaluate(pSlip gd, pSlipObject exp) { pSlipEnvironment env; env = get_global_environment(gd); return slip_eval(gd, exp, env); }
/*! * This function performs the garbage collection for the Scheme interpreter. * It also contains code to track how many objects were collected on each run, * and also it can optionally be set to do GC when the total memory used grows * beyond a certain limit. */ void collect_garbage() { Environment *global_env; PtrStack *eval_stack; int i; EvaluationContext *eval; #ifdef GC_STATS int vals_before, procs_before, envs_before; int vals_after, procs_after, envs_after; vals_before = allocated_values.size; procs_before = allocated_lambdas.size; envs_before = allocated_environments.size; #endif #ifndef ALWAYS_GC /* Don't perform garbage collection if we still have room to grow. */ if (allocation_size() < max_allocation_size) return; #endif /*==========================================================* * TODO: Implement mark-and-sweep garbage collection here! * * * * Mark all objects referenceable from either the global * * environment, or from the evaluation stack. Then sweep * * through all allocated objects, freeing unmarked objects. * * * * Reminder to self: DECLARE THESE FUNCTIONS @ TOP * *==========================================================*/ global_env = get_global_environment(); eval_stack = get_eval_stack(); /* ... TODO ... */ // Mark everything mark_environment(global_env); for (i = 0; i < (*eval_stack).size; i++) { eval = (EvaluationContext *) pv_get_elem(eval_stack, i); mark_eval_stack(eval); } // Sweep everything sweep_values(); sweep_lambdas(); sweep_environments(); #ifndef ALWAYS_GC /* If we are still above the maximum allocation size, increase it. */ if (allocation_size() > max_allocation_size) { max_allocation_size *= 2; printf("Increasing maximum allocation size to %ld bytes.\n", max_allocation_size); } #endif #ifdef GC_STATS vals_after = allocated_values.size; procs_after = allocated_lambdas.size; envs_after = allocated_environments.size; printf("GC Results:\n"); printf("\tBefore: \t%d vals \t%d lambdas \t%d envs\n", vals_before, procs_before, envs_before); printf("\tAfter: \t%d vals \t%d lambdas \t%d envs\n", vals_after, procs_after, envs_after); printf("\tChange: \t%d vals \t%d lambdas \t%d envs\n", vals_after - vals_before, procs_after - procs_before, envs_after - envs_before); #endif }