progress on c_library.cpp

This commit is contained in:
Edward R. Gonzalez 2024-12-01 01:40:31 -05:00
parent a96d03eaed
commit c7b072266f
3 changed files with 82 additions and 13 deletions

View File

@ -18,6 +18,8 @@ GEN_NS_END
#include "components/memory.fixed_arena.hpp" #include "components/memory.fixed_arena.hpp"
#include "components/misc.hpp" #include "components/misc.hpp"
#include "components/containers.array.hpp"
#include "components/containers.hashtable.hpp"
using namespace gen; using namespace gen;
@ -114,6 +116,14 @@ int gen_main()
Code basic_types = scan_file( project_dir "dependencies/basic_types.hpp" ); Code basic_types = scan_file( project_dir "dependencies/basic_types.hpp" );
Code debug = scan_file( project_dir "dependencies/debug.hpp" ); Code debug = scan_file( project_dir "dependencies/debug.hpp" );
header.print_fmt( roll_own_dependencies_guard_start );
header.print( platform );
header.print_fmt( "\nGEN_NS_BEGIN\n" );
header.print( macros );
header.print( basic_types );
header.print( debug );
CodeBody parsed_memory = parse_file( project_dir "dependencies/memory.hpp" ); CodeBody parsed_memory = parse_file( project_dir "dependencies/memory.hpp" );
CodeBody memory = def_body(ECode::Struct_Body); CodeBody memory = def_body(ECode::Struct_Body);
for ( Code entry = parsed_memory.begin(); entry != parsed_memory.end(); ++ entry ) for ( Code entry = parsed_memory.begin(); entry != parsed_memory.end(); ++ entry )
@ -164,7 +174,12 @@ int gen_main()
break; break;
case ECode::Preprocess_If: case ECode::Preprocess_If:
{ {
ignore_preprocess_cond_block(txt("GEN_SUPPORT_CPP_MEMBER_FEATURES"), entry, memory ); ignore_preprocess_cond_block(txt("GEN_SUPPORT_CPP_MEMBER_FEATURES"), entry, parsed_memory );
}
break;
case ECode::Preprocess_IfDef:
{
ignore_preprocess_cond_block(txt("GEN_INTELLISENSE_DIRECTIVES"), entry, parsed_memory );
} }
break; break;
case ECode::Preprocess_Pragma: case ECode::Preprocess_Pragma:
@ -179,14 +194,58 @@ int gen_main()
} }
} }
header.print_fmt( roll_own_dependencies_guard_start );
header.print( platform );
header.print_fmt( "\nGEN_NS_BEGIN\n" );
header.print( macros );
header.print( basic_types );
header.print( debug );
header.print( memory ); header.print( memory );
Code string_ops = scan_file( project_dir "dependencies/string_ops.hpp" );
header.print( string_ops );
CodeBody printing_parsed = parse_file( project_dir "dependencies/printing.hpp" );
CodeBody printing = def_body(ECode::Struct_Body);
for ( Code entry = printing_parsed.begin(); entry != printing_parsed.end(); ++ entry )
{
switch (entry->Type)
{
case ECode::Preprocess_IfDef:
{
ignore_preprocess_cond_block(txt("GEN_INTELLISENSE_DIRECTIVES"), entry, printing_parsed );
}
}
if (entry->Type == ECode::Variable &&
contains(entry->Name, txt("Msg_Invalid_Value")))
{
CodeDefine define = def_define(entry->Name, entry->Value->Content);
printing.append(define);
continue;
}
printing.append(entry);
}
header.print(printing);
CodeBody parsed_containers = parse_file( project_dir "dependencies/containers.hpp" );
CodeBody containers = def_body(ECode::Struct_Body);
for ( Code entry = parsed_containers.begin(); entry != parsed_containers.end(); ++ entry )
{
switch ( entry->Type )
{
case ECode::Preprocess_Pragma:
{
bool found = false;
found = swap_pragma_region_implementation( txt("Array"), gen_array_base, entry, containers);
if (found) break;
found = swap_pragma_region_implementation( txt("Hashtable"), gen_hashtable_base, entry, containers);
if (found) break;
containers.append(entry);
}
break;
}
}
header.print(containers);
} }
header.print( pop_ignores ); header.print( pop_ignores );

