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 OS_API_H "4ed_os_custom_api.h"
#include "../4ed_defines.h"
#include "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"
@ -75,18 +75,17 @@ char *keys_that_need_codes[] = {
internal void
generate_keycode_enum(){
Temp temp = fm_begin_temp();
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);
Out_Context context = {0};
if (begin_file_out(&context, filename_keycodes, &out)){
int32_t count = ArrayCount(keys_that_need_codes);
i32 count = ArrayCount(keys_that_need_codes);
append(&out, "enum{\n");
for (int32_t i = 0; i < count;){
for (i32 i = 0; i < count;){
append(&out, "key_");
append(&out, keys_that_need_codes[i++]);
append(&out, " = ");
@ -101,7 +100,7 @@ generate_keycode_enum(){
"char *result = 0;\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, keys_that_need_codes[i]);
append(&out, ": result = \"");
@ -116,26 +115,27 @@ generate_keycode_enum(){
"return(result);\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){
append(str, "struct ");
append(str, name);
append(str, "{\n"); //}
}
static void
internal void
enum_begin(String *str, char *name){
append(str, "enum ");
append(str, name);
append(str, "{\n"); //}
}
static void
internal void
struct_end(String *str){ //{
append(str, "};\n\n");
}
@ -180,47 +180,40 @@ static char* main_style_fields[] = {
"next_undo",
};
static char*
internal char*
make_style_tag(char *tag){
char *str;
int32_t len;
len = (int32_t)strlen(tag);
str = (char*)malloc(len + 1);
to_camel_cc(tag, str);
i32 len = (i32)strlen(tag);
char *str = fm_push_array(char, len + 1);
to_camel(tag, str);
str[len] = 0;
return(str);
}
static void
internal void
generate_style(){
Temp temp = fm_begin_temp();
char filename_4coder[] = STYLE_FILE;
char filename_4ed[] = "4ed_style.h";
String out = make_out_string(10 << 20);
Out_Context context = {0};
if (begin_file_out(&context, filename_4coder, &out)){
String out = str_alloc(10 << 20);;
enum_begin(&out, "Style_Tag");
{
int32_t count = ArrayCount(bar_style_fields);
for (int32_t i = 0; i < count; ++i){
i32 count = ArrayCount(bar_style_fields);
for (i32 i = 0; i < count; ++i){
char *tag = make_style_tag(bar_style_fields[i]);
append(&out, "Stag_");
append(&out, tag);
append(&out, ",\n");
free(tag);
}
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]);
append(&out, "Stag_");
append(&out, tag);
append(&out, ",\n");
free(tag);
}
append(&out, "Stag_COUNT\n");
@ -229,35 +222,30 @@ generate_style(){
append(&out, "static char *style_tag_names[] = {\n");
{
int32_t count = ArrayCount(bar_style_fields);
for (int32_t i = 0; i < count; ++i){
i32 count = ArrayCount(bar_style_fields);
for (i32 i = 0; i < count; ++i){
char *tag = make_style_tag(bar_style_fields[i]);
append(&out, "\"");
append(&out, tag);
append(&out, "\",\n");
free(tag);
}
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]);
append(&out, "\"");
append(&out, tag);
append(&out, "\",\n");
free(tag);
}
}
append(&out, "};\n");
end_file_out(context);
}
if (begin_file_out(&context, filename_4ed, &out)){
end_file_out(filename_4coder, &out);
struct_begin(&out, "Interactive_Style");
{
int32_t count = ArrayCount(bar_style_fields);
for (int32_t i = 0; i < count; ++i){
i32 count = ArrayCount(bar_style_fields);
for (i32 i = 0; i < count; ++i){
append(&out, "u32 ");
append(&out, bar_style_fields[i]);
append(&out, "_color;\n");
@ -267,8 +255,8 @@ generate_style(){
struct_begin(&out, "Style_Main_Data");
{
int32_t count = ArrayCount(main_style_fields);
for (int32_t i = 0; i < count; ++i){
i32 count = ArrayCount(main_style_fields);
for (i32 i = 0; i < count; ++i){
append(&out, "u32 ");
append(&out, main_style_fields[i]);
append(&out, "_color;\n");
@ -284,26 +272,24 @@ generate_style(){
"u32 *result = 0;\n"
"switch (tag){\n");
int32_t count = ArrayCount(bar_style_fields);
for (int32_t i = 0; i < count; ++i){
i32 count = ArrayCount(bar_style_fields);
for (i32 i = 0; i < count; ++i){
char *tag = make_style_tag(bar_style_fields[i]);
append(&out, "case Stag_");
append(&out, tag);
append(&out, ": result = &s->file_info_style.");
append(&out, bar_style_fields[i]);
append(&out, "_color; break;\n");
free(tag);
}
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]);
append(&out, "case Stag_");
append(&out, tag);
append(&out, ": result = &s->");
append(&out, main_style_fields[i]);
append(&out, "_color; break;\n");
free(tag);
}
append(&out,
@ -312,10 +298,9 @@ generate_style(){
"}\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
//
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){
@ -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 public_name;
} App_API_Name;
};
typedef struct App_API{
struct App_API{
App_API_Name *names;
} App_API;
};
static App_API
allocate_app_api(int32_t count){
internal App_API
allocate_app_api(i32 count){
App_API app_api = {0};
app_api.names = fm_push_array(App_API_Name, count);
memset(app_api.names, 0, sizeof(App_API_Name)*count);
return(app_api);
}
static void
internal void
generate_custom_headers(){
META_BEGIN();
int32_t size = (512 << 20);
void *mem = malloc(size);
memset(mem, 0, size);
Temp temp = fm_begin_temp();
// NOTE(allen): Parse the customization API files
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
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 *macro = &func_4ed_names.names[i].macro;
String *public_name = &func_4ed_names.names[i].public_name;
@ -430,15 +411,13 @@ generate_custom_headers(){
// NOTE(allen): Output
String out = str_alloc(10 << 20);
Out_Context context = {0};
// NOTE(allen): Custom API headers
if (begin_file_out(&context, OS_API_H, &out)){
int32_t main_api_count = unit_custom.parse[0].item_count;
int32_t os_api_count = unit_custom.parse[1].item_count;
i32 main_api_count = unit_custom.parse[0].item_count;
i32 os_api_count = unit_custom.parse[1].item_count;
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, func_4ed_names.names[i].macro);
append(&out, "(n) ");
@ -448,7 +427,7 @@ generate_custom_headers(){
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, func_4ed_names.names[i].macro);
append_s_char(&out, '(');
@ -456,16 +435,11 @@ generate_custom_headers(){
append(&out, "_Function);\n");
}
end_file_out(context);
}
else{
// TODO(allen): warning
}
end_file_out(OS_API_H, &out);
if (begin_file_out(&context, API_H, &out)){
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, func_4ed_names.names[i].macro);
append(&out, "(n) ");
@ -475,7 +449,7 @@ generate_custom_headers(){
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, func_4ed_names.names[i].macro);
append_s_char(&out, '(');
@ -487,7 +461,7 @@ generate_custom_headers(){
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, "_Function *");
append(&out, func_4ed_names.names[i].public_name);
@ -496,7 +470,7 @@ generate_custom_headers(){
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, "_Function *");
append(&out, func_4ed_names.names[i].public_name);
@ -514,7 +488,7 @@ generate_custom_headers(){
"};\n");
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, func_4ed_names.names[i].public_name);
append(&out, "_ = ");
@ -524,8 +498,8 @@ generate_custom_headers(){
append(&out, "} while(false)\n");
append(&out, "#if defined(ALLOW_DEP_4CODER)\n");
for (int32_t use_dep = 1; use_dep >= 0; --use_dep){
for (int32_t i = 0; i < unit_custom.set.count; ++i){
for (i32 use_dep = 1; use_dep >= 0; --use_dep){
for (i32 i = 0; i < unit_custom.set.count; ++i){
Argument_Breakdown breakdown = unit_custom.set.items[i].breakdown;
String ret = unit_custom.set.items[i].ret;
String public_name = func_4ed_names.names[i].public_name;
@ -536,7 +510,7 @@ generate_custom_headers(){
append(&out, public_name);
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);
if (j+1 != breakdown.count){
append(&out, ", ");
@ -558,7 +532,7 @@ generate_custom_headers(){
}
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);
if (j+1 != breakdown.count){
append(&out, ", ");
@ -574,20 +548,20 @@ generate_custom_headers(){
}
append(&out, "#endif\n");
end_file_out(context);
}
else{
// TODO(allen): warning
}
end_file_out(API_H, &out);
META_FINISH();
fm_end_temp(temp);
}
int main(int argc, char **argv){
META_BEGIN();
fm_init_system();
generate_keycode_enum();
generate_style();
generate_custom_headers();
META_FINISH();
}
// BOTTOM

View File

@ -12,60 +12,17 @@
#if !defined(OUT_CONTEXT_4CODER)
#define OUT_CONTEXT_4CODER
typedef struct Out_Context{
char out_directory_space[256];
String out_directory;
FILE *file;
String *str;
} Out_Context;
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, "/");
internal void
end_file_out(char *out_file, String *out_data){
FILE *file = fopen(out_file, "wb");
if (file != 0){
fwrite(out_data->str, 1, out_data->size, file);
fclose(file);
}
append_sc(&name, filename);
terminate_with_null(&name);
int32_t r = 0;
out_context->file = fopen(name.str, "wb");
out_context->str = out;
out->size = 0;
if (out_context->file){
r = 1;
else{
fprintf(stdout, "Could not open output file %s\n", out_file);
}
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);
out_data->size = 0;
}
#endif

View File

@ -91,28 +91,15 @@ print_function_body_code(String *out, Parse_Context *context, i32 start){
static void
do_html_output(Document_System *doc_system, char *dst_directory, Abstract_Item *doc){
// NOTE(allen): Output
i32 out_size = 10 << 20;
void *mem = malloc(out_size);
Assert(mem != 0);
String out = make_string_cap(mem, 0, out_size);
String out = make_string_cap(fm__push(10 << 20), 0, 10 << 20);
Assert(out.str != 0);
Out_Context context = {0};
set_context_directory(&context, dst_directory);
// Output Docs
char space[256];
if (doc_get_link_string(doc, space, sizeof(space))){
if (begin_file_out(&context, space, &out)){
char doc_link[256];
if (doc_get_link_string(doc, doc_link, sizeof(doc_link))){
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

View File

@ -1,5 +1,5 @@
1
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
if (begin_file_out(&context, GENERATED_FILE, &out)){
String out = str_alloc(10 << 20);
Cpp_Token *token = 0;
i32 start = 0;
@ -436,8 +433,7 @@ int main(){
pstr = str_start_end(pcontext.data, start, parse.code.size);
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).
{