diff --git a/big_int_c3.cpp b/big_int_c3.cpp index 0482b89..8e3e970 100644 --- a/big_int_c3.cpp +++ b/big_int_c3.cpp @@ -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) diff --git a/ccodegen.cpp b/ccodegen.cpp index 4d83373..228d2d0 100644 --- a/ccodegen.cpp +++ b/ccodegen.cpp @@ -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; diff --git a/new_ast.cpp b/new_ast.cpp index c3fe3b2..3f4eedb 100644 --- a/new_ast.cpp +++ b/new_ast.cpp @@ -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); diff --git a/new_types.kl b/new_types.kl index c817fa3..281dbcd 100644 --- a/new_types.kl +++ b/new_types.kl @@ -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 diff --git a/typecheck.h b/typecheck.h index 5eb37e5..e977480 100644 --- a/typecheck.h +++ b/typecheck.h @@ -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;