klisp

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

commit b0e3260681c0a17e3d062479d7d1ca9e28a04d6e
parent 7806e8083125ea15678111e4d990e54e9b2c2c9a
Author: Andres Navarro <canavarro82@gmail.com>
Date:   Tue, 12 Apr 2011 00:25:41 -0300

Rewritten the bigint constructors (new & copy) to use IMath.

Diffstat:
Msrc/kinteger.c | 22++++++++++++++--------
1 file changed, 14 insertions(+), 8 deletions(-)

diff --git a/src/kinteger.c b/src/kinteger.c @@ -28,12 +28,14 @@ TValue kbigint_new(klisp_State *K, bool sign, uint32_t digit) new_bigint->flags = 0; /* bigint specific fields */ - - /* GC: root bigint */ - /* put dummy value to work if garbage collections happens while allocating - node */ - - /* TODO */ + /* If later changed to alloc obj: + GC: root bigint & put dummy value to work if garbage collections + happens while allocating array */ + new_bigint->single = digit; + new_bigint->digits = &(new_bigint->single); + new_bigint->alloc = 1; + new_bigint->used = 1; + new_bigint->sign = sign? MP_NEG : MP_ZPOS; return gc2bigint(new_bigint); } @@ -41,8 +43,12 @@ 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 */ - return src; + TValue copy = kbigint_new(K, false, 0); + Bigint *src_bigint = tv2bigint(src); + Bigint *copy_bigint = tv2bigint(copy); + /* TODO: when the klisp allocator is used mem errors throw exceptions */ + UNUSED(mp_int_init_copy(copy_bigint, src_bigint)); + return copy; } /* This algorithm is like a fused multiply add on bignums,