Commit 9089156c
9089156cb709Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 5 files · +2 added · ~3 modified
Description
parse,codegen: keep integer literals wider than int64 as arbitrary-precision bigints
An integer literal that does not fit in signed 64 bits
(100000000000000000000) was saturated to LLONG_MAX at parse time, so it
printed as 9223372036854775807 instead of its real value. In CRuby such a
literal is a Bignum in every overflow mode -- this is exact literal text,
not a runtime overflow, so it is independent of --int-overflow.
The parser now keeps the exact decimal text in a bigval field when the
value overflows int64 (via Prism's pm_integer_string). An IntegerNode with
bigval infers as TY_BIGINT and lowers to sp_bigint_new_str("...", 10)
rather than a saturated mrb_int literal; the int-constant folder declines
such nodes. Negative and underscored forms work; arithmetic flows through
the existing bigint paths (x + 1, x * 3).
Co-Authored-By: Claude Opus 4.8 [email protected]
Details
- Commit
- 9089156cb709
- Parent
- 102e2bb52557
src/analyze_infer.cmodifiedView file
if (!ty) return TY_UNKNOWN; NodeKind nk = nt_kind(nt, id); if (nk == NK_IntegerNode) return TY_INT; if (nk == NK_IntegerNode) return nt_str(nt, id, "bigval") ? TY_BIGINT : TY_INT; if (nk == NK_FloatNode) return TY_FLOAT; if (nk == NK_ImaginaryNode) return TY_COMPLEX; if (nk == NK_RationalNode) return TY_RATIONAL;src/codegen_expr.cmodifiedView file
Loading diff…
src/spinel_parse.cmodifiedView file
Loading diff…
test/bigint_literal.rbaddedView file
Loading diff…
test/bigint_literal.rb.expectedaddedView file
Loading diff…