VM: better version of bignum_to_fixnum_strict that doesn't allocate

db4
Björn Lindqvist 2014-06-07 13:09:00 +02:00
parent 4f49edaa66
commit 1300a27dca
2 changed files with 7 additions and 6 deletions

View File

@ -383,14 +383,15 @@ BIGNUM_TO_FOO(fixnum, fixnum, fixnum, cell)
BIGNUM_TO_FOO(long_long, int64_t, int64_t, uint64_t)
BIGNUM_TO_FOO(ulong_long, uint64_t, int64_t, uint64_t)
/* does allocate memory */
/* cannot allocate memory */
fixnum factor_vm::bignum_to_fixnum_strict(bignum* bignum_in) {
fixnum fix = bignum_to_fixnum(bignum_in);
bignum* bignum_out = fixnum_to_bignum(fix);
GC_BIGNUM(bignum_out);
if (bignum_compare(bignum_in, bignum_out) != bignum_comparison_equal) {
fixnum len = BIGNUM_LENGTH(bignum_in);
bignum_digit_type *digits = BIGNUM_START_PTR(bignum_in);
if ((len == 1 && digits[0] > fixnum_max) || (len > 1)) {
general_error(ERROR_OUT_OF_FIXNUM_RANGE, tag<bignum>(bignum_in), false_object);
}
fixnum fix = bignum_to_fixnum(bignum_in);
FACTOR_ASSERT(fix <= fixnum_max && fix >= fixnum_min);
return fix;
}

View File

@ -277,7 +277,7 @@ void factor_vm::primitive_bits_double() {
ctx->push(allot_float(bits_double(to_unsigned_8(ctx->pop()))));
}
/* Allocates memory */
/* Cannot allocate */
fixnum factor_vm::to_fixnum(cell tagged) {
switch (TAG(tagged)) {
case FIXNUM_TYPE: