almost removed out context completely

master
Allen Webster 2017-07-10 13:05:30 -04:00
parent bd090a2504
commit b3c40ba79b
5 changed files with 544 additions and 630 deletions

View File

@ -15,12 +15,12 @@
#define API_H "4coder_API/app_functions.h" #define API_H "4coder_API/app_functions.h"
#define OS_API_H "4ed_os_custom_api.h" #define OS_API_H "4ed_os_custom_api.h"
#include "../4ed_defines.h"
#include "4ed_meta_defines.h" #include "4ed_meta_defines.h"
#include "../4coder_API/version.h" #include "../4coder_API/version.h"
#define FSTRING_IMPLEMENTATION #define FSTRING_IMPLEMENTATION
#include "../4coder_lib/4coder_string.h" #include "../4coder_lib/4coder_string.h"
//#include "../4coder_lib/4coder_mem.h"
#include "../4cpp/4cpp_lexer.h" #include "../4cpp/4cpp_lexer.h"
@ -75,18 +75,17 @@ char *keys_that_need_codes[] = {
internal void internal void
generate_keycode_enum(){ generate_keycode_enum(){
Temp temp = fm_begin_temp();
char *filename_keycodes = KEYCODES_FILE; char *filename_keycodes = KEYCODES_FILE;
uint16_t code = 0xD800; u16 code = 0xD800;
String out = str_alloc(10 << 20);
String out = make_out_string(10 << 20); i32 count = ArrayCount(keys_that_need_codes);
Out_Context context = {0};
if (begin_file_out(&context, filename_keycodes, &out)){
int32_t count = ArrayCount(keys_that_need_codes);
append(&out, "enum{\n"); append(&out, "enum{\n");
for (int32_t i = 0; i < count;){ for (i32 i = 0; i < count;){
append(&out, "key_"); append(&out, "key_");
append(&out, keys_that_need_codes[i++]); append(&out, keys_that_need_codes[i++]);
append(&out, " = "); append(&out, " = ");
@ -101,7 +100,7 @@ generate_keycode_enum(){
"char *result = 0;\n" "char *result = 0;\n"
"switch(key_code){\n"); "switch(key_code){\n");
for (int32_t i = 0; i < count; ++i){ for (i32 i = 0; i < count; ++i){
append(&out, "case key_"); append(&out, "case key_");
append(&out, keys_that_need_codes[i]); append(&out, keys_that_need_codes[i]);
append(&out, ": result = \""); append(&out, ": result = \"");
@ -116,26 +115,27 @@ generate_keycode_enum(){
"return(result);\n" "return(result);\n"
"}\n"); "}\n");
end_file_out(context); end_file_out(filename_keycodes, &out);
}
fm_end_temp(temp);
} }
////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////
static void internal void
struct_begin(String *str, char *name){ struct_begin(String *str, char *name){
append(str, "struct "); append(str, "struct ");
append(str, name); append(str, name);
append(str, "{\n"); //} append(str, "{\n"); //}
} }
static void internal void
enum_begin(String *str, char *name){ enum_begin(String *str, char *name){
append(str, "enum "); append(str, "enum ");
append(str, name); append(str, name);
append(str, "{\n"); //} append(str, "{\n"); //}
} }
static void internal void
struct_end(String *str){ //{ struct_end(String *str){ //{
append(str, "};\n\n"); append(str, "};\n\n");
} }
@ -180,47 +180,40 @@ static char* main_style_fields[] = {
"next_undo", "next_undo",
}; };
static char* internal char*
make_style_tag(char *tag){ make_style_tag(char *tag){
char *str; i32 len = (i32)strlen(tag);
int32_t len; char *str = fm_push_array(char, len + 1);
to_camel(tag, str);
len = (int32_t)strlen(tag);
str = (char*)malloc(len + 1);
to_camel_cc(tag, str);
str[len] = 0; str[len] = 0;
return(str); return(str);
} }
static void internal void
generate_style(){ generate_style(){
Temp temp = fm_begin_temp();
char filename_4coder[] = STYLE_FILE; char filename_4coder[] = STYLE_FILE;
char filename_4ed[] = "4ed_style.h"; char filename_4ed[] = "4ed_style.h";
String out = make_out_string(10 << 20); String out = str_alloc(10 << 20);;
Out_Context context = {0};
if (begin_file_out(&context, filename_4coder, &out)){
enum_begin(&out, "Style_Tag"); enum_begin(&out, "Style_Tag");
{ {
int32_t count = ArrayCount(bar_style_fields); i32 count = ArrayCount(bar_style_fields);
for (int32_t i = 0; i < count; ++i){ for (i32 i = 0; i < count; ++i){
char *tag = make_style_tag(bar_style_fields[i]); char *tag = make_style_tag(bar_style_fields[i]);
append(&out, "Stag_"); append(&out, "Stag_");
append(&out, tag); append(&out, tag);
append(&out, ",\n"); append(&out, ",\n");
free(tag);
} }
count = ArrayCount(main_style_fields); count = ArrayCount(main_style_fields);
for (int32_t i = 0; i < count; ++i){ for (i32 i = 0; i < count; ++i){
char *tag = make_style_tag(main_style_fields[i]); char *tag = make_style_tag(main_style_fields[i]);
append(&out, "Stag_"); append(&out, "Stag_");
append(&out, tag); append(&out, tag);
append(&out, ",\n"); append(&out, ",\n");
free(tag);
} }
append(&out, "Stag_COUNT\n"); append(&out, "Stag_COUNT\n");
@ -229,35 +222,30 @@ generate_style(){
append(&out, "static char *style_tag_names[] = {\n"); append(&out, "static char *style_tag_names[] = {\n");
{ {
int32_t count = ArrayCount(bar_style_fields); i32 count = ArrayCount(bar_style_fields);
for (int32_t i = 0; i < count; ++i){ for (i32 i = 0; i < count; ++i){
char *tag = make_style_tag(bar_style_fields[i]); char *tag = make_style_tag(bar_style_fields[i]);
append(&out, "\""); append(&out, "\"");
append(&out, tag); append(&out, tag);
append(&out, "\",\n"); append(&out, "\",\n");
free(tag);
} }
count = ArrayCount(main_style_fields); count = ArrayCount(main_style_fields);
for (int32_t i = 0; i < count; ++i){ for (i32 i = 0; i < count; ++i){
char *tag = make_style_tag(main_style_fields[i]); char *tag = make_style_tag(main_style_fields[i]);
append(&out, "\""); append(&out, "\"");
append(&out, tag); append(&out, tag);
append(&out, "\",\n"); append(&out, "\",\n");
free(tag);
} }
} }
append(&out, "};\n"); append(&out, "};\n");
end_file_out(context); end_file_out(filename_4coder, &out);
}
if (begin_file_out(&context, filename_4ed, &out)){
struct_begin(&out, "Interactive_Style"); struct_begin(&out, "Interactive_Style");
{ {
int32_t count = ArrayCount(bar_style_fields); i32 count = ArrayCount(bar_style_fields);
for (int32_t i = 0; i < count; ++i){ for (i32 i = 0; i < count; ++i){
append(&out, "u32 "); append(&out, "u32 ");
append(&out, bar_style_fields[i]); append(&out, bar_style_fields[i]);
append(&out, "_color;\n"); append(&out, "_color;\n");
@ -267,8 +255,8 @@ generate_style(){
struct_begin(&out, "Style_Main_Data"); struct_begin(&out, "Style_Main_Data");
{ {
int32_t count = ArrayCount(main_style_fields); i32 count = ArrayCount(main_style_fields);
for (int32_t i = 0; i < count; ++i){ for (i32 i = 0; i < count; ++i){
append(&out, "u32 "); append(&out, "u32 ");
append(&out, main_style_fields[i]); append(&out, main_style_fields[i]);
append(&out, "_color;\n"); append(&out, "_color;\n");
@ -284,26 +272,24 @@ generate_style(){
"u32 *result = 0;\n" "u32 *result = 0;\n"
"switch (tag){\n"); "switch (tag){\n");
int32_t count = ArrayCount(bar_style_fields); i32 count = ArrayCount(bar_style_fields);
for (int32_t i = 0; i < count; ++i){ for (i32 i = 0; i < count; ++i){
char *tag = make_style_tag(bar_style_fields[i]); char *tag = make_style_tag(bar_style_fields[i]);
append(&out, "case Stag_"); append(&out, "case Stag_");
append(&out, tag); append(&out, tag);
append(&out, ": result = &s->file_info_style."); append(&out, ": result = &s->file_info_style.");
append(&out, bar_style_fields[i]); append(&out, bar_style_fields[i]);
append(&out, "_color; break;\n"); append(&out, "_color; break;\n");
free(tag);
} }
count = ArrayCount(main_style_fields); count = ArrayCount(main_style_fields);
for (int32_t i = 0; i < count; ++i){ for (i32 i = 0; i < count; ++i){
char *tag = make_style_tag(main_style_fields[i]); char *tag = make_style_tag(main_style_fields[i]);
append(&out, "case Stag_"); append(&out, "case Stag_");
append(&out, tag); append(&out, tag);
append(&out, ": result = &s->"); append(&out, ": result = &s->");
append(&out, main_style_fields[i]); append(&out, main_style_fields[i]);
append(&out, "_color; break;\n"); append(&out, "_color; break;\n");
free(tag);
} }
append(&out, append(&out,
@ -312,10 +298,9 @@ generate_style(){
"}\n\n"); "}\n\n");
} }
end_file_out(context); end_file_out(filename_4ed, &out);
}
free(out.str); fm_end_temp(temp);
} }
////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////
@ -324,16 +309,16 @@ generate_style(){
// Meta Parse Rules // Meta Parse Rules
// //
static void internal void
print_function_body_code(String *out, Parse_Context *context, int32_t start){ print_function_body_code(String *out, Parse_Context *context, i32 start){
String pstr = {0}, lexeme = {0}; String pstr = {0}, lexeme = {0};
Cpp_Token *token = 0; Cpp_Token *token = 0;
int32_t do_print = 0; i32 do_print = 0;
int32_t nest_level = 0; i32 nest_level = 0;
int32_t finish = false; i32 finish = false;
int32_t do_whitespace_print = false; i32 do_whitespace_print = false;
int32_t is_first = true; i32 is_first = true;
for (; (token = get_token(context)) != 0; get_next_token(context)){ for (; (token = get_token(context)) != 0; get_next_token(context)){
if (do_whitespace_print){ if (do_whitespace_print){
@ -378,30 +363,26 @@ print_function_body_code(String *out, Parse_Context *context, int32_t start){
} }
} }
typedef struct App_API_Name{ struct App_API_Name{
String macro; String macro;
String public_name; String public_name;
} App_API_Name; };
typedef struct App_API{ struct App_API{
App_API_Name *names; App_API_Name *names;
} App_API; };
static App_API internal App_API
allocate_app_api(int32_t count){ allocate_app_api(i32 count){
App_API app_api = {0}; App_API app_api = {0};
app_api.names = fm_push_array(App_API_Name, count); app_api.names = fm_push_array(App_API_Name, count);
memset(app_api.names, 0, sizeof(App_API_Name)*count); memset(app_api.names, 0, sizeof(App_API_Name)*count);
return(app_api); return(app_api);
} }
static void internal void
generate_custom_headers(){ generate_custom_headers(){
META_BEGIN(); Temp temp = fm_begin_temp();
int32_t size = (512 << 20);
void *mem = malloc(size);
memset(mem, 0, size);
// NOTE(allen): Parse the customization API files // NOTE(allen): Parse the customization API files
static char *functions_files[] = { "4ed_api_implementation.cpp", 0 }; static char *functions_files[] = { "4ed_api_implementation.cpp", 0 };
@ -413,7 +394,7 @@ generate_custom_headers(){
// NOTE(allen): Compute and store variations of the function names // NOTE(allen): Compute and store variations of the function names
App_API func_4ed_names = allocate_app_api(unit_custom.set.count); App_API func_4ed_names = allocate_app_api(unit_custom.set.count);
for (int32_t i = 0; i < unit_custom.set.count; ++i){ for (i32 i = 0; i < unit_custom.set.count; ++i){
String name_string = unit_custom.set.items[i].name; String name_string = unit_custom.set.items[i].name;
String *macro = &func_4ed_names.names[i].macro; String *macro = &func_4ed_names.names[i].macro;
String *public_name = &func_4ed_names.names[i].public_name; String *public_name = &func_4ed_names.names[i].public_name;
@ -430,15 +411,13 @@ generate_custom_headers(){
// NOTE(allen): Output // NOTE(allen): Output
String out = str_alloc(10 << 20); String out = str_alloc(10 << 20);
Out_Context context = {0};
// NOTE(allen): Custom API headers // NOTE(allen): Custom API headers
if (begin_file_out(&context, OS_API_H, &out)){ i32 main_api_count = unit_custom.parse[0].item_count;
int32_t main_api_count = unit_custom.parse[0].item_count; i32 os_api_count = unit_custom.parse[1].item_count;
int32_t os_api_count = unit_custom.parse[1].item_count;
append(&out, "struct Application_Links;\n"); append(&out, "struct Application_Links;\n");
for (int32_t i = main_api_count; i < os_api_count; ++i){ for (i32 i = main_api_count; i < os_api_count; ++i){
append(&out, "#define "); append(&out, "#define ");
append(&out, func_4ed_names.names[i].macro); append(&out, func_4ed_names.names[i].macro);
append(&out, "(n) "); append(&out, "(n) ");
@ -448,7 +427,7 @@ generate_custom_headers(){
append_s_char(&out, '\n'); append_s_char(&out, '\n');
} }
for (int32_t i = main_api_count; i < os_api_count; ++i){ for (i32 i = main_api_count; i < os_api_count; ++i){
append(&out, "typedef "); append(&out, "typedef ");
append(&out, func_4ed_names.names[i].macro); append(&out, func_4ed_names.names[i].macro);
append_s_char(&out, '('); append_s_char(&out, '(');
@ -456,16 +435,11 @@ generate_custom_headers(){
append(&out, "_Function);\n"); append(&out, "_Function);\n");
} }
end_file_out(context); end_file_out(OS_API_H, &out);
}
else{
// TODO(allen): warning
}
if (begin_file_out(&context, API_H, &out)){
append(&out, "struct Application_Links;\n"); append(&out, "struct Application_Links;\n");
for (int32_t i = 0; i < unit_custom.set.count; ++i){ for (i32 i = 0; i < unit_custom.set.count; ++i){
append(&out, "#define "); append(&out, "#define ");
append(&out, func_4ed_names.names[i].macro); append(&out, func_4ed_names.names[i].macro);
append(&out, "(n) "); append(&out, "(n) ");
@ -475,7 +449,7 @@ generate_custom_headers(){
append_s_char(&out, '\n'); append_s_char(&out, '\n');
} }
for (int32_t i = 0; i < unit_custom.set.count; ++i){ for (i32 i = 0; i < unit_custom.set.count; ++i){
append(&out, "typedef "); append(&out, "typedef ");
append(&out, func_4ed_names.names[i].macro); append(&out, func_4ed_names.names[i].macro);
append_s_char(&out, '('); append_s_char(&out, '(');
@ -487,7 +461,7 @@ generate_custom_headers(){
append(&out, "#if defined(ALLOW_DEP_4CODER)\n"); append(&out, "#if defined(ALLOW_DEP_4CODER)\n");
for (int32_t i = 0; i < unit_custom.set.count; ++i){ for (i32 i = 0; i < unit_custom.set.count; ++i){
append(&out, unit_custom.set.items[i].name); append(&out, unit_custom.set.items[i].name);
append(&out, "_Function *"); append(&out, "_Function *");
append(&out, func_4ed_names.names[i].public_name); append(&out, func_4ed_names.names[i].public_name);
@ -496,7 +470,7 @@ generate_custom_headers(){
append(&out, "#else\n"); append(&out, "#else\n");
for (int32_t i = 0; i < unit_custom.set.count; ++i){ for (i32 i = 0; i < unit_custom.set.count; ++i){
append(&out, unit_custom.set.items[i].name); append(&out, unit_custom.set.items[i].name);
append(&out, "_Function *"); append(&out, "_Function *");
append(&out, func_4ed_names.names[i].public_name); append(&out, func_4ed_names.names[i].public_name);
@ -514,7 +488,7 @@ generate_custom_headers(){
"};\n"); "};\n");
append(&out, "#define FillAppLinksAPI(app_links) do{"); append(&out, "#define FillAppLinksAPI(app_links) do{");
for (int32_t i = 0; i < unit_custom.set.count; ++i){ for (i32 i = 0; i < unit_custom.set.count; ++i){
append(&out, "\\\napp_links->"); append(&out, "\\\napp_links->");
append(&out, func_4ed_names.names[i].public_name); append(&out, func_4ed_names.names[i].public_name);
append(&out, "_ = "); append(&out, "_ = ");
@ -524,8 +498,8 @@ generate_custom_headers(){
append(&out, "} while(false)\n"); append(&out, "} while(false)\n");
append(&out, "#if defined(ALLOW_DEP_4CODER)\n"); append(&out, "#if defined(ALLOW_DEP_4CODER)\n");
for (int32_t use_dep = 1; use_dep >= 0; --use_dep){ for (i32 use_dep = 1; use_dep >= 0; --use_dep){
for (int32_t i = 0; i < unit_custom.set.count; ++i){ for (i32 i = 0; i < unit_custom.set.count; ++i){
Argument_Breakdown breakdown = unit_custom.set.items[i].breakdown; Argument_Breakdown breakdown = unit_custom.set.items[i].breakdown;
String ret = unit_custom.set.items[i].ret; String ret = unit_custom.set.items[i].ret;
String public_name = func_4ed_names.names[i].public_name; String public_name = func_4ed_names.names[i].public_name;
@ -536,7 +510,7 @@ generate_custom_headers(){
append(&out, public_name); append(&out, public_name);
append(&out, "("); append(&out, "(");
for (int32_t j = 0; j < breakdown.count; ++j){ for (i32 j = 0; j < breakdown.count; ++j){
append(&out, breakdown.args[j].param_string); append(&out, breakdown.args[j].param_string);
if (j+1 != breakdown.count){ if (j+1 != breakdown.count){
append(&out, ", "); append(&out, ", ");
@ -558,7 +532,7 @@ generate_custom_headers(){
} }
append(&out, "("); append(&out, "(");
for (int32_t j = 0; j < breakdown.count; ++j){ for (i32 j = 0; j < breakdown.count; ++j){
append(&out, breakdown.args[j].param_name); append(&out, breakdown.args[j].param_name);
if (j+1 != breakdown.count){ if (j+1 != breakdown.count){
append(&out, ", "); append(&out, ", ");
@ -574,20 +548,20 @@ generate_custom_headers(){
} }
append(&out, "#endif\n"); append(&out, "#endif\n");
end_file_out(context); end_file_out(API_H, &out);
}
else{
// TODO(allen): warning
}
META_FINISH(); fm_end_temp(temp);
} }
int main(int argc, char **argv){ int main(int argc, char **argv){
META_BEGIN();
fm_init_system(); fm_init_system();
generate_keycode_enum(); generate_keycode_enum();
generate_style(); generate_style();
generate_custom_headers(); generate_custom_headers();
META_FINISH();
} }
// BOTTOM // BOTTOM

View File

@ -12,60 +12,17 @@
#if !defined(OUT_CONTEXT_4CODER) #if !defined(OUT_CONTEXT_4CODER)
#define OUT_CONTEXT_4CODER #define OUT_CONTEXT_4CODER
typedef struct Out_Context{ internal void
char out_directory_space[256]; end_file_out(char *out_file, String *out_data){
String out_directory; FILE *file = fopen(out_file, "wb");
FILE *file; if (file != 0){
String *str; fwrite(out_data->str, 1, out_data->size, file);
} Out_Context; fclose(file);
static void
set_context_directory(Out_Context *context, char *dst_directory){
context->out_directory = make_fixed_width_string(context->out_directory_space);
copy_sc(&context->out_directory, dst_directory);
}
static int32_t
begin_file_out(Out_Context *out_context, char *filename, String *out){
char str_space[512];
String name = make_fixed_width_string(str_space);
if (out_context->out_directory.size > 0){
append_ss(&name, out_context->out_directory);
append_sc(&name, "/");
} }
append_sc(&name, filename); else{
terminate_with_null(&name); fprintf(stdout, "Could not open output file %s\n", out_file);
int32_t r = 0;
out_context->file = fopen(name.str, "wb");
out_context->str = out;
out->size = 0;
if (out_context->file){
r = 1;
} }
out_data->size = 0;
return(r);
}
static void
dump_file_out(Out_Context out_context){
fwrite(out_context.str->str, 1, out_context.str->size, out_context.file);
out_context.str->size = 0;
}
static void
end_file_out(Out_Context out_context){
dump_file_out(out_context);
fclose(out_context.file);
}
static String
make_out_string(int32_t x){
String str;
str.size = 0;
str.memory_size = x;
str.str = (char*)malloc(x);
return(str);
} }
#endif #endif

View File

@ -91,28 +91,15 @@ print_function_body_code(String *out, Parse_Context *context, i32 start){
static void static void
do_html_output(Document_System *doc_system, char *dst_directory, Abstract_Item *doc){ do_html_output(Document_System *doc_system, char *dst_directory, Abstract_Item *doc){
// NOTE(allen): Output String out = make_string_cap(fm__push(10 << 20), 0, 10 << 20);
i32 out_size = 10 << 20; Assert(out.str != 0);
void *mem = malloc(out_size);
Assert(mem != 0);
String out = make_string_cap(mem, 0, out_size);
Out_Context context = {0}; char doc_link[256];
set_context_directory(&context, dst_directory); if (doc_get_link_string(doc, doc_link, sizeof(doc_link))){
// Output Docs
char space[256];
if (doc_get_link_string(doc, space, sizeof(space))){
if (begin_file_out(&context, space, &out)){
generate_document_html(&out, doc_system, doc); generate_document_html(&out, doc_system, doc);
end_file_out(context); char *name = fm_str(dst_directory, "/", doc_link);
end_file_out(name, &out);
} }
else{
fprintf(stderr, "Failed to open %s\n", space);
}
}
free(mem);
} }
// TODO(allen): replace the documentation declaration system with a straight up enriched text system // TODO(allen): replace the documentation declaration system with a straight up enriched text system

View File

@ -1,5 +1,5 @@
1 1
0 0
99 100

View File

@ -192,12 +192,9 @@ int main(){
} }
} }
// NOTE(allen): Output
String out = str_alloc(10 << 20);
Out_Context context = {0};
// NOTE(allen): String Library // NOTE(allen): String Library
if (begin_file_out(&context, GENERATED_FILE, &out)){ String out = str_alloc(10 << 20);
Cpp_Token *token = 0; Cpp_Token *token = 0;
i32 start = 0; i32 start = 0;
@ -436,8 +433,7 @@ int main(){
pstr = str_start_end(pcontext.data, start, parse.code.size); pstr = str_start_end(pcontext.data, start, parse.code.size);
append(&out, pstr); append(&out, pstr);
end_file_out(context); end_file_out(GENERATED_FILE, &out);
}
// NOTE(allen): Publish the new file. (Would like to be able to automatically test the result before publishing). // NOTE(allen): Publish the new file. (Would like to be able to automatically test the result before publishing).
{ {