Skip to content

Commit

Permalink
vm: rename [u]long_long_to_bignum to [u]int64_to_bignum.
Browse files Browse the repository at this point in the history
  • Loading branch information
mrjbq7 committed Aug 11, 2024
1 parent c96b60f commit 32536cd
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 15 deletions.
15 changes: 8 additions & 7 deletions vm/bignum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,8 +320,8 @@ bignum* factor_vm::bignum_remainder(bignum* numerator, bignum* denominator) {
}
}

// cell_to_bignum, fixnum_to_bignum, long_long_to_bignum, ulong_long_to_bignum

// cell_to_bignum, fixnum_to_bignum, int64_to_bignum, uint64_to_bignum
// int32_to_bignum, int64_to_bignum
// Allocates memory
#define FOO_TO_BIGNUM_SIGNED(name, type, utype) \
bignum* factor_vm::name##_to_bignum(type n) { \
Expand Down Expand Up @@ -396,15 +396,16 @@ bignum* factor_vm::bignum_remainder(bignum* numerator, bignum* denominator) {

FOO_TO_BIGNUM_SIGNED(fixnum, fixnum, cell)
FOO_TO_BIGNUM_UNSIGNED(cell, cell, cell)
FOO_TO_BIGNUM_SIGNED(long_long, int64_t, uint64_t)
FOO_TO_BIGNUM_UNSIGNED(ulong_long, uint64_t, uint64_t)
FOO_TO_BIGNUM_SIGNED(int64, int64_t, uint64_t)
FOO_TO_BIGNUM_UNSIGNED(uint64, uint64_t, uint64_t)
#ifndef FACTOR_64
FOO_TO_BIGNUM_SIGNED(int32, int32_t, uint32_t)
FOO_TO_BIGNUM_UNSIGNED(uint32, uint32_t, uint32_t)
#endif

// cannot allocate memory
// bignum_to_cell, fixnum_to_cell, long_long_to_cell, ulong_long_to_cell
// bignum_to_cell, bignum_to_fixnum, bignum_to_int64, bignum_to_uint64
// bignum_to_int32, bignum_to_uint32
#define BIGNUM_TO_FOO(name, type, stype, utype) \
type bignum_to_##name(bignum* bn) { \
if (BIGNUM_ZERO_P(bn)) \
Expand All @@ -424,8 +425,8 @@ BIGNUM_TO_FOO(cell, cell, fixnum, cell)
BIGNUM_TO_FOO(fixnum, fixnum, fixnum, cell)
BIGNUM_TO_FOO(int32, int32_t, int32_t, uint64_t)
BIGNUM_TO_FOO(uint32, uint32_t, int32_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(int64, int64_t, int64_t, uint64_t)
BIGNUM_TO_FOO(uint64, uint64_t, int64_t, uint64_t)

bool bignum_fits_fixnum_p(bignum* bn) {
fixnum len = BIGNUM_LENGTH(bn);
Expand Down
4 changes: 2 additions & 2 deletions vm/bignum.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ enum bignum_comparison {
cell bignum_maybe_to_fixnum(bignum* bn);
cell bignum_to_cell(bignum* bn);
fixnum bignum_to_fixnum(bignum* bn);
int64_t bignum_to_long_long(bignum* bn);
uint64_t bignum_to_ulong_long(bignum* bn);
int64_t bignum_to_int64(bignum* bn);
uint64_t bignum_to_uint64(bignum* bn);
int32_t bignum_to_int32(bignum* bn);
uint32_t bignum_to_uint32(bignum* bn);

Expand Down
8 changes: 4 additions & 4 deletions vm/math.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -345,8 +345,8 @@ void factor_vm::primitive_bits_double() {
CELL_TO_FOO(to_fixnum, fixnum, bignum_to_fixnum)
CELL_TO_FOO(to_fixnum_strict, fixnum, bignum_to_fixnum_strict)
CELL_TO_FOO(to_cell, cell, bignum_to_cell)
CELL_TO_FOO(to_signed_8, int64_t, bignum_to_long_long)
CELL_TO_FOO(to_unsigned_8, uint64_t, bignum_to_ulong_long)
CELL_TO_FOO(to_signed_8, int64_t, bignum_to_int64)
CELL_TO_FOO(to_unsigned_8, uint64_t, bignum_to_uint64)
CELL_TO_FOO(to_signed_4, int32_t, bignum_to_int32)
CELL_TO_FOO(to_unsigned_4, uint32_t, bignum_to_uint32)

Expand All @@ -363,7 +363,7 @@ VM_C_API cell from_unsigned_cell(cell integer, factor_vm* parent) {
// Allocates memory
cell factor_vm::from_signed_8(int64_t n) {
if (n < fixnum_min || n > fixnum_max)
return tag<bignum>(long_long_to_bignum(n));
return tag<bignum>(int64_to_bignum(n));
else
return tag_fixnum((fixnum)n);
}
Expand All @@ -375,7 +375,7 @@ VM_C_API cell from_signed_8(int64_t n, factor_vm* parent) {
// Allocates memory
cell factor_vm::from_unsigned_8(uint64_t n) {
if (n > (uint64_t)fixnum_max)
return tag<bignum>(ulong_long_to_bignum(n));
return tag<bignum>(uint64_to_bignum(n));
else
return tag_fixnum((fixnum)n);
}
Expand Down
4 changes: 2 additions & 2 deletions vm/vm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -446,8 +446,8 @@ struct factor_vm {
void primitive_fixnum_divmod();
bignum* fixnum_to_bignum(fixnum);
bignum* cell_to_bignum(cell);
bignum* long_long_to_bignum(int64_t n);
bignum* ulong_long_to_bignum(uint64_t n);
bignum* int64_to_bignum(int64_t n);
bignum* uint64_to_bignum(uint64_t n);
#ifndef FACTOR_64
bignum* int32_to_bignum(int32_t n);
bignum* uint32_to_bignum(uint32_t n);
Expand Down

0 comments on commit 32536cd

Please sign in to comment.