mirror of
https://github.com/ashinn/chibi-scheme.git
synced 2025-05-21 14:49:18 +02:00
adding sexp_make_unsigned_integer, using that in the stubber for unsigned types
This commit is contained in:
parent
f897ecc9c1
commit
e5bcac2142
3 changed files with 26 additions and 5 deletions
|
@ -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
|
||||
|
||||
|
|
23
opt/bignum.c
23
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;
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Add table
Reference in a new issue