mirror of
https://github.com/wren-lang/wren.git
synced 2026-01-09 21:28:39 +01:00
Use strtoll() for hex literals to handle 64-bit ones even on 32-bit.
This commit is contained in:
@ -130,9 +130,8 @@ class Literals is SyntaxExample {
|
||||
1.0
|
||||
-12.34
|
||||
0x1000000
|
||||
// Literals larger than 0x1000000 are only valid in 64 bit builds
|
||||
// 0xdeadbeef
|
||||
// 0x1234567890ABCDEF
|
||||
0xdeadbeef
|
||||
0x1234567890ABCDEF
|
||||
}
|
||||
|
||||
strings {
|
||||
|
||||
@ -712,16 +712,23 @@ static void makeNumber(Parser* parser, bool isHex)
|
||||
{
|
||||
errno = 0;
|
||||
|
||||
// We don't check that the entire token is consumed because we've already
|
||||
// scanned it ourselves and know it's valid.
|
||||
parser->current.value = NUM_VAL(isHex ? strtol(parser->tokenStart, NULL, 16)
|
||||
: strtod(parser->tokenStart, NULL));
|
||||
if (isHex)
|
||||
{
|
||||
parser->current.value = NUM_VAL(strtoll(parser->tokenStart, NULL, 16));
|
||||
}
|
||||
else
|
||||
{
|
||||
parser->current.value = NUM_VAL(strtod(parser->tokenStart, NULL));
|
||||
}
|
||||
|
||||
if (errno == ERANGE)
|
||||
{
|
||||
lexError(parser, "Number literal was too large.");
|
||||
lexError(parser, "Number literal was too large (%d).", sizeof(long int));
|
||||
parser->current.value = NUM_VAL(0);
|
||||
}
|
||||
|
||||
// We don't check that the entire token is consumed after calling strtoll()
|
||||
// or strtod() because we've already scanned it ourselves and know it's valid.
|
||||
|
||||
makeToken(parser, TOKEN_NUMBER);
|
||||
}
|
||||
|
||||
@ -5,4 +5,5 @@ System.print(x + 1) // expect: 256
|
||||
System.print(x == 255) // expect: true
|
||||
System.print(0x09 is Num) // expect: true
|
||||
System.print(x is Num) // expect: true
|
||||
System.print(-0xFF) // expect: -255
|
||||
System.print(-0xFF) // expect: -255
|
||||
System.print(0xdeadbeef) // expect: 3735928559
|
||||
|
||||
Reference in New Issue
Block a user