compressed file reading and parsing into meta_parse

This commit is contained in:
Allen Webster 2016-09-02 19:14:25 -04:00
parent 56b04115b3
commit 59f1731746
7 changed files with 1349 additions and 87 deletions

File diff suppressed because it is too large Load Diff

View File

@ -50,7 +50,7 @@
#define FREE_FILE_LIST_SIG(n) void n(Application_Links *app, File_List list)
#define MEMORY_ALLOCATE_SIG(n) void* n(Application_Links *app, int32_t size)
#define MEMORY_SET_PROTECTION_SIG(n) bool32 n(Application_Links *app, void *ptr, int32_t size, Memory_Protect_Flags flags)
#define MEMORY_FREE_SIG(n) void n(Application_Links *app, void *mem, int32_t size)
#define MEMORY_FREE_SIG(n) void n(Application_Links *app, void *ptr, int32_t size)
#define FILE_EXISTS_SIG(n) bool32 n(Application_Links *app, char *filename, int32_t len)
#define DIRECTORY_CD_SIG(n) bool32 n(Application_Links *app, char *dir, int32_t *len, int32_t capacity, char *rel_path, int32_t rel_len)
#define GET_4ED_PATH_SIG(n) bool32 n(Application_Links *app, char *out, int32_t capacity)

View File

