summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--pez.c17
1 files changed, 9 insertions, 8 deletions
diff --git a/pez.c b/pez.c
index d2c920b..3e2816b 100644
--- a/pez.c
+++ b/pez.c
@@ -318,6 +318,9 @@ static bool
_vecpush(PezContext *cx, void **at, size_t sz,
uint *len, uint *cap, const void *src, size_t n)
{
+ if (cx->gccanrun && (cx->dbg & DBGstressgc)) {
+ gc(cx);
+ }
if (*len + n - 1 >= *cap) {
uint newcap = (*len + n - 1) * 2;
uint8_t *new;
@@ -726,6 +729,7 @@ markarray(PezContext *cx, Array *arr)
static void
gcmark(PezContext *cx, Obj *o)
{
+ assert(cx->gccanrun);
if (o->gc) {
return;
}
@@ -2240,7 +2244,6 @@ lambdaexpr(Comp *cm, const char *name)
memset(&cm->con, 0, sizeof cm->con);
cm->proto = proto;
cm->fenv = fenv;
- ETRY(push(cm->cx, box_obj(proto))); // gc keep
if (matchspchr(cm, '[')) {
while (!matchspchr(cm, ']')) {
@@ -2262,7 +2265,6 @@ lambdaexpr(Comp *cm, const char *name)
}
}
- pop(cm->cx); // proto gc
ETRY(block(cm, '}'));
ETRY(compop(cm, Oret));
fincompfn(cm);
@@ -2276,7 +2278,7 @@ Cleanup:
return ret && compclosure(cm, proto);
Err:
- ret = 1;
+ ret = 0;
goto Cleanup;
}
@@ -3398,6 +3400,7 @@ pez_eval_cb(PezContext *cx, const char *fname, int (*cb)(void *), void *ud)
Proto *pr;
Fn *fn;
Comp cm;
+ int gccanrun = cx->gccanrun;
cx->gccanrun = 0;
if (!(pr = newproto(cx, fname, "<eval>", /* line */ 1))) {
return 0;
@@ -3415,23 +3418,21 @@ pez_eval_cb(PezContext *cx, const char *fname, int (*cb)(void *), void *ud)
if (cx->dbg & DBGbytecode) {
inspectproto(pr);
}
- cx->gccanrun = 1;
ETRY(push(cx, box_obj(fn))); // gc keep
+ cx->gccanrun = 1;
ETRY(exefn(cx, fn, 0));
cx->stktop[-2] = cx->stktop[-1];
--cx->stktop; // gc unkeep
- if (cx->dbg & DBGstressgc) {
- gc(cx);
- }
- cx->gccanrun = 0;
deinitcomp(&cm);
+ cx->gccanrun = gccanrun;
return 1;
Err:
cx->stktop = stktop;
deinitcomp(&cm);
delfenv(cx, &cm.fenv);
+ cx->gccanrun = gccanrun;
return 0;
}