VM: better version of bignum_to_fixnum_strict that doesn't allocate
parent
4f49edaa66
commit
1300a27dca
|
@ -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(long_long, int64_t, int64_t, uint64_t)
|
||||||
BIGNUM_TO_FOO(ulong_long, uint64_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 factor_vm::bignum_to_fixnum_strict(bignum* bignum_in) {
|
||||||
fixnum fix = bignum_to_fixnum(bignum_in);
|
fixnum len = BIGNUM_LENGTH(bignum_in);
|
||||||
bignum* bignum_out = fixnum_to_bignum(fix);
|
bignum_digit_type *digits = BIGNUM_START_PTR(bignum_in);
|
||||||
GC_BIGNUM(bignum_out);
|
if ((len == 1 && digits[0] > fixnum_max) || (len > 1)) {
|
||||||
if (bignum_compare(bignum_in, bignum_out) != bignum_comparison_equal) {
|
|
||||||
general_error(ERROR_OUT_OF_FIXNUM_RANGE, tag<bignum>(bignum_in), false_object);
|
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;
|
return fix;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -277,7 +277,7 @@ void factor_vm::primitive_bits_double() {
|
||||||
ctx->push(allot_float(bits_double(to_unsigned_8(ctx->pop()))));
|
ctx->push(allot_float(bits_double(to_unsigned_8(ctx->pop()))));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Allocates memory */
|
/* Cannot allocate */
|
||||||
fixnum factor_vm::to_fixnum(cell tagged) {
|
fixnum factor_vm::to_fixnum(cell tagged) {
|
||||||
switch (TAG(tagged)) {
|
switch (TAG(tagged)) {
|
||||||
case FIXNUM_TYPE:
|
case FIXNUM_TYPE:
|
||||||
|
|
Loading…
Reference in New Issue