klisp

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

commit 3abe4c413192db697ecf8fc6dc1cdaef534546b0
parent 237cb2a3b9c09990fa846eb48c1ad2e217318712
Author: Andres Navarro <canavarro82@gmail.com>
Date:   Sat, 16 Apr 2011 17:39:55 -0300

Completed gc rooting.

Diffstat:
Msrc/keval.c | 2+-
Msrc/kinteger.c | 6+++---
Msrc/kread.c | 8++++++--
Msrc/krepl.c | 17++++++++---------
Msrc/ksymbol.c | 5+++--
Msrc/ktoken.c | 8+++++---
6 files changed, 26 insertions(+), 20 deletions(-)

diff --git a/src/keval.c b/src/keval.c @@ -114,7 +114,7 @@ void combine_cfn(klisp_State *K, TValue *xparams, TValue obj) TValue comb_cont = kmake_continuation(K, kget_cc(K), &combine_cfn, 2, arg_ls, env); - krooted_tvs_pop(K, arg_ls); /* already in cont */ + krooted_tvs_pop(K); /* already in cont */ krooted_tvs_push(K, comb_cont); TValue els_cont = kmake_continuation(K, comb_cont, &eval_ls_cfn, 4, arg_ls, env, diff --git a/src/kinteger.c b/src/kinteger.c @@ -67,7 +67,7 @@ TValue kbigint_copy(klisp_State *K, TValue src) /* This algorithm is like a fused multiply add on bignums, unlike any other function here it modifies bigint. It is used in read and it assumes that bigint is positive */ -/* assumes tv_bigint is rooted */ +/* GC: Assumes tv_bigint is rooted */ void kbigint_add_digit(klisp_State *K, TValue tv_bigint, int32_t base, int32_t digit) { @@ -78,7 +78,7 @@ void kbigint_add_digit(klisp_State *K, TValue tv_bigint, int32_t base, /* This is used by the writer to get the digits of a number tv_bigint must be positive */ -/* assumes tv_bigint is rooted */ +/* GC: Assumes tv_bigint is rooted */ int32_t kbigint_remove_digit(klisp_State *K, TValue tv_bigint, int32_t base) { UNUSED(K); @@ -97,7 +97,7 @@ bool kbigint_has_digits(klisp_State *K, TValue tv_bigint) /* Mutate the bigint to have the opposite sign, used in read and write*/ -/* assumes tv_bigint is rooted */ +/* GC: Assumes tv_bigint is rooted */ void kbigint_invert_sign(klisp_State *K, TValue tv_bigint) { Bigint *bigint = tv2bigint(tv_bigint); diff --git a/src/kread.c b/src/kread.c @@ -117,8 +117,10 @@ void try_shared_def(klisp_State *K, TValue def_token, TValue value) tail = kcdr(tail); } - K->shared_dict = kcons(K, kcons(K, kcdr(def_token), value), - K->shared_dict); /* value is protected by cons */ + TValue new_tok = kcons(K, kcdr(def_token), value); + krooted_tvs_push(K, new_tok); + K->shared_dict = kcons(K, new_tok, K->shared_dict); /* value is protected by cons */ + krooted_tvs_pop(K); return; } @@ -417,12 +419,14 @@ TValue kread_fsm(klisp_State *K) /* construct the list with the correct type of pair */ /* GC: np is rooted by push_data */ TValue np = kcons_g(K, K->read_mconsp, obj, KNIL); + krooted_tvs_push(K, np); kset_source_info(np, obj_si); kset_cdr(get_data(K), np); /* replace last pair of the (still incomplete) read next obj */ pop_data(K); push_data(K, np); push_state(K, ST_MIDDLE_LIST); + krooted_tvs_pop(K); read_next_token = true; break; } diff --git a/src/krepl.c b/src/krepl.c @@ -21,9 +21,8 @@ /* the exit continuation, it exits the loop */ void exit_fn(klisp_State *K, TValue *xparams, TValue obj) { - /* avoid warnings */ - (void) xparams; - (void) obj; + UNUSED(xparams); + UNUSED(obj); /* force the loop to terminate */ K->next_func = NULL; @@ -33,8 +32,8 @@ void exit_fn(klisp_State *K, TValue *xparams, TValue obj) /* the underlying function of the read cont */ void read_fn(klisp_State *K, TValue *xparams, TValue obj) { - (void) obj; - (void) xparams; + UNUSED(xparams); + UNUSED(obj); /* show prompt */ fprintf(stdout, "klisp> "); @@ -72,12 +71,14 @@ void loop_fn(klisp_State *K, TValue *xparams, TValue obj); /* GC: assumes denv is rooted */ inline void create_loop(klisp_State *K, TValue denv) { - /* GC: the intermediate conts are protected by the - others */ TValue loop_cont = kmake_continuation(K, K->root_cont, &loop_fn, 1, denv); + krooted_tvs_push(K, loop_cont); TValue eval_cont = kmake_continuation(K, loop_cont, &eval_cfn, 1, denv); + krooted_tvs_pop(K); /* in eval cont */ + krooted_tvs_push(K, eval_cont); TValue read_cont = kmake_continuation(K, eval_cont, &read_fn, 0); + krooted_tvs_pop(K); kset_cc(K, read_cont); kapply_cc(K, KINERT); } @@ -119,12 +120,10 @@ void error_fn(klisp_State *K, TValue *xparams, TValue obj) void kinit_repl(klisp_State *K) { TValue std_env = kmake_environment(K, K->ground_env); - krooted_tvs_push(K, std_env); /* set up the continuations */ TValue root_cont = kmake_continuation(K, KNIL, exit_fn, 0); - krooted_tvs_push(K, root_cont); TValue error_cont = kmake_continuation(K, root_cont, error_fn, 1, std_env); diff --git a/src/ksymbol.c b/src/ksymbol.c @@ -50,7 +50,9 @@ TValue ksymbol_new_g(klisp_State *K, const char *buf, int32_t size, new_sym->str = new_str; TValue new_symv = gc2sym(new_sym); + krooted_tvs_push(K, new_symv); K->symbol_table = kcons(K, new_symv, K->symbol_table); + krooted_tvs_pop(K); return new_symv; } @@ -68,6 +70,7 @@ TValue ksymbol_new(klisp_State *K, const char *buf) } /* for string->symbol */ +/* GC: assumes str is rooted */ TValue ksymbol_new_check_i(klisp_State *K, TValue str) { int32_t size = kstring_size(str); @@ -104,9 +107,7 @@ TValue ksymbol_new_check_i(klisp_State *K, TValue str) size = kstring_size(str); buf = kstring_buf(str); - krooted_tvs_push(K, str); TValue new_sym = ksymbol_new_g(K, buf, size, identifierp); - krooted_tvs_pop(K); return new_sym; } diff --git a/src/ktoken.c b/src/ktoken.c @@ -192,9 +192,11 @@ TValue ktok_get_source_info(klisp_State *K) strlen(K->ktok_source_info.saved_filename)); krooted_tvs_push(K, filename_str); /* TEMP: for now, lines and column names are fixints */ - TValue res = kcons(K, filename_str, - kcons(K, i2tv(K->ktok_source_info.saved_line), - i2tv(K->ktok_source_info.saved_col))); + TValue res = kcons(K, i2tv(K->ktok_source_info.saved_line), + i2tv(K->ktok_source_info.saved_col)); + krooted_tvs_push(K, res); + res = kcons(K, filename_str, res); + krooted_tvs_pop(K); krooted_tvs_pop(K); return res; }