Skip to content

Commit

Permalink
VM: fixes a bug with the handling of 0 bignums, and declares bignum/mod
Browse files Browse the repository at this point in the history
to maybe output fixnums
  • Loading branch information
bjourne committed Jun 27, 2015
1 parent 0d02ff8 commit 35b04f8
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion basis/stack-checker/known-words/known-words.factor
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ M: object infer-call* \ call bad-macro-input ;
\ bignum-gcd { bignum bignum } { bignum } define-primitive \ bignum-gcd make-foldable
\ bignum-shift { bignum fixnum } { bignum } define-primitive \ bignum-shift make-foldable
\ bignum/i { bignum bignum } { bignum } define-primitive \ bignum/i make-foldable
\ bignum/mod { bignum bignum } { bignum bignum } define-primitive \ bignum/mod make-foldable
\ bignum/mod { bignum bignum } { bignum integer } define-primitive \ bignum/mod make-foldable
\ bignum< { bignum bignum } { object } define-primitive \ bignum< make-foldable
\ bignum<= { bignum bignum } { object } define-primitive \ bignum<= make-foldable
\ bignum= { bignum bignum } { object } define-primitive \ bignum= make-foldable
Expand Down
4 changes: 3 additions & 1 deletion vm/math.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
namespace factor {

cell bignum_maybe_to_fixnum(bignum* bn) {
if (BIGNUM_ZERO_P(bn))
return tag_fixnum(0);
fixnum len = BIGNUM_LENGTH(bn);
bignum_digit_type *digits = BIGNUM_START_PTR(bn);
if (len == 1 && digits[0] >= fixnum_min && digits[0] <= fixnum_max) {
Expand Down Expand Up @@ -143,7 +145,7 @@ void factor_vm::primitive_bignum_divmod() {
bignum* q, *r;
bignum_divide(x, y, &q, &r);
*s1 = tag<bignum>(q);
*s0 = tag<bignum>(r);
*s0 = bignum_maybe_to_fixnum(r);
}

void factor_vm::primitive_bignum_mod() {
Expand Down

0 comments on commit 35b04f8

Please sign in to comment.