Draft
Conversation
Add a new compiler option :bigint_integers (default: false) that maps Ruby Integer literals to JavaScript BigInt (e.g., 42 -> 42n) instead of Number. This enables gradual migration to BigInt for better Integer semantics. The option can be enabled via: - Compiler option: Opal.compile(code, bigint_integers: true) - Magic comment: # bigint_integers: true Float literals remain unchanged regardless of this setting.
Document the phased approach to migrate from JavaScript Number to BigInt for representing Ruby Integer literals throughout the codebase.
When bigint_integers option is enabled, transform integer literals
inside %x{} blocks (backtick JavaScript) to BigInt notation.
This allows existing corelib code using embedded JS to work correctly
with BigInt without manual rewriting.
Transformations:
- Decimal: 42 -> 42n
- Hex: 0xFF -> 0xFFn
- Octal: 0o77 -> 0o77n
- Binary: 0b1010 -> 0b1010n
Preserved:
- Floats: 3.14 stays 3.14 (not 3.14n)
- Already BigInt: 123n stays 123n (not 123nn)
- Decimal parts: 3.14 doesn't transform the 14
Keep the default as false to maintain backward compatibility with existing tests and code. The option can be explicitly enabled when ready. This allows gradual adoption and testing of BigInt support before making it the default behavior.
hmdne
reviewed
Dec 28, 2025
| # But NOT if: | ||
| # - already followed by 'n' (BigInt) or '.' (Float) | ||
| # - preceded by '.' (decimal part of a float) | ||
| js_code.gsub(/(?<!\.)(\b(?:0[xX][0-9a-fA-F]+|0[oO][0-7]+|0[bB][01]+|\d+))(?![n.\d])/) do |
Member
There was a problem hiding this comment.
Interesting approach, but I'm afraid it will transmute numbers inside strings.
Though I'd rather just mandate using #{1} inside x-strings.
Remove automatic transformation of integers in embedded JavaScript (%x{}).
This simplifies the implementation and avoids complex parsing issues.
Strategy:
- Ruby Integer literals become BigInt (42 -> 42n)
- JS embedded code stays as-is (backticks use Number)
- Runtime must handle mixed Number/BigInt operations
This is safer and lets us focus on runtime support for mixed operations
rather than trying to parse and transform JavaScript code.
Document completed work and identified blockers: - Compiler support complete (bigint_integers option) - Runtime operators need mixed Number/BigInt support - Next step: fix op_helpers.rb to handle both types - Architectural decision: don't transform JS embedded code
No Italian content should remain in the repository.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.