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

57
common.c Normal file
View File

@@ -0,0 +1,57 @@
function S64
clamp_top_s64(S64 val, S64 max){
if(val>max)return max;
return val;
}
function SizeU
get_align_offset(SizeU size, SizeU align){
SizeU mask = align - 1;
SizeU val = size & mask;
if(val){
val = align - val;
}
return val;
}
function SizeU
align_up(SizeU size, SizeU align){
SizeU result = size + get_align_offset(size, align);
return result;
}
function U64
hash_fnv(String string) {
U64 hash = (U64)14695981039346656037ULL;
for (U64 i = 0; i < string.len; i++) {
hash = hash ^ (U64)(string.str[i]);
hash = hash * (U64)1099511628211ULL;
}
return hash;
}
function U64
is_pow2(U64 x) {
assert(x != 0);
B32 result = (x & (x - 1llu)) == 0;
return result;
}
function U64
wrap_around_pow2(U64 x, U64 power_of_2) {
assert(is_pow2(power_of_2));
U64 r = (((x)&((power_of_2)-1llu)));
return r;
}
function B32
string_compare(String a, String b){
if(a.len != b.len)
return false;
for(S64 i = 0; i < a.len; i++){
if(a.str[i] != b.str[i])
return false;
}
return true;
}