minor cleanup & logs

This commit is contained in:
jacob 2024-04-01 15:38:31 -05:00
parent ecbc0c8501
commit 9ebb75f6c3
4 changed files with 60 additions and 59 deletions

View File

@ -155,7 +155,7 @@ void app_entry_point(void)
{
struct temp_arena scratch = scratch_begin_no_conflict();
struct sys_window_settings window_settings = default_window_settings(&window);
struct sys_window_settings window_settings = { 0 };
struct string settings_path = app_write_path_cat(scratch.arena, STR(SETTINGS_FILENAME));
logf_info("Looking for settings file \"%F\"", FMT_STR(settings_path));
if (sys_is_file(settings_path)) {
@ -179,10 +179,12 @@ void app_entry_point(void)
FMT_STR(settings_path),
FMT_STR(error));
sys_panic(msg);
} else {
}
logf_info("Settings file loaded successfully");
window_settings = *res;
}
} else {
logf_info("Settings file not found, loading default");
window_settings = default_window_settings(&window);
}
string_copy_buff(BUFFER_FROM_ARRAY(window_settings.title), STR(WINDOW_TITLE));
sys_window_update_settings(&window, &window_settings);

View File

@ -229,6 +229,5 @@ u64 br_read_var_uint(struct byte_reader *br)
i64 br_read_var_sint(struct byte_reader *br)
{
/* TODO: real varint read */
return br_read_i64(br);
}

View File

