diff --git a/include/chibi/sexp.h b/include/chibi/sexp.h index 72fbe564..28f2fed8 100644 --- a/include/chibi/sexp.h +++ b/include/chibi/sexp.h @@ -474,10 +474,12 @@ sexp sexp_make_flonum(sexp ctx, double f); #endif #if SEXP_USE_BIGNUMS -SEXP_API sexp sexp_make_integer(sexp ctx, sexp_sint_t x); +SEXP_API sexp sexp_make_integer(sexp ctx, sexp_lsint_t x); +SEXP_API sexp sexp_make_unsigned_integer(sexp ctx, sexp_luint_t x); #define sexp_exact_integerp(x) (sexp_fixnump(x) || sexp_bignump(x)) #else #define sexp_make_integer(ctx, x) sexp_make_fixnum(x) +#define sexp_make_unsigned_integer(ctx, x) sexp_make_fixnum(x) #define sexp_exact_integerp(x) sexp_fixnump(x) #endif diff --git a/opt/bignum.c b/opt/bignum.c index 90f71661..60215de8 100644 --- a/opt/bignum.c +++ b/opt/bignum.c @@ -25,14 +25,31 @@ sexp sexp_fixnum_to_bignum (sexp ctx, sexp a) { return res; } -sexp sexp_make_integer (sexp ctx, sexp_sint_t x) { +sexp sexp_make_integer (sexp ctx, sexp_lsint_t x) { sexp res; if ((SEXP_MIN_FIXNUM < x) && (x < SEXP_MAX_FIXNUM)) { res = sexp_make_fixnum(x); } else { res = sexp_make_bignum(ctx, 1); - sexp_bignum_sign(res) = (x < 0 ? -1 : 1); - sexp_bignum_data(res)[0] = x * sexp_bignum_sign(res); + if (x < 0) { + sexp_bignum_sign(res) = -1; + sexp_bignum_data(res)[0] = -x; + } else { + sexp_bignum_sign(res) = 1; + sexp_bignum_data(res)[0] = x; + } + } + return res; +} + +sexp sexp_make_unsigned_integer (sexp ctx, sexp_luint_t x) { + sexp res; + if (x < SEXP_MAX_FIXNUM) { + res = sexp_make_fixnum(x); + } else { + res = sexp_make_bignum(ctx, 1); + sexp_bignum_sign(res) = 1; + sexp_bignum_data(res)[0] = x; } return res; } diff --git a/tools/genstubs.scm b/tools/genstubs.scm index 037e853e..4f248554 100755 --- a/tools/genstubs.scm +++ b/tools/genstubs.scm @@ -452,7 +452,9 @@ (cat "sexp_make_boolean(" val ")")) ((eq? base 'time_t) (cat "sexp_make_integer(ctx, sexp_shift_epoch(" val "))")) - ((int-type? base) + ((unsigned-int-type? base) + (cat "sexp_make_unsigned_integer(ctx, " val ")")) + ((signed-int-type? base) (cat "sexp_make_integer(ctx, " val ")")) ((eq? base 'char) (if (type-array type)