Switched to bigint in lexer
This commit is contained in:
20
new_lex.cpp
20
new_lex.cpp
@@ -103,7 +103,7 @@ struct Token{
|
||||
|
||||
union {
|
||||
U32 unicode;
|
||||
U64 int_val;
|
||||
BigInt int_val;
|
||||
F64 f64_val;
|
||||
String error_val;
|
||||
Intern_String intern_val;
|
||||
@@ -209,19 +209,15 @@ token_error(Token *t, String error_val){
|
||||
function void
|
||||
lex_parse_u64(Token *t){
|
||||
t->kind = TK_Integer;
|
||||
U64 result = 0;
|
||||
U64 m = 1;
|
||||
BigInt m = bigint_u64(1); // @leak, it accumulates and potentially needs allocation
|
||||
BigInt val10 = bigint_u64(10);
|
||||
|
||||
for(S64 i = t->len - 1; i >= 0; --i){
|
||||
U64 val = t->str[i] - '0';
|
||||
U64 new_val = val * m;
|
||||
if((result + new_val) < result){
|
||||
token_error(t, "Integer overflow"_s);
|
||||
return;
|
||||
}
|
||||
result+=new_val;
|
||||
m *= 10;
|
||||
BigInt val = bigint_u64(t->str[i] - '0'); // I dont think this is a leak, too small
|
||||
BigInt new_val = bigint_mul(&val, &m); // @leak
|
||||
bigint_add(&t->int_val, &t->int_val, &new_val);
|
||||
bigint_mul(&m, &m, &val10);
|
||||
}
|
||||
t->int_val = result;
|
||||
}
|
||||
|
||||
function void
|
||||
|
||||
Reference in New Issue
Block a user