klisp

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

commit 2bc2c7c73f76a36c715c90584cdd080dd8fa8eb3
parent d42799bda832be3d88a870be32b19aff2be441b3
Author: Andres Navarro <canavarro82@gmail.com>
Date:   Sat, 16 Apr 2011 22:16:35 -0300

Bugfix: klist was consing backwards!!

Diffstat:
Msrc/kpair.c | 21+++++++++++++++------
1 file changed, 15 insertions(+), 6 deletions(-)

diff --git a/src/kpair.c b/src/kpair.c @@ -29,23 +29,32 @@ TValue kcons_g(klisp_State *K, bool m, TValue car, TValue cdr) return gc2pair(new_pair); } +#define MAX_LIST_N 16 + /* GC: assumes all argps are rooted */ TValue klist_g(klisp_State *K, bool m, int32_t n, ...) { va_list argp; - TValue tail = KNIL; - - krooted_vars_push(K, &tail); + + klisp_assert(n < MAX_LIST_N); + + /* don't use any of the klisp dummys, because this is + called from many places */ + TValue dummy = kcons_g(K, m, KINERT, KNIL); + krooted_tvs_push(K, dummy); + TValue tail = dummy; va_start(argp, n); for (int i = 0; i < n; i++) { TValue next_car = va_arg(argp, TValue); - tail = kcons_g(K, m, next_car, tail); + TValue np = kcons_g(K, m, next_car, KNIL); + kset_cdr(tail, np); + tail = np; } va_end(argp); - krooted_vars_pop(K); - return tail; + krooted_tvs_pop(K); + return kcdr(dummy); }