klisp

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

commit 2986c284d0b3d6a06d3d39a91a9591c7d6e3d206
parent 8a5173acbe9ddc2908d23ccc89de694d2b01848c
Author: Andres Navarro <canavarro82@gmail.com>
Date:   Sat, 23 Apr 2011 17:34:17 -0300

Bugfix: the code in kbigrat_try_integer checked denom against zero instead of one... Changed for the logical mp_rat_is_integer. TODO: disallow some accepted syntax of imath (like a trailing '.' and sign after the '/'.

Diffstat:
Msrc/Makefile | 4++--
Msrc/kgc.c | 1+
Msrc/kgnumbers.c | 3++-
Msrc/kobject.h | 4++--
Msrc/krational.c | 2+-
5 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/src/Makefile b/src/Makefile @@ -151,5 +151,5 @@ kgstrings.o: kgstrings.c kgstrings.h kghelpers.h kstate.h klisp.h \ kstring.h ksymbol.h kgnumbers.h imath.o: kobject.h kstate.h kmem.h kerror.h imrath.o: kobject.h kstate.h kmem.h kerror.h -kgc.o: kgc.c kgc.h kobject.h kmem.h kstate.h kport.h imath.h ktable.h \ - kstring.h +kgc.o: kgc.c kgc.h kobject.h kmem.h kstate.h kport.h imath.h imrat.h \ + ktable.h kstring.h diff --git a/src/kgc.c b/src/kgc.c @@ -17,6 +17,7 @@ #include "kmem.h" #include "kport.h" #include "imath.h" +#include "imrat.h" #include "ktable.h" #include "kstring.h" diff --git a/src/kgnumbers.c b/src/kgnumbers.c @@ -34,7 +34,8 @@ bool kfinitep(TValue obj) { return (!ttiseinf(obj) && !ttisiinf(obj)); } /* TEMP: for now only fixint & bigints, should also include inexact integers */ - bool kintegerp(TValue obj) { return ttisinteger(obj); } +bool kintegerp(TValue obj) { return ttisinteger(obj); } +bool krationalp(TValue obj) { return ttisrational(obj); } /* 12.5.2 =? */ /* uses typed_bpredp */ diff --git a/src/kobject.h b/src/kobject.h @@ -234,9 +234,9 @@ typedef struct __attribute__ ((__packed__)) GCheader { #define ttisinteger(o_) ({ int32_t t_ = tbasetype_(o_); \ t_ == K_TAG_FIXINT || t_ == K_TAG_BIGINT;}) #define ttisbigrat(o) (tbasetype_(o) == K_TAG_BIGRAT) -#define ttisrational(o) ({ int32_t t_ = tbasetype_(o_); \ +#define ttisrational(o_) ({ int32_t t_ = tbasetype_(o_); \ t_ == K_TAG_BIGRAT || t_== K_TAG_BIGINT || \ - t == K_TAG_FIXINT;}) + t_ == K_TAG_FIXINT;}) #define ttisnumber(o) (ttype(o) <= K_LAST_NUMBER_TYPE); }) #define ttiseinf(o) (tbasetype_(o) == K_TAG_EINF) #define ttisiinf(o) (tbasetype_(o) == K_TAG_IINF) diff --git a/src/krational.c b/src/krational.c @@ -21,7 +21,7 @@ inline TValue kbigrat_try_integer(klisp_State *K, TValue n) { Bigrat *b = tv2bigrat(n); - if (mp_int_compare_zero(MP_DENOM_P(b)) == 0) + if (!mp_rat_is_integer(b)) return n; /* sadly we have to repeat the code from try_fixint here... */