klisp

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

commit 42c59c8b753ee03171ce779a12b2b47a3e1273d6
parent 36db428b30a3be0056a1fd3d3302735ef241c1e5
Author: Andres Navarro <canavarro82@gmail.com>
Date:   Sat, 16 Apr 2011 10:53:32 -0300

Bugfix: tails wan't being properly protected in transpose. Simplified a little with the use of the vars stack.

Diffstat:
Msrc/kgcombiners.c | 13+++++++++----
Msrc/kgcombiners.h | 4++++
2 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/src/kgcombiners.c b/src/kgcombiners.c @@ -321,7 +321,13 @@ TValue map_for_each_transpose(klisp_State *K, TValue lss, TValue lp = kget_dummy3(K); TValue lap = lp; + TValue cars = KNIL; /* put something for GC */ TValue tail = lss; + + /* GC: both cars & tail vary in each loop, to protect them we need + the vars stack */ + krooted_vars_push(K, &cars); + krooted_vars_push(K, &tail); /* Loop over list of lists, creating a list of cars and a list of cdrs, accumulate the list of cars and loop @@ -339,11 +345,8 @@ TValue map_for_each_transpose(klisp_State *K, TValue lss, while(pairs--) { /* accumulate cars and replace tail with cdrs */ - TValue cars = - map_for_each_get_cars_cdrs(K, &tail, app_apairs, app_cpairs); - krooted_tvs_push(K, cars); + cars = map_for_each_get_cars_cdrs(K, &tail, app_apairs, app_cpairs); TValue np = kcons(K, cars, KNIL); - krooted_tvs_pop(K); kset_cdr(lp, np); lp = np; } @@ -359,6 +362,8 @@ TValue map_for_each_transpose(klisp_State *K, TValue lss, } } + krooted_vars_pop(K); + krooted_vars_pop(K); return kcutoff_dummy3(K); } diff --git a/src/kgcombiners.h b/src/kgcombiners.h @@ -54,12 +54,16 @@ void map_for_each_get_metrics( /* Return two lists, isomorphic to lss: one list of cars and one list of cdrs (replacing the value of lss) */ +/* GC: Assumes lss is rooted, uses dummys 2 & 3 */ TValue map_for_each_get_cars_cdrs(klisp_State *K, TValue *lss, int32_t apairs, int32_t cpairs); /* Transpose lss so that the result is a list of lists, each one having metrics (app_apairs, app_cpairs). The metrics of the returned list should be (res_apairs, res_cpairs) */ + +/* GC: Assumes lss is rooted, uses dummys 1, & + (through get_cars_cdrs, 2, 3) */ TValue map_for_each_transpose(klisp_State *K, TValue lss, int32_t app_apairs, int32_t app_cpairs, int32_t res_apairs, int32_t res_cpairs);