diff --git a/include/chibi/sexp.h b/include/chibi/sexp.h index b110a973..05cdb7b5 100644 --- a/include/chibi/sexp.h +++ b/include/chibi/sexp.h @@ -848,7 +848,7 @@ SEXP_API sexp sexp_string_concatenate_op (sexp ctx sexp_api_params(self, n), sex SEXP_API sexp sexp_intern (sexp ctx, const char *str, sexp_sint_t len); SEXP_API sexp sexp_string_to_symbol_op (sexp ctx sexp_api_params(self, n), sexp str); SEXP_API sexp sexp_string_to_number_op (sexp ctx sexp_api_params(self, n), sexp str, sexp b); -SEXP_API sexp sexp_make_vector (sexp ctx, sexp len, sexp dflt); +SEXP_API sexp sexp_make_vector_op (sexp ctx sexp_api_params(self, n), sexp len, sexp dflt); SEXP_API sexp sexp_list_to_vector_op (sexp ctx sexp_api_params(self, n), sexp ls); SEXP_API sexp sexp_make_cpointer (sexp ctx, sexp_uint_t type_id, void* value, sexp parent, int freep); SEXP_API sexp sexp_write_op (sexp ctx sexp_api_params(self, n), sexp obj, sexp out); @@ -915,6 +915,7 @@ SEXP_API sexp sexp_finalize_c_type (sexp ctx sexp_api_params(self, n), sexp obj) #define sexp_nreverse(ctx, x) sexp_nreverse_op(ctx sexp_api_pass(NULL, 1), x) #define sexp_cons(ctx, a, b) sexp_cons_op(ctx sexp_api_pass(NULL, 2), a, b) #define sexp_append2(ctx, a, b) sexp_append2_op(ctx sexp_api_pass(NULL, 2), a, b) +#define sexp_make_vector(ctx, a, b) sexp_make_vector_op(ctx sexp_api_pass(NULL, 2), a, b); #define sexp_list_to_vector(ctx, x) sexp_list_to_vector_op(ctx sexp_api_pass(NULL, 1), x) #define sexp_exception_type(ctx, x) sexp_exception_type_op(ctx sexp_api_pass(NULL, 1), x) #define sexp_string_to_number(ctx, s, b) sexp_make_string_op(ctx sexp_api_pass(NULL, 2), s, b) diff --git a/opt/bignum.c b/opt/bignum.c index 588dbde5..5ad40e70 100644 --- a/opt/bignum.c +++ b/opt/bignum.c @@ -27,7 +27,7 @@ sexp sexp_fixnum_to_bignum (sexp ctx, sexp a) { sexp sexp_make_integer (sexp ctx, sexp_lsint_t x) { sexp res; - if ((SEXP_MIN_FIXNUM < x) && (x < SEXP_MAX_FIXNUM)) { + if ((SEXP_MIN_FIXNUM <= x) && (x <= SEXP_MAX_FIXNUM)) { res = sexp_make_fixnum(x); } else { res = sexp_make_bignum(ctx, 1); @@ -44,7 +44,7 @@ sexp sexp_make_integer (sexp ctx, sexp_lsint_t x) { sexp sexp_make_unsigned_integer (sexp ctx, sexp_luint_t x) { sexp res; - if (x < SEXP_MAX_FIXNUM) { + if (x <= SEXP_MAX_FIXNUM) { res = sexp_make_fixnum(x); } else { res = sexp_make_bignum(ctx, 1); @@ -487,7 +487,7 @@ enum sexp_number_combs { }; static int sexp_number_types[] = - {0, 0, 1, 0, 0, 0, 0, 0, 0, 2, 3, 0, 0, 0, 0, 0}; + {0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 2, 3, 0, 0, 0, 0}; static int sexp_number_type (sexp a) { return sexp_pointerp(a) ? sexp_number_types[sexp_pointer_tag(a)&15] diff --git a/sexp.c b/sexp.c index 82dfb36f..f92d13c5 100644 --- a/sexp.c +++ b/sexp.c @@ -784,7 +784,7 @@ sexp sexp_string_to_symbol_op (sexp ctx sexp_api_params(self, n), sexp str) { return sexp_intern(ctx, sexp_string_data(str), sexp_string_length(str)); } -sexp sexp_make_vector (sexp ctx, sexp len, sexp dflt) { +sexp sexp_make_vector_op (sexp ctx sexp_api_params(self, n), sexp len, sexp dflt) { sexp vec, *x; int i, clen = sexp_unbox_fixnum(len); if (! clen) return sexp_global(ctx, SEXP_G_EMPTY_VECTOR); @@ -1643,9 +1643,13 @@ sexp sexp_read_raw (sexp ctx, sexp in) { else #endif #if SEXP_USE_BIGNUMS - if (sexp_bignump(res)) - sexp_bignum_sign(res) = -sexp_bignum_sign(res); - else + if (sexp_bignump(res)) { + if ((sexp_bignum_hi(res) == 1) + && sexp_bignum_data(res)[0] == SEXP_MAX_FIXNUM) + res = sexp_make_fixnum(-sexp_bignum_data(res)[0]); + else + sexp_bignum_sign(res) = -sexp_bignum_sign(res); + } else #endif res = sexp_fx_mul(res, SEXP_NEG_ONE); }