core changes
This commit is contained in:
@@ -64,7 +64,7 @@ typedef double f64;
|
||||
|
||||
#define zero_struct(x) memory_zero((x), sizeof(*(x)))
|
||||
|
||||
#define DEFER_LOOP(begin, end) for (i32 PASTE(_i_, __LINE__) = (begin, 0); !PASTE(_i_, __LINE__); PASTE(_i_, __LINE__) += (end, 1))
|
||||
#define defer_block(begin, end) for (i32 PASTE(_i_, __LINE__) = (begin, 0); !PASTE(_i_, __LINE__); PASTE(_i_, __LINE__) += (end, 1))
|
||||
#define STACK(type, size) struct { type data[size]; i32 len; }
|
||||
#define STACK_PUSH(stack, ...) (assert((stack).len < lengthof((stack).data)), (stack).data[(stack).len++] = __VA_ARGS__)
|
||||
#define STACK_POP(stack) (assert((stack).len > 0), (stack).data[--(stack).len])
|
||||
|
||||
@@ -33,8 +33,8 @@ struct ht_dict_t {
|
||||
ht_bucket_t *buckets;
|
||||
};
|
||||
|
||||
u64 ht_hash(s8_t string) {
|
||||
u8 *data = string.str;
|
||||
u64 ht_hash_data(s8_t string) {
|
||||
u8 *data = (u8 *)string.str;
|
||||
uint64_t hash = (u64)14695981039346656037ULL;
|
||||
for (i64 i = 0; i < string.len; i++) {
|
||||
hash = hash ^ (u64)(data[i]);
|
||||
@@ -61,7 +61,7 @@ ht_node_t *ht_insert_kv(ht_dict_t *ht, u64 hash, ht_key_value_t kv) {
|
||||
}
|
||||
|
||||
ht_node_t *ht_insert_u64_u64(ht_dict_t *ht, u64 key, u64 value) {
|
||||
u64 hash = ht_hash(s8((char *)&key, sizeof(key)));
|
||||
u64 hash = ht_hash_data(s8((char *)&key, sizeof(key)));
|
||||
return ht_insert_kv(ht, hash, (ht_key_value_t){.key_u64 = key, .value_u64 = value});
|
||||
}
|
||||
|
||||
@@ -70,12 +70,12 @@ ht_node_t *ht_insert_ptr(ht_dict_t *ht, void *key, void *value) {
|
||||
}
|
||||
|
||||
ht_node_t *ht_insert_string(ht_dict_t *ht, s8_t key, s8_t value) {
|
||||
u64 hash = ht_hash(key);
|
||||
u64 hash = ht_hash_data(key);
|
||||
return ht_insert_kv(ht, hash, (ht_key_value_t){.key_string = key, .value_string = value});
|
||||
}
|
||||
|
||||
ht_node_t *ht_search_u64(ht_dict_t *ht, u64 key) {
|
||||
u64 hash = ht_hash(s8((char *)&key, sizeof(key)));
|
||||
u64 hash = ht_hash_data(s8((char *)&key, sizeof(key)));
|
||||
i64 idx = hash % ht->bucket_count;
|
||||
ht_bucket_t *bucket = ht->buckets + idx;
|
||||
for (ht_node_t *it = bucket->first; it; it = it->next) {
|
||||
@@ -91,7 +91,7 @@ ht_node_t *ht_search_ptr(ht_dict_t *ht, void *key_ptr) {
|
||||
}
|
||||
|
||||
ht_node_t *ht_search_string(ht_dict_t *ht, s8_t key) {
|
||||
u64 hash = ht_hash(key);
|
||||
u64 hash = ht_hash_data(key);
|
||||
i64 idx = hash % ht->bucket_count;
|
||||
ht_bucket_t *bucket = ht->buckets + idx;
|
||||
for (ht_node_t *it = bucket->first; it; it = it->next) {
|
||||
|
||||
@@ -31,7 +31,7 @@ fn void default_log_proc(log_event_t ev) {
|
||||
}
|
||||
|
||||
sb8_printf(sb, "%S\n", ev.string);
|
||||
s8_t result = sb8_serial_end(sb);
|
||||
s8_t result = sb8_serial_end(scratch.arena, sb);
|
||||
|
||||
if (ev.level != log_level_fatal) {
|
||||
os_console_log(result.str);
|
||||
|
||||
@@ -410,9 +410,9 @@ fn int64_t sb8_char_size(sb8_t *sb) {
|
||||
return result;
|
||||
}
|
||||
|
||||
fn s8_t sb8_merge(sb8_t *sb) {
|
||||
fn s8_t sb8_merge(ma_arena_t *arena, sb8_t *sb) {
|
||||
int64_t size = sb8_char_size(sb) + 1;
|
||||
char *str = ma_push_size(sb->arena, size);
|
||||
char *str = ma_push_size(arena, size);
|
||||
s8_t result = {str, 0};
|
||||
for (sb8_node_t *it = sb->first; it; it = it->next) {
|
||||
memory_copy(result.str + result.len, it->str, it->len);
|
||||
|
||||
@@ -123,13 +123,13 @@ fn s8_t s8_printf(ma_arena_t *ma, const char *str, ...);
|
||||
//
|
||||
// string builder
|
||||
#define sb8_serial_begin(ARENA) &(sb8_t){.arena = ARENA}
|
||||
#define sb8_serial_end(sb) sb8_merge(sb)
|
||||
#define sb8_serial_end(ARENA, SB) sb8_merge(ARENA, SB)
|
||||
|
||||
fn s8_t sb8_printf(sb8_t *sb, const char *str, ...);
|
||||
fn sb8_node_t *sb8_append(sb8_t *list, s8_t string);
|
||||
fn sb8_node_t *sb8_create_node(ma_arena_t *ma, s8_t str);
|
||||
|
||||
fn s8_t sb8_merge(sb8_t *sb);
|
||||
fn s8_t sb8_merge(ma_arena_t *arena, sb8_t *sb);
|
||||
fn void sb8_indent(sb8_t *sb);
|
||||
fn s8_t sb8_stmtf(sb8_t *sb, const char *str, ...);
|
||||
fn int64_t sb8_char_size(sb8_t *sb);
|
||||
|
||||
@@ -225,9 +225,11 @@ fn void ti__serial_data_ex(sb8_t *sb, void *p, type_t *type) {
|
||||
}
|
||||
|
||||
fn s8_t ti__serial_data(ma_arena_t *arena, void *p, type_t *type) {
|
||||
sb8_t *sb = sb8_serial_begin(arena);
|
||||
ma_temp_t scratch = ma_begin_scratch1(arena);
|
||||
sb8_t *sb = sb8_serial_begin(scratch.arena);
|
||||
ti__serial_data_ex(sb, p, type);
|
||||
s8_t string = sb8_serial_end(sb);
|
||||
s8_t string = sb8_serial_end(arena, sb);
|
||||
ma_end_scratch(scratch);
|
||||
return string;
|
||||
}
|
||||
|
||||
|
||||
@@ -21,13 +21,14 @@ enum {
|
||||
type_kind_int,
|
||||
type_kind_char,
|
||||
|
||||
type_kind_count,
|
||||
|
||||
type_kind_pointer,
|
||||
type_kind_array,
|
||||
type_kind_struct,
|
||||
type_kind_union,
|
||||
type_kind_enum,
|
||||
|
||||
type_kind_first_basic = type_kind_i8,
|
||||
type_kind_last_basic = type_kind_char,
|
||||
};
|
||||
|
||||
typedef struct type_member_t type_member_t;
|
||||
|
||||
Reference in New Issue
Block a user