Parsing exprs, enum_decls, Introduce intern table, symbol table

This commit is contained in:
Krzosa Karol
2022-04-29 11:22:10 +02:00
parent d462892e14
commit 9cbbb4d616
20 changed files with 1831 additions and 335 deletions

47
memory.c Normal file
View File

@@ -0,0 +1,47 @@
global const SizeU default_reserve_size = gib(4);
global const SizeU default_alignment = 8;
global const SizeU additional_commit_size = mib(1);
function void
memory_copy(U8 *dst, U8 *src, SizeU size){
for(SizeU i = 0; i < size; i++){
dst[i] = src[i];
}
}
function void
memory_zero(void *p, SizeU size){
U8 *pp = p;
for(SizeU i = 0; i < size; i++)
pp[i] = 0;
}
function void
arena_init(Arena *a){
a->memory = os_reserve(default_reserve_size);
a->alignment = default_alignment;
}
function void *
arena_push_size(Arena *a, SizeU size){
SizeU generous_size = size + a->alignment;
if(generous_size>a->memory.commit){
if(a->memory.reserve == 0){
arena_init(a);
}
os_commit(&a->memory, generous_size+additional_commit_size);
}
a->len = align_up(a->len, a->alignment);
void *result = (U8*)a->memory.data + a->len;
a->len += size;
return result;
}
function String
arena_push_string_copy(Arena *arena, String string){
U8 *copy = arena_push_array(arena, U8, string.len+1);
memory_copy(copy, string.str, string.len);
copy[string.len] = 0;
return (String){copy, string.len};
}