cleaned up the complex memory in sitegen

This commit is contained in:
Allen Webster 2017-07-10 10:51:19 -04:00
parent ea2f28ce82
commit 312035ac8c
15 changed files with 1755 additions and 1805 deletions

View File

@ -9,9 +9,7 @@
// TOP
// TODO(allen): get away from assert.h
// TODO(allen): get away from string.h
#include <assert.h>
#include <string.h>
#include "4ed_defines.h"

View File

@ -67,13 +67,13 @@ buffer_quick_unsort_cursors(Cursor_With_Index *positions, i32 start, i32 pivot){
inline void
buffer_sort_cursors(Cursor_With_Index *positions, i32 count){
assert(count > 0);
Assert(count > 0);
buffer_quick_sort_cursors(positions, 0, count-1);
}
inline void
buffer_unsort_cursors(Cursor_With_Index *positions, i32 count){
assert(count > 0);
Assert(count > 0);
buffer_quick_unsort_cursors(positions, 0, count-1);
}
@ -460,9 +460,9 @@ buffer_replace_range(Gap_Buffer *buffer, i32 start, i32 end, char *str, i32 len,
i32 result = 0;
i32 move_size = 0;
assert(0 <= start);
assert(start <= end);
assert(end <= size);
Assert(0 <= start);
Assert(start <= end);
Assert(end <= size);
*shift_amount = (len - (end - start));
if (*shift_amount + size <= buffer->max){
@ -484,8 +484,8 @@ buffer_replace_range(Gap_Buffer *buffer, i32 start, i32 end, char *str, i32 len,
buffer->size1 = start + len;
buffer->gap_size -= *shift_amount;
assert(buffer->size1 + buffer->size2 == size + *shift_amount);
assert(buffer->size1 + buffer->gap_size + buffer->size2 == buffer->max);
Assert(buffer->size1 + buffer->size2 == size + *shift_amount);
Assert(buffer->size1 + buffer->gap_size + buffer->size2 == buffer->max);
}
else{
*request_amount = l_round_up_i32(2*(*shift_amount + size), 4 << 10);
@ -531,7 +531,7 @@ buffer_edit_provide_memory(Gap_Buffer *buffer, void *new_data, i32 new_max){
i32 size = buffer_size(buffer);
i32 new_gap_size = new_max - size;
assert(new_max >= size);
Assert(new_max >= size);
memcpy(new_data, buffer->data, buffer->size1);
memcpy((char*)new_data + buffer->size1 + new_gap_size, buffer->data + buffer->size1 + buffer->gap_size, buffer->size2);
@ -569,7 +569,7 @@ buffer_convert_out(Gap_Buffer *buffer, char *dest, i32 max){
Gap_Buffer_Stream stream = {0};
i32 i = 0;
i32 size = buffer_size(buffer);
assert(size + buffer->line_count <= max);
Assert(size + buffer->line_count <= max);
i32 pos = 0;
if (buffer_stringify_loop(&stream, buffer, 0, size)){
@ -578,7 +578,7 @@ buffer_convert_out(Gap_Buffer *buffer, char *dest, i32 max){
i32 chunk_size = stream.end - i;
i32 out_size = 0;
i32 result = eol_convert_out(dest + pos, max - pos, stream.data + i, chunk_size, &out_size);
assert(result);
Assert(result);
i = stream.end;
pos += out_size;
still_looping = buffer_stringify_next(&stream);
@ -594,9 +594,9 @@ buffer_count_newlines(Gap_Buffer *buffer, i32 start, i32 end){
i32 i = start;
i32 count = 0;
assert(0 <= start);
assert(start <= end);
assert(end <= buffer_size(buffer));
Assert(0 <= start);
Assert(start <= end);
Assert(end <= buffer_size(buffer));
if (buffer_stringify_loop(&stream, buffer, i, end)){
b32 still_looping = 0;
@ -647,7 +647,7 @@ buffer_measure_starts(Buffer_Measure_Starts *state, Gap_Buffer *buffer){
}while(still_looping);
}
assert(i == size);
Assert(i == size);
if (start_ptr == start_end){
goto buffer_measure_starts_widths_end;
@ -671,7 +671,7 @@ internal void
buffer_measure_character_starts(System_Functions *system, Render_Font *font, Gap_Buffer *buffer, i32 *character_starts, i32 mode, i32 virtual_white){
PRFL_FUNC_GROUP();
assert(mode == 0);
Assert(mode == 0);
Gap_Buffer_Stream stream = {0};
i32 i = 0;
@ -726,7 +726,7 @@ buffer_measure_character_starts(System_Functions *system, Render_Font *font, Gap
}while(still_looping);
}
assert(line_index-1 == buffer->line_count);
Assert(line_index-1 == buffer->line_count);
}
enum{
@ -902,7 +902,7 @@ buffer_measure_wrap_y(Buffer_Measure_Wrap_State *S_ptr, Buffer_Measure_Wrap_Para
++S.current_wrap_index;
params.wrap_line_index[S.line_index++] = S.current_wrap_index;
assert(S.line_index-1 == params.buffer->line_count);
Assert(S.line_index-1 == params.buffer->line_count);
S_stop.status = BLStatus_Finished;
DrReturn(S_stop);
@ -917,10 +917,10 @@ buffer_remeasure_starts(Gap_Buffer *buffer, i32 line_start, i32 line_end, i32 li
i32 *starts = buffer->line_starts;
i32 line_count = buffer->line_count;
assert(0 <= line_start);
assert(line_start <= line_end);
assert(line_end < line_count);
assert(line_count + line_shift <= buffer->line_max);
Assert(0 <= line_start);
Assert(line_start <= line_end);
Assert(line_end < line_count);
Assert(line_count + line_shift <= buffer->line_max);
++line_end;
@ -981,19 +981,19 @@ buffer_remeasure_starts(Gap_Buffer *buffer, i32 line_start, i32 line_end, i32 li
}
buffer_remeasure_starts_end:;
assert(line_count >= 1);
Assert(line_count >= 1);
buffer->line_count = new_line_count;
}
internal void
buffer_remeasure_character_starts(System_Functions *system, Render_Font *font, Gap_Buffer *buffer, i32 line_start, i32 line_end, i32 line_shift, i32 *character_starts, i32 mode, i32 virtual_whitespace){
assert(mode == 0);
Assert(mode == 0);
i32 new_line_count = buffer->line_count;
assert(0 <= line_start);
assert(line_start <= line_end);
assert(line_end < new_line_count - line_shift);
Assert(0 <= line_start);
Assert(line_start <= line_end);
Assert(line_end < new_line_count - line_shift);
++line_end;
@ -1066,7 +1066,7 @@ buffer_remeasure_character_starts(System_Functions *system, Render_Font *font, G
}while(still_looping);
}
assert(line_i >= new_line_end);
Assert(line_i >= new_line_end);
buffer_remeasure_character_starts_end:;
@ -1088,9 +1088,9 @@ buffer_remeasure_wrap_y(Gap_Buffer *buffer, i32 line_start, i32 line_end, i32 li
f32 *wraps, f32 font_height, f32 *adv, f32 max_width){
i32 new_line_count = buffer->line_count;
assert(0 <= line_start);
assert(line_start <= line_end);
assert(line_end < new_line_count - line_shift);
Assert(0 <= line_start);
Assert(line_start <= line_end);
Assert(line_end < new_line_count - line_shift);
++line_end;
@ -1185,7 +1185,7 @@ binary_search(i32 *array, i32 value, i32 l_bound, i32 u_bound){
else{
break;
}
assert(start < end);
Assert(start < end);
if (start == end - 1){
i = start;
break;
@ -1197,11 +1197,11 @@ binary_search(i32 *array, i32 value, i32 l_bound, i32 u_bound){
inline i32
buffer_get_line_index_range(Gap_Buffer *buffer, i32 pos, i32 l_bound, i32 u_bound){
assert(0 <= l_bound);
assert(l_bound <= u_bound);
assert(u_bound <= buffer->line_count);
Assert(0 <= l_bound);
Assert(l_bound <= u_bound);
Assert(u_bound <= buffer->line_count);
assert(buffer->line_starts != 0);
Assert(buffer->line_starts != 0);
i32 i = binary_search(buffer->line_starts, pos, l_bound, u_bound);
return(i);
@ -1666,8 +1666,8 @@ buffer_invert_edit_shift(Gap_Buffer *buffer, Buffer_Edit edit, Buffer_Edit *inve
i32 *str_pos, i32 max, i32 shift_amount){
i32 pos = *str_pos;
i32 len = edit.end - edit.start;
assert(pos >= 0);
assert(pos + len <= max);
Assert(pos >= 0);
Assert(pos + len <= max);
*str_pos = pos + len;
inverse->str_start = pos;
@ -2019,7 +2019,7 @@ buffer_render_data(Buffer_Render_State *S_ptr, Buffer_Render_Params params, f32
}
*params.count = (i32)(S.write.item - params.items);
assert(*params.count <= params.max);
Assert(*params.count <= params.max);
S_stop.status = BLStatus_Finished;
DrReturn(S_stop);

View File

@ -435,7 +435,7 @@ view_compute_cursor(System_Functions *system, View *view, Buffer_Seek seek, b32
first_wrap_determination = 0;
}
else{
assert(stop.pos == wrap_unit_end);
Assert(stop.pos == wrap_unit_end);
do_wrap = 1;
++wrap_array_index;
wrap_unit_end = file->state.wrap_positions[wrap_array_index];
@ -6005,7 +6005,7 @@ draw_file_loaded(System_Functions *system, View *view, i32_Rect rect, b32 is_act
first_wrap_determination = 0;
}
else{
assert(stop.pos == wrap_unit_end);
Assert(stop.pos == wrap_unit_end);
do_wrap = 1;
++wrap_array_index;
wrap_unit_end = file->state.wrap_positions[wrap_array_index];

View File

@ -591,7 +591,7 @@ package(char *cdir){
char *tier = tiers[tier_index];
u32 flags = base_flags | tier_flags[tier_index];
String_Temp temp = fm_begin_temp();
Temp temp = fm_begin_temp();
char *tier_package_root = fm_str(base_package_root, "_", tier);
for (u32 arch = 0; arch < Arch_COUNT; ++arch){
char *par_dir = fm_str(tier_package_root, "_", arch_names[arch]);
@ -645,7 +645,7 @@ package(char *cdir){
// NOTE(allen): power
{
String_Temp temp = fm_begin_temp();
Temp temp = fm_begin_temp();
char *pack_power_par_dir = fm_str("../current_dist_power");
char *pack_power_dir = fm_str(pack_power_par_dir, "/power");

View File

@ -75,10 +75,15 @@ internal char **fm_prepare_list_internal(char **l1, ...);
internal char **fm_list_one_item(char *item);
internal void *fm__push(umem size);
internal void fm_align();
#define fm_push_array(T,c) (T*)fm__push(sizeof(T)*c)
// File System Navigation
typedef umem String_Temp;
internal String_Temp fm_begin_temp();
internal void fm_end_temp(String_Temp temp);
typedef umem Temp;
internal Temp fm_begin_temp();
internal void fm_end_temp(Temp temp);
internal i32 fm_get_current_directory(char *buffer, i32 max);
@ -182,17 +187,18 @@ umem fm_arena_max = 0;
internal void
fm__init_memory(){
Assert(fm_arena_memory == 0);
fm_arena_max = MB(16);
fm_arena_memory = (char*)malloc(fm_arena_max);
}
internal String_Temp
internal Temp
fm_begin_temp(){
return(fm_arena_pos);
}
internal void
fm_end_temp(String_Temp temp){
fm_end_temp(Temp temp){
fm_arena_pos = temp;
}
@ -208,6 +214,11 @@ fm__push(umem size){
return(result);
}
internal void
fm_align(){
fm_arena_pos = (fm_arena_pos+7)&(~7);
}
#if defined(IS_WINDOWS)
typedef uint32_t DWORD;

29
meta/4ed_meta_keywords.h Normal file
View File

@ -0,0 +1,29 @@
/*
* Mr. 4th Dimention - Allen Webster
*
* 10.07.2017
*
* Standard meta-parser configuration for 4coder code.
*
*/
// TOP
#if !defined(FRED_META_KEYWORDS_H)
#define FRED_META_KEYWORDS_H
internal Meta_Keywords meta_keywords[] = {
{make_lit_string("API_EXPORT") , Item_Function } ,
{make_lit_string("API_EXPORT_INLINE") , Item_Function } ,
{make_lit_string("API_EXPORT_MACRO") , Item_Macro } ,
{make_lit_string("CPP_NAME") , Item_CppName } ,
{make_lit_string("TYPEDEF") , Item_Typedef } ,
{make_lit_string("STRUCT") , Item_Struct } ,
{make_lit_string("UNION") , Item_Union } ,
{make_lit_string("ENUM") , Item_Enum } ,
};
#endif
// BOTTOM

View File

@ -9,37 +9,37 @@
// TOP
#if !defined(META_PARSER_CPP)
#define META_PARSER_CPP
#if !defined(FRED_META_PARSER_CPP)
#define FRED_META_PARSER_CPP
typedef struct Parse_Context{
struct Parse_Context{
Cpp_Token *token_s;
Cpp_Token *token_e;
Cpp_Token *token;
char *data;
} Parse_Context;
};
typedef struct Argument{
struct Argument{
String param_string;
String param_name;
} Argument;
};
typedef struct Argument_Breakdown{
int32_t count;
struct Argument_Breakdown{
i32 count;
Argument *args;
} Argument_Breakdown;
};
typedef struct Documentation{
int32_t param_count;
struct Documentation{
i32 param_count;
String *param_name;
String *param_docs;
String return_doc;
String main_doc;
int32_t see_also_count;
i32 see_also_count;
String *see_also;
} Documentation;
};
typedef enum Item_Type{
enum Item_Type{
Item_Null,
Item_Function,
Item_CppName,
@ -50,10 +50,10 @@ typedef enum Item_Type{
Item_Enum,
Item_Type_Count,
#define Item_Type_User0 Item_Type_Count
} Item_Type;
};
typedef struct Item_Node{
int32_t t;
struct Item_Node{
i32 t;
String cpp_name;
String name;
@ -72,50 +72,49 @@ typedef struct Item_Node{
Item_Node *first_child;
Item_Node *next_sibling;
} Item_Node;
};
typedef struct Item_Set{
struct Item_Set{
Item_Node *items;
int32_t count;
} Item_Set;
i32 count;
};
typedef struct Parse{
struct Parse{
String code;
Cpp_Token_Array tokens;
int32_t item_count;
} Parse;
i32 item_count;
};
typedef struct Meta_Unit{
struct Meta_Unit{
Item_Set set;
Parse *parse;
int32_t count;
} Meta_Unit;
i32 count;
};
typedef struct Meta_Keywords{
struct Meta_Keywords{
String key;
Item_Type type;
} Meta_Keywords;
};
typedef struct Used_Links{
struct Used_Links{
String *strs;
int32_t count, max;
} Used_Links;
i32 count, max;
};
static Item_Node null_item_node = {0};
internal Item_Node null_item_node = {0};
static String
str_start_end(char *data, int32_t start, int32_t end){
internal String
str_start_end(char *data, i32 start, i32 end){
return(make_string(data + start, end - start));
}
static String
internal String
get_lexeme(Cpp_Token token, char *code){
String str = make_string(code + token.start, token.size);
return(str);
}
static Parse_Context
internal Parse_Context
setup_parse_context(char *data, Cpp_Token_Array array){
Parse_Context context;
context.token_s = array.tokens;
@ -125,7 +124,7 @@ setup_parse_context(char *data, Cpp_Token_Array array){
return(context);
}
static Parse_Context
internal Parse_Context
setup_parse_context(Parse parse){
Parse_Context context;
context.token_s = parse.tokens.tokens;
@ -135,7 +134,7 @@ setup_parse_context(Parse parse){
return(context);
}
static Cpp_Token*
internal Cpp_Token*
get_token(Parse_Context *context){
Cpp_Token *result = context->token;
if (result >= context->token_e){
@ -144,7 +143,7 @@ get_token(Parse_Context *context){
return(result);
}
static Cpp_Token*
internal Cpp_Token*
get_next_token(Parse_Context *context){
Cpp_Token *result = context->token+1;
context->token = result;
@ -155,7 +154,7 @@ get_next_token(Parse_Context *context){
return(result);
}
static Cpp_Token*
internal Cpp_Token*
get_prev_token(Parse_Context *context){
Cpp_Token *result = context->token-1;
if (result < context->token_s){
@ -167,7 +166,7 @@ get_prev_token(Parse_Context *context){
return(result);
}
static Cpp_Token*
internal Cpp_Token*
can_back_step(Parse_Context *context){
Cpp_Token *result = context->token-1;
if (result < context->token_s){
@ -176,7 +175,7 @@ can_back_step(Parse_Context *context){
return(result);
}
static Cpp_Token*
internal Cpp_Token*
set_token(Parse_Context *context, Cpp_Token *token){
Cpp_Token *result = 0;
if (token >= context->token_s && token < context->token_e){
@ -186,23 +185,23 @@ set_token(Parse_Context *context, Cpp_Token *token){
return(result);
}
static String
str_alloc(Partition *part, int32_t cap){
return(make_string_cap(push_array(part, char, cap), 0, cap));
internal String
str_alloc(i32 cap){
return(make_string_cap(fm_push_array(char, cap), 0, cap));
}
static Item_Set
allocate_item_set(Partition *part, int32_t count){
internal Item_Set
allocate_item_set(i32 count){
Item_Set item_set = {0};
if (count > 0){
item_set.items = push_array(part, Item_Node, count);
item_set.items = fm_push_array(Item_Node, count);
item_set.count = count;
memset(item_set.items, 0, sizeof(Item_Node)*count);
}
return(item_set);
}
static String
internal String
file_dump(char *filename){
String result = {0};
FILE *file = fopen(filename, "rb");
@ -224,7 +223,7 @@ file_dump(char *filename){
return(result);
}
static Parse
internal Parse
meta_lex(char *filename){
Parse result = {0};
result.code = file_dump(filename);
@ -235,19 +234,19 @@ meta_lex(char *filename){
return(result);
}
static String
internal String
get_first_line(String source){
String line = {0};
int32_t pos = find_s_char(source, 0, '\n');
i32 pos = find_s_char(source, 0, '\n');
line = substr(source, 0, pos);
return(line);
}
static String
internal String
get_next_line(String source, String line){
String next = {0};
int32_t pos = (int32_t)(line.str - source.str) + line.size;
int32_t start = 0;
i32 pos = (i32)(line.str - source.str) + line.size;
i32 start = 0;
if (pos < source.size){
Assert(source.str[pos] == '\n');
@ -262,9 +261,9 @@ get_next_line(String source, String line){
return(next);
}
static int32_t
internal i32
is_comment(String str){
int32_t result = 0;
i32 result = 0;
if (str.size >= 2){
if (str.str[0] == '/' &&
str.str[1] == '/'){
@ -283,7 +282,7 @@ typedef enum Doc_Note_Type{
HIDE_MEMBERS,
} Doc_Note_Type;
static String
internal String
defined_doc_notes[] = {
make_lit_string("DOC_PARAM"),
make_lit_string("DOC_RETURN"),
@ -293,9 +292,9 @@ defined_doc_notes[] = {
make_lit_string("HIDE_MEMBERS"),
};
static int32_t
internal i32
check_and_fix_docs(String *doc_string){
int32_t result = false;
i32 result = false;
if (doc_string->size > 4){
if (doc_string->str[0] == '/'){
@ -314,9 +313,9 @@ check_and_fix_docs(String *doc_string){
return(result);
}
static int32_t
internal i32
get_doc_string_from_prev(Parse_Context *context, String *doc_string){
int32_t result = false;
i32 result = false;
if (can_back_step(context)){
Cpp_Token *prev_token = get_token(context) - 1;
@ -334,12 +333,12 @@ get_doc_string_from_prev(Parse_Context *context, String *doc_string){
return(result);
}
static String
doc_parse_note(String source, int32_t *pos){
internal String
doc_parse_note(String source, i32 *pos){
String result = {0};
int32_t p = *pos;
int32_t start = p;
i32 p = *pos;
i32 start = p;
for (; p < source.size; ++p){
if (source.str[p] == '('){
break;
@ -354,16 +353,16 @@ doc_parse_note(String source, int32_t *pos){
return(result);
}
static String
doc_parse_note_string(String source, int32_t *pos){
internal String
doc_parse_note_string(String source, i32 *pos){
String result = {0};
Assert(source.str[*pos] == '(');
int32_t p = *pos + 1;
int32_t start = p;
i32 p = *pos + 1;
i32 start = p;
int32_t nest_level = 0;
i32 nest_level = 0;
for (; p < source.size; ++p){
if (source.str[p] == ')'){
@ -388,12 +387,12 @@ doc_parse_note_string(String source, int32_t *pos){
return(result);
}
static String
doc_parse_parameter(String source, int32_t *pos){
internal String
doc_parse_parameter(String source, i32 *pos){
String result = {0};
int32_t p = *pos;
int32_t start = p;
i32 p = *pos;
i32 start = p;
for (; p < source.size; ++p){
if (source.str[p] == ','){
@ -410,12 +409,12 @@ doc_parse_parameter(String source, int32_t *pos){
return(result);
}
static String
doc_parse_last_parameter(String source, int32_t *pos){
internal String
doc_parse_last_parameter(String source, i32 *pos){
String result = {0};
int32_t p = *pos;
int32_t start = p;
i32 p = *pos;
i32 start = p;
for (; p < source.size; ++p){
if (source.str[p] == ')'){
@ -431,13 +430,13 @@ doc_parse_last_parameter(String source, int32_t *pos){
return(result);
}
static void
perform_doc_parse(Partition *part, String doc_string, Documentation *doc){
int32_t keep_parsing = true;
int32_t pos = 0;
internal void
perform_doc_parse(String doc_string, Documentation *doc){
i32 keep_parsing = true;
i32 pos = 0;
int32_t param_count = 0;
int32_t see_count = 0;
i32 param_count = 0;
i32 see_count = 0;
do{
String doc_note = doc_parse_note(doc_string, &pos);
@ -445,7 +444,7 @@ perform_doc_parse(Partition *part, String doc_string, Documentation *doc){
keep_parsing = false;
}
else{
int32_t doc_note_type;
i32 doc_note_type;
if (string_set_match(defined_doc_notes, ArrayCount(defined_doc_notes), doc_note, &doc_note_type)){
doc_parse_note_string(doc_string, &pos);
@ -459,8 +458,8 @@ perform_doc_parse(Partition *part, String doc_string, Documentation *doc){
}while(keep_parsing);
if (param_count + see_count > 0){
int32_t memory_size = sizeof(String)*(2*param_count + see_count);
doc->param_name = push_array(part, String, memory_size);
i32 memory_size = sizeof(String)*(2*param_count + see_count);
doc->param_name = fm_push_array(String, memory_size);
doc->param_docs = doc->param_name + param_count;
doc->see_also = doc->param_docs + param_count;
@ -468,8 +467,8 @@ perform_doc_parse(Partition *part, String doc_string, Documentation *doc){
doc->see_also_count = see_count;
}
int32_t param_index = 0;
int32_t see_index = 0;
i32 param_index = 0;
i32 see_index = 0;
keep_parsing = true;
pos = 0;
@ -479,7 +478,7 @@ perform_doc_parse(Partition *part, String doc_string, Documentation *doc){
keep_parsing = false;
}
else{
int32_t doc_note_type;
i32 doc_note_type;
if (string_set_match(defined_doc_notes, ArrayCount(defined_doc_notes), doc_note, &doc_note_type)){
String doc_note_string = doc_parse_note_string(doc_string, &pos);
@ -488,7 +487,7 @@ perform_doc_parse(Partition *part, String doc_string, Documentation *doc){
case DOC_PARAM:
{
Assert(param_index < param_count);
int32_t param_pos = 0;
i32 param_pos = 0;
String param_name = doc_parse_parameter(doc_note_string, &param_pos);
String param_docs = doc_parse_last_parameter(doc_note_string, &param_pos);
doc->param_name[param_index] = param_name;
@ -520,13 +519,12 @@ perform_doc_parse(Partition *part, String doc_string, Documentation *doc){
}while(keep_parsing);
}
static int32_t
struct_parse(Partition *part, int32_t is_struct,
Parse_Context *context, Item_Node *top_member);
internal i32
struct_parse(i32 is_struct, Parse_Context *context, Item_Node *top_member);
static int32_t
struct_parse_member(Partition *part, Parse_Context *context, Item_Node *member){
int32_t result = false;
internal i32
struct_parse_member(Parse_Context *context, Item_Node *member){
i32 result = false;
Cpp_Token *token = get_token(context);
@ -544,7 +542,7 @@ struct_parse_member(Partition *part, Parse_Context *context, Item_Node *member){
if (token){
String name = {0};
Cpp_Token *token_j = 0;
int32_t nest_level = 0;
i32 nest_level = 0;
for (; (token_j = get_token(context)) > start_token; get_prev_token(context)){
if (token_j->type == CPP_TOKEN_BRACKET_CLOSE){
@ -584,8 +582,8 @@ struct_parse_member(Partition *part, Parse_Context *context, Item_Node *member){
return(result);
}
static Item_Node*
struct_parse_next_member(Partition *part, Parse_Context *context){
internal Item_Node*
struct_parse_next_member(Parse_Context *context){
Item_Node *result = 0;
Cpp_Token *token = 0;
@ -595,9 +593,9 @@ struct_parse_next_member(Partition *part, Parse_Context *context){
(token->flags & CPP_TFLAG_IS_KEYWORD)){
String lexeme = get_lexeme(*token, context->data);
if (match_ss(lexeme, make_lit_string("STRUCT"))){
Item_Node *member = push_struct(part, Item_Node);
if (struct_parse(part, true, context, member)){
if (match(lexeme, "STRUCT")){
Item_Node *member = fm_push_array(Item_Node, 1);
if (struct_parse(true, context, member)){
result = member;
break;
}
@ -605,9 +603,9 @@ struct_parse_next_member(Partition *part, Parse_Context *context){
Assert(!"unhandled error");
}
}
else if (match_ss(lexeme, make_lit_string("UNION"))){
Item_Node *member = push_struct(part, Item_Node);
if (struct_parse(part, false, context, member)){
else if (match(lexeme, "UNION")){
Item_Node *member = fm_push_array(Item_Node, 1);
if (struct_parse(false, context, member)){
result = member;
break;
}
@ -616,8 +614,8 @@ struct_parse_next_member(Partition *part, Parse_Context *context){
}
}
else{
Item_Node *member = push_struct(part, Item_Node);
if (struct_parse_member(part, context, member)){
Item_Node *member = fm_push_array(Item_Node, 1);
if (struct_parse_member(context, member)){
result = member;
break;
}
@ -634,9 +632,9 @@ struct_parse_next_member(Partition *part, Parse_Context *context){
return(result);
}
static int32_t
struct_parse(Partition *part, int32_t is_struct, Parse_Context *context, Item_Node *top_member){
int32_t result = false;
internal i32
struct_parse(i32 is_struct, Parse_Context *context, Item_Node *top_member){
i32 result = false;
Cpp_Token *start_token = get_token(context);
Cpp_Token *token = 0;
@ -673,14 +671,14 @@ struct_parse(Partition *part, int32_t is_struct, Parse_Context *context, Item_No
}
set_token(context, token+1);
Item_Node *new_member = struct_parse_next_member(part, context);
Item_Node *new_member = struct_parse_next_member(context);
if (new_member){
top_member->first_child = new_member;
Item_Node *head_member = new_member;
for(;;){
new_member = struct_parse_next_member(part, context);
new_member = struct_parse_next_member(context);
if (new_member){
head_member->next_sibling = new_member;
head_member = new_member;
@ -715,9 +713,9 @@ struct_parse(Partition *part, int32_t is_struct, Parse_Context *context, Item_No
return(result);
}
static int32_t
internal i32
typedef_parse(Parse_Context *context, Item_Node *item){
int32_t result = false;
i32 result = false;
Cpp_Token *token = get_token(context);
String doc_string = {0};
@ -756,9 +754,9 @@ typedef_parse(Parse_Context *context, Item_Node *item){
return(result);
}
static int32_t
enum_parse(Partition *part, Parse_Context *context, Item_Node *item){
int32_t result = false;
internal i32
enum_parse(Parse_Context *context, Item_Node *item){
i32 result = false;
String parent_doc_string = {0};
get_doc_string_from_prev(context, &parent_doc_string);
@ -829,7 +827,7 @@ enum_parse(Partition *part, Parse_Context *context, Item_Node *item){
}
}
Item_Node *new_member = push_struct(part, Item_Node);
Item_Node *new_member = fm_push_array(Item_Node, 1);
if (first_member == 0){
first_member = new_member;
}
@ -866,12 +864,12 @@ enum_parse(Partition *part, Parse_Context *context, Item_Node *item){
return(result);
}
static Argument_Breakdown
allocate_argument_breakdown(Partition *part, int32_t count){
internal Argument_Breakdown
allocate_argument_breakdown(i32 count){
Argument_Breakdown breakdown = {0};
if (count > 0){
breakdown.count = count;
breakdown.args = push_array(part, Argument, count);
breakdown.args = fm_push_array(Argument, count);
memset(breakdown.args, 0, sizeof(Argument)*count);
}
return(breakdown);
@ -882,13 +880,13 @@ Parse arguments by giving pointers to the tokens:
foo(a, ... , z)
^ ^
*/
static Argument_Breakdown
parameter_parse(Partition *part, char *data, Cpp_Token *args_start_token, Cpp_Token *args_end_token){
int32_t arg_index = 0;
internal Argument_Breakdown
parameter_parse(char *data, Cpp_Token *args_start_token, Cpp_Token *args_end_token){
i32 arg_index = 0;
Cpp_Token *arg_token = args_start_token + 1;
int32_t param_string_start = arg_token->start;
i32 param_string_start = arg_token->start;
int32_t arg_count = 1;
i32 arg_count = 1;
arg_token = args_start_token;
for (; arg_token < args_end_token; ++arg_token){
if (arg_token->type == CPP_TOKEN_COMMA){
@ -896,14 +894,14 @@ parameter_parse(Partition *part, char *data, Cpp_Token *args_start_token, Cpp_To
}
}
Argument_Breakdown breakdown = allocate_argument_breakdown(part, arg_count);
Argument_Breakdown breakdown = allocate_argument_breakdown(arg_count);
arg_token = args_start_token + 1;
for (; arg_token <= args_end_token; ++arg_token){
if (arg_token->type == CPP_TOKEN_COMMA ||
arg_token->type == CPP_TOKEN_PARENTHESE_CLOSE){
int32_t size = arg_token->start - param_string_start;
i32 size = arg_token->start - param_string_start;
String param_string = make_string(data + param_string_start, size);
param_string = chop_whitespace(param_string);
breakdown.args[arg_index].param_string = param_string;
@ -912,8 +910,8 @@ parameter_parse(Partition *part, char *data, Cpp_Token *args_start_token, Cpp_To
param_name_token->start > param_string_start;
--param_name_token){
if (param_name_token->type == CPP_TOKEN_IDENTIFIER){
int32_t name_start = param_name_token->start;
int32_t name_size = param_name_token->size;
i32 name_start = param_name_token->start;
i32 name_size = param_name_token->size;
breakdown.args[arg_index].param_name = make_string(data + name_start, name_size);
break;
}
@ -935,9 +933,9 @@ Moves the context in the following way:
~~~~~~~ name( ~~~~~~~
^ -> ^
*/
static int32_t
internal i32
function_parse_goto_name(Parse_Context *context){
int32_t result = false;
i32 result = false;
Cpp_Token *token = 0;
@ -967,9 +965,9 @@ Moves the context in the following way:
~~~~~~~ name( ~~~~~~~ /* XXX //
^ ---------------> ^
*/
static int32_t
internal i32
function_get_doc(Parse_Context *context, char *data, String *doc_string){
int32_t result = false;
i32 result = false;
Cpp_Token *token = get_token(context);
String lexeme = {0};
@ -995,9 +993,9 @@ function_get_doc(Parse_Context *context, char *data, String *doc_string){
return(result);
}
static int32_t
internal i32
cpp_name_parse(Parse_Context *context, String *name){
int32_t result = false;
i32 result = false;
Cpp_Token *token = 0;
Cpp_Token *token_start = get_token(context);
@ -1026,9 +1024,9 @@ Moves the context in the following way:
RETTY~ name( ~~~~~~~ )
^ ---------------> ^
*/
static int32_t
function_sig_parse(Partition *part, Parse_Context *context, Item_Node *item, String cpp_name){
int32_t result = false;
internal i32
function_sig_parse(Parse_Context *context, Item_Node *item, String cpp_name){
i32 result = false;
Cpp_Token *token = 0;
Cpp_Token *args_start_token = 0;
@ -1051,7 +1049,7 @@ function_sig_parse(Partition *part, Parse_Context *context, Item_Node *item, Str
item->args = str_start_end(context->data, args_start_token->start, token->start + token->size);
item->t = Item_Function;
item->cpp_name = cpp_name;
item->breakdown = parameter_parse(part, context->data, args_start_token, token);
item->breakdown = parameter_parse(context->data, args_start_token, token);
Assert(get_token(context)->type == CPP_TOKEN_PARENTHESE_CLOSE);
result = true;
@ -1066,9 +1064,9 @@ Moves the context in the following way:
MARKER ~~~ name( ~~~~~~~ )
^ -------------------> ^
*/
static int32_t
function_parse(Partition *part, Parse_Context *context, Item_Node *item, String cpp_name){
int32_t result = false;
internal i32
function_parse(Parse_Context *context, Item_Node *item, String cpp_name){
i32 result = false;
String doc_string = {0};
Cpp_Token *token = get_token(context);
@ -1081,7 +1079,7 @@ function_parse(Partition *part, Parse_Context *context, Item_Node *item, String
set_token(context, token);
if (get_next_token(context)){
if (function_sig_parse(part, context, item, cpp_name)){
if (function_sig_parse(context, item, cpp_name)){
Assert(get_token(context)->type == CPP_TOKEN_PARENTHESE_CLOSE);
result = true;
}
@ -1095,9 +1093,9 @@ Moves the context in the following way:
/* ~~~ // #define
^ ----> ^
*/
static int32_t
internal i32
macro_parse_check(Parse_Context *context){
int32_t result = false;
i32 result = false;
Cpp_Token *token = 0;
@ -1119,9 +1117,9 @@ Moves the context in the following way:
/* ~~~ // #define ~~~~~~~~~~~~~~~~~ NOT_IN_MACRO_BODY
^ ----------------------------> ^
*/
static int32_t
macro_parse(Partition *part, Parse_Context *context, Item_Node *item){
int32_t result = false;
internal i32
macro_parse(Parse_Context *context, Item_Node *item){
i32 result = false;
Cpp_Token *token = 0;
Cpp_Token *doc_token = 0;
@ -1159,7 +1157,7 @@ macro_parse(Partition *part, Parse_Context *context, Item_Node *item){
if (token){
item->args = str_start_end(context->data, args_start_token->start, token->start + token->size);
item->breakdown = parameter_parse(part, context->data, args_start_token, token);
item->breakdown = parameter_parse(context->data, args_start_token, token);
if ((token = get_next_token(context)) != 0){
Cpp_Token *body_start = token;
@ -1189,18 +1187,18 @@ macro_parse(Partition *part, Parse_Context *context, Item_Node *item){
return(result);
}
static Meta_Unit
compile_meta_unit(Partition *part, char *code_directory, char **files, Meta_Keywords *meta_keywords, int32_t key_count){
internal Meta_Unit
compile_meta_unit(char *code_directory, char **files, Meta_Keywords *meta_keywords, i32 key_count){
Meta_Unit unit = {0};
int32_t file_count = 0;
i32 file_count = 0;
for (char **file_ptr = files; *file_ptr; ++file_ptr, ++file_count);
unit.count = file_count;
unit.parse = push_array(part, Parse, file_count);
unit.parse = fm_push_array(Parse, file_count);
b32 all_files_lexed = true;
int32_t i = 0;
i32 i = 0;
for (char **file_ptr = files; *file_ptr; ++file_ptr, ++i){
char str_space[512];
String name = make_fixed_width_string(str_space);
@ -1222,7 +1220,7 @@ compile_meta_unit(Partition *part, char *code_directory, char **files, Meta_Keyw
if (all_files_lexed){
// TODO(allen): This stage counts nested structs and unions which is not correct. Luckily it only means we over allocate by a few items, but fixing it to be exactly correct would be nice.
for (int32_t J = 0; J < unit.count; ++J){
for (i32 J = 0; J < unit.count; ++J){
Cpp_Token *token = 0;
Parse_Context context_ = setup_parse_context(unit.parse[J]);
Parse_Context *context = &context_;
@ -1231,7 +1229,7 @@ compile_meta_unit(Partition *part, char *code_directory, char **files, Meta_Keyw
if (!(token->flags & CPP_TFLAG_PP_BODY)){
String lexeme = get_lexeme(*token, context->data);
int32_t match_index = 0;
i32 match_index = 0;
if (string_set_match_table(meta_keywords, sizeof(*meta_keywords), key_count, lexeme, &match_index)){
Item_Type type = meta_keywords[match_index].type;
@ -1247,31 +1245,31 @@ compile_meta_unit(Partition *part, char *code_directory, char **files, Meta_Keyw
}
if (unit.set.count > 0){
unit.set = allocate_item_set(part, unit.set.count);
unit.set = allocate_item_set(unit.set.count);
}
int32_t index = 0;
i32 index = 0;
for (int32_t J = 0; J < unit.count; ++J){
for (i32 J = 0; J < unit.count; ++J){
Cpp_Token *token = 0;
Parse_Context context_ = setup_parse_context(unit.parse[J]);
Parse_Context *context = &context_;
String cpp_name = {0};
int32_t has_cpp_name = 0;
i32 has_cpp_name = 0;
for (; (token = get_token(context)) != 0; get_next_token(context)){
if (!(token->flags & CPP_TFLAG_PP_BODY)){
String lexeme = get_lexeme(*token, context->data);
int32_t match_index = 0;
i32 match_index = 0;
if (string_set_match_table(meta_keywords, sizeof(*meta_keywords), key_count, lexeme, &match_index)){
Item_Type type = meta_keywords[match_index].type;
switch (type){
case Item_Function:
{
if (function_parse(part, context, unit.set.items + index, cpp_name)){
if (function_parse(context, unit.set.items + index, cpp_name)){
Assert(unit.set.items[index].t == Item_Function);
++index;
}
@ -1292,7 +1290,7 @@ compile_meta_unit(Partition *part, char *code_directory, char **files, Meta_Keyw
case Item_Macro:
{
if (macro_parse(part, context, unit.set.items + index)){
if (macro_parse(context, unit.set.items + index)){
Assert(unit.set.items[index].t == Item_Macro);
++index;
}
@ -1314,9 +1312,8 @@ compile_meta_unit(Partition *part, char *code_directory, char **files, Meta_Keyw
case Item_Struct: case Item_Union: //struct/union
{
if (struct_parse(part, (type == Item_Struct), context, unit.set.items + index)){
Assert(unit.set.items[index].t == Item_Struct ||
unit.set.items[index].t == Item_Union);
if (struct_parse((type == Item_Struct), context, unit.set.items + index)){
Assert(unit.set.items[index].t == Item_Struct ||unit.set.items[index].t == Item_Union);
++index;
}
else{
@ -1326,7 +1323,7 @@ compile_meta_unit(Partition *part, char *code_directory, char **files, Meta_Keyw
case Item_Enum: //ENUM
{
if (enum_parse(part, context, unit.set.items + index)){
if (enum_parse(context, unit.set.items + index)){
Assert(unit.set.items[index].t == Item_Enum);
++index;
}
@ -1363,10 +1360,10 @@ compile_meta_unit(Partition *part, char *code_directory, char **files, Meta_Keyw
return(unit);
}
static Meta_Unit
compile_meta_unit(Partition *part, char *code_directory, char *file, Meta_Keywords *meta_keywords, int32_t key_count){
internal Meta_Unit
compile_meta_unit(char *code_directory, char *file, Meta_Keywords *meta_keywords, i32 key_count){
char *file_array[2] = {file, 0};
Meta_Unit unit = compile_meta_unit(part, code_directory, file_array, meta_keywords, key_count);
Meta_Unit unit = compile_meta_unit(code_directory, file_array, meta_keywords, key_count);
return(unit);
}

View File

@ -68,44 +68,6 @@ make_out_string(int32_t x){
return(str);
}
static void
do_file_copy(Partition *part, char *src_file, char *dst_dir, char *dst_file){
char dst[256];
String str = {0};
int32_t success = 0;
str = make_fixed_width_string(dst);
append_sc(&str, dst_dir);
append_sc(&str, "/");
append_sc(&str, dst_file);
terminate_with_null(&str);
Temp_Memory temp = begin_temp_memory(part);
int32_t mem_size = partition_remaining(part);
void *mem = push_block(part, mem_size);
FILE *in = fopen(src_file, "rb");
if (in){
fseek(in, 0, SEEK_END);
int32_t file_size = ftell(in);
if (mem_size >= file_size){
fseek(in, 0, SEEK_SET);
fread(mem, 1, file_size, in);
FILE *out = fopen(dst, "wb");
if (out){
fwrite(mem, 1, file_size, out);
fclose(out);
success = 1;
}
}
fclose(in);
}
end_temp_memory(temp);
if (!success){
fprintf(stderr, "Could not copy from %s to %s\n", src_file, dst);
}
}
#endif
// BOTTOM

View File

@ -12,7 +12,6 @@
#define IS_PLAT_LAYER
#include <assert.h>
#include <string.h>
#include "4ed_defines.h"
#include "4coder_API/version.h"

View File

@ -40,7 +40,6 @@
#define WINDOW_NAME L"4coder: " L_VERSION
#include <assert.h>
#include <string.h>
#include "4coder_lib/4coder_utf8.h"

File diff suppressed because it is too large Load Diff

View File

@ -15,8 +15,8 @@ struct Enriched_Text{
String source;
};
static Enriched_Text
load_enriched_text(Partition *part, char *directory, char *filename){
internal Enriched_Text
load_enriched_text(char *directory, char *filename){
Enriched_Text result = {0};
char space[256];
@ -81,7 +81,7 @@ struct Document_Item{
} text;
};
};
static Document_Item null_document_item = {0};
global Document_Item null_document_item = {0};
enum{
ItemType_Document,
@ -111,7 +111,6 @@ struct Abstract_Item{
// TODO(allen): make these external
// Document building members
Partition *part;
Document_Item *section_stack[16];
i32 section_top;
@ -122,7 +121,7 @@ struct Abstract_Item{
float h_w_ratio;
Basic_List img_instantiations;
};
static Abstract_Item null_abstract_item = {0};
global Abstract_Item null_abstract_item = {0};
struct Image_Instantiation{
i32 w, h;
@ -132,21 +131,19 @@ struct Document_System{
Basic_List doc_list;
Basic_List img_list;
Basic_List file_list;
Partition *part;
};
static Document_System
create_document_system(Partition *part){
internal Document_System
create_document_system(){
Document_System system = {0};
system.part = part;
return(system);
}
static void*
push_item_on_list(Partition *part, Basic_List *list, i32 item_size){
internal void*
push_item_on_list(Basic_List *list, i32 item_size){
i32 mem_size = item_size + sizeof(Basic_Node);
void *mem = push_block(part, mem_size);
assert(mem != 0);
void *mem = fm__push(mem_size);
Assert(mem != 0);
memset(mem, 0, mem_size);
Basic_Node *node = (Basic_Node*)mem;
@ -163,7 +160,7 @@ push_item_on_list(Partition *part, Basic_List *list, i32 item_size){
return(result);
}
static Abstract_Item*
internal Abstract_Item*
get_item_by_name(Basic_List list, String name){
Abstract_Item *result = 0;
@ -180,7 +177,7 @@ get_item_by_name(Basic_List list, String name){
return(result);
}
static Abstract_Item*
internal Abstract_Item*
get_item_by_name(Basic_List list, char *name){
Abstract_Item *result = 0;
@ -197,7 +194,7 @@ get_item_by_name(Basic_List list, char *name){
return(result);
}
static Image_Instantiation*
internal Image_Instantiation*
get_image_instantiation(Basic_List list, i32 w, i32 h){
Image_Instantiation *result = 0;
@ -214,59 +211,58 @@ get_image_instantiation(Basic_List list, i32 w, i32 h){
return(result);
}
static Abstract_Item*
create_item(Partition *part, Basic_List *list, char *name){
internal Abstract_Item*
create_item(Basic_List *list, char *name){
Abstract_Item *lookup = get_item_by_name(*list, name);
Abstract_Item *result = 0;
if (lookup == 0){
result = (Abstract_Item*)push_item_on_list(part, list, sizeof(Abstract_Item));
result = (Abstract_Item*)push_item_on_list(list, sizeof(Abstract_Item));
}
return(result);
}
static void
add_image_instantiation(Partition *part, Basic_List *list, i32 w, i32 h){
Image_Instantiation *instantiation = (Image_Instantiation*)push_item_on_list(part, list, sizeof(Image_Instantiation));
internal void
add_image_instantiation(Basic_List *list, i32 w, i32 h){
Image_Instantiation *instantiation = (Image_Instantiation*)push_item_on_list(list, sizeof(Image_Instantiation));
instantiation->w = w;
instantiation->h = h;
}
static void
set_section_name(Partition *part, Document_Item *item, char *name, i32 show_title){
internal void
set_section_name(Document_Item *item, char *name, i32 show_title){
i32 name_len = str_size(name);
item->section.name = make_string_cap(push_array(part, char, name_len+1), 0, name_len+1);
partition_align(part, 8);
item->section.name = make_string_cap(fm_push_array(char, name_len+1), 0, name_len+1);
fm_align();
append_sc(&item->section.name, name);
item->section.show_title = show_title;
}
static void
set_section_id(Partition *part, Document_Item *item, char *id){
internal void
set_section_id(Document_Item *item, char *id){
i32 id_len = str_size(id);
item->section.id = make_string_cap(push_array(part, char, id_len+1), 0, id_len+1);
partition_align(part, 8);
item->section.id = make_string_cap(fm_push_array(char, id_len+1), 0, id_len+1);
fm_align();
append_sc(&item->section.id, id);
}
static void
begin_document_description(Abstract_Item *doc, Partition *part, char *title, i32 show_title){
internal void
begin_document_description(Abstract_Item *doc, char *title, i32 show_title){
*doc = null_abstract_item;
doc->item_type = ItemType_Document;
doc->part = part;
doc->root_item = push_struct(doc->part, Document_Item);
doc->root_item = fm_push_array(Document_Item, 1);
*doc->root_item = null_document_item;
doc->section_stack[doc->section_top] = doc->root_item;
doc->root_item->type = Doc_Root;
set_section_name(doc->part, doc->root_item, title, show_title);
set_section_name(doc->root_item, title, show_title);
}
static Abstract_Item*
internal Abstract_Item*
add_generic_file(Document_System *system, char *source_file, char *extension, char *name){
Abstract_Item *item = create_item(system->part, &system->file_list, name);
Abstract_Item *item = create_item(&system->file_list, name);
if (item){
item->item_type = ItemType_GenericFile;
item->extension = extension;
@ -276,10 +272,10 @@ add_generic_file(Document_System *system, char *source_file, char *extension, ch
return(item);
}
static Abstract_Item*
internal Abstract_Item*
add_image_description(Document_System *system, char *source_file, char *extension, char *name){
Abstract_Item *item = create_item(system->part, &system->img_list, name);
if (item){
Abstract_Item *item = create_item(&system->img_list, name);
if (item != 0){
item->item_type = ItemType_Image;
item->extension = extension;
item->source_file = source_file;
@ -300,22 +296,22 @@ add_image_description(Document_System *system, char *source_file, char *extensio
return(item);
}
static Abstract_Item*
internal Abstract_Item*
begin_document_description(Document_System *system, char *title, char *name, i32 show_title){
Abstract_Item *item = create_item(system->part, &system->doc_list, name);
Abstract_Item *item = create_item(&system->doc_list, name);
if (item){
begin_document_description(item, system->part, title, show_title);
begin_document_description(item, title, show_title);
item->name = name;
}
return(item);
}
static void
internal void
end_document_description(Abstract_Item *item){
Assert(item->section_top == 0);
}
static void
internal void
append_child(Document_Item *parent, Document_Item *item){
Assert(parent->type == Doc_Root || parent->type == Doc_Section);
if (parent->section.last_child == 0){
@ -328,45 +324,45 @@ append_child(Document_Item *parent, Document_Item *item){
item->parent = parent;
}
static void
internal void
begin_section(Abstract_Item *item, char *title, char *id){
Assert(item->section_top+1 < ArrayCount(item->section_stack));
Document_Item *parent = item->section_stack[item->section_top];
Document_Item *section = push_struct(item->part, Document_Item);
Document_Item *section = fm_push_array(Document_Item, 1);
*section = null_document_item;
item->section_stack[++item->section_top] = section;
section->type = Doc_Section;
set_section_name(item->part, section, title, 1);
if (id){
set_section_id(item->part, section, id);
set_section_name(section, title, 1);
if (id != 0){
set_section_id(section, id);
}
append_child(parent, section);
}
static void
internal void
end_section(Abstract_Item *doc){
Assert(doc->section_top > 0);
--doc->section_top;
}
static void
internal void
add_todo(Abstract_Item *doc){
Document_Item *parent = doc->section_stack[doc->section_top];
Document_Item *item = push_struct(doc->part, Document_Item);
Document_Item *item = fm_push_array(Document_Item, 1);
*item = null_document_item;
item->type = Doc_Todo;
append_child(parent, item);
}
static void
internal void
add_element_list(Abstract_Item *doc, Meta_Unit *unit){
Document_Item *parent = doc->section_stack[doc->section_top];
Document_Item *item = push_struct(doc->part, Document_Item);
Document_Item *item = fm_push_array(Document_Item, 1);
*item = null_document_item;
item->type = Doc_Element_List;
item->unit_elements.unit = unit;
@ -374,10 +370,10 @@ add_element_list(Abstract_Item *doc, Meta_Unit *unit){
append_child(parent, item);
}
static void
internal void
add_element_list(Abstract_Item *doc, Meta_Unit *unit, Alternate_Names_Array *alt_names, i32 alt_name_type){
Document_Item *parent = doc->section_stack[doc->section_top];
Document_Item *item = push_struct(doc->part, Document_Item);
Document_Item *item = fm_push_array(Document_Item, 1);
*item = null_document_item;
item->type = Doc_Element_List;
item->unit_elements.unit = unit;
@ -387,10 +383,10 @@ add_element_list(Abstract_Item *doc, Meta_Unit *unit, Alternate_Names_Array *alt
append_child(parent, item);
}
static void
internal void
add_full_elements(Abstract_Item *doc, Meta_Unit *unit){
Document_Item *parent = doc->section_stack[doc->section_top];
Document_Item *item = push_struct(doc->part, Document_Item);
Document_Item *item = fm_push_array(Document_Item, 1);
*item = null_document_item;
item->type = Doc_Full_Elements;
item->unit_elements.unit = unit;
@ -398,10 +394,10 @@ add_full_elements(Abstract_Item *doc, Meta_Unit *unit){
append_child(parent, item);
}
static void
internal void
add_full_elements(Abstract_Item *doc, Meta_Unit *unit, Alternate_Names_Array *alt_names, i32 alt_name_type){
Document_Item *parent = doc->section_stack[doc->section_top];
Document_Item *item = push_struct(doc->part, Document_Item);
Document_Item *item = fm_push_array(Document_Item, 1);
*item = null_document_item;
item->type = Doc_Full_Elements;
item->unit_elements.unit = unit;
@ -411,22 +407,22 @@ add_full_elements(Abstract_Item *doc, Meta_Unit *unit, Alternate_Names_Array *al
append_child(parent, item);
}
static void
internal void
add_table_of_contents(Abstract_Item *doc){
Document_Item *parent = doc->section_stack[doc->section_top];
Document_Item *item = push_struct(doc->part, Document_Item);
Document_Item *item = fm_push_array(Document_Item, 1);
*item = null_document_item;
item->type = Doc_Table_Of_Contents;
append_child(parent, item);
}
static void
internal void
add_enriched_text(Abstract_Item *doc, Enriched_Text *text){
Assert(doc->section_top+1 < ArrayCount(doc->section_stack));
Document_Item *parent = doc->section_stack[doc->section_top];
Document_Item *item = push_struct(doc->part, Document_Item);
Document_Item *item = fm_push_array(Document_Item, 1);
*item = null_document_item;
item->type = Doc_Enriched_Text;
item->text.text = text;
@ -478,7 +474,7 @@ struct Section_Counter{
i32 nest_level;
};
static i32
internal i32
doc_get_link_string(Abstract_Item *doc, char *space, i32 capacity){
String str = make_string_cap(space, 0, capacity);
append_sc(&str, doc->name);
@ -487,7 +483,7 @@ doc_get_link_string(Abstract_Item *doc, char *space, i32 capacity){
return(result);
}
static i32
internal i32
img_get_link_string(Abstract_Item *img, char *space, i32 capacity, i32 w, i32 h){
String str = make_string_cap(space, 0, capacity);
append_sc(&str, img->name);
@ -503,7 +499,7 @@ img_get_link_string(Abstract_Item *img, char *space, i32 capacity, i32 w, i32 h)
return(result);
}
static void
internal void
append_section_number_reduced(String *out, Section_Counter *section_counter, i32 reduce){
i32 level = section_counter->nest_level-reduce;
for (i32 i = 1; i <= level; ++i){
@ -514,12 +510,12 @@ append_section_number_reduced(String *out, Section_Counter *section_counter, i32
}
}
static void
internal void
append_section_number(String *out, Section_Counter *section_counter){
append_section_number_reduced(out, section_counter, 0);
}
static i32
internal i32
extract_command_body(String *out, String l, i32 *i_in_out, i32 *body_start_out, i32 *body_end_out, String command_name, i32 require_body){
i32 result = 0;
@ -569,7 +565,7 @@ extract_command_body(String *out, String l, i32 *i_in_out, i32 *body_start_out,
return(result);
}
static void
internal void
html_render_section_header(String *out, String section_name, String section_id, Section_Counter *section_counter){
if (section_counter->nest_level <= 1){
if (section_id.size > 0){
@ -603,8 +599,8 @@ html_render_section_header(String *out, String section_name, String section_id,
#define HTML_WIDTH 800
static void
write_enriched_text_html(String *out, Partition *part, Enriched_Text *text, Document_System *doc_system, Section_Counter *section_counter){
internal void
write_enriched_text_html(String *out, Enriched_Text *text, Document_System *doc_system, Section_Counter *section_counter){
String source = text->source;
append_sc(out, "<div>");
@ -675,7 +671,7 @@ write_enriched_text_html(String *out, Partition *part, Enriched_Text *text, Docu
Cmd_COUNT,
};
static String enriched_commands[Cmd_COUNT];
local_persist String enriched_commands[Cmd_COUNT];
enriched_commands[Cmd_BackSlash] = make_lit_string("\\");
enriched_commands[Cmd_Version] = make_lit_string("VERSION");
@ -854,7 +850,7 @@ write_enriched_text_html(String *out, Partition *part, Enriched_Text *text, Docu
char space[256];
if (img_get_link_string(img_lookup, space, sizeof(space), pixel_width, pixel_height)){
append_sc(out, space);
add_image_instantiation(part, &img_lookup->img_instantiations, pixel_width, pixel_height);
add_image_instantiation(&img_lookup->img_instantiations, pixel_width, pixel_height);
}
else{
NotImplemented;
@ -918,7 +914,7 @@ write_enriched_text_html(String *out, Partition *part, Enriched_Text *text, Docu
append_sc(out, "</div>");
}
static void
internal void
print_item_in_list(String *out, String name, char *id_postfix){
append_sc(out, "<li><a href='#");
append_ss(out, name);
@ -928,14 +924,14 @@ print_item_in_list(String *out, String name, char *id_postfix){
append_sc(out, "</a></li>");
}
static void
init_used_links(Partition *part, Used_Links *used, i32 count){
used->strs = push_array(part, String, count);
internal void
init_used_links(Used_Links *used, i32 count){
used->strs = fm_push_array(String, count);
used->count = 0;
used->max = count;
}
static i32
internal i32
try_to_use(Used_Links *used, String str){
i32 result = 1;
i32 index = 0;
@ -950,7 +946,7 @@ try_to_use(Used_Links *used, String str){
return(result);
}
static void
internal void
print_struct_html(String *out, Item_Node *member, i32 hide_children){
String name = member->name;
String type = member->type;
@ -984,7 +980,7 @@ print_struct_html(String *out, Item_Node *member, i32 hide_children){
}
}
static void
internal void
print_function_html(String *out, Used_Links *used, String cpp_name, String ret, char *function_call_head, String name, Argument_Breakdown breakdown){
append_ss (out, ret);
@ -1015,7 +1011,7 @@ print_function_html(String *out, Used_Links *used, String cpp_name, String ret,
}
}
static void
internal void
print_macro_html(String *out, String name, Argument_Breakdown breakdown){
append_sc (out, "#define ");
@ -1051,12 +1047,12 @@ enum Doc_Chunk_Type{
DocChunk_Count
};
static String doc_chunk_headers[] = {
global String doc_chunk_headers[] = {
make_lit_string(""),
make_lit_string("CODE_EXAMPLE"),
};
static String
internal String
get_next_doc_chunk(String source, String prev_chunk, Doc_Chunk_Type *type){
String chunk = {0};
String word = {0};
@ -1121,15 +1117,15 @@ get_next_doc_chunk(String source, String prev_chunk, Doc_Chunk_Type *type){
return(chunk);
}
static String
internal String
get_first_doc_chunk(String source, Doc_Chunk_Type *type){
String start_str = make_string(source.str, 0);
String chunk = get_next_doc_chunk(source, start_str, type);
return(chunk);
}
static void
print_doc_description(String *out, Partition *part, String src){
internal void
print_doc_description(String *out, String src){
Doc_Chunk_Type type;
for (String chunk = get_first_doc_chunk(src, &type);
@ -1191,19 +1187,19 @@ print_doc_description(String *out, Partition *part, String src){
}
}
static void
print_struct_docs(String *out, Partition *part, Item_Node *member){
internal void
print_struct_docs(String *out, Item_Node *member){
for (Item_Node *member_iter = member->first_child;
member_iter != 0;
member_iter = member_iter->next_sibling){
String type = member_iter->type;
if (match_ss(type, make_lit_string("struct")) ||
match_ss(type, make_lit_string("union"))){
print_struct_docs(out, part, member_iter);
print_struct_docs(out, member_iter);
}
else{
Documentation doc = {0};
perform_doc_parse(part, member_iter->doc_string, &doc);
perform_doc_parse(member_iter->doc_string, &doc);
append_sc(out, "<div>");
@ -1212,7 +1208,7 @@ print_struct_docs(String *out, Partition *part, Item_Node *member){
append_sc(out, HTML_DOC_ITEM_HEAD_INL_CLOSE"</div>");
append_sc(out, "<div style='margin-bottom: 6mm;'>"HTML_DOC_ITEM_OPEN);
print_doc_description(out, part, doc.main_doc);
print_doc_description(out, doc.main_doc);
append_sc(out, HTML_DOC_ITEM_CLOSE"</div>");
append_sc(out, "</div>");
@ -1220,7 +1216,7 @@ print_struct_docs(String *out, Partition *part, Item_Node *member){
}
}
static void
internal void
print_see_also(String *out, Documentation *doc){
i32 doc_see_count = doc->see_also_count;
if (doc_see_count > 0){
@ -1237,18 +1233,18 @@ print_see_also(String *out, Documentation *doc){
}
}
static void
print_function_docs(String *out, Partition *part, String name, String doc_string){
internal void
print_function_docs(String *out, String name, String doc_string){
if (doc_string.size == 0){
append_sc(out, "No documentation generated for this function.");
fprintf(stderr, "warning: no documentation string for %.*s\n", name.size, name.str);
}
Temp_Memory temp = begin_temp_memory(part);
Temp temp = fm_begin_temp();
Documentation doc = {0};
perform_doc_parse(part, doc_string, &doc);
perform_doc_parse(doc_string, &doc);
i32 doc_param_count = doc.param_count;
if (doc_param_count > 0){
@ -1279,18 +1275,18 @@ print_function_docs(String *out, Partition *part, String name, String doc_string
String main_doc = doc.main_doc;
if (main_doc.size != 0){
append_sc(out, HTML_DOC_HEAD_OPEN"Description"HTML_DOC_HEAD_CLOSE HTML_DOC_ITEM_OPEN);
print_doc_description(out, part, main_doc);
print_doc_description(out, main_doc);
append_sc(out, HTML_DOC_ITEM_CLOSE);
}
print_see_also(out, &doc);
end_temp_memory(temp);
fm_end_temp(temp);
}
static void
print_item_html(String *out, Partition *part, Used_Links *used, Item_Node *item, char *id_postfix, char *section, i32 I, Alternate_Name *alt_name, i32 alt_name_type){
Temp_Memory temp = begin_temp_memory(part);
internal void
print_item_html(String *out, Used_Links *used, Item_Node *item, char *id_postfix, char *section, i32 I, Alternate_Name *alt_name, i32 alt_name_type){
Temp temp = fm_begin_temp();
String name = item->name;
@ -1347,7 +1343,7 @@ print_item_html(String *out, Partition *part, Used_Links *used, Item_Node *item,
append_sc(out, "</div>");
// NOTE(allen): Descriptive section
print_function_docs(out, part, name, item->doc_string);
print_function_docs(out, name, item->doc_string);
}break;
case Item_Macro:
@ -1359,7 +1355,7 @@ print_item_html(String *out, Partition *part, Used_Links *used, Item_Node *item,
append_sc(out, "</div>");
// NOTE(allen): Descriptive section
print_function_docs(out, part, name, item->doc_string);
print_function_docs(out, name, item->doc_string);
}break;
case Item_Typedef:
@ -1379,14 +1375,14 @@ print_item_html(String *out, Partition *part, Used_Links *used, Item_Node *item,
// NOTE(allen): Descriptive section
String doc_string = item->doc_string;
Documentation doc = {0};
perform_doc_parse(part, doc_string, &doc);
perform_doc_parse(doc_string, &doc);
String main_doc = doc.main_doc;
if (main_doc.size != 0){
append_sc(out, HTML_DOC_HEAD_OPEN"Description"HTML_DOC_HEAD_CLOSE);
append_sc(out, HTML_DOC_ITEM_OPEN);
print_doc_description(out, part, main_doc);
print_doc_description(out, main_doc);
append_sc(out, HTML_DOC_ITEM_CLOSE);
}
else{
@ -1410,14 +1406,14 @@ print_item_html(String *out, Partition *part, Used_Links *used, Item_Node *item,
// NOTE(allen): Descriptive section
String doc_string = item->doc_string;
Documentation doc = {0};
perform_doc_parse(part, doc_string, &doc);
perform_doc_parse(doc_string, &doc);
String main_doc = doc.main_doc;
if (main_doc.size != 0){
append_sc(out, HTML_DOC_HEAD_OPEN"Description"HTML_DOC_HEAD_CLOSE);
append_sc(out, HTML_DOC_ITEM_OPEN);
print_doc_description(out, part, main_doc);
print_doc_description(out, main_doc);
append_sc(out, HTML_DOC_ITEM_CLOSE);
}
else{
@ -1431,7 +1427,7 @@ print_item_html(String *out, Partition *part, Used_Links *used, Item_Node *item,
member;
member = member->next_sibling){
Documentation doc = {0};
perform_doc_parse(part, member->doc_string, &doc);
perform_doc_parse(member->doc_string, &doc);
append_sc(out, "<div>");
@ -1448,7 +1444,7 @@ print_item_html(String *out, Partition *part, Used_Links *used, Item_Node *item,
append_sc(out, "</span></div>");
append_sc(out, "<div style='margin-bottom: 6mm;'>"HTML_DOC_ITEM_OPEN);
print_doc_description(out, part, doc.main_doc);
print_doc_description(out, doc.main_doc);
append_sc(out, HTML_DOC_ITEM_CLOSE"</div>");
append_sc(out, "</div>");
@ -1488,14 +1484,14 @@ print_item_html(String *out, Partition *part, Used_Links *used, Item_Node *item,
// NOTE(allen): Descriptive section
{
Documentation doc = {0};
perform_doc_parse(part, doc_string, &doc);
perform_doc_parse(doc_string, &doc);
String main_doc = doc.main_doc;
if (main_doc.size != 0){
append_sc(out, HTML_DOC_HEAD_OPEN"Description"HTML_DOC_HEAD_CLOSE);
append_sc(out, HTML_DOC_ITEM_OPEN);
print_doc_description(out, part, main_doc);
print_doc_description(out, main_doc);
append_sc(out, HTML_DOC_ITEM_CLOSE);
}
else{
@ -1505,7 +1501,7 @@ print_item_html(String *out, Partition *part, Used_Links *used, Item_Node *item,
if (!hide_members){
if (item->first_child){
append_sc(out, HTML_DOC_HEAD_OPEN"Fields"HTML_DOC_HEAD_CLOSE);
print_struct_docs(out, part, item);
print_struct_docs(out, item);
}
}
@ -1521,11 +1517,11 @@ print_item_html(String *out, Partition *part, Used_Links *used, Item_Node *item,
// NOTE(allen): Close the item box
append_sc(out, "</div><hr>");
end_temp_memory(temp);
fm_end_temp(temp);
}
static void
doc_item_head_html(String *out, Partition *part, Document_System *doc_system, Used_Links *used_links, Document_Item *item, Section_Counter *section_counter){
internal void
doc_item_head_html(String *out, Document_System *doc_system, Used_Links *used_links, Document_Item *item, Section_Counter *section_counter){
switch (item->type){
case Doc_Root:
{
@ -1610,7 +1606,7 @@ doc_item_head_html(String *out, Partition *part, Document_System *doc_system, Us
case Doc_Enriched_Text:
{
write_enriched_text_html(out, part, item->text.text, doc_system, section_counter);
write_enriched_text_html(out, item->text.text, doc_system, section_counter);
}break;
case Doc_Element_List:
@ -1661,13 +1657,13 @@ doc_item_head_html(String *out, Partition *part, Document_System *doc_system, Us
if (alt_names){
i32 I = 1;
for (i32 i = 0; i < count; ++i, ++I){
print_item_html(out, part, used_links, &unit->set.items[i], "_doc", section_str.str, I, &alt_names->names[i], item->unit_elements.alt_name_type);
print_item_html(out, used_links, &unit->set.items[i], "_doc", section_str.str, I, &alt_names->names[i], item->unit_elements.alt_name_type);
}
}
else{
i32 I = 1;
for (i32 i = 0; i < count; ++i, ++I){
print_item_html(out, part, used_links, &unit->set.items[i], "_doc", section_str.str, I, 0, 0);
print_item_html(out, used_links, &unit->set.items[i], "_doc", section_str.str, I, 0, 0);
}
}
}break;
@ -1702,8 +1698,8 @@ doc_item_head_html(String *out, Partition *part, Document_System *doc_system, Us
}
}
static void
doc_item_foot_html(String *out, Partition *part, Document_System *doc_system, Used_Links *used_links, Document_Item *item, Section_Counter *section_counter){
internal void
doc_item_foot_html(String *out, Document_System *doc_system, Used_Links *used_links, Document_Item *item, Section_Counter *section_counter){
switch (item->type){
case Doc_Root:
{
@ -1716,9 +1712,9 @@ doc_item_foot_html(String *out, Partition *part, Document_System *doc_system, Us
}
}
static void
generate_item_html(String *out, Partition *part, Document_System *doc_system, Used_Links *used_links, Document_Item *item, Section_Counter *section_counter){
doc_item_head_html(out, part, doc_system, used_links, item, section_counter);
internal void
generate_item_html(String *out, Document_System *doc_system, Used_Links *used_links, Document_Item *item, Section_Counter *section_counter){
doc_item_head_html(out, doc_system, used_links, item, section_counter);
if (item->type == Doc_Root || item->type == Doc_Section){
i32 level = ++section_counter->nest_level;
@ -1726,25 +1722,25 @@ generate_item_html(String *out, Partition *part, Document_System *doc_system, Us
for (Document_Item *m = item->section.first_child;
m != 0;
m = m->next){
generate_item_html(out, part, doc_system, used_links, m, section_counter);
generate_item_html(out, doc_system, used_links, m, section_counter);
}
--section_counter->nest_level;
++section_counter->counter[section_counter->nest_level];
}
doc_item_foot_html(out, part, doc_system, used_links, item, section_counter);
doc_item_foot_html(out, doc_system, used_links, item, section_counter);
}
static void
generate_document_html(String *out, Partition *part, Document_System *doc_system, Abstract_Item *doc){
assert(doc->root_item != 0);
internal void
generate_document_html(String *out, Document_System *doc_system, Abstract_Item *doc){
Assert(doc->root_item != 0);
Used_Links used_links = {0};
init_used_links(part, &used_links, 4000);
init_used_links(&used_links, 4000);
Section_Counter section_counter = {0};
section_counter.counter[section_counter.nest_level] = 1;
generate_item_html(out, part, doc_system, &used_links, doc->root_item, &section_counter);
generate_item_html(out, doc_system, &used_links, doc->root_item, &section_counter);
}
// BOTTOM

View File

@ -23,14 +23,15 @@
#include "../4ed_defines.h"
#include "../meta/4ed_meta_defines.h"
#include "../4coder_API/version.h"
#define FSTRING_IMPLEMENTATION
#include "../4coder_lib/4coder_string.h"
#include "../4coder_lib/4coder_mem.h"
#include "../4cpp/4cpp_lexer.h"
#define FTECH_FILE_MOVING_IMPLEMENTATION
#include "../meta/4ed_file_moving.h"
#include "../meta/4ed_meta_parser.cpp"
#include "../meta/4ed_meta_keywords.h"
#include "../meta/4ed_out_context.cpp"
#include "4ed_abstract_document.cpp"
@ -89,13 +90,13 @@ print_function_body_code(String *out, Parse_Context *context, i32 start){
}
static void
do_html_output(Document_System *doc_system, Partition *part, char *dst_directory, Abstract_Item *doc){
do_html_output(Document_System *doc_system, char *dst_directory, Abstract_Item *doc){
// NOTE(allen): Output
i32 out_size = 10 << 20;
Tail_Temp_Partition temp = begin_tail_part(part, out_size);
void *mem = malloc(out_size);
Assert(mem != 0);
String out = make_string_cap(mem, 0, out_size);
String out = str_alloc(&temp.part, out_size);
assert(out.str);
Out_Context context = {0};
set_context_directory(&context, dst_directory);
@ -103,7 +104,7 @@ do_html_output(Document_System *doc_system, Partition *part, char *dst_directory
char space[256];
if (doc_get_link_string(doc, space, sizeof(space))){
if (begin_file_out(&context, space, &out)){
generate_document_html(&out, part, doc_system, doc);
generate_document_html(&out, doc_system, doc);
end_file_out(context);
}
else{
@ -111,13 +112,13 @@ do_html_output(Document_System *doc_system, Partition *part, char *dst_directory
}
}
end_tail_part(temp);
free(mem);
}
static Abstract_Item*
generate_homepage(Document_System *doc_system, Partition *part, char *src_directory){
Enriched_Text *home = push_struct(part, Enriched_Text);
*home = load_enriched_text(part, src_directory, "home.txt");
generate_homepage(Document_System *doc_system, char *src_directory){
Enriched_Text *home = fm_push_array(Enriched_Text, 1);
*home = load_enriched_text(src_directory, "home.txt");
Abstract_Item *doc = begin_document_description(doc_system, "4coder Home", "home", 0);
add_enriched_text(doc, home);
@ -128,49 +129,38 @@ generate_homepage(Document_System *doc_system, Partition *part, char *src_direct
// TODO(allen): replace the documentation declaration system with a straight up enriched text system
static Abstract_Item*
generate_4coder_docs(Document_System *doc_system, Partition *part, char *code_directory, char *src_directory){
static Meta_Keywords meta_keywords[] = {
{make_lit_string("API_EXPORT") , Item_Function } ,
{make_lit_string("API_EXPORT_INLINE") , Item_Function } ,
{make_lit_string("API_EXPORT_MACRO") , Item_Macro } ,
{make_lit_string("CPP_NAME") , Item_CppName } ,
{make_lit_string("TYPEDEF") , Item_Typedef } ,
{make_lit_string("STRUCT") , Item_Struct } ,
{make_lit_string("UNION") , Item_Union } ,
{make_lit_string("ENUM") , Item_Enum } ,
};
generate_4coder_docs(Document_System *doc_system, char *code_directory, char *src_directory){
#define ExpandArray(a) (a), (ArrayCount(a))
Meta_Unit *custom_types_unit = push_struct(part, Meta_Unit);
Meta_Unit *lexer_funcs_unit = push_struct(part, Meta_Unit);
Meta_Unit *lexer_types_unit = push_struct(part, Meta_Unit);
Meta_Unit *string_unit = push_struct(part, Meta_Unit);
Meta_Unit *custom_funcs_unit = push_struct(part, Meta_Unit);
Meta_Unit *custom_types_unit = fm_push_array(Meta_Unit, 1);
Meta_Unit *lexer_funcs_unit = fm_push_array(Meta_Unit, 1);
Meta_Unit *lexer_types_unit = fm_push_array(Meta_Unit, 1);
Meta_Unit *string_unit = fm_push_array(Meta_Unit, 1);
Meta_Unit *custom_funcs_unit = fm_push_array(Meta_Unit, 1);
Enriched_Text *introduction = push_struct(part, Enriched_Text);
Enriched_Text *lexer_introduction = push_struct(part, Enriched_Text);
Enriched_Text *introduction = fm_push_array(Enriched_Text, 1);
Enriched_Text *lexer_introduction = fm_push_array(Enriched_Text, 1);
// NOTE(allen): Parse the code.
*custom_types_unit = compile_meta_unit(part, code_directory, "4coder_API/types.h", ExpandArray(meta_keywords));
*custom_types_unit = compile_meta_unit(code_directory, "4coder_API/types.h", ExpandArray(meta_keywords));
Assert(custom_types_unit->count != 0);
*lexer_funcs_unit = compile_meta_unit(part, code_directory, "4cpp/4cpp_lexer.h", ExpandArray(meta_keywords));
*lexer_funcs_unit = compile_meta_unit(code_directory, "4cpp/4cpp_lexer.h", ExpandArray(meta_keywords));
Assert(lexer_funcs_unit->count != 0);
*lexer_types_unit = compile_meta_unit(part, code_directory, "4cpp/4cpp_lexer_types.h", ExpandArray(meta_keywords));
*lexer_types_unit = compile_meta_unit(code_directory, "4cpp/4cpp_lexer_types.h", ExpandArray(meta_keywords));
Assert(lexer_types_unit->count != 0);
*string_unit = compile_meta_unit(part, code_directory, "string/internal_4coder_string.cpp", ExpandArray(meta_keywords));
*string_unit = compile_meta_unit(code_directory, "string/internal_4coder_string.cpp", ExpandArray(meta_keywords));
Assert(string_unit->count != 0);
*custom_funcs_unit = compile_meta_unit(part, code_directory, "4ed_api_implementation.cpp", ExpandArray(meta_keywords));
*custom_funcs_unit = compile_meta_unit(code_directory, "4ed_api_implementation.cpp", ExpandArray(meta_keywords));
Assert(custom_funcs_unit->count != 0);
// NOTE(allen): Compute and store variations of the custom function names
Alternate_Names_Array *custom_func_names = push_struct(part, Alternate_Names_Array);
Alternate_Names_Array *custom_func_names = fm_push_array(Alternate_Names_Array, 1);
i32 name_count = custom_funcs_unit->set.count;
custom_func_names->names = push_array(part, Alternate_Name, name_count);
custom_func_names->names = fm_push_array(Alternate_Name, name_count);
memset(custom_func_names->names, 0, sizeof(*custom_func_names->names)*name_count);
for (i32 i = 0; i < custom_funcs_unit->set.count; ++i){
@ -178,19 +168,19 @@ generate_4coder_docs(Document_System *doc_system, Partition *part, char *code_di
String *macro = &custom_func_names->names[i].macro;
String *public_name = &custom_func_names->names[i].public_name;
*macro = str_alloc(part, name_string.size+4);
*macro = str_alloc(name_string.size+4);
to_upper_ss(macro, name_string);
append_ss(macro, make_lit_string("_SIG"));
*public_name = str_alloc(part, name_string.size);
*public_name = str_alloc(name_string.size);
to_lower_ss(public_name, name_string);
partition_align(part, 4);
fm_align();
}
// NOTE(allen): Load enriched text materials
*introduction = load_enriched_text(part, src_directory, "introduction.txt");
*lexer_introduction = load_enriched_text(part, src_directory, "lexer_introduction.txt");
*introduction = load_enriched_text(src_directory, "introduction.txt");
*lexer_introduction = load_enriched_text(src_directory, "lexer_introduction.txt");
// NOTE(allen): Put together the abstract document
Abstract_Item *doc = begin_document_description(doc_system, "4coder API Docs", "custom_docs", 1);
@ -262,9 +252,9 @@ generate_4coder_docs(Document_System *doc_system, Partition *part, char *code_di
}
static Abstract_Item*
generate_feature_list(Document_System *doc_system, Partition *part, char *src_directory){
Enriched_Text *feature_list = push_struct(part, Enriched_Text);
*feature_list = load_enriched_text(part, src_directory, "feature_list.txt");
generate_feature_list(Document_System *doc_system, char *src_directory){
Enriched_Text *feature_list = fm_push_array(Enriched_Text, 1);
*feature_list = load_enriched_text(src_directory, "feature_list.txt");
Abstract_Item *doc = begin_document_description(doc_system, "4coder Feature List", "features", 0);
add_enriched_text(doc, feature_list);
@ -274,9 +264,9 @@ generate_feature_list(Document_System *doc_system, Partition *part, char *src_di
}
static Abstract_Item*
generate_binding_list(Document_System *doc_system, Partition *part, char *src_directory){
Enriched_Text *binding_list = push_struct(part, Enriched_Text);
*binding_list = load_enriched_text(part, src_directory, "binding_list.txt");
generate_binding_list(Document_System *doc_system, char *src_directory){
Enriched_Text *binding_list = fm_push_array(Enriched_Text, 1);
*binding_list = load_enriched_text(src_directory, "binding_list.txt");
Abstract_Item *doc = begin_document_description(doc_system, "4coder Binding List", "bindings", 0);
add_enriched_text(doc, binding_list);
@ -286,9 +276,9 @@ generate_binding_list(Document_System *doc_system, Partition *part, char *src_di
}
static Abstract_Item*
generate_roadmap(Document_System *doc_system, Partition *part, char *src_directory){
Enriched_Text *roadmap = push_struct(part, Enriched_Text);
*roadmap = load_enriched_text(part, src_directory, "roadmap.txt");
generate_roadmap(Document_System *doc_system, char *src_directory){
Enriched_Text *roadmap = fm_push_array(Enriched_Text, 1);
*roadmap = load_enriched_text(src_directory, "roadmap.txt");
Abstract_Item *doc = begin_document_description(doc_system, "4coder Roadmap", "roadmap", 0);
add_enriched_text(doc, roadmap);
@ -298,9 +288,9 @@ generate_roadmap(Document_System *doc_system, Partition *part, char *src_directo
}
static Abstract_Item*
generate_tutorials(Document_System *doc_system, Partition *part, char *src_directory){
Enriched_Text *roadmap = push_struct(part, Enriched_Text);
*roadmap = load_enriched_text(part, src_directory, "tutorials.txt");
generate_tutorials(Document_System *doc_system, char *src_directory){
Enriched_Text *roadmap = fm_push_array(Enriched_Text, 1);
*roadmap = load_enriched_text(src_directory, "tutorials.txt");
Abstract_Item *doc = begin_document_description(doc_system, "4coder Tutorials", "tutorials", 0);
add_enriched_text(doc, roadmap);
@ -310,16 +300,16 @@ generate_tutorials(Document_System *doc_system, Partition *part, char *src_direc
}
static String
push_string(Partition *part, i32 size){
push_string(i32 size){
String str = {0};
str.memory_size = size;
str.str = push_array(part, char, size);
partition_align(part, 4);
str.str = fm_push_array(char, size);
fm_align();
return(str);
}
static void
do_image_resize(Partition *part, char *src_file, char *dst_file, char *extension, i32 w, i32 h){
do_image_resize(char *src_file, char *dst_file, char *extension, i32 w, i32 h){
i32 x = 0, y = 0, channels = 0;
stbi_uc *image = stbi_load(src_file, &x, &y, &channels, 0);
@ -336,15 +326,9 @@ do_image_resize(Partition *part, char *src_file, char *dst_file, char *extension
static void
generate_site(char *code_directory, char *asset_directory, char *src_directory, char *dst_directory){
i32 size = (512 << 20);
void *mem = malloc(size);
memset(mem, 0, size);
Partition part_ = make_part(mem, size);
Partition *part = &part_;
String str;
Document_System doc_system = create_document_system(part);
Document_System doc_system = create_document_system();
// TODO(allen): code compression here
struct Site_Asset{
@ -370,7 +354,7 @@ generate_site(char *code_directory, char *asset_directory, char *src_directory,
for (u32 i = 0; i < ArrayCount(asset_list); ++i){
Site_Asset *asset = &asset_list[i];
str = push_string(part, 256);
str = push_string(256);
append_sc(&str, asset_directory);
append_sc(&str, "/");
append_sc(&str, asset->filename);
@ -391,42 +375,36 @@ generate_site(char *code_directory, char *asset_directory, char *src_directory,
}
}
generate_homepage(&doc_system, part, src_directory);
generate_4coder_docs(&doc_system, part, code_directory, src_directory);
generate_feature_list(&doc_system, part, src_directory);
generate_binding_list(&doc_system, part, src_directory);
generate_roadmap(&doc_system, part, src_directory);
generate_tutorials(&doc_system, part, src_directory);
generate_homepage(&doc_system, src_directory);
generate_4coder_docs(&doc_system, code_directory, src_directory);
generate_feature_list(&doc_system, src_directory);
generate_binding_list(&doc_system, src_directory);
generate_roadmap(&doc_system, src_directory);
generate_tutorials(&doc_system, src_directory);
for (Basic_Node *node = doc_system.doc_list.head;
node != 0;
node = node->next){
Abstract_Item *doc = NodeGetData(node, Abstract_Item);
assert(doc->item_type == ItemType_Document);
do_html_output(&doc_system, part, dst_directory, doc);
Assert(doc->item_type == ItemType_Document);
do_html_output(&doc_system, dst_directory, doc);
}
for (Basic_Node *node = doc_system.file_list.head;
node != 0;
node = node->next){
Abstract_Item *file = NodeGetData(node, Abstract_Item);
assert(file->item_type == ItemType_GenericFile);
Assert(file->item_type == ItemType_GenericFile);
char space[256];
String str = make_fixed_width_string(space);
append_sc(&str, file->name);
append_sc(&str, ".");
append_sc(&str, file->extension);
terminate_with_null(&str);
do_file_copy(part, file->source_file, dst_directory, space);
char *file_name = fm_str(file->name, ".", file->extension);
fm_copy_file(fm_str(file_name), fm_str(dst_directory, "/", file_name));
}
for (Basic_Node *node = doc_system.img_list.head;
node != 0;
node = node->next){
Abstract_Item *img = NodeGetData(node, Abstract_Item);
assert(img->item_type == ItemType_Image);
Assert(img->item_type == ItemType_Image);
for (Basic_Node *node = img->img_instantiations.head;
node != 0;
@ -443,7 +421,7 @@ generate_site(char *code_directory, char *asset_directory, char *src_directory,
append_sc(&str, space);
terminate_with_null(&str);
do_image_resize(part, img->source_file, space2, img->extension, inst->w, inst->h);
do_image_resize(img->source_file, space2, img->extension, inst->w, inst->h);
}
}
}
@ -451,6 +429,7 @@ generate_site(char *code_directory, char *asset_directory, char *src_directory,
int main(int argc, char **argv){
META_BEGIN();
fm_init_system();
if (argc == 5){
generate_site(argv[1], argv[2], argv[3], argv[4]);

View File

@ -1,5 +1,5 @@
1
0
93
95

View File

@ -25,11 +25,12 @@
#include "../4ed_defines.h"
#include "../meta/4ed_meta_defines.h"
#define FTECH_FILE_MOVING_IMPLEMENTATION
#include "../meta/4ed_file_moving.h"
#include "../4coder_lib/4coder_mem.h"
#define FTECH_FILE_MOVING_IMPLEMENTATION
#include "../meta/4ed_file_moving.h"
#include "../meta/4ed_meta_parser.cpp"
#include "../meta/4ed_meta_keywords.h"
#include "../meta/4ed_out_context.cpp"
#include <stdlib.h>
@ -42,44 +43,40 @@
#define V_MAJ STR_(V_MAJ_NUM)
#define V_MIN STR_(V_MIN_NUM)
static b32
internal char*
parse_next_line(char *str, char *str_end){
char *ptr = str;
for (; ptr < str_end && *ptr != '\n'; ++ptr);
++ptr;
return(ptr);
}
internal b32
parse_build_number(char *file_name, i32 *major_out, i32 *minor_out, i32 *build_out){
b32 result = false;
String file = file_dump(file_name);
if (file.str != 0){
char *end_str = file.str + file.size;
char *major_str = file.str;
char *minor_str = major_str;
for (; minor_str < end_str && *minor_str != '\n'; ++minor_str);
++minor_str;
*major_out = 0;
*minor_out = 0;
*build_out = 0;
if (major_str < end_str){
char *build_str = minor_str;
for (; build_str < end_str && *build_str != '\n'; ++build_str);
++build_str;
char *end_str = file.str + file.size;
char *major_str = file.str;
char *minor_str = parse_next_line(major_str, end_str);
char *build_str = parse_next_line(minor_str, end_str);
char *ender = parse_next_line(build_str, end_str);
if (major_str < end_str && build_str < end_str && ender < end_str){
minor_str[-1] = 0;
build_str[-1] = 0;
ender[-1] = 0;
if (build_str < end_str){
char *ender = build_str;
for (; ender < end_str && *ender != '\n'; ++ender);
if (ender < end_str){
*ender = 0;
}
minor_str[-1] = 0;
build_str[-1] = 0;
*major_out = str_to_int_c(major_str);
*minor_out = str_to_int_c(minor_str);
*build_out = str_to_int_c(build_str);
result = true;
}
*major_out = str_to_int_c(major_str);
*minor_out = str_to_int_c(minor_str);
*build_out = str_to_int_c(build_str);
result = true;
}
free(file.str);
@ -88,12 +85,10 @@ parse_build_number(char *file_name, i32 *major_out, i32 *minor_out, i32 *build_o
return(result);
}
static void
internal void
save_build_number(char *file_name, i32 major, i32 minor, i32 build){
FILE *out = fopen(file_name, "wb");
fprintf(out, "%d\n", major);
fprintf(out, "%d\n", minor);
fprintf(out, "%d\n\n\n", build);
fprintf(out, "%d\n%d\n%d\n\n\n", major, minor, build);
fclose(out);
}
@ -103,21 +98,21 @@ save_build_number(char *file_name, i32 major, i32 minor, i32 build){
// Meta Parse Rules
//
static void
print_function_body_code(String *out, Parse_Context *context, int32_t start){
internal void
print_function_body_code(String *out, Parse_Context *context, i32 start){
String pstr = {0}, lexeme = {0};
Cpp_Token *token = 0;
int32_t do_print = 0;
int32_t nest_level = 0;
int32_t finish = false;
int32_t do_whitespace_print = false;
int32_t is_first = true;
i32 do_print = 0;
i32 nest_level = 0;
i32 finish = false;
i32 do_whitespace_print = false;
i32 is_first = true;
for (; (token = get_token(context)) != 0; get_next_token(context)){
if (do_whitespace_print){
pstr = str_start_end(context->data, start, token->start);
append_ss(out, pstr);
append(out, pstr);
}
else{
do_whitespace_print = true;
@ -146,7 +141,7 @@ print_function_body_code(String *out, Parse_Context *context, int32_t start){
if (do_print){
pstr = get_lexeme(*token, context->data);
append_ss(out, pstr);
append(out, pstr);
}
start = token->start + token->size;
@ -166,25 +161,12 @@ int main(){
META_BEGIN();
fm_init_system();
fm_init_system();
i32 size = (512 << 20);
void *mem = malloc(size);
memset(mem, 0, size);
Partition part_ = make_part(mem, size);
Partition *part = &part_;
static Meta_Keywords meta_keywords[] = {
{make_lit_string("API_EXPORT") , Item_Function } ,
{make_lit_string("API_EXPORT_INLINE") , Item_Function } ,
{make_lit_string("API_EXPORT_MACRO") , Item_Macro } ,
{make_lit_string("CPP_NAME") , Item_CppName } ,
{make_lit_string("TYPEDEF") , Item_Typedef } ,
{make_lit_string("STRUCT") , Item_Struct } ,
{make_lit_string("UNION") , Item_Union } ,
{make_lit_string("ENUM") , Item_Enum } ,
};
//Partition *part = &part_;
// NOTE(allen): Parse the internal string file.
char *string_files[] = { INTERNAL_STRING, 0 };
@ -226,7 +208,7 @@ int main(){
// NOTE(allen): String Library
if (begin_file_out(&context, GENERATED_FILE, &out)){
Cpp_Token *token = 0;
int32_t start = 0;
i32 start = 0;
Parse parse = string_unit.parse[0];
Parse_Context pcontext = setup_parse_context(parse);
@ -235,33 +217,33 @@ int main(){
if (!(token->flags & CPP_TFLAG_PP_BODY) &&
token->type == CPP_TOKEN_IDENTIFIER){
String lexeme = get_lexeme(*token, pcontext.data);
if (match_ss(lexeme, make_lit_string("FSTRING_BEGIN"))){
if (match(lexeme, "FSTRING_BEGIN")){
start = token->start + token->size;
break;
}
}
}
append_sc(&out, "/*\n");
append(&out, "/*\n");
append_sc(&out, GENERATED_FILE " - Version "V_MAJ"."V_MIN".");
append(&out, GENERATED_FILE " - Version "V_MAJ"."V_MIN".");
append_int_to_str(&out, build_number);
append_sc(&out, "\n");
append(&out, "\n");
append_sc(&out, STANDARD_DISCLAIMER);
append_sc(&out,
"To include implementation: #define FSTRING_IMPLEMENTATION\n"
"To use in C mode: #define FSTRING_C\n");
append(&out, STANDARD_DISCLAIMER);
append(&out,
"To include implementation: #define FSTRING_IMPLEMENTATION\n"
"To use in C mode: #define FSTRING_C\n");
append_sc(&out, "*/\n");
append(&out, "*/\n");
String pstr = {0};
int32_t do_whitespace_print = true;
i32 do_whitespace_print = true;
for(;(token = get_next_token(&pcontext)) != 0;){
if (do_whitespace_print){
pstr = str_start_end(pcontext.data, start, token->start);
append_ss(&out, pstr);
append(&out, pstr);
}
else{
do_whitespace_print = true;
@ -269,56 +251,56 @@ int main(){
String lexeme = get_lexeme(*token, pcontext.data);
int32_t do_print = true;
if (match_ss(lexeme, make_lit_string("FSTRING_DECLS"))){
append_sc(&out, "#if !defined(FCODER_STRING_H)\n#define FCODER_STRING_H\n\n");
i32 do_print = true;
if (match(lexeme, "FSTRING_DECLS")){
append(&out, "#if !defined(FCODER_STRING_H)\n#define FCODER_STRING_H\n\n");
do_print = false;
static int32_t RETURN_PADDING = 16;
static int32_t SIG_PADDING = 35;
local_persist i32 RETURN_PADDING = 16;
local_persist i32 SIG_PADDING = 35;
for (int32_t j = 0; j < string_unit.set.count; ++j){
for (i32 j = 0; j < string_unit.set.count; ++j){
char line_[2048];
String line = make_fixed_width_string(line_);
Item_Node *item = string_unit.set.items + j;
if (item->t == Item_Function){
append_ss (&line, item->ret);
append (&line, item->ret);
append_padding (&line, ' ', SIG_PADDING);
append_ss (&line, item->name);
append_ss (&line, item->args);
append_sc (&line, ";\n");
append (&line, item->name);
append (&line, item->args);
append (&line, ";\n");
}
else if (item->t == Item_Macro){
append_ss (&line, make_lit_string("#ifndef "));
append (&line, "#ifndef ");
append_padding (&line, ' ', 10);
append_ss (&line, item->name);
append (&line, item->name);
append_s_char (&line, '\n');
append_ss (&line, make_lit_string("# define "));
append (&line, "# define ");
append_padding (&line, ' ', 10);
append_ss (&line, item->name);
append_ss (&line, item->args);
append (&line, item->name);
append (&line, item->args);
append_s_char (&line, ' ');
append_ss (&line, item->body);
append (&line, item->body);
append_s_char (&line, '\n');
append_ss (&line, make_lit_string("#endif"));
append (&line, "#endif");
append_s_char (&line, '\n');
}
else{
InvalidCodePath;
}
append_ss(&out, line);
append(&out, line);
}
append_sc(&out, "\n#endif\n");
append(&out, "\n#endif\n");
// NOTE(allen): C++ overload definitions
append_sc(&out, "\n#if !defined(FSTRING_C) && !defined(FSTRING_GUARD)\n\n");
append(&out, "\n#if !defined(FSTRING_C) && !defined(FSTRING_GUARD)\n\n");
for (int32_t j = 0; j < string_unit.set.count; ++j){
for (i32 j = 0; j < string_unit.set.count; ++j){
char line_space[2048];
String line = make_fixed_width_string(line_space);
@ -329,42 +311,42 @@ int main(){
if (cpp_name.str != 0){
Argument_Breakdown breakdown = item->breakdown;
append_ss (&line, item->ret);
append (&line, item->ret);
append_padding(&line, ' ', SIG_PADDING);
append_ss (&line, cpp_name);
append_ss (&line, item->args);
if (match_ss(item->ret, make_lit_string("void"))){
append_ss(&line, make_lit_string("{("));
append (&line, cpp_name);
append (&line, item->args);
if (match(item->ret, "void")){
append(&line, "{(");
}
else{
append_ss(&line, make_lit_string("{return("));
append(&line, "{return(");
}
append_ss (&line, item->name);
append (&line, item->name);
append_s_char(&line, '(');
if (breakdown.count > 0){
for (int32_t i = 0; i < breakdown.count; ++i){
for (i32 i = 0; i < breakdown.count; ++i){
if (i != 0){
append_s_char(&line, ',');
}
append_ss(&line, breakdown.args[i].param_name);
append(&line, breakdown.args[i].param_name);
}
}
else{
append_ss(&line, make_lit_string("void"));
append(&line, "void");
}
append_ss(&line, make_lit_string("));}\n"));
append(&line, "));}\n");
append_ss(&out, line);
append(&out, line);
}
}
}
append_sc(&out, "\n#endif\n");
append(&out, "\n#endif\n");
}
else if (match_ss(lexeme, make_lit_string("API_EXPORT_MACRO"))){
else if (match(lexeme, "API_EXPORT_MACRO")){
token = get_next_token(&pcontext);
if (token && token->type == CPP_TOKEN_COMMENT){
token = get_next_token(&pcontext);
@ -383,24 +365,23 @@ int main(){
}
}
else if (match_ss(lexeme, make_lit_string("API_EXPORT")) ||
match_ss(lexeme, make_lit_string("API_EXPORT_INLINE"))){
else if (match(lexeme, "API_EXPORT") || match(lexeme, "API_EXPORT_INLINE")){
if (!(token->flags & CPP_TFLAG_PP_BODY)){
if (match_ss(lexeme, make_lit_string("API_EXPORT_INLINE"))){
append_sc(&out, "#if !defined(FSTRING_GUARD)\n");
if (match(lexeme, "API_EXPORT_INLINE")){
append(&out, "#if !defined(FSTRING_GUARD)\n");
}
else{
append_sc(&out, "#if defined(FSTRING_IMPLEMENTATION)\n");
append(&out, "#if defined(FSTRING_IMPLEMENTATION)\n");
}
print_function_body_code(&out, &pcontext, start);
append_sc(&out, "\n#endif");
append(&out, "\n#endif");
do_print = false;
}
}
else if (match_ss(lexeme, make_lit_string("CPP_NAME"))){
else if (match(lexeme, "CPP_NAME")){
Cpp_Token *token_start = token;
int32_t has_cpp_name = false;
i32 has_cpp_name = false;
token = get_next_token(&pcontext);
if (token && token->type == CPP_TOKEN_PARENTHESE_OPEN){
@ -434,18 +415,18 @@ int main(){
char space[512];
String str = make_fixed_width_string(space);
append_ss(&str, lexeme);
append(&str, lexeme);
terminate_with_null(&str);
String dump = file_dump(str.str);
if (dump.str){
append_ss(&out, dump);
append(&out, dump);
}
else{
lexeme.size += 2;
lexeme.str -= 1;
append_sc(&out, "#error Could not find ");
append_ss(&out, lexeme);
append_sc(&out, "\n");
append(&out, "#error Could not find ");
append(&out, lexeme);
append(&out, "\n");
}
free(dump.str);
}
@ -456,13 +437,13 @@ int main(){
if ((token = get_token(&pcontext)) != 0){
if (do_print){
pstr = get_lexeme(*token, pcontext.data);
append_ss(&out, pstr);
append(&out, pstr);
}
start = token->start + token->size;
}
}
pstr = str_start_end(pcontext.data, start, parse.code.size);
append_ss(&out, pstr);
append(&out, pstr);
end_file_out(context);
}