From 26dc0cd04378dfe7e0af03afac710caf690189d9 Mon Sep 17 00:00:00 2001 From: Vincent St-Amour Date: Wed, 19 Aug 2009 14:25:11 -0400 Subject: [PATCH] A couple of fixes for numerical operations without bignums. --- bignums.c | 10 +++++----- gc.c | 2 +- picobit-vm.h | 4 +++- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/bignums.c b/bignums.c index 47f544d..d0a025c 100644 --- a/bignums.c +++ b/bignums.c @@ -459,9 +459,9 @@ obj encode_int (uint16 n) { // regular (finite, 24 bits) bignums uint16 decode_int (obj o) { - uint8 u; - uint8 h; - uint8 l; + uint16 u; // TODO should be 32, but is lost anyway since this returns a uint16 + uint16 h; + uint8 l; if (o < MIN_FIXNUM_ENCODING) TYPE_ERROR("decode_int.0", "integer"); @@ -489,9 +489,9 @@ uint16 decode_int (obj o) { TYPE_ERROR("decode_int.3", "integer"); if (u >= 128) // negative - return ((uint32)((((uint16)u - 256) << 8) + h) << 8) + l; // TODO ints are all 16 bits, 24 bits won't work + return ((((u - 256) << 8) + h) << 8) + l; // TODO ints are all 16 bits, 24 bits won't work - return ((uint32)(((uint16)u << 8) + h) << 8) + l; + return (((u << 8) + h) << 8) + l; } obj encode_int (uint16 n) { // TODO does not use the full 24 bits diff --git a/gc.c b/gc.c index 00b0110..657e794 100644 --- a/gc.c +++ b/gc.c @@ -186,7 +186,7 @@ void sweep () { } ram_set_car (visit, free_list); free_list = visit; - } + } else { if (RAM_COMPOSITE(visit)) ram_set_gc_tags (visit, GC_TAG_UNMARKED); diff --git a/picobit-vm.h b/picobit-vm.h index 6e62061..4d5989f 100644 --- a/picobit-vm.h +++ b/picobit-vm.h @@ -355,8 +355,10 @@ void set_global (uint8 i, obj o); Gs represent mark bits used by the gc ifdef INFINITE_PRECISION_BIGNUMS - bignum n 0GG***** **next** hhhhhhhh llllllll (16 bit digit) + bignum n 00G***** **next** hhhhhhhh llllllll (16 bit digit) TODO what to do with the gc tags for the bignums ? will this work ? + TODO since bignums have only 1 field, only one gc tag is should be enough + (only one is used anyway), so no conflict with closures ifndef INFINITE_PRECISION_BIGNUMS bignum n 00000000 uuuuuuuu hhhhhhhh llllllll (24 bit signed integer) -- 2.11.4.GIT