From be368fbac6b8d80033ccb8e4138b55c4b0954c34 Mon Sep 17 00:00:00 2001 From: Teddy Date: Wed, 14 Aug 2013 15:34:03 +0800 Subject: ready for alpha 2 --- eval.cpp | 3 +-- gc.cpp | 7 +++++++ gc.h | 1 + main.cpp | 6 ++---- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/eval.cpp b/eval.cpp index 06b66af..5d50335 100644 --- a/eval.cpp +++ b/eval.cpp @@ -207,8 +207,7 @@ EvalObj *Evaluator::run_expr(Pair *prog) { call(args, envt, cont, top_ptr); else throw TokenError(opt->ext_repr(), SYN_ERR_CAN_NOT_APPLY); - gc.force(); - gc.cycle_resolve(); + gc.collect(); } } } diff --git a/gc.cpp b/gc.cpp index 775463f..ee3eb6f 100644 --- a/gc.cpp +++ b/gc.cpp @@ -151,6 +151,13 @@ void GarbageCollector::cycle_resolve() { #ifdef GC_INFO fprintf(stderr, "GC: cycle resolved.\n"); #endif +} + +void GarbageCollector::collect() { + force(); + if (mapping.size() < resolve_threshold) + return; + cycle_resolve(); force(); } diff --git a/gc.h b/gc.h index eae0958..124588b 100644 --- a/gc.h +++ b/gc.h @@ -37,6 +37,7 @@ class GarbageCollector { public: GarbageCollector(); + void collect(); void cycle_resolve(); void force(); void expose(EvalObj *ptr); diff --git a/main.cpp b/main.cpp index 1b4c56c..455d6d0 100644 --- a/main.cpp +++ b/main.cpp @@ -35,8 +35,7 @@ void load_file(const char *fname) { { fprintf(stderr, "An error occured: %s\n", e.get_msg().c_str()); } - gc.force(); - gc.cycle_resolve(); + gc.collect(); } } @@ -109,7 +108,6 @@ int main(int argc, char **argv) { { fprintf(stderr, "An error occured: %s\n", e.get_msg().c_str()); } - gc.force(); - gc.cycle_resolve(); + gc.collect(); } } -- cgit v1.2.3-70-g09d2