@ -1,5 +1,8 @@
#define ENUM(type,name) typedef type name; enum name##_
#define FLAGENUM(name) typedef uint32_t name; enum name##_
/* DOC(bool32 is an alias name to signal that an integer parameter or field is for
true/false vales.) */
typedef int32_t bool32;
@ -20,9 +23,6 @@ typedef int32_t Buffer_ID;
the interval [1,16].) */
typedef int32_t View_ID;
#define ENUM(type,name) typedef type name; enum name##_
#define FLAGENUM(name) typedef uint32_t name; enum name##_
/* DOC(A Key_Modifier acts as an index for specifying modifiers in arrays.) */
ENUM(int32_t, Key_Modifier){
MDFR_SHIFT_INDEX,

View File

@ -387,9 +387,10 @@ typedef struct Item_Set{
Item_Node *items;
} Item_Set;
typedef struct Struct_Set{
Item_Node *structs;
} Struct_Set;
typedef struct Parse{
String code;
Cpp_Token_Stack tokens;
} Parse;
static Item_Node null_item_node = {0};
@ -415,6 +416,15 @@ file_dump(char *filename){
return(result);
}
static Parse
meta_parse(char *filename){
Parse result = {0};
result.code = file_dump(filename);
result.tokens = cpp_make_token_stack(1024);
cpp_lex_file(result.code.str, result.code.size, &result.tokens);
return(result);
}
static String
get_first_line(String source){
String line = {0};
@ -454,9 +464,12 @@ is_comment(String str){
return(result);
}
typedef struct Parse{
Cpp_Token_Stack tokens;
} Parse;
typedef enum Doc_Note_Type{
DOC_PARAM,
DOC_RETURN,
DOC,
DOC_SEE
} Doc_Note_Type;
static int32_t
check_and_fix_docs(String *lexeme){
@ -479,13 +492,6 @@ check_and_fix_docs(String *lexeme){
return(result);
}
typedef enum Doc_Note_Type{
DOC_PARAM,
DOC_RETURN,
DOC,
DOC_SEE
} Doc_Note_Type;
static String
doc_note_string[] = {
make_lit_string("DOC_PARAM"),
@ -1163,7 +1169,7 @@ parse_enum(Partition *part, char *data,
int32_t start_i = i;
for (; i < count; ++i, ++token){
if (token->type == CPP_TOKEN_PARENTHESE_CLOSE){
if (token->type == CPP_TOKEN_BRACE_OPEN){
break;
}
}
@ -1804,24 +1810,15 @@ generate_custom_headers(){
Partition part_ = make_part(mem, size);
Partition *part = &part_;
String string_code = file_dump("internal_4coder_string.cpp");
Cpp_Token_Stack string_tokens = {0};
Parse string_parse = meta_parse("internal_4coder_string.cpp");
int32_t string_function_count = 0;
{
String *code = &string_code;
Cpp_Token_Stack *token_stack = &string_tokens;
char *data = string_parse.code.str;
char *data = code->str;
int32_t size = code->size;
*token_stack = cpp_make_token_stack(1024);
cpp_lex_file(data, size, token_stack);
int32_t count = token_stack->count;
Cpp_Token *tokens = token_stack->tokens;
int32_t count = string_parse.tokens.count;
Cpp_Token *tokens = string_parse.tokens.tokens;
Cpp_Token *token = tokens;
for (int32_t i = 0; i < count; ++i, ++token){
@ -1850,8 +1847,8 @@ generate_custom_headers(){
int32_t string_sig_count = 0;
{
String *code = &string_code;
Cpp_Token_Stack *token_stack = &string_tokens;
String *code = &string_parse.code;
Cpp_Token_Stack *token_stack = &string_parse.tokens;
char *data = code->str;
@ -1904,22 +1901,16 @@ generate_custom_headers(){
// App API parsing
//
String code_data[2];
code_data[0] = file_dump("4ed_api_implementation.cpp");
code_data[1] = file_dump("win32_api_impl.cpp");
Parse parses[2];
parses[0] = meta_parse("4ed_api_implementation.cpp");
parses[1] = meta_parse("win32_api_impl.cpp");
int32_t line_count = 0;
for (int32_t J = 0; J < 2; ++J){
String *code = &code_data[J];
Parse *parse = &parses[J];
char *data = code->str;
int32_t size = code->size;
parse->tokens = cpp_make_token_stack(512);
cpp_lex_file(data, size, &parse->tokens);
char *data = parse->code.str;
int32_t count = parse->tokens.count;
Cpp_Token *tokens = parse->tokens.tokens;
@ -1944,10 +1935,9 @@ generate_custom_headers(){
int32_t sig_count_per_file[2];
for (int32_t J = 0; J < 2; ++J){
String *code = &code_data[J];
Parse *parse = &parses[J];
char *data = code->str;
char *data = parse->code.str;
int32_t count = parse->tokens.count;
Cpp_Token *tokens = parse->tokens.tokens;
@ -2084,14 +2074,14 @@ generate_custom_headers(){
// NOTE(allen): Documentation
{
Item_Set typedef_set = {0};
Struct_Set struct_set = {0};
Item_Set struct_set = {0};
Item_Set flag_set = {0};
Item_Set enum_set = {0};
String type_code[1];
type_code[0] = file_dump("4coder_os_types.h");
Parse type_parse[1];
type_parse[0] = meta_parse("4coder_types.h");
Cpp_Token_Stack types_token_array[1];
int32_t file_count = ArrayCount(type_parse);
int32_t typedef_count = 0;
int32_t struct_count = 0;
@ -2106,16 +2096,11 @@ generate_custom_headers(){
make_lit_string("FLAGENUM"),
};
for (int32_t J = 0; J < 1; ++J){
char *data = type_code[J].str;
int32_t size = type_code[J].size;
for (int32_t J = 0; J < file_count; ++J){
char *data = type_parse[J].code.str;
Cpp_Token_Stack types_tokens = cpp_make_token_stack(512);
cpp_lex_file(data, size, &types_tokens);
types_token_array[J] = types_tokens;
int32_t count = types_tokens.count;
Cpp_Token *tokens = types_tokens.tokens;
int32_t count = type_parse[J].tokens.count;
Cpp_Token *tokens = type_parse[J].tokens.tokens;
Cpp_Token *token = tokens;
for (int32_t i = 0; i < count; ++i, ++token){
@ -2150,7 +2135,7 @@ generate_custom_headers(){
}
if (struct_count > 0){
struct_set.structs = push_array(part, Item_Node, struct_count);
struct_set.items = push_array(part, Item_Node, struct_count);
}
if (enum_count > 0){
@ -2166,10 +2151,9 @@ generate_custom_headers(){
int32_t flag_index = 0;
int32_t enum_index = 0;
for (int32_t J = 0; J < 1; ++J){
char *data = type_code[J].str;
Cpp_Token_Stack types_tokens = types_token_array[J];
for (int32_t J = 0; J < file_count; ++J){
char *data = type_parse[J].code.str;
Cpp_Token_Stack types_tokens = type_parse[J].tokens;
int32_t count = types_tokens.count;
Cpp_Token *tokens = types_tokens.tokens;
@ -2199,7 +2183,7 @@ generate_custom_headers(){
{
if (parse_struct(part, (match_index == 1),
data, tokens, count, &token,
struct_set.structs + struct_index)){
struct_set.items + struct_index)){
++struct_index;
}
i = (int32_t)(token - tokens);
@ -2242,8 +2226,8 @@ generate_custom_headers(){
file = fopen(STRING_H, "wb");
{
String *code = &string_code;
Cpp_Token_Stack *token_stack = &string_tokens;
String *code = &string_parse.code;
Cpp_Token_Stack *token_stack = &string_parse.tokens;
int32_t start = 0;
@ -2705,7 +2689,7 @@ generate_custom_headers(){
}
for (int32_t i = 0; i < struct_count; ++i){
String name = struct_set.structs[i].name;
String name = struct_set.items[i].name;
fprintf(file,
"<li>"
"<a href='#%.*s_doc'>%.*s</a>"
@ -2913,7 +2897,7 @@ generate_custom_headers(){
}
for (int32_t i = 0; i < struct_count; ++i, ++I){
Item_Node *member = &struct_set.structs[i];
Item_Node *member = &struct_set.items[i];
String name = member->name;
fprintf(file,
"<div id='%.*s_doc' style='margin-bottom: 1cm;'>\n"

View File

@ -1,6 +1,6 @@
#define MEMORY_ALLOCATE_SIG(n) void* n(Application_Links *app, int32_t size)
#define MEMORY_SET_PROTECTION_SIG(n) bool32 n(Application_Links *app, void *ptr, int32_t size, Memory_Protect_Flags flags)
#define MEMORY_FREE_SIG(n) void n(Application_Links *app, void *mem, int32_t size)
#define MEMORY_FREE_SIG(n) void n(Application_Links *app, void *ptr, int32_t size)
#define FILE_EXISTS_SIG(n) bool32 n(Application_Links *app, char *filename, int32_t len)
#define DIRECTORY_CD_SIG(n) bool32 n(Application_Links *app, char *dir, int32_t *len, int32_t capacity, char *rel_path, int32_t rel_len)
#define GET_4ED_PATH_SIG(n) bool32 n(Application_Links *app, char *out, int32_t capacity)

View File

@ -267,7 +267,7 @@ standard_build(char *cdir, uint32_t flags){
#if 1
{
BEGIN_TIME_SECTION();
build(OPTS, cdir, "fsm_table_generator.cpp",
build(OPTS | DEBUG_INFO, cdir, "fsm_table_generator.cpp",
META_DIR, "fsmgen", 0);
END_TIME_SECTION("build fsm generator");
}

View File

@ -13,7 +13,11 @@ as this is the only one that will be used for generating headers and docs.
API_EXPORT void*
Memory_Allocate(Application_Links *app, int32_t size)/*
DOC(TODO)
DOC_PARAM(size, The size in bytes of the block that should be returned.)
DOC(This calls to a low level OS allocator which means it is best used
for infrequent, large allocations. The size of the block must be remembered
if it will be freed or if it's mem protection status will be changed.)
DOC_SEE(memory_free)
*/{
void *result = VirtualAlloc(0, size, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
return(result);
@ -21,7 +25,13 @@ DOC(TODO)
API_EXPORT bool32
Memory_Set_Protection(Application_Links *app, void *ptr, int32_t size, Memory_Protect_Flags flags)/*
DOC(TODO)
DOC_PARAM(ptr, The base of the block on which to set memory protection flags.)
DOC_PARAM(size, The size that was originally used to allocate this block.)
DOC_PARAM(flags, The new memory protection flags.)
DOC(This call sets the memory protection flags of a block of memory that was previously
allocate by memory_allocate.)
DOC_SEE(memory_allocate)
DOC_SEE(Memory_Protect_Flags)
*/{
bool32 result = false;
DWORD old_protect = 0;
@ -56,10 +66,14 @@ DOC(TODO)
}
API_EXPORT void
Memory_Free(Application_Links *app, void *mem, int32_t size)/*
DOC(TODO)
Memory_Free(Application_Links *app, void *ptr, int32_t size)/*
DOC_PARAM(mem, The base of a block to free.)
DOC_PARAM(size, The size that was originally used to allocate this block.)
DOC(This call frees a block of memory that was previously allocated by
memory_allocate.)
DOC_SEE(memory_allocate)
*/{
VirtualFree(mem, 0, MEM_RELEASE);
VirtualFree(ptr, 0, MEM_RELEASE);
}
API_EXPORT bool32
@ -177,7 +191,12 @@ DOC_SEE(Mouse_Cursor_Show_Type)
}
API_EXPORT void
Toggle_Fullscreen(Application_Links *app){
Toggle_Fullscreen(Application_Links *app)/*
DOC(This call tells 4coder to switch into or out of full screen mode.
The changes of full screen mode do not take effect until the end of the current frame.
On Windows this call will not work unless 4coder was started in "stream mode".
Stream mode can be enabled with -S or -F flags on the command line to 4ed.)
*/{
/* NOTE(allen): Don't actually change window size now!
Tell the platform layer to do the toggle (or to cancel the toggle)
later when the app.step function isn't running. If the size changes
@ -193,7 +212,13 @@ Toggle_Fullscreen(Application_Links *app){
}
API_EXPORT bool32
Is_Fullscreen(Application_Links *app){
Is_Fullscreen(Application_Links *app)/*
DOC_SEE(This call returns true if the 4coder is in full screen mode. This call
takes toggles that have already occured this frame into account. So it may return
true even though the frame has not ended and actually put 4coder into full screen. If
it returns true though, 4coder will definitely be full screen by the beginning of the next
frame if the state is not changed.)
*/{
/* NOTE(allen): This is a fancy way to say 'full_screen XOR do_toggle'
This way this function can always report the state the fullscreen
will have when the next frame runs, given the number of toggles
@ -203,7 +228,10 @@ Is_Fullscreen(Application_Links *app){
}
API_EXPORT void
Send_Exit_Signal(Application_Links *app){
Send_Exit_Signal(Application_Links *app)/*
DOC_SEE(This call sends a signal to 4coder to attempt to exit. If there are unsaved
files this triggers a dialogue ensuring you're okay with closing.)
*/{
win32vars.send_exit_signal = 1;
}