json layer refactor
This commit is contained in:
parent
ca07cde1a9
commit
9e353dd1c9
@ -409,7 +409,7 @@ void gp_startup(void)
|
||||
G.fenced_releases_arena = AllocArena(Gibi(64));
|
||||
|
||||
/* Initialize embedded shader archive */
|
||||
String embedded_data = inc_dxc_tar();
|
||||
String embedded_data = INC_GetDxcTar();
|
||||
if (embedded_data.len <= 0) {
|
||||
P_Panic(Lit("No embedded shaders found"));
|
||||
}
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
|
||||
#if RESOURCES_EMBEDDED
|
||||
IncbinInclude(res_tar, IncbinDir "res.tar");
|
||||
String inc_res_tar(void)
|
||||
String INC_GetResTar(void)
|
||||
{
|
||||
return IncbinGet(res_tar);
|
||||
}
|
||||
@ -13,7 +13,7 @@ String inc_res_tar(void)
|
||||
|
||||
|
||||
IncbinInclude(dxc_tar, IncbinDir "dxc.tar");
|
||||
String inc_dxc_tar(void)
|
||||
String INC_GetDxcTar(void)
|
||||
{
|
||||
return IncbinGet(dxc_tar);
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
#if RESOURCES_EMBEDDED
|
||||
String inc_res_tar(void);
|
||||
String INC_GetResTar(void);
|
||||
#endif
|
||||
|
||||
String inc_dxc_tar(void);
|
||||
String INC_GetDxcTar(void);
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -1,14 +1,18 @@
|
||||
////////////////////////////////
|
||||
//~ Blob types
|
||||
|
||||
typedef i32 JSON_Type; enum {
|
||||
JSON_TYPE_NULL,
|
||||
JSON_TYPE_BOOL,
|
||||
JSON_TYPE_NUMBER,
|
||||
JSON_TYPE_STRING,
|
||||
JSON_TYPE_ARRAY,
|
||||
JSON_TYPE_OBJECT
|
||||
typedef i32 JSON_Type; enum
|
||||
{
|
||||
JSON_Type_Null,
|
||||
JSON_Type_Bool,
|
||||
JSON_Type_Number,
|
||||
JSON_Type_String,
|
||||
JSON_Type_Array,
|
||||
JSON_Type_Object
|
||||
};
|
||||
|
||||
Struct(JSON_Blob) {
|
||||
Struct(JSON_Blob)
|
||||
{
|
||||
JSON_Type type;
|
||||
String key;
|
||||
|
||||
@ -17,29 +21,139 @@ Struct(JSON_Blob) {
|
||||
JSON_Blob *child_first;
|
||||
JSON_Blob *child_last;
|
||||
|
||||
union {
|
||||
union
|
||||
{
|
||||
String string;
|
||||
f64 number;
|
||||
b32 boolean;
|
||||
} value;
|
||||
};
|
||||
|
||||
Struct(JSON_Error) {
|
||||
Struct(JSON_Error)
|
||||
{
|
||||
String msg;
|
||||
u64 start;
|
||||
u64 end;
|
||||
JSON_Error *next;
|
||||
};
|
||||
|
||||
Struct(JSON_ErrorList) {
|
||||
Struct(JSON_ErrorList)
|
||||
{
|
||||
u64 count;
|
||||
JSON_Error *first;
|
||||
JSON_Error *last;
|
||||
};
|
||||
|
||||
Struct(JSON_Result) {
|
||||
Struct(JSON_Result)
|
||||
{
|
||||
JSON_Blob *root;
|
||||
JSON_ErrorList errors;
|
||||
};
|
||||
|
||||
JSON_Result json_from_string(Arena *arena, String src);
|
||||
////////////////////////////////
|
||||
//~ Lexer types
|
||||
|
||||
#define JSON_Case_Newline \
|
||||
case 0x0A: /* Line feed or New line */ \
|
||||
case 0x0D /* Carriage return */
|
||||
|
||||
#define JSON_Case_Space \
|
||||
case 0x20: /* Space */ \
|
||||
case 0x09 /* Horizontal tab */
|
||||
|
||||
#define JSON_Case_Digit0Through9 \
|
||||
case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9'
|
||||
|
||||
#define JSON_Case_Digit1Through9 \
|
||||
case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9'
|
||||
|
||||
#define JSON_Case_Symbol \
|
||||
case ',': case ':': case '[': case ']': case '{': case '}'
|
||||
|
||||
typedef i32 JSON_TokenKind; enum
|
||||
{
|
||||
JSON_TokenKind_Unknown,
|
||||
|
||||
JSON_TokenKind_Number,
|
||||
JSON_TokenKind_String,
|
||||
|
||||
JSON_TokenKind_KeywordTrue,
|
||||
JSON_TokenKind_KeywordFalse,
|
||||
JSON_TokenKind_KeywordNull,
|
||||
|
||||
JSON_TokenKind_Comma,
|
||||
JSON_TokenKind_Colon,
|
||||
JSON_TokenKind_SquareBraceOpen,
|
||||
JSON_TokenKind_SquareBraceClose,
|
||||
JSON_TokenKind_CurlyBraceOpen,
|
||||
JSON_TokenKind_CurlyBraceClose,
|
||||
|
||||
JSON_TokenKind_Bof,
|
||||
JSON_TokenKind_Eof
|
||||
};
|
||||
|
||||
Struct(JSON_Token)
|
||||
{
|
||||
JSON_TokenKind kind;
|
||||
u64 start;
|
||||
u64 end;
|
||||
JSON_Token *next;
|
||||
};
|
||||
|
||||
Struct(JSON_TokenList)
|
||||
{
|
||||
JSON_Token *token_first;
|
||||
JSON_Token *token_last;
|
||||
};
|
||||
|
||||
typedef i32 JSON_LexNumberState; enum
|
||||
{
|
||||
JSON_LexNumberState_Whole,
|
||||
JSON_LexNumberState_Fraction,
|
||||
JSON_LexNumberState_Exponent
|
||||
};
|
||||
|
||||
Global Readonly String JSON_keyword_strings[] = {
|
||||
['t'] = LitNoCast("true"),
|
||||
['f'] = LitNoCast("false"),
|
||||
['n'] = LitNoCast("null")
|
||||
};
|
||||
|
||||
Global Readonly JSON_TokenKind JSON_keyword_types[] = {
|
||||
['t'] = JSON_TokenKind_KeywordTrue,
|
||||
['f'] = JSON_TokenKind_KeywordFalse,
|
||||
['n'] = JSON_TokenKind_KeywordNull
|
||||
};
|
||||
|
||||
////////////////////////////////
|
||||
//~ Parser types
|
||||
|
||||
Struct(JSON_Parser)
|
||||
{
|
||||
/* Input */
|
||||
String src;
|
||||
JSON_Token *at;
|
||||
|
||||
/* Output */
|
||||
JSON_Blob *root;
|
||||
JSON_ErrorList errors;
|
||||
};
|
||||
|
||||
////////////////////////////////
|
||||
//~ Lex
|
||||
|
||||
JSON_Token *JSON_PushToken(Arena *arena, JSON_TokenList *list);
|
||||
JSON_TokenList JSON_TokensFromString(Arena *arena, String src);
|
||||
|
||||
////////////////////////////////
|
||||
//~ Interpret
|
||||
|
||||
f64 interpret_number(String src);
|
||||
String interpret_string(Arena *arena, String src, String *error);
|
||||
|
||||
////////////////////////////////
|
||||
//~ Parse
|
||||
|
||||
void JSON_PushError(Arena *arena, JSON_Parser *p, JSON_Token *t, String msg);
|
||||
void JSON_Parse(Arena *arena, JSON_Parser *p);
|
||||
JSON_Result JSON_BlobFromString(Arena *arena, String src);
|
||||
|
||||
@ -3,38 +3,6 @@
|
||||
|
||||
P_SharedLogCtx P_shared_log_ctx = ZI;
|
||||
|
||||
Readonly P_LogLevelSettings P_log_settings[P_LogLevel_Count] = {
|
||||
[P_LogLevel_Critical] = {
|
||||
LitNoCast("CRITICAL"),
|
||||
ColorPurple
|
||||
},
|
||||
|
||||
[P_LogLevel_Error] = {
|
||||
LitNoCast("ERROR"),
|
||||
ColorRed
|
||||
},
|
||||
|
||||
[P_LogLevel_Warning] = {
|
||||
LitNoCast("WARNING"),
|
||||
ColorYellow
|
||||
},
|
||||
|
||||
[P_LogLevel_Success] = {
|
||||
LitNoCast("SUCCESS"),
|
||||
ColorGreen
|
||||
},
|
||||
|
||||
[P_LogLevel_Info] = {
|
||||
LitNoCast("INFO"),
|
||||
ColorWhite
|
||||
},
|
||||
|
||||
[P_LogLevel_Debug] = {
|
||||
LitNoCast("DEBUG"),
|
||||
ColorBlue
|
||||
}
|
||||
};
|
||||
|
||||
////////////////////////////////
|
||||
//~ Startup
|
||||
|
||||
|
||||
@ -81,7 +81,38 @@ Struct(P_LogLevelSettings)
|
||||
u32 color;
|
||||
};
|
||||
|
||||
extern Readonly P_LogLevelSettings P_log_settings[P_LogLevel_Count];
|
||||
Global Readonly P_LogLevelSettings P_log_settings[P_LogLevel_Count] = {
|
||||
[P_LogLevel_Critical] = {
|
||||
LitNoCast("CRITICAL"),
|
||||
ColorPurple
|
||||
},
|
||||
|
||||
[P_LogLevel_Error] = {
|
||||
LitNoCast("ERROR"),
|
||||
ColorRed
|
||||
},
|
||||
|
||||
[P_LogLevel_Warning] = {
|
||||
LitNoCast("WARNING"),
|
||||
ColorYellow
|
||||
},
|
||||
|
||||
[P_LogLevel_Success] = {
|
||||
LitNoCast("SUCCESS"),
|
||||
ColorGreen
|
||||
},
|
||||
|
||||
[P_LogLevel_Info] = {
|
||||
LitNoCast("INFO"),
|
||||
ColorWhite
|
||||
},
|
||||
|
||||
[P_LogLevel_Debug] = {
|
||||
LitNoCast("DEBUG"),
|
||||
ColorBlue
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
////////////////////////////////
|
||||
//~ Startup
|
||||
|
||||
@ -22,7 +22,7 @@ R_StartupReceipt resource_startup(void)
|
||||
G.arena = AllocArena(Gibi(64));
|
||||
|
||||
#if RESOURCES_EMBEDDED
|
||||
String embedded_data = inc_res_tar();
|
||||
String embedded_data = INC_GetResTar();
|
||||
if (embedded_data.len <= 0) {
|
||||
P_Panic(Lit("No embedded resources found"));
|
||||
}
|
||||
|
||||
@ -46,7 +46,7 @@ P_WindowSettings *settings_deserialize(Arena *arena, String src, String *error_o
|
||||
JSON_Error json_error = ZI;
|
||||
|
||||
P_WindowSettings *settings = PushStruct(arena, P_WindowSettings);
|
||||
JSON_Result parse_result = json_from_string(scratch.arena, src);
|
||||
JSON_Result parse_result = JSON_BlobFromString(scratch.arena, src);
|
||||
|
||||
if (parse_result.errors.count > 0) {
|
||||
json_error = *parse_result.errors.first;
|
||||
@ -60,7 +60,7 @@ P_WindowSettings *settings_deserialize(Arena *arena, String src, String *error_o
|
||||
}
|
||||
|
||||
JSON_Blob *window = root->child_first;
|
||||
if (!window || window->type != JSON_TYPE_OBJECT || !EqString(window->key, Lit("window"))) {
|
||||
if (!window || window->type != JSON_Type_Object || !EqString(window->key, Lit("window"))) {
|
||||
error = Lit("\"window\" object not found");
|
||||
goto abort;
|
||||
}
|
||||
@ -75,7 +75,7 @@ P_WindowSettings *settings_deserialize(Arena *arena, String src, String *error_o
|
||||
String key = child->key;
|
||||
|
||||
if (EqString(key, Lit("maximized"))) {
|
||||
if (child->type != JSON_TYPE_BOOL) {
|
||||
if (child->type != JSON_Type_Bool) {
|
||||
error = Lit("Expected boolean for \"maximized\"");
|
||||
goto abort;
|
||||
}
|
||||
@ -84,7 +84,7 @@ P_WindowSettings *settings_deserialize(Arena *arena, String src, String *error_o
|
||||
}
|
||||
found_maximized = 1;
|
||||
} else if (EqString(key, Lit("fullscreen"))) {
|
||||
if (child->type != JSON_TYPE_BOOL) {
|
||||
if (child->type != JSON_Type_Bool) {
|
||||
error = Lit("Expected boolean for \"fulscreen\"");
|
||||
goto abort;
|
||||
}
|
||||
@ -93,28 +93,28 @@ P_WindowSettings *settings_deserialize(Arena *arena, String src, String *error_o
|
||||
}
|
||||
found_fullscreen = 1;
|
||||
} else if (EqString(key, Lit("x"))) {
|
||||
if (child->type != JSON_TYPE_NUMBER) {
|
||||
if (child->type != JSON_Type_Number) {
|
||||
error = Lit("Expected number for \"x\"");
|
||||
goto abort;
|
||||
}
|
||||
settings->floating_x = RoundF32ToI32(child->value.number);
|
||||
found_x = 1;
|
||||
} else if (EqString(key, Lit("y"))) {
|
||||
if (child->type != JSON_TYPE_NUMBER) {
|
||||
if (child->type != JSON_Type_Number) {
|
||||
error = Lit("Expected number for \"y\"");
|
||||
goto abort;
|
||||
}
|
||||
settings->floating_y = RoundF32ToI32(child->value.number);
|
||||
found_y = 1;
|
||||
} else if (EqString(key, Lit("width"))) {
|
||||
if (child->type != JSON_TYPE_NUMBER) {
|
||||
if (child->type != JSON_Type_Number) {
|
||||
error = Lit("Expected number for \"width\"");
|
||||
goto abort;
|
||||
}
|
||||
settings->floating_width = RoundF32ToI32(child->value.number);
|
||||
found_width = 1;
|
||||
} else if (EqString(key, Lit("height"))) {
|
||||
if (child->type != JSON_TYPE_NUMBER) {
|
||||
if (child->type != JSON_Type_Number) {
|
||||
error = Lit("Expected number for \"height\"");
|
||||
goto abort;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user