klisp

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

commit b518f806585494f034d9304fea3ae573be1639c7
parent 6223d322fd5c396f0c3f255b1fb332f7f6b7c74a
Author: Andres Navarro <canavarro82@gmail.com>
Date:   Tue, 12 Apr 2011 16:34:48 -0300

Bugfix: kensure_bigint was declaring the stack allocated Bigint struct inside a local block so two different calls to kensure_bigint returned the same (invalid) address. Replaced the if with a if not then goto end.

Diffstat:
Msrc/kinteger.h | 30+++++++++++++++++-------------
1 file changed, 17 insertions(+), 13 deletions(-)

diff --git a/src/kinteger.h b/src/kinteger.h @@ -22,8 +22,6 @@ TValue kbigint_new(klisp_State *K, bool sign, uint32_t digit); /* used in write to destructively get the digits */ TValue kbigint_copy(klisp_State *K, TValue src); -/* XXX/TODO: rewrite this to use IMath */ - /* Create a stack allocated bigints from a fixint, useful for mixed operations, relatively light weight compared to creating it in the heap and burdening the gc */ @@ -45,10 +43,13 @@ TValue kbigint_copy(klisp_State *K, TValue src); to automatically convert fixints to bigints. NOTE: calls to this macro should go in different lines! */ #define kensure_bigint(n) \ - if (ttisfixint(n)) { \ - kbind_bigint(KUNIQUE_NAME(bint), n); \ - n = gc2bigint(KUNIQUE_NAME(bint)); \ - } + /* must use goto, no block should be entered before calling \ + kbind_bigint */ \ + if (!ttisfixint(n)) \ + goto KUNIQUE_NAME(exit_lbl); \ + kbind_bigint(KUNIQUE_NAME(bint), (n)); \ + (n) = gc2bigint(KUNIQUE_NAME(bint)); \ + KUNIQUE_NAME(exit_lbl): /* This is used by the reader to destructively add digits to a number tv_bigint must be positive */ @@ -62,6 +63,14 @@ int32_t kbigint_remove_digit(klisp_State *K, TValue tv_bigint, int32_t base); /* This is used by write to test if there is any digit left to print */ bool kbigint_has_digits(klisp_State *K, TValue tv_bigint); +/* Mutate the bigint to have the opposite sign, used in read & write */ +void kbigint_invert_sign(klisp_State *K, TValue tv_bigint); + +/* this is used by write to estimate the number of chars necessary to + print the number */ +int32_t kbigint_print_size(TValue tv_bigint, int32_t base); + +/* Interface for kgnumbers */ bool kbigint_eqp(TValue bigint1, TValue bigint2); bool kbigint_ltp(TValue bigint1, TValue bigint2); @@ -69,6 +78,8 @@ bool kbigint_lep(TValue bigint1, TValue bigint2); bool kbigint_gtp(TValue bigint1, TValue bigint2); bool kbigint_gep(TValue bigint1, TValue bigint2); +TValue kbigint_plus(klisp_State *K, TValue n1, TValue n2); + bool kbigint_negativep(TValue tv_bigint); bool kbigint_positivep(TValue tv_bigint); @@ -78,11 +89,4 @@ bool kbigint_evenp(TValue tv_bigint); /* needs the state to create a copy if negative */ TValue kbigint_abs(klisp_State *K, TValue tv_bigint); -/* Mutate the bigint to have the opposite sign, used in read & write */ -void kbigint_invert_sign(klisp_State *K, TValue tv_bigint); - -/* this is used by write to estimate the number of chars necessary to - print the number */ -int32_t kbigint_print_size(TValue tv_bigint, int32_t base); - #endif