aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--eval.cpp3
-rw-r--r--gc.cpp7
-rw-r--r--gc.h1
-rw-r--r--main.cpp6
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();
}
}