aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTeddy <[email protected]>2013-08-14 15:34:03 +0800
committerTeddy <[email protected]>2013-08-14 15:34:03 +0800
commitbe368fbac6b8d80033ccb8e4138b55c4b0954c34 (patch)
treec36d4418568b30eccba02788bc86ec55404fcebb
parent4c083e4776a7bff4683dc3f64d7ccd83dbb3d235 (diff)
ready for alpha 2
-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();
}
}