//////////////////////////////////////////////////////////// //~ Error types Struct(M_Error) { M_Error *next; String msg; struct M_Token *token; }; Struct(M_ErrorList) { M_Error *first; M_Error *last; u64 count; }; //////////////////////////////////////////////////////////// //~ File types Struct(M_File) { String name; String data; }; //////////////////////////////////////////////////////////// //~ Token types Enum(M_TokenKind) { M_TokenKind_Ident, M_TokenKind_Eol, // End of line }; Struct(M_Token) { b32 valid; M_Token *next; M_TokenKind kind; struct M_TokenFile *file; String s; }; Struct(M_TokenFile) { b32 valid; M_TokenFile *next; String name; String data; M_Token *first_token; M_Token *last_token; u64 tokens_count; M_ErrorList errors; }; Struct(M_TokenFileList) { M_TokenFile *first; M_TokenFile *last; u64 count; }; //////////////////////////////////////////////////////////// //~ Entry types Enum(M_EntryKind) { M_EntryKind_Unknown, M_EntryKind_Layer, M_EntryKind_Dep, M_EntryKind_IncludeC, M_EntryKind_IncludeG, M_EntryKind_DefaultDownstream, M_EntryKind_Bootstrap, M_EntryKind_VertexShader, M_EntryKind_PixelShader, M_EntryKind_ComputeShader, M_EntryKind_EmbedDir, }; Enum(M_PlatformKind) { M_PlatformKind_Any, M_PlatformKind_Win32, }; Global Readonly char *M_entry_kind_rules[] = { [M_EntryKind_Layer] = "@Layer", [M_EntryKind_Dep] = "@Dep", [M_EntryKind_IncludeC] = "@IncludeC", [M_EntryKind_IncludeG] = "@IncludeG", [M_EntryKind_DefaultDownstream] = "@DefaultDownstream", [M_EntryKind_Bootstrap] = "@Bootstrap", [M_EntryKind_VertexShader] = "@VertexShader", [M_EntryKind_PixelShader] = "@PixelShader", [M_EntryKind_ComputeShader] = "@ComputeShader", [M_EntryKind_EmbedDir] = "@EmbedDir", }; Struct(M_Entry) { b32 valid; M_Entry *next; M_EntryKind kind; M_Token *name_token; M_Token *arg_tokens[2]; u64 args_count; }; Struct(M_Layer) { b32 valid; M_Layer *next; M_TokenFile *file; M_Entry *first; M_Entry *last; u64 count; M_ErrorList errors; }; Struct(M_LayerList) { M_Layer *first; M_Layer *last; u64 count; }; //////////////////////////////////////////////////////////// //~ State types extern Readonly M_Token M_NilToken; extern Readonly M_TokenFile M_NilTokenFile; extern Readonly M_Entry M_NilEntry; extern Readonly M_Layer M_NilLayer; //////////////////////////////////////////////////////////// //~ Error helpers M_Error *M_PushError(Arena *arena, M_ErrorList *l, M_Token *token, String msg); void M_AppendErrors(Arena *arena, M_ErrorList *dst, M_ErrorList src); //////////////////////////////////////////////////////////// //~ Lex M_Token *M_PushToken(Arena *arena, M_TokenFile *file, String s, M_TokenKind kind); M_TokenFileList M_TokensFromSrcDirs(Arena *arena, StringList src_dirs); //////////////////////////////////////////////////////////// //~ Parse M_Layer *M_PushLayer(Arena *arena, M_LayerList *list, M_TokenFile *file); M_Entry *M_PushEntry(Arena *arena, M_Layer *l, M_EntryKind kind, M_Token *entry_token, u64 args_count, M_Token **args); M_LayerList M_LayersFromTokenFiles(Arena *arena, M_TokenFileList token_files); //////////////////////////////////////////////////////////// //~ Flatten M_Layer M_FlattenEntries(Arena *arena, M_LayerList unflattened, StringList starting_layer_names);