klisp

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

commit 605b782c8563c4ba57d194e4e3832cdba4bc0d14
parent 073b3c8ff6db6b60385108a84829f60b517bf531
Author: Andres Navarro <canavarro82@gmail.com>
Date:   Tue, 12 Apr 2011 22:19:08 -0300

Added support for bigints to encycle! (just throw error because there can't be that many pairs).

Diffstat:
Msrc/Makefile | 2+-
Msrc/kgnumbers.h | 3+++
Msrc/kgpair_mut.c | 23+++++++++++++++--------
3 files changed, 19 insertions(+), 9 deletions(-)

diff --git a/src/Makefile b/src/Makefile @@ -111,7 +111,7 @@ kgenv_mut.o: kgenv_mut.c kgenv_mut.h kghelpers.h kstate.h \ kenvironment.h kgcontrol.h kgcombiners.o: kgcombiners.c kgenvironments.h kghelpers.h kstate.h \ klisp.h kobject.h kerror.h kpair.h ksymbol.h kcontinuation.h \ - kenvironment.h kapplicative.h koperative.h kgpair_mut.h + kenvironment.h kapplicative.h koperative.h kgpair_mut.h kgnumbers.h kgcontinuations.o: kgcontinuations.c kgcontinuations.h kghelpers.h kstate.h \ klisp.h kobject.h kerror.h kpair.h ksymbol.h kcontinuation.h \ kenvironment.h kapplicative.h koperative.h diff --git a/src/kgnumbers.h b/src/kgnumbers.h @@ -109,6 +109,9 @@ void kmin_max(klisp_State *K, TValue *xparams, TValue ptree, TValue denv); void kgcd(klisp_State *K, TValue *xparams, TValue ptree, TValue denv); void klcm(klisp_State *K, TValue *xparams, TValue ptree, TValue denv); + +/* REFACTOR: These should be in a knumber.h header */ + /* Misc Helpers */ /* TEMP: only infinities, fixints and bigints for now */ inline bool kfast_zerop(TValue n) { return ttisfixint(n) && ivalue(n) == 0; } diff --git a/src/kgpair_mut.c b/src/kgpair_mut.c @@ -20,6 +20,7 @@ #include "kghelpers.h" #include "kgpair_mut.h" #include "kgeqp.h" /* eq? checking in memq and assq */ +#include "kgnumbers.h" /* for kpositivep and kintegerp */ /* 4.7.1 set-car!, set-cdr! */ void set_carB(klisp_State *K, TValue *xparams, TValue ptree, TValue denv) @@ -154,20 +155,26 @@ void encycleB(klisp_State *K, TValue *xparams, TValue ptree, than needed */ (void) denv; (void) xparams; - /* XXX: should be integer instead of fixint, but that's all - we have for now */ - bind_3tp(K, "encycle!", ptree, "any", anytype, obj, - "finite integer", ttisfixint, tk1, - "finite integer", ttisfixint, tk2); - int32_t k1 = ivalue(tk1); - int32_t k2 = ivalue(tk2); + bind_3tp(K, "encycle!", ptree, "any", anytype, obj, + "finite integer", kintegerp, tk1, + "finite integer", kintegerp, tk2); - if (k1 < 0 || k2 < 0) { + if (knegativep(tk1) || knegativep(tk2)) { klispE_throw(K, "encycle!: negative index"); return; } + if (!ttisfixint(tk1) || !ttisfixint(tk2)) { + /* no list can have that many pairs */ + klispE_throw(K, "encycle!: non pair found while traversing " + "object"); + return; + } + + int32_t k1 = ivalue(tk1); + int32_t k2 = ivalue(tk2); + TValue tail = obj; while(k1) {