View File

@ -6,6 +6,7 @@ using namespace gen;
CodeBody gen_fixed_arenas() CodeBody gen_fixed_arenas()
{ {
CodeBody result = def_body(ECode::Global_Body); CodeBody result = def_body(ECode::Global_Body);
result.append(def_pragma(txt("region FixedArena")));
char const* template_struct = stringize( char const* template_struct = stringize(
struct FixedArena_<Name> struct FixedArena_<Name>
@ -115,5 +116,7 @@ CodeBody gen_fixed_arenas()
)" )"
))); )));
result.append(def_pragma(txt("endregion FixedArena")));
return result; return result;
} }

View File

@ -11,7 +11,7 @@ b32 ignore_preprocess_cond_block( StrC cond_sig, Code& entry_iter, CodeBody& bod
if ( cond->Content.contains(cond_sig) ) if ( cond->Content.contains(cond_sig) )
{ {
s32 depth = 1; s32 depth = 1;
++ entry_iter; for(b32 continue_for = true; continue_for && entry_iter != body.end(); ++ entry_iter) switch ++ entry_iter; for(b32 continue_for = true; continue_for && entry_iter != body.end(); ) switch
(entry_iter->Type) { (entry_iter->Type) {
case ECode::Preprocess_If: case ECode::Preprocess_If:
case ECode::Preprocess_IfDef: case ECode::Preprocess_IfDef:
@ -24,24 +24,30 @@ b32 ignore_preprocess_cond_block( StrC cond_sig, Code& entry_iter, CodeBody& bod
depth --; depth --;
if (depth == 0) { if (depth == 0) {
continue_for = false; continue_for = false;
break;
} }
} }
break; break;
default:
++ entry_iter;
break;
} }
} }
return entry_iter != body.end(); return entry_iter != body.end();
} }
void swap_pragma_region_implementation( StrC region_name, SwapContentProc* swap_content, Code& entry_iter, CodeBody& body ) bool swap_pragma_region_implementation( StrC region_name, SwapContentProc* swap_content, Code& entry_iter, CodeBody& body )
{ {
bool found = false;
CodePragma possible_region = entry_iter.cast<CodePragma>(); CodePragma possible_region = entry_iter.cast<CodePragma>();
String region_sig = string_fmt_buf(GlobalAllocator, "region %s", region_name.Ptr); String region_sig = string_fmt_buf(GlobalAllocator, "region %s", region_name.Ptr);
String endregion_sig = string_fmt_buf(GlobalAllocator, "endregion %s", region_name.Ptr); String endregion_sig = string_fmt_buf(GlobalAllocator, "endregion %s", region_name.Ptr);
if ( possible_region->Content.contains(region_sig)) if ( possible_region->Content.contains(region_sig))
{ {
body.append(possible_region); found = true;
// body.append(possible_region);
body.append(swap_content()); body.append(swap_content());
++ entry_iter; for(b32 continue_for = true; continue_for; ++entry_iter) switch ++ entry_iter; for(b32 continue_for = true; continue_for; ++entry_iter) switch
@ -50,12 +56,13 @@ void swap_pragma_region_implementation( StrC region_name, SwapContentProc* swap_
{ {
CodePragma possible_end_region = entry_iter.cast<CodePragma>(); CodePragma possible_end_region = entry_iter.cast<CodePragma>();
if ( possible_end_region->Content.contains(endregion_sig) ) { if ( possible_end_region->Content.contains(endregion_sig) ) {
body.append(possible_end_region); // body.append(possible_end_region);
continue_for = false; continue_for = false;
} }
} }
break; break;
} }
body.append(entry_iter);
} }
body.append(entry_iter); return found;
} }