converted api header printing to using the Out_Context

master
Allen Webster 2016-09-03 21:44:12 -04:00
parent a1afaa0e40
commit 8fdff026af
5 changed files with 225 additions and 212 deletions

View File

@ -3185,17 +3185,17 @@ string in place.</div></div><hr>
<div id='to_lower_ss_str_doc'><h4>&sect;4.3.81: to_lower_ss</h4> <div id='to_lower_ss_str_doc'><h4>&sect;4.3.81: to_lower_ss</h4>
<div style='font-family: "Courier New", Courier, monospace; text-align: left; margin-top: 3mm; margin-bottom: 3mm; font-size: .95em; background: #DFDFDF; padding: 0.25em;'> <div style='font-family: "Courier New", Courier, monospace; text-align: left; margin-top: 3mm; margin-bottom: 3mm; font-size: .95em; background: #DFDFDF; padding: 0.25em;'>
void to_lower_ss( void to_lower_ss(
<div style='margin-left: 4mm;'>String *src,<br>String *dst<br></div>) <div style='margin-left: 4mm;'>String *dst,<br>String src<br></div>)
</div> </div>
<div style='margin-top: 3mm; margin-bottom: 3mm; color: #309030;'><b><i>Parameters</i></b></div><div> <div style='margin-top: 3mm; margin-bottom: 3mm; color: #309030;'><b><i>Parameters</i></b></div><div>
<div style='font-weight: 600;'>src</div>
<div style='margin-bottom: 6mm;'><div style='margin-left: 5mm; margin-right: 5mm;'>The source string to conver to lowercase.</div></div>
</div>
<div>
<div style='font-weight: 600;'>dst</div> <div style='font-weight: 600;'>dst</div>
<div style='margin-bottom: 6mm;'><div style='margin-left: 5mm; margin-right: 5mm;'>The destination buffer to receive the converted string. <div style='margin-bottom: 6mm;'><div style='margin-left: 5mm; margin-right: 5mm;'>The destination buffer to receive the converted string.
This must have a capacity of at least the size of src.</div></div> This must have a capacity of at least the size of src.</div></div>
</div> </div>
<div>
<div style='font-weight: 600;'>src</div>
<div style='margin-bottom: 6mm;'><div style='margin-left: 5mm; margin-right: 5mm;'>The source string to conver to lowercase.</div></div>
</div>
<div style='margin-top: 3mm; margin-bottom: 3mm; color: #309030;'><b><i>Description</i></b></div><div style='margin-left: 5mm; margin-right: 5mm;'>Rewrites the string in src into dst. src and dst should not overlap with the exception <div style='margin-top: 3mm; margin-bottom: 3mm; color: #309030;'><b><i>Description</i></b></div><div style='margin-left: 5mm; margin-right: 5mm;'>Rewrites the string in src into dst. src and dst should not overlap with the exception
that src and dst may be exactly equal in order to convert the string in place.</div></div><hr> that src and dst may be exactly equal in order to convert the string in place.</div></div><hr>
<div id='to_lower_s_str_doc'><h4>&sect;4.3.82: to_lower_s</h4> <div id='to_lower_s_str_doc'><h4>&sect;4.3.82: to_lower_s</h4>
@ -3227,17 +3227,17 @@ that src and dst may be exactly equal in order to convert the string in place.</
<div id='to_upper_ss_str_doc'><h4>&sect;4.3.84: to_upper_ss</h4> <div id='to_upper_ss_str_doc'><h4>&sect;4.3.84: to_upper_ss</h4>
<div style='font-family: "Courier New", Courier, monospace; text-align: left; margin-top: 3mm; margin-bottom: 3mm; font-size: .95em; background: #DFDFDF; padding: 0.25em;'> <div style='font-family: "Courier New", Courier, monospace; text-align: left; margin-top: 3mm; margin-bottom: 3mm; font-size: .95em; background: #DFDFDF; padding: 0.25em;'>
void to_upper_ss( void to_upper_ss(
<div style='margin-left: 4mm;'>String *src,<br>String *dst<br></div>) <div style='margin-left: 4mm;'>String *dst,<br>String src<br></div>)
</div> </div>
<div style='margin-top: 3mm; margin-bottom: 3mm; color: #309030;'><b><i>Parameters</i></b></div><div> <div style='margin-top: 3mm; margin-bottom: 3mm; color: #309030;'><b><i>Parameters</i></b></div><div>
<div style='font-weight: 600;'>src</div>
<div style='margin-bottom: 6mm;'><div style='margin-left: 5mm; margin-right: 5mm;'>The source string to convert to uppercase.</div></div>
</div>
<div>
<div style='font-weight: 600;'>dst</div> <div style='font-weight: 600;'>dst</div>
<div style='margin-bottom: 6mm;'><div style='margin-left: 5mm; margin-right: 5mm;'>The destination buffer to receive the converted string. <div style='margin-bottom: 6mm;'><div style='margin-left: 5mm; margin-right: 5mm;'>The destination buffer to receive the converted string.
This must have a capacity of at least the size of src.</div></div> This must have a capacity of at least the size of src.</div></div>
</div> </div>
<div>
<div style='font-weight: 600;'>src</div>
<div style='margin-bottom: 6mm;'><div style='margin-left: 5mm; margin-right: 5mm;'>The source string to convert to uppercase.</div></div>
</div>
<div style='margin-top: 3mm; margin-bottom: 3mm; color: #309030;'><b><i>Description</i></b></div><div style='margin-left: 5mm; margin-right: 5mm;'>Rewrites the string in src into dst. src and dst should not overlap with the exception <div style='margin-top: 3mm; margin-bottom: 3mm; color: #309030;'><b><i>Description</i></b></div><div style='margin-left: 5mm; margin-right: 5mm;'>Rewrites the string in src into dst. src and dst should not overlap with the exception
that src and dst may be exactly equal in order to convert the string in place.</div></div><hr> that src and dst may be exactly equal in order to convert the string in place.</div></div><hr>
<div id='to_upper_s_str_doc'><h4>&sect;4.3.85: to_upper_s</h4> <div id='to_upper_s_str_doc'><h4>&sect;4.3.85: to_upper_s</h4>

View File

@ -119,8 +119,6 @@ typedef TOGGLE_FULLSCREEN_SIG(Toggle_Fullscreen_Function);
typedef IS_FULLSCREEN_SIG(Is_Fullscreen_Function); typedef IS_FULLSCREEN_SIG(Is_Fullscreen_Function);
typedef SEND_EXIT_SIGNAL_SIG(Send_Exit_Signal_Function); typedef SEND_EXIT_SIGNAL_SIG(Send_Exit_Signal_Function);
struct Application_Links{ struct Application_Links{
void *memory;
int32_t memory_size;
Exec_Command_Function *exec_command; Exec_Command_Function *exec_command;
Exec_System_Command_Function *exec_system_command; Exec_System_Command_Function *exec_system_command;
Clipboard_Post_Function *clipboard_post; Clipboard_Post_Function *clipboard_post;
@ -181,6 +179,8 @@ struct Application_Links{
Toggle_Fullscreen_Function *toggle_fullscreen; Toggle_Fullscreen_Function *toggle_fullscreen;
Is_Fullscreen_Function *is_fullscreen; Is_Fullscreen_Function *is_fullscreen;
Send_Exit_Signal_Function *send_exit_signal; Send_Exit_Signal_Function *send_exit_signal;
void *memory;
int32_t memory_size;
void *cmd_context; void *cmd_context;
void *system_links; void *system_links;
void *current_coroutine; void *current_coroutine;

View File

@ -133,10 +133,10 @@ FSTRING_LINK fstr_bool terminate_with_null(String *str);
FSTRING_LINK fstr_bool append_padding(String *dest, char c, int32_t target_size); FSTRING_LINK fstr_bool append_padding(String *dest, char c, int32_t target_size);
FSTRING_LINK void replace_char(String *str, char replace, char with); FSTRING_LINK void replace_char(String *str, char replace, char with);
FSTRING_LINK void to_lower_cc(char *src, char *dst); FSTRING_LINK void to_lower_cc(char *src, char *dst);
FSTRING_LINK void to_lower_ss(String *src, String *dst); FSTRING_LINK void to_lower_ss(String *dst, String src);
FSTRING_LINK void to_lower_s(String *str); FSTRING_LINK void to_lower_s(String *str);
FSTRING_LINK void to_upper_cc(char *src, char *dst); FSTRING_LINK void to_upper_cc(char *src, char *dst);
FSTRING_LINK void to_upper_ss(String *src, String *dst); FSTRING_LINK void to_upper_ss(String *dst, String src);
FSTRING_LINK void to_upper_s(String *str); FSTRING_LINK void to_upper_s(String *str);
FSTRING_LINK void to_camel_cc(char *src, char *dst); FSTRING_LINK void to_camel_cc(char *src, char *dst);
FSTRING_LINK int32_t int_to_str_size(int32_t x); FSTRING_LINK int32_t int_to_str_size(int32_t x);
@ -229,10 +229,10 @@ FSTRING_INLINE fstr_bool append(String *dest, char c);
FSTRING_INLINE fstr_bool append(String *dest, String src); FSTRING_INLINE fstr_bool append(String *dest, String src);
FSTRING_INLINE fstr_bool append(String *dest, char *src); FSTRING_INLINE fstr_bool append(String *dest, char *src);
FSTRING_INLINE void to_lower(char *src, char *dst); FSTRING_INLINE void to_lower(char *src, char *dst);
FSTRING_INLINE void to_lower(String *src, String *dst); FSTRING_INLINE void to_lower(String *dst, String src);
FSTRING_INLINE void to_lower(String *str); FSTRING_INLINE void to_lower(String *str);
FSTRING_INLINE void to_upper(char *src, char *dst); FSTRING_INLINE void to_upper(char *src, char *dst);
FSTRING_INLINE void to_upper(String *src, String *dst); FSTRING_INLINE void to_upper(String *dst, String src);
FSTRING_INLINE void to_upper(String *str); FSTRING_INLINE void to_upper(String *str);
FSTRING_INLINE void to_camel(char *src, char *dst); FSTRING_INLINE void to_camel(char *src, char *dst);
FSTRING_INLINE int32_t str_is_int(char *str); FSTRING_INLINE int32_t str_is_int(char *str);
@ -361,13 +361,13 @@ append(String *dest, char *src){return(append_sc(dest,src));}
FSTRING_INLINE void FSTRING_INLINE void
to_lower(char *src, char *dst){(to_lower_cc(src,dst));} to_lower(char *src, char *dst){(to_lower_cc(src,dst));}
FSTRING_INLINE void FSTRING_INLINE void
to_lower(String *src, String *dst){(to_lower_ss(src,dst));} to_lower(String *dst, String src){(to_lower_ss(dst,src));}
FSTRING_INLINE void FSTRING_INLINE void
to_lower(String *str){(to_lower_s(str));} to_lower(String *str){(to_lower_s(str));}
FSTRING_INLINE void FSTRING_INLINE void
to_upper(char *src, char *dst){(to_upper_cc(src,dst));} to_upper(char *src, char *dst){(to_upper_cc(src,dst));}
FSTRING_INLINE void FSTRING_INLINE void
to_upper(String *src, String *dst){(to_upper_ss(src,dst));} to_upper(String *dst, String src){(to_upper_ss(dst,src));}
FSTRING_INLINE void FSTRING_INLINE void
to_upper(String *str){(to_upper_s(str));} to_upper(String *str){(to_upper_s(str));}
FSTRING_INLINE void FSTRING_INLINE void
@ -1442,16 +1442,17 @@ to_lower_cc(char *src, char *dst){
#if defined(FSTRING_IMPLEMENTATION) #if defined(FSTRING_IMPLEMENTATION)
FSTRING_LINK void FSTRING_LINK void
to_lower_ss(String *src, String *dst){ to_lower_ss(String *dst, String src){
int32_t i = 0; int32_t i = 0;
int32_t size = src->size; int32_t size = src.size;
char *c = src->str; char *c = src.str;
char *d = dst->str; char *d = dst->str;
if (dst->memory_size >= size){ if (dst->memory_size >= size){
for (; i < size; ++i){ for (; i < size; ++i){
*d++ = char_to_lower(*c++); *d++ = char_to_lower(*c++);
} }
dst->size = size;
} }
} }
#endif #endif
@ -1483,16 +1484,17 @@ to_upper_cc(char *src, char *dst){
#if defined(FSTRING_IMPLEMENTATION) #if defined(FSTRING_IMPLEMENTATION)
FSTRING_LINK void FSTRING_LINK void
to_upper_ss(String *src, String *dst){ to_upper_ss(String *dst, String src){
int32_t i = 0; int32_t i = 0;
int32_t size = src->size; int32_t size = src.size;
char *c = src->str; char *c = src.str;
char *d = dst->str; char *d = dst->str;
if (dst->memory_size >= size){ if (dst->memory_size >= size){
for (; i < size; ++i){ for (; i < size; ++i){
*d++ = char_to_upper(*c++); *d++ = char_to_upper(*c++);
} }
dst->size = size;
} }
} }
#endif #endif

View File

@ -31,10 +31,15 @@ typedef struct Out_Context{
} Out_Context; } Out_Context;
static String static String
get_string(char *data, int32_t start, int32_t end){ str_start_end(char *data, int32_t start, int32_t end){
return(make_string(data + start, end - start)); return(make_string(data + start, end - start));
} }
static String
str_alloc(Partition *part, int32_t cap){
return(make_string_cap(push_array(part, char, cap), 0, cap));
}
static int32_t static int32_t
begin_file_out(Out_Context *out_context, char *filename, String *out){ begin_file_out(Out_Context *out_context, char *filename, String *out){
int32_t r = 0; int32_t r = 0;
@ -872,10 +877,10 @@ struct_parse_member(Partition *part, Parse_Context *context, Item_Node *member){
name = skip_chop_whitespace(get_lexeme(*token_j, context->data)); name = skip_chop_whitespace(get_lexeme(*token_j, context->data));
String type = skip_chop_whitespace(get_string(context->data, start_token->start, token_j->start)); String type = skip_chop_whitespace(str_start_end(context->data, start_token->start, token_j->start));
String type_postfix = String type_postfix =
skip_chop_whitespace(get_string(context->data, token_j->start + token_j->size, token->start)); skip_chop_whitespace(str_start_end(context->data, token_j->start + token_j->size, token->start));
set_token(context, token+1); set_token(context, token+1);
result = true; result = true;
@ -1052,7 +1057,7 @@ typedef_parse(Parse_Context *context, Item_Node *item){
String name = get_lexeme(*token_j, context->data); String name = get_lexeme(*token_j, context->data);
String type = skip_chop_whitespace( String type = skip_chop_whitespace(
get_string(context->data, start_token->start + start_token->size, token_j->start) str_start_end(context->data, start_token->start + start_token->size, token_j->start)
); );
item->t = Item_Typedef; item->t = Item_Typedef;
@ -1133,7 +1138,7 @@ enum_parse(Partition *part, Parse_Context *context, Item_Node *item){
} }
value = skip_chop_whitespace( value = skip_chop_whitespace(
get_string(context->data, start_token->start + start_token->size, token->start) str_start_end(context->data, start_token->start + start_token->size, token->start)
); );
get_prev_token(context); get_prev_token(context);
@ -1354,7 +1359,7 @@ function_sig_parse(Partition *part, Parse_Context *context, Item_Node *item, Str
item->name = get_lexeme(*token, context->data); item->name = get_lexeme(*token, context->data);
item->ret = chop_whitespace( item->ret = chop_whitespace(
get_string(context->data, ret_token->start, token->start) str_start_end(context->data, ret_token->start, token->start)
); );
for (; (token = get_token(context)) != 0; get_next_token(context)){ for (; (token = get_token(context)) != 0; get_next_token(context)){
@ -1365,7 +1370,7 @@ function_sig_parse(Partition *part, Parse_Context *context, Item_Node *item, Str
if (token){ if (token){
item->args = item->args =
get_string(context->data, args_start_token->start, token->start + token->size); str_start_end(context->data, args_start_token->start, token->start + token->size);
item->t = Item_Function; item->t = Item_Function;
item->cpp_name = cpp_name; item->cpp_name = cpp_name;
item->breakdown = parameter_parse(part, context->data, args_start_token, token); item->breakdown = parameter_parse(part, context->data, args_start_token, token);
@ -1474,7 +1479,7 @@ macro_parse(Partition *part, Parse_Context *context, Item_Node *item){
} }
if (token){ if (token){
item->args = get_string(context->data, args_start_token->start, item->args = str_start_end(context->data, args_start_token->start,
token->start + token->size); token->start + token->size);
item->breakdown = parameter_parse(part, context->data, args_start_token, token); item->breakdown = parameter_parse(part, context->data, args_start_token, token);
@ -1492,7 +1497,7 @@ macro_parse(Partition *part, Parse_Context *context, Item_Node *item){
token = get_prev_token(context); token = get_prev_token(context);
item->body = item->body =
get_string(context->data, body_start->start, str_start_end(context->data, body_start->start,
token->start + token->size); token->start + token->size);
} }
} }
@ -1884,7 +1889,7 @@ print_function_body_code(FILE *file, int32_t *index, Cpp_Token **token_ptr, int3
int32_t do_whitespace_print = false; int32_t do_whitespace_print = false;
for (; i < count; ++i, ++token){ for (; i < count; ++i, ++token){
if (do_whitespace_print){ if (do_whitespace_print){
pstr = get_string(code->str, start, token->start); pstr = str_start_end(code->str, start, token->start);
print_str(file, pstr); print_str(file, pstr);
} }
else{ else{
@ -2172,6 +2177,8 @@ generate_custom_headers(){
Partition part_ = make_part(mem, size); Partition part_ = make_part(mem, size);
Partition *part = &part_; Partition *part = &part_;
// NOTE(allen): Parse the internal string file.
static char *string_files[] = { static char *string_files[] = {
"internal_4coder_string.cpp" "internal_4coder_string.cpp"
}; };
@ -2186,10 +2193,8 @@ generate_custom_headers(){
Meta_Unit string_unit = compile_meta_unit(part, string_files, ArrayCount(string_files), Meta_Unit string_unit = compile_meta_unit(part, string_files, ArrayCount(string_files),
string_keys, ArrayCount(string_keys)); string_keys, ArrayCount(string_keys));
//
// App API parsing
//
// NOTE(allen): Parse the customization API files
static char *functions_files[] = { static char *functions_files[] = {
"4ed_api_implementation.cpp", "4ed_api_implementation.cpp",
"win32_api_impl.cpp" "win32_api_impl.cpp"
@ -2202,6 +2207,8 @@ generate_custom_headers(){
Meta_Unit unit_custom = compile_meta_unit(part, functions_files, ArrayCount(functions_files), Meta_Unit unit_custom = compile_meta_unit(part, functions_files, ArrayCount(functions_files),
functions_keys, ArrayCount(functions_keys)); functions_keys, ArrayCount(functions_keys));
// NOTE(allen): Compute and store variations of the function names
App_API func_4ed_names = allocate_app_api(part, unit_custom.set.count); App_API func_4ed_names = allocate_app_api(part, unit_custom.set.count);
for (int32_t i = 0; i < unit_custom.set.count; ++i){ for (int32_t i = 0; i < unit_custom.set.count; ++i){
@ -2209,116 +2216,23 @@ generate_custom_headers(){
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;
macro->size = 0; *macro = str_alloc(part, name_string.size+4);
macro->memory_size = name_string.size+4; to_upper_ss(macro, name_string);
macro->str = (char*)malloc(macro->memory_size);
copy_ss(macro, name_string);
to_upper_s(macro);
append_ss(macro, make_lit_string("_SIG")); append_ss(macro, make_lit_string("_SIG"));
*public_name = str_alloc(part, name_string.size);
to_lower_ss(public_name, name_string);
public_name->size = 0; partition_align(part, 4);
public_name->memory_size = name_string.size;
public_name->str = (char*)malloc(public_name->memory_size);
copy_ss(public_name, name_string);
to_lower_s(public_name);
} }
// NOTE(allen): Header
FILE *file = fopen(OS_API_H, "wb");
int32_t main_api_count = unit_custom.parse[0].item_count; // NOTE(allen): Parse the customization API types
int32_t os_api_count = unit_custom.parse[1].item_count;
for (int32_t i = main_api_count; i < os_api_count; ++i){
String ret_string = unit_custom.set.items[i].ret;
String args_string = unit_custom.set.items[i].args;
String macro_string = func_4ed_names.names[i].macro;
fprintf(file, "#define %.*s(n) %.*s n%.*s\n",
macro_string.size, macro_string.str,
ret_string.size, ret_string.str,
args_string.size, args_string.str);
}
for (int32_t i = main_api_count; i < os_api_count; ++i){
String name_string = unit_custom.set.items[i].name;
String macro_string = func_4ed_names.names[i].macro;
fprintf(file, "typedef %.*s(%.*s_Function);\n",
macro_string.size, macro_string.str,
name_string.size, name_string.str);
}
fclose(file);
file = fopen(API_H, "wb");
for (int32_t i = 0; i < unit_custom.set.count; ++i){
String ret_string = unit_custom.set.items[i].ret;
String args_string = unit_custom.set.items[i].args;
String macro_string = func_4ed_names.names[i].macro;
fprintf(file, "#define %.*s(n) %.*s n%.*s\n",
macro_string.size, macro_string.str,
ret_string.size, ret_string.str,
args_string.size, args_string.str);
}
for (int32_t i = 0; i < unit_custom.set.count; ++i){
String name_string = unit_custom.set.items[i].name;
String macro_string = func_4ed_names.names[i].macro;
fprintf(file, "typedef %.*s(%.*s_Function);\n",
macro_string.size, macro_string.str,
name_string.size, name_string.str);
}
fprintf(file, "struct Application_Links{\n");
fprintf(file,
" void *memory;\n"
" int32_t memory_size;\n"
);
for (int32_t i = 0; i < unit_custom.set.count; ++i){
String name_string = unit_custom.set.items[i].name;
String public_string = func_4ed_names.names[i].public_name;
fprintf(file, " %.*s_Function *%.*s;\n",
name_string.size, name_string.str,
public_string.size, public_string.str);
}
fprintf(file,
" void *cmd_context;\n"
" void *system_links;\n"
" void *current_coroutine;\n"
" int32_t type_coroutine;\n"
);
fprintf(file, "};\n");
fprintf(file, "#define FillAppLinksAPI(app_links) do{");
for (int32_t i = 0; i < unit_custom.set.count; ++i){
String name = unit_custom.set.items[i].name;
String public_string = func_4ed_names.names[i].public_name;
fprintf(file,
"\\\n"
"app_links->%.*s = %.*s;",
public_string.size, public_string.str,
name.size, name.str
);
}
fprintf(file, " } while(false)\n");
fclose(file);
// NOTE(allen): Documentation
{
static char *type_files[] = { static char *type_files[] = {
"4coder_types.h" "4coder_types.h"
}; };
static Meta_Keywords type_spec_keys[] = { static Meta_Keywords type_keys[] = {
{make_lit_string("typedef") , Item_Typedef } , {make_lit_string("typedef") , Item_Typedef } ,
{make_lit_string("struct") , Item_Struct } , {make_lit_string("struct") , Item_Struct } ,
{make_lit_string("union") , Item_Union } , {make_lit_string("union") , Item_Union } ,
@ -2326,7 +2240,102 @@ generate_custom_headers(){
}; };
Meta_Unit unit = compile_meta_unit(part, type_files, ArrayCount(type_files), Meta_Unit unit = compile_meta_unit(part, type_files, ArrayCount(type_files),
type_spec_keys, ArrayCount(type_spec_keys)); type_keys, ArrayCount(type_keys));
// NOTE(allen): Output
String out = str_alloc(part, 10 << 20);
Out_Context context = {0};
// TODO(allen): delete this ASAP
FILE *file = 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;
for (int32_t i = main_api_count; i < os_api_count; ++i){
append_sc(&out, "#define ");
append_ss(&out, func_4ed_names.names[i].macro);
append_sc(&out, "(n) ");
append_ss(&out, unit_custom.set.items[i].ret);
append_sc(&out, " n");
append_ss(&out, unit_custom.set.items[i].args);
append_s_char(&out, '\n');
}
dump_file_out(context);
for (int32_t i = main_api_count; i < os_api_count; ++i){
append_sc(&out, "typedef ");
append_ss(&out, func_4ed_names.names[i].macro);
append_s_char(&out, '(');
append_ss(&out, unit_custom.set.items[i].name);
append_sc(&out, "_Function);\n");
}
end_file_out(context);
}
else{
// TODO(allen): warning
}
if (begin_file_out(&context, API_H, &out)){
file = context.file;
for (int32_t i = 0; i < unit_custom.set.count; ++i){
append_sc(&out, "#define ");
append_ss(&out, func_4ed_names.names[i].macro);
append_sc(&out, "(n) ");
append_ss(&out, unit_custom.set.items[i].ret);
append_sc(&out, " n");
append_ss(&out, unit_custom.set.items[i].args);
append_s_char(&out, '\n');
}
for (int32_t i = 0; i < unit_custom.set.count; ++i){
append_sc(&out, "typedef ");
append_ss(&out, func_4ed_names.names[i].macro);
append_s_char(&out, '(');
append_ss(&out, unit_custom.set.items[i].name);
append_sc(&out, "_Function);\n");
}
append_sc(&out,
"struct Application_Links{\n");
for (int32_t i = 0; i < unit_custom.set.count; ++i){
append_ss(&out, unit_custom.set.items[i].name);
append_sc(&out, "_Function *");
append_ss(&out, func_4ed_names.names[i].public_name);
append_sc(&out, ";\n");
}
append_sc(&out,
"void *memory;\n"
"int32_t memory_size;\n"
"void *cmd_context;\n"
"void *system_links;\n"
"void *current_coroutine;\n"
"int32_t type_coroutine;\n"
"};\n");
append_sc(&out, "#define FillAppLinksAPI(app_links) do{");
for (int32_t i = 0; i < unit_custom.set.count; ++i){
append_sc(&out, "\\\napp_links->");
append_ss(&out, func_4ed_names.names[i].public_name);
append_sc(&out, " = ");
append_ss(&out, unit_custom.set.items[i].name);
append_s_char(&out, ';');
}
append_sc(&out, "} while(false)\n");
end_file_out(context);
}
// NOTE(allen): Documentation
{
// //
// Output 4coder_string.h // Output 4coder_string.h
@ -2361,7 +2370,7 @@ generate_custom_headers(){
for(++i, ++token; i < count; ++i, ++token){ for(++i, ++token; i < count; ++i, ++token){
if (do_whitespace_print){ if (do_whitespace_print){
pstr = get_string(code->str, start, token->start); pstr = str_start_end(code->str, start, token->start);
print_str(file, pstr); print_str(file, pstr);
} }
else{ else{
@ -2597,7 +2606,7 @@ generate_custom_headers(){
start = token->start + token->size; start = token->start + token->size;
} }
} }
pstr = get_string(code->str, start, code->size); pstr = str_start_end(code->str, start, code->size);
print_str(file, pstr); print_str(file, pstr);
} }

View File

@ -1140,22 +1140,23 @@ string in place.)
CPP_NAME(to_lower) CPP_NAME(to_lower)
FSTRING_LINK void FSTRING_LINK void
to_lower_ss(String *src, String *dst)/* to_lower_ss(String *dst, String src)/*
DOC_PARAM(src, The source string to conver to lowercase.)
DOC_PARAM(dst, The destination buffer to receive the converted string. DOC_PARAM(dst, The destination buffer to receive the converted string.
This must have a capacity of at least the size of src.) This must have a capacity of at least the size of src.)
DOC_PARAM(src, The source string to conver to lowercase.)
DOC(Rewrites the string in src into dst. src and dst should not overlap with the exception DOC(Rewrites the string in src into dst. src and dst should not overlap with the exception
that src and dst may be exactly equal in order to convert the string in place.) that src and dst may be exactly equal in order to convert the string in place.)
*/{ */{
int32_t i = 0; int32_t i = 0;
int32_t size = src->size; int32_t size = src.size;
char *c = src->str; char *c = src.str;
char *d = dst->str; char *d = dst->str;
if (dst->memory_size >= size){ if (dst->memory_size >= size){
for (; i < size; ++i){ for (; i < size; ++i){
*d++ = char_to_lower(*c++); *d++ = char_to_lower(*c++);
} }
dst->size = size;
} }
} }
@ -1190,22 +1191,23 @@ that src and dst may be exactly equal in order to convert the string in place.)
CPP_NAME(to_upper) CPP_NAME(to_upper)
FSTRING_LINK void FSTRING_LINK void
to_upper_ss(String *src, String *dst)/* to_upper_ss(String *dst, String src)/*
DOC_PARAM(src, The source string to convert to uppercase.)
DOC_PARAM(dst, The destination buffer to receive the converted string. DOC_PARAM(dst, The destination buffer to receive the converted string.
This must have a capacity of at least the size of src.) This must have a capacity of at least the size of src.)
DOC_PARAM(src, The source string to convert to uppercase.)
DOC(Rewrites the string in src into dst. src and dst should not overlap with the exception DOC(Rewrites the string in src into dst. src and dst should not overlap with the exception
that src and dst may be exactly equal in order to convert the string in place.) that src and dst may be exactly equal in order to convert the string in place.)
*/{ */{
int32_t i = 0; int32_t i = 0;
int32_t size = src->size; int32_t size = src.size;
char *c = src->str; char *c = src.str;
char *d = dst->str; char *d = dst->str;
if (dst->memory_size >= size){ if (dst->memory_size >= size){
for (; i < size; ++i){ for (; i < size; ++i){
*d++ = char_to_upper(*c++); *d++ = char_to_upper(*c++);
} }
dst->size = size;
} }
} }