minor cleanup & logs
This commit is contained in:
parent
ecbc0c8501
commit
9ebb75f6c3
@ -155,7 +155,7 @@ void app_entry_point(void)
|
|||||||
{
|
{
|
||||||
struct temp_arena scratch = scratch_begin_no_conflict();
|
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));
|
struct string settings_path = app_write_path_cat(scratch.arena, STR(SETTINGS_FILENAME));
|
||||||
logf_info("Looking for settings file \"%F\"", FMT_STR(settings_path));
|
logf_info("Looking for settings file \"%F\"", FMT_STR(settings_path));
|
||||||
if (sys_is_file(settings_path)) {
|
if (sys_is_file(settings_path)) {
|
||||||
@ -179,10 +179,12 @@ void app_entry_point(void)
|
|||||||
FMT_STR(settings_path),
|
FMT_STR(settings_path),
|
||||||
FMT_STR(error));
|
FMT_STR(error));
|
||||||
sys_panic(msg);
|
sys_panic(msg);
|
||||||
} else {
|
}
|
||||||
logf_info("Settings file loaded successfully");
|
logf_info("Settings file loaded successfully");
|
||||||
window_settings = *res;
|
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));
|
string_copy_buff(BUFFER_FROM_ARRAY(window_settings.title), STR(WINDOW_TITLE));
|
||||||
sys_window_update_settings(&window, &window_settings);
|
sys_window_update_settings(&window, &window_settings);
|
||||||
|
|||||||
@ -229,6 +229,5 @@ u64 br_read_var_uint(struct byte_reader *br)
|
|||||||
i64 br_read_var_sint(struct byte_reader *br)
|
i64 br_read_var_sint(struct byte_reader *br)
|
||||||
{
|
{
|
||||||
/* TODO: real varint read */
|
/* TODO: real varint read */
|
||||||
|
|
||||||
return br_read_i64(br);
|
return br_read_i64(br);
|
||||||
}
|
}
|
||||||
|
|||||||
104
src/json.c
104
src/json.c
@ -58,7 +58,7 @@ struct token {
|
|||||||
struct token *next;
|
struct token *next;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct lex_result {
|
struct token_list {
|
||||||
struct token *token_first;
|
struct token *token_first;
|
||||||
struct token *token_last;
|
struct token *token_last;
|
||||||
};
|
};
|
||||||
@ -81,9 +81,9 @@ GLOBAL READONLY enum token_type g_keyword_types[] = {
|
|||||||
['n'] = TOKEN_TYPE_NULL
|
['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;
|
u64 pos = 0;
|
||||||
b32 lexing_done = false;
|
b32 lexing_done = false;
|
||||||
@ -374,10 +374,6 @@ INTERNAL f64 interpret_number(struct string src)
|
|||||||
u64 exponent_left = 0;
|
u64 exponent_left = 0;
|
||||||
u64 exponent_right = 0;
|
u64 exponent_right = 0;
|
||||||
i32 exponent_sign = 1;
|
i32 exponent_sign = 1;
|
||||||
(UNUSED)exponent_present;
|
|
||||||
(UNUSED)exponent_left;
|
|
||||||
(UNUSED)exponent_right;
|
|
||||||
(UNUSED)exponent_sign;
|
|
||||||
|
|
||||||
/* Lex number parts */
|
/* 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)
|
INTERNAL struct string interpret_string(struct arena *arena, struct string src, struct string *error)
|
||||||
{
|
{
|
||||||
(UNUSED)arena;
|
|
||||||
(UNUSED)src;
|
|
||||||
(UNUSED)error;
|
|
||||||
|
|
||||||
struct string res = {
|
struct string res = {
|
||||||
.len = 0,
|
.len = 0,
|
||||||
.text = arena_dry_push(arena, u8)
|
.text = arena_dry_push(arena, u8)
|
||||||
@ -640,8 +632,12 @@ INTERNAL struct string interpret_string(struct arena *arena, struct string src,
|
|||||||
* ========================== */
|
* ========================== */
|
||||||
|
|
||||||
struct parser {
|
struct parser {
|
||||||
|
/* Input */
|
||||||
struct string src;
|
struct string src;
|
||||||
struct token *t;
|
struct token *at;
|
||||||
|
|
||||||
|
/* Output */
|
||||||
|
struct json *root;
|
||||||
struct json_error_list errors;
|
struct json_error_list errors;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -663,15 +659,16 @@ INTERNAL void push_error(struct arena *arena, struct parser *p, struct token *t,
|
|||||||
++list->count;
|
++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 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 string src = p->src;
|
||||||
struct json *res = arena_push_zero(arena, struct json);
|
|
||||||
|
|
||||||
/* Depth first stack */
|
/* Depth first stack */
|
||||||
*arena_push(scratch.arena, struct json *) = res;
|
*arena_push(scratch.arena, struct json *) = root;
|
||||||
u64 stack_count = 1;
|
u64 stack_count = 1;
|
||||||
|
|
||||||
while (stack_count > 0) {
|
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) {
|
if (json->type == JSON_TYPE_OBJECT || json->type == JSON_TYPE_ARRAY) {
|
||||||
/* No more children to parse for object/array, check for closing brace. */
|
/* 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;
|
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) {
|
if (at->type == tok_close_type) {
|
||||||
p->t = p->t->next;
|
at = at->next;
|
||||||
} else {
|
} else {
|
||||||
push_error(arena, p, p->t, STR("Expected comma."));
|
push_error(arena, p, at, STR("Expected comma."));
|
||||||
p->t = p->t->next;
|
at = at->next;
|
||||||
goto abort;
|
goto abort;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (parent_json) {
|
if (parent_json) {
|
||||||
if (parent_json->type == JSON_TYPE_OBJECT) {
|
if (parent_json->type == JSON_TYPE_OBJECT) {
|
||||||
/* Parse key */
|
/* Parse key */
|
||||||
if (p->t->type == TOKEN_TYPE_STRING) {
|
if (at->type == 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 error = { 0 };
|
||||||
struct string key = interpret_string(arena, t_text, &error);
|
struct string key = interpret_string(arena, t_text, &error);
|
||||||
if (error.len > 0) {
|
if (error.len > 0) {
|
||||||
push_error(arena, p, p->t, error);
|
push_error(arena, p, at, error);
|
||||||
goto abort;
|
goto abort;
|
||||||
} else {
|
} else {
|
||||||
json->key = key;
|
json->key = key;
|
||||||
p->t = p->t->next;
|
at = at->next;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
push_error(arena, p, p->t, STR("Key expected."));
|
push_error(arena, p, at, STR("Key expected."));
|
||||||
goto abort;
|
goto abort;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Parse colon */
|
/* Parse colon */
|
||||||
if (p->t->type == TOKEN_TYPE_COLON) {
|
if (at->type == TOKEN_TYPE_COLON) {
|
||||||
p->t = p->t->next;
|
at = at->next;
|
||||||
} else {
|
} else {
|
||||||
push_error(arena, p, p->t, STR("Colon expected."));
|
push_error(arena, p, at, STR("Colon expected."));
|
||||||
goto abort;
|
goto abort;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -729,61 +726,61 @@ INTERNAL struct json *parse(struct arena *arena, struct parser *p)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Parse value */
|
/* Parse value */
|
||||||
switch (p->t->type) {
|
switch (at->type) {
|
||||||
case TOKEN_TYPE_NUMBER: {
|
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);
|
f64 value = interpret_number(t_text);
|
||||||
json->type = JSON_TYPE_NUMBER;
|
json->type = JSON_TYPE_NUMBER;
|
||||||
json->value.number = value;
|
json->value.number = value;
|
||||||
p->t = p->t->next;
|
at = at->next;
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case TOKEN_TYPE_STRING: {
|
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 error = { 0 };
|
||||||
struct string value = interpret_string(arena, t_text, &error);
|
struct string value = interpret_string(arena, t_text, &error);
|
||||||
if (error.len > 0) {
|
if (error.len > 0) {
|
||||||
push_error(arena, p, p->t, error);
|
push_error(arena, p, at, error);
|
||||||
goto abort;
|
goto abort;
|
||||||
} else {
|
} else {
|
||||||
json->type = JSON_TYPE_STRING;
|
json->type = JSON_TYPE_STRING;
|
||||||
json->value.string = value;
|
json->value.string = value;
|
||||||
p->t = p->t->next;
|
at = at->next;
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case TOKEN_TYPE_TRUE: {
|
case TOKEN_TYPE_TRUE: {
|
||||||
json->type = JSON_TYPE_BOOL;
|
json->type = JSON_TYPE_BOOL;
|
||||||
json->value.boolean = true;
|
json->value.boolean = true;
|
||||||
p->t = p->t->next;
|
at = at->next;
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case TOKEN_TYPE_FALSE: {
|
case TOKEN_TYPE_FALSE: {
|
||||||
json->type = JSON_TYPE_BOOL;
|
json->type = JSON_TYPE_BOOL;
|
||||||
json->value.boolean = false;
|
json->value.boolean = false;
|
||||||
p->t = p->t->next;
|
at = at->next;
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case TOKEN_TYPE_NULL: {
|
case TOKEN_TYPE_NULL: {
|
||||||
json->type = JSON_TYPE_NULL;
|
json->type = JSON_TYPE_NULL;
|
||||||
p->t = p->t->next;
|
at = at->next;
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case TOKEN_TYPE_CURLY_BRACE_OPEN: {
|
case TOKEN_TYPE_CURLY_BRACE_OPEN: {
|
||||||
json->type = JSON_TYPE_OBJECT;
|
json->type = JSON_TYPE_OBJECT;
|
||||||
p->t = p->t->next;
|
at = at->next;
|
||||||
is_new_parent = true;
|
is_new_parent = true;
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case TOKEN_TYPE_SQUARE_BRACE_OPEN: {
|
case TOKEN_TYPE_SQUARE_BRACE_OPEN: {
|
||||||
json->type = JSON_TYPE_ARRAY;
|
json->type = JSON_TYPE_ARRAY;
|
||||||
p->t = p->t->next;
|
at = at->next;
|
||||||
is_new_parent = true;
|
is_new_parent = true;
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
default: {
|
default: {
|
||||||
push_error(arena, p, p->t, STR("Value expected."));
|
push_error(arena, p, at, STR("Value expected."));
|
||||||
p->t = p->t->next;
|
at = at->next;
|
||||||
goto abort;
|
goto abort;
|
||||||
} break;
|
} break;
|
||||||
}
|
}
|
||||||
@ -801,20 +798,21 @@ INTERNAL struct json *parse(struct arena *arena, struct parser *p)
|
|||||||
++stack_count;
|
++stack_count;
|
||||||
} else if (parent_json) {
|
} else if (parent_json) {
|
||||||
/* Check for comma */
|
/* Check for comma */
|
||||||
if (p->t->type == TOKEN_TYPE_COMMA) {
|
if (at->type == TOKEN_TYPE_COMMA) {
|
||||||
/* Create sibling & push to stack */
|
/* Create sibling & push to stack */
|
||||||
struct json *sibling = arena_push(arena, struct json);
|
struct json *sibling = arena_push(arena, struct json);
|
||||||
sibling->parent = parent_json;
|
sibling->parent = parent_json;
|
||||||
*arena_push(scratch.arena, struct json *) = sibling;
|
*arena_push(scratch.arena, struct json *) = sibling;
|
||||||
++stack_count;
|
++stack_count;
|
||||||
p->t = p->t->next;
|
at = at->next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
abort:
|
abort:
|
||||||
scratch_end(scratch);
|
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 json_parse_result json_from_string(struct arena *arena, struct string src)
|
||||||
{
|
{
|
||||||
struct temp_arena scratch = scratch_begin(arena);
|
struct temp_arena scratch = scratch_begin(arena);
|
||||||
struct lex_result lex_res = lex(scratch.arena, src);
|
|
||||||
struct parser p = {
|
struct token_list tl = lex(scratch.arena, src);
|
||||||
.src = src,
|
|
||||||
.t = lex_res.token_first,
|
|
||||||
.errors = { 0 }
|
|
||||||
};
|
|
||||||
|
|
||||||
/* Parse root */
|
/* Parse root */
|
||||||
struct json *root = parse(arena, &p);
|
struct parser p = {
|
||||||
|
.src = src,
|
||||||
|
.at = tl.token_first
|
||||||
|
};
|
||||||
|
parse(arena, &p);
|
||||||
|
|
||||||
/* Verify end of file */
|
/* Verify end of file */
|
||||||
if (p.errors.count == 0 && p.t->type != TOKEN_TYPE_EOF) {
|
if (p.errors.count == 0 && p.at->type != TOKEN_TYPE_EOF) {
|
||||||
push_error(arena, &p, p.t, STR("Expected end of file."));
|
push_error(arena, &p, p.at, STR("Expected end of file."));
|
||||||
}
|
}
|
||||||
|
|
||||||
scratch_end(scratch);
|
scratch_end(scratch);
|
||||||
|
|
||||||
return (struct json_parse_result) {
|
return (struct json_parse_result) {
|
||||||
.root = root,
|
.root = p.root,
|
||||||
.errors = p.errors
|
.errors = p.errors
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1471,7 +1471,7 @@ INTERNAL DWORD WINAPI win32_thread_proc(LPVOID params)
|
|||||||
scratch_end(scratch);
|
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 */
|
/* Start thread */
|
||||||
thread_params.thread_func(thread_params.thread_data);
|
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);
|
ASSERT(thread_func != NULL);
|
||||||
|
|
||||||
|
logf_info("Creating thread \"%F\"", FMT_STR(thread_name));
|
||||||
|
|
||||||
/* Create thread params */
|
/* Create thread params */
|
||||||
struct win32_thread_params *tp = thread_params_alloc();
|
struct win32_thread_params *tp = thread_params_alloc();
|
||||||
tp->thread_func = thread_func;
|
tp->thread_func = thread_func;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user