commit 46a21b0b3786010b1ecf1ce0e3f1a8a1f19a399e
parent 01e390acccf336e0e6f4141a4f0d739e64aa3b22
Author: Andres Navarro <canavarro82@gmail.com>
Date: Sat, 16 Apr 2011 14:30:03 -0300
Added gc rooting to kgpromises. Removed NAME and SI parameters to kmakepromise, and add GC assumtion: all params rooted.
Diffstat:
3 files changed, 8 insertions(+), 16 deletions(-)
diff --git a/src/kgpromises.c b/src/kgpromises.c
@@ -91,7 +91,7 @@ void Slazy(klisp_State *K, TValue *xparams, TValue ptree, TValue denv)
UNUSED(xparams);
bind_1p(K, "$lazy", ptree, exp);
- TValue new_prom = kmake_promise(K, KNIL, KNIL, exp, denv);
+ TValue new_prom = kmake_promise(K, exp, denv);
kapply_cc(K, new_prom);
}
@@ -102,6 +102,6 @@ void memoize(klisp_State *K, TValue *xparams, TValue ptree, TValue denv)
UNUSED(denv);
bind_1p(K, "memoize", ptree, exp);
- TValue new_prom = kmake_promise(K, KNIL, KNIL, exp, KNIL);
+ TValue new_prom = kmake_promise(K, exp, KNIL);
kapply_cc(K, new_prom);
}
diff --git a/src/kpromise.c b/src/kpromise.c
@@ -11,25 +11,17 @@
#include "kmem.h"
#include "kgc.h"
-TValue kmake_promise(klisp_State *K, TValue name, TValue si,
- TValue exp, TValue maybe_env)
+/* GC: Assumes exp & maybe_env are roooted */
+TValue kmake_promise(klisp_State *K, TValue exp, TValue maybe_env)
{
- krooted_tvs_push(K, name);
- krooted_tvs_push(K, si);
- krooted_tvs_push(K, exp);
- krooted_tvs_push(K, maybe_env);
Promise *new_prom = klispM_new(K, Promise);
- krooted_tvs_pop(K);
- krooted_tvs_pop(K);
- krooted_tvs_pop(K);
- krooted_tvs_pop(K);
/* header + gc_fields */
klispC_link(K, (GCObject *) new_prom, K_TPROMISE, 0);
/* promise specific fields */
- new_prom->name = name;
- new_prom->si = si;
+ new_prom->name = KNIL;
+ new_prom->si = KNIL;
new_prom->node = KNIL; /* temp in case of GC */
krooted_tvs_push(K, gc2prom(new_prom));
new_prom->node = kcons(K, exp, maybe_env);
diff --git a/src/kpromise.h b/src/kpromise.h
@@ -11,8 +11,8 @@
#include "kstate.h"
#include "kpair.h"
-TValue kmake_promise(klisp_State *K, TValue name, TValue si,
- TValue exp, TValue maybe_env);
+/* GC: Assumes exp & maybe_env are roooted */
+TValue kmake_promise(klisp_State *K, TValue exp, TValue maybe_env);
#define kpromise_node(p_) (tv2prom(p_)->node)
#define kpromise_exp(p_) (kcar(kpromise_node(p_)))