@ -58,7 +58,7 @@ struct token {
struct token *next;
};
struct lex_result {
struct token_list {
struct token *token_first;
struct token *token_last;
};
@ -81,9 +81,9 @@ GLOBAL READONLY enum token_type g_keyword_types[] = {
['n'] = TOKEN_TYPE_NULL
};
INTERNAL struct lex_result lex(struct arena *arena, struct string src)
INTERNAL struct token_list lex(struct arena *arena, struct string src)
{
struct lex_result res = { 0 };
struct token_list res = { 0 };
u64 pos = 0;
b32 lexing_done = false;
@ -374,10 +374,6 @@ INTERNAL f64 interpret_number(struct string src)
u64 exponent_left = 0;
u64 exponent_right = 0;
i32 exponent_sign = 1;
(UNUSED)exponent_present;
(UNUSED)exponent_left;
(UNUSED)exponent_right;
(UNUSED)exponent_sign;
/* Lex number parts */
{
@ -527,10 +523,6 @@ INTERNAL f64 interpret_number(struct string src)
INTERNAL struct string interpret_string(struct arena *arena, struct string src, struct string *error)
{
(UNUSED)arena;
(UNUSED)src;
(UNUSED)error;
struct string res = {
.len = 0,
.text = arena_dry_push(arena, u8)
@ -640,8 +632,12 @@ INTERNAL struct string interpret_string(struct arena *arena, struct string src,
* ========================== */
struct parser {
/* Input */
struct string src;
struct token *t;
struct token *at;
/* Output */
struct json *root;
struct json_error_list errors;
};
@ -663,15 +659,16 @@ INTERNAL void push_error(struct arena *arena, struct parser *p, struct token *t,
++list->count;
}
INTERNAL struct json *parse(struct arena *arena, struct parser *p)
INTERNAL void parse(struct arena *arena, struct parser *p)
{
struct temp_arena scratch = scratch_begin(arena);
struct json *root = arena_push_zero(arena, struct json);
struct token *at = p->at;
struct string src = p->src;
struct json *res = arena_push_zero(arena, struct json);
/* Depth first stack */
*arena_push(scratch.arena, struct json *) = res;
*arena_push(scratch.arena, struct json *) = root;
u64 stack_count = 1;
while (stack_count > 0) {
@ -684,38 +681,38 @@ INTERNAL struct json *parse(struct arena *arena, struct parser *p)
if (json->type == JSON_TYPE_OBJECT || json->type == JSON_TYPE_ARRAY) {
/* No more children to parse for object/array, check for closing brace. */
enum token_type tok_close_type = json->type == JSON_TYPE_OBJECT ? TOKEN_TYPE_CURLY_BRACE_CLOSE : TOKEN_TYPE_SQUARE_BRACE_CLOSE;
if (p->t->type == tok_close_type) {
p->t = p->t->next;
if (at->type == tok_close_type) {
at = at->next;
} else {
push_error(arena, p, p->t, STR("Expected comma."));
p->t = p->t->next;
push_error(arena, p, at, STR("Expected comma."));
at = at->next;
goto abort;
}
} else {
if (parent_json) {
if (parent_json->type == JSON_TYPE_OBJECT) {
/* Parse key */
if (p->t->type == TOKEN_TYPE_STRING) {
struct string t_text = (struct string) { .len = p->t->end - p->t->start, .text = &src.text[p->t->start] };
if (at->type == TOKEN_TYPE_STRING) {
struct string t_text = (struct string) { .len = at->end - at->start, .text = &src.text[at->start] };
struct string error = { 0 };
struct string key = interpret_string(arena, t_text, &error);
if (error.len > 0) {
push_error(arena, p, p->t, error);
push_error(arena, p, at, error);
goto abort;
} else {
json->key = key;
p->t = p->t->next;
at = at->next;
}
} else {
push_error(arena, p, p->t, STR("Key expected."));
push_error(arena, p, at, STR("Key expected."));
goto abort;
}
/* Parse colon */
if (p->t->type == TOKEN_TYPE_COLON) {
p->t = p->t->next;
if (at->type == TOKEN_TYPE_COLON) {
at = at->next;
} else {
push_error(arena, p, p->t, STR("Colon expected."));
push_error(arena, p, at, STR("Colon expected."));
goto abort;
}
}
@ -729,61 +726,61 @@ INTERNAL struct json *parse(struct arena *arena, struct parser *p)
}
/* Parse value */
switch (p->t->type) {
switch (at->type) {
case TOKEN_TYPE_NUMBER: {
struct string t_text = (struct string) { .len = p->t->end - p->t->start, .text = &src.text[p->t->start] };
struct string t_text = (struct string) { .len = at->end - at->start, .text = &src.text[at->start] };
f64 value = interpret_number(t_text);
json->type = JSON_TYPE_NUMBER;
json->value.number = value;
p->t = p->t->next;
at = at->next;
} break;
case TOKEN_TYPE_STRING: {
struct string t_text = (struct string) { .len = p->t->end - p->t->start, .text = &src.text[p->t->start] };
struct string t_text = (struct string) { .len = at->end - at->start, .text = &src.text[at->start] };
struct string error = { 0 };
struct string value = interpret_string(arena, t_text, &error);
if (error.len > 0) {
push_error(arena, p, p->t, error);
push_error(arena, p, at, error);
goto abort;
} else {
json->type = JSON_TYPE_STRING;
json->value.string = value;
p->t = p->t->next;
at = at->next;
}
} break;
case TOKEN_TYPE_TRUE: {
json->type = JSON_TYPE_BOOL;
json->value.boolean = true;
p->t = p->t->next;
at = at->next;
} break;
case TOKEN_TYPE_FALSE: {
json->type = JSON_TYPE_BOOL;
json->value.boolean = false;
p->t = p->t->next;
at = at->next;
} break;
case TOKEN_TYPE_NULL: {
json->type = JSON_TYPE_NULL;
p->t = p->t->next;
at = at->next;
} break;
case TOKEN_TYPE_CURLY_BRACE_OPEN: {
json->type = JSON_TYPE_OBJECT;
p->t = p->t->next;
at = at->next;
is_new_parent = true;
} break;
case TOKEN_TYPE_SQUARE_BRACE_OPEN: {
json->type = JSON_TYPE_ARRAY;
p->t = p->t->next;
at = at->next;
is_new_parent = true;
} break;
default: {
push_error(arena, p, p->t, STR("Value expected."));
p->t = p->t->next;
push_error(arena, p, at, STR("Value expected."));
at = at->next;
goto abort;
} break;
}
@ -801,20 +798,21 @@ INTERNAL struct json *parse(struct arena *arena, struct parser *p)
++stack_count;
} else if (parent_json) {
/* Check for comma */
if (p->t->type == TOKEN_TYPE_COMMA) {
if (at->type == TOKEN_TYPE_COMMA) {
/* Create sibling & push to stack */
struct json *sibling = arena_push(arena, struct json);
sibling->parent = parent_json;
*arena_push(scratch.arena, struct json *) = sibling;
++stack_count;
p->t = p->t->next;
at = at->next;
}
}
}
abort:
scratch_end(scratch);
return res;
p->at = at;
p->root = root;
}
/* ========================== *
@ -824,25 +822,25 @@ abort:
struct json_parse_result json_from_string(struct arena *arena, struct string src)
{
struct temp_arena scratch = scratch_begin(arena);
struct lex_result lex_res = lex(scratch.arena, src);
struct parser p = {
.src = src,
.t = lex_res.token_first,
.errors = { 0 }
};
struct token_list tl = lex(scratch.arena, src);
/* Parse root */
struct json *root = parse(arena, &p);
struct parser p = {
.src = src,
.at = tl.token_first
};
parse(arena, &p);
/* Verify end of file */
if (p.errors.count == 0 && p.t->type != TOKEN_TYPE_EOF) {
push_error(arena, &p, p.t, STR("Expected end of file."));
if (p.errors.count == 0 && p.at->type != TOKEN_TYPE_EOF) {
push_error(arena, &p, p.at, STR("Expected end of file."));
}
scratch_end(scratch);
return (struct json_parse_result) {
.root = root,
.root = p.root,
.errors = p.errors
};
}

View File

@ -1471,7 +1471,7 @@ INTERNAL DWORD WINAPI win32_thread_proc(LPVOID params)
scratch_end(scratch);
}
logf_info("New thread \"%F\" with ID %F", FMT_STR(thread_name), FMT_UINT(sys_thread_id()));
logf_info("New thread \"%F\" created with ID %F", FMT_STR(thread_name), FMT_UINT(sys_thread_id()));
/* Start thread */
thread_params.thread_func(thread_params.thread_data);
@ -1491,6 +1491,8 @@ struct sys_thread sys_thread_init(sys_thread_func *thread_func, void *thread_dat
ASSERT(thread_func != NULL);
logf_info("Creating thread \"%F\"", FMT_STR(thread_name));
/* Create thread params */
struct win32_thread_params *tp = thread_params_alloc();
tp->thread_func = thread_func;