klisp

an open source interpreter for the Kernel Programming Language.
git clone http://git.hanabi.in/repos/klisp.git
Log | Files | Refs | README

commit e40f7907d6cfd6036e7d162e105f916f908ad5bc
parent fdd7793625c903ecf7b71270a08b1bf00b44bf8f
Author: Andres Navarro <canavarro82@gmail.com>
Date:   Sat, 16 Apr 2011 11:40:34 -0300

Added gc rooting to kgencapsulations. Removed implicit rooting in make_encapsulation.

Diffstat:
Msrc/kencapsulation.c | 18++++--------------
Msrc/kencapsulation.h | 5+++--
Msrc/kgencapsulations.c | 13+++++++++++--
3 files changed, 18 insertions(+), 18 deletions(-)

diff --git a/src/kencapsulation.c b/src/kencapsulation.c @@ -11,27 +11,17 @@ #include "kpair.h" #include "kgc.h" -TValue kmake_encapsulation(klisp_State *K, TValue name, TValue si, - TValue key, TValue val) +/* GC: Assumes that key & val are rooted */ +TValue kmake_encapsulation(klisp_State *K, TValue key, TValue val) { - krooted_tvs_push(K, name); - krooted_tvs_push(K, si); - krooted_tvs_push(K, key); - krooted_tvs_push(K, val); - Encapsulation *new_enc = klispM_new(K, Encapsulation); - krooted_tvs_pop(K); - krooted_tvs_pop(K); - krooted_tvs_pop(K); - krooted_tvs_pop(K); - /* header + gc_fields */ klispC_link(K, (GCObject *) new_enc, K_TENCAPSULATION, 0); /* encapsulation specific fields */ - new_enc->name = name; - new_enc->si = si; + new_enc->name = KNIL; + new_enc->si = KNIL; new_enc->key = key; new_enc->value = val; diff --git a/src/kencapsulation.h b/src/kencapsulation.h @@ -10,8 +10,9 @@ #include "kobject.h" #include "kstate.h" -TValue kmake_encapsulation(klisp_State *K, TValue name, TValue si, - TValue key, TValue val); +/* GC: Assumes that key & val are rooted */ +TValue kmake_encapsulation(klisp_State *K, TValue key, TValue val); + TValue kmake_encapsulation_key(klisp_State *K); inline bool kis_encapsulation_type(TValue enc, TValue key); diff --git a/src/kgencapsulations.c b/src/kgencapsulations.c @@ -62,7 +62,7 @@ void enc_wrap(klisp_State *K, TValue *xparams, TValue ptree, TValue denv) ** xparams[0]: encapsulation key */ TValue key = xparams[0]; - TValue enc = kmake_encapsulation(K, KNIL, KNIL, key, obj); + TValue enc = kmake_encapsulation(K, key, obj); kapply_cc(K, enc); } @@ -95,10 +95,19 @@ void make_encapsulation_type(klisp_State *K, TValue *xparams, TValue ptree, /* GC: root intermediate values & pairs */ TValue key = kmake_encapsulation_key(K); + krooted_tvs_push(K, key); TValue e = kmake_applicative(K, enc_wrap, 1, key); + krooted_tvs_push(K, e); TValue p = kmake_applicative(K, enc_typep, 1, key); + krooted_tvs_push(K, p); TValue d = kmake_applicative(K, enc_unwrap, 1, key); + krooted_tvs_push(K, d); - TValue ls = kcons(K, e, kcons(K, p, kcons(K, d, KNIL))); + TValue ls = klist(K, 3, e, p, d); + + krooted_tvs_pop(K); + krooted_tvs_pop(K); + krooted_tvs_pop(K); + krooted_tvs_pop(K); kapply_cc(K, ls); }