Testing big ints
This commit is contained in:
@@ -9,11 +9,13 @@ function void parsing_error(Token *token, const char *str, ...);
|
|||||||
|
|
||||||
#define Set_BigInt_Allocator(x) BigInt_Allocator bigint_allocator(x)
|
#define Set_BigInt_Allocator(x) BigInt_Allocator bigint_allocator(x)
|
||||||
struct BigInt_Allocator{
|
struct BigInt_Allocator{
|
||||||
BigInt_Allocator(Allocator *allocator){bigint_allocator = allocator;}
|
Allocator *old;
|
||||||
~BigInt_Allocator(){bigint_allocator = 0;}
|
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 ALLOC_DIGITS(_digits) (uint64_t *)((_digits) ? malloc_arena(sizeof(uint64_t) * (_digits)) : NULL)
|
||||||
#define FATAL_ERROR(x) parsing_error(0, x)
|
#define FATAL_ERROR(x) parsing_error(0, x)
|
||||||
|
|
||||||
|
|||||||
@@ -68,7 +68,11 @@ function void
|
|||||||
gen_value(Value a){
|
gen_value(Value a){
|
||||||
gen("%s", docname(a.type));
|
gen("%s", docname(a.type));
|
||||||
switch(a.type->kind){
|
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_STRING: gen("LIT(\"%s\")", a.intern_val.str); break;
|
||||||
CASE_BOOL: a.bool_val ? gen("true"):gen("false"); break;
|
CASE_BOOL: a.bool_val ? gen("true"):gen("false"); break;
|
||||||
CASE_FLOAT: gen("%f", a.f64_val); break;
|
CASE_FLOAT: gen("%f", a.f64_val); break;
|
||||||
|
|||||||
@@ -55,6 +55,7 @@ struct Parse_Ctx:Lexer{
|
|||||||
syms = {heap};
|
syms = {heap};
|
||||||
type_map = {heap};
|
type_map = {heap};
|
||||||
local_syms = {heap};
|
local_syms = {heap};
|
||||||
|
bigint_allocator = perm;
|
||||||
|
|
||||||
lex_init(perm, heap, this);
|
lex_init(perm, heap, this);
|
||||||
keyword_struct= intern("struct"_s);
|
keyword_struct= intern("struct"_s);
|
||||||
|
|||||||
@@ -21,7 +21,13 @@ unary_test :: ()
|
|||||||
// var := -true
|
// var := -true
|
||||||
// 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
|
int_val :: 1000
|
||||||
add :: int_val + 10 + 2.242 + 124
|
add :: int_val + 10 + 2.242 + 124
|
||||||
mul :: 4 * 2
|
mul :: 4 * 2
|
||||||
|
|||||||
@@ -206,7 +206,7 @@ function Operand
|
|||||||
operand_int(BigInt big_int){
|
operand_int(BigInt big_int){
|
||||||
Operand result = {};
|
Operand result = {};
|
||||||
result.type = untyped_int;
|
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_const = true;
|
||||||
result.is_lvalue = false;
|
result.is_lvalue = false;
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
Reference in New Issue
Block a user