Testing big ints

This commit is contained in:
Krzosa Karol
2022-06-06 17:00:01 +02:00
parent dc56bd54f3
commit 7173557d26
5 changed files with 19 additions and 6 deletions

View File

@@ -9,11 +9,13 @@ function void parsing_error(Token *token, const char *str, ...);
#define Set_BigInt_Allocator(x) BigInt_Allocator bigint_allocator(x)
struct BigInt_Allocator{
BigInt_Allocator(Allocator *allocator){bigint_allocator = allocator;}
~BigInt_Allocator(){bigint_allocator = 0;}
Allocator *old;
BigInt_Allocator(Allocator *allocator){old = bigint_allocator; bigint_allocator = allocator;}
~BigInt_Allocator(){bigint_allocator = old;}
};
#define malloc_arena(x) (bigint_allocation_count++, exp_alloc(bigint_allocator, x, AF_ZeroMemory))
#define count_bigint_alloc() (bigint_allocator != thread_ctx.scratch ? bigint_allocation_count++ : 0)
#define malloc_arena(x) (count_bigint_alloc(), exp_alloc(bigint_allocator, x, AF_ZeroMemory))
#define ALLOC_DIGITS(_digits) (uint64_t *)((_digits) ? malloc_arena(sizeof(uint64_t) * (_digits)) : NULL)
#define FATAL_ERROR(x) parsing_error(0, x)

View File

@@ -68,7 +68,11 @@ function void
gen_value(Value a){
gen("%s", docname(a.type));
switch(a.type->kind){
CASE_INT: gen("%lld", bigint_as_signed(&a.big_int_val)); break;
CASE_INT: {
Scratch scratch;
const char *string = bigint_to_error_string(scratch, &a.big_int_val, 10);
gen("%s", string);
}break;
CASE_STRING: gen("LIT(\"%s\")", a.intern_val.str); break;
CASE_BOOL: a.bool_val ? gen("true"):gen("false"); break;
CASE_FLOAT: gen("%f", a.f64_val); break;

View File

@@ -55,6 +55,7 @@ struct Parse_Ctx:Lexer{
syms = {heap};
type_map = {heap};
local_syms = {heap};
bigint_allocator = perm;
lex_init(perm, heap, this);
keyword_struct= intern("struct"_s);

View File

@@ -21,7 +21,13 @@ unary_test :: ()
// var := -true
// var := +true
binary_test :: (thing: S32 = 1051514424242424242442424242424252525252)
// @note: Poggers
big_number1 :: 12512512512512521524242
big_number2 :: 12512512512512521524242
big_number3 :: 12512512512512521524242
big_number4 :: 12512512512512521524242
big_number5 :: 12512512512512521524242 + big_number1 * big_number1
binary_test :: (thing: S32 = 442)
int_val :: 1000
add :: int_val + 10 + 2.242 + 124
mul :: 4 * 2

View File

@@ -206,7 +206,7 @@ function Operand
operand_int(BigInt big_int){
Operand result = {};
result.type = untyped_int;
bigint_init_bigint(&result.big_int_val, &big_int);
result.big_int_val = bigint_copy(pctx->perm, &big_int);
result.is_const = true;
result.is_lvalue = false;
return result;