-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Proposal: BigInteger literals #40
Comments
Yeah, I'd like to support I don't think |
You can implement it if you want - I'll keep busy with LESv3 in the meantime. One approach would be to rewrite this method in ParseHelpers and then fix all the resulting compiler errors: static bool TryParseUInt(ref UString s, ref ulong result, int radix, ParseNumberFlag flags, out int numDigits)
// new version:
static bool TryParseUInt(ref UString s, ref BigInteger result, int radix, ParseNumberFlag flags, out int numDigits) When it comes to truly huge numbers, this algorithm isn't efficient, though... but I don't know what the efficient algorithm is. Maybe BigInteger already has that algorithm, but it won't support embedded underscores or take a |
P.S. I just pushed some stuff to master including the LESv3 parser. |
Actually, Flame doesn't use Note that any integer type also requires back-end support at the moment - the CLR back-end certainly doesn't accept 128-bit integers - but perhaps a lowering pass could dispense with that restriction in the future. I like the Using So I have a slightly different implementation strategy in mind: have the lexer use the The LES printershould append a Would that be acceptable? |
That all sounds good to me ( |
P.S. if you could only have one syntax, which do you like better, |
I like to think that About treating numeric types as strings, isn't that what the The only downside to this that I can imagine, is that encoding custom literals as strings may be wasteful for binary formats. I don't think that's much of a show-stopper, though, and I don't see any real way around that. |
|
I'm proposing to add
BigInteger
literals to LES. First, I'll describe my use case, and then I'll propose a syntax for these literals.All right, so I've recently added (theoretical) support for arbitrarily-sized integer types to Flame. There's just a small catch: the new integer types don't play nice with on-disk Flame IR, because those IR files are LES-based. And LES only supports the C# primitive types. For example, I can encode
UInt64.MaxValue
as aulong
literal right now, but there's just no appropriate literal type forUInt128.MaxValue
at the moment. A hypotheticalBigInteger
literal, on the other hand, should be capable of handling any integer size.I could solve this problem with an ugly workaround, and encode
BigInteger
values as byte arrays. But I'd really rather not, because that would only make reading and writing IR files harder.So instead I propose to add built-in support for
BigInteger
literals to LES. These are then to be represented as normal integers, with some suffix that marks them asBigInteger
values. I was thinking of using 'B' for this purpose, but any suffix will do, really.The
UInt128.MaxValue
constant would, under this scheme, be encoded as340282366920938463463374607431768211456B
.Do you think that this proposal has merit? If so, would you mind if I implemented this feature and sent you a pull request?
The text was updated successfully, but these errors were encountered: