diff --git a/gen_c_library/c_library.cpp b/gen_c_library/c_library.cpp index 69ac6c1..d10243d 100644 --- a/gen_c_library/c_library.cpp +++ b/gen_c_library/c_library.cpp @@ -836,16 +836,16 @@ R"(#define AST_ArrSpecs_Cap \ CodeBody array_arena = gen_array(txt("Arena"), txt("Array_Arena")); CodeBody array_pool = gen_array(txt("Pool"), txt("Array_Pool")); - Code src_static_data = scan_file( project_dir "components/static_data.cpp" ); - Code src_ast_case_macros = scan_file( project_dir "components/ast_case_macros.cpp" ); - Code src_ast = scan_file( project_dir "components/ast.cpp" ); - Code src_code = scan_file( project_dir "components/code_serialization.cpp" ); - Code src_interface = scan_file( project_dir "components/interface.cpp" ); - Code src_upfront = scan_file( project_dir "components/interface.upfront.cpp" ); - Code src_lexer = scan_file( project_dir "components/lexer.cpp" ); - Code src_parser = scan_file( project_dir "components/parser.cpp" ); - Code src_parsing_interface = scan_file( project_dir "components/interface.parsing.cpp" ); - Code src_untyped = scan_file( project_dir "components/interface.untyped.cpp" ); + Code src_static_data = scan_file( project_dir "components/static_data.cpp" ); + Code src_ast_case_macros = scan_file( project_dir "components/ast_case_macros.cpp" ); + Code src_ast = scan_file( project_dir "components/ast.cpp" ); + Code src_code_serialization = scan_file( project_dir "components/code_serialization.cpp" ); + Code src_interface = scan_file( project_dir "components/interface.cpp" ); + Code src_upfront = scan_file( project_dir "components/interface.upfront.cpp" ); + Code src_lexer = scan_file( project_dir "components/lexer.cpp" ); + Code src_parser = scan_file( project_dir "components/parser.cpp" ); + Code src_parsing_interface = scan_file( project_dir "components/interface.parsing.cpp" ); + Code src_untyped = scan_file( project_dir "components/interface.untyped.cpp" ); #pragma endregion Resolve Components // THERE SHOULD BE NO NEW GENERIC CONTAINER DEFINTIONS PAST THIS POINT (It will not have slots for the generic selection generated macros) @@ -985,12 +985,12 @@ R"(#define AST_ArrSpecs_Cap \ header.print_fmt( "#pragma region AST\n\n" ); header.print( src_ast_case_macros ); - header.print( src_ast ); - // header.print( src_code ); + header.print( src_ast ); + header.print( src_code_serialization ); header.print_fmt( "#pragma endregion AST\n\n" ); - // header.print_fmt( "#pragma region Interface\n" ); - // header.print( src_interface ); + header.print_fmt( "#pragma region Interface\n" ); + header.print( src_interface ); // header.print( src_upfront ); // header.print_fmt( "\n#pragma region Parsing\n\n" ); // header.print( format_code_to_untyped(parser_nspace) ); @@ -999,7 +999,7 @@ R"(#define AST_ArrSpecs_Cap \ // header.print( parsing_interface ); // header.print_fmt( "\n#pragma endregion Parsing\n" ); // header.print( untyped ); - // header.print_fmt( "\n#pragma endregion Interface\n\n"); + header.print_fmt( "\n#pragma endregion Interface\n\n"); // header.print_fmt( "#pragma region Builder\n" ); // header.print( scan_file( project_dir "auxillary/builder.cpp" ) ); diff --git a/gen_c_library/components/containers.hashtable.hpp b/gen_c_library/components/containers.hashtable.hpp index 7401997..eee83f5 100644 --- a/gen_c_library/components/containers.hashtable.hpp +++ b/gen_c_library/components/containers.hashtable.hpp @@ -107,7 +107,7 @@ CodeBody gen_hashtable( StrC type, StrC hashtable_name ) HT_FindResult __find ( self, u64 key ); b32 __full ( self ); - init( AllocatorInfo allocator ) + _init( AllocatorInfo allocator ) { result = hashtable_init_reserve(, allocator, 8); return result; @@ -379,7 +379,7 @@ CodeBody gen_hashtable( StrC type, StrC hashtable_name ) R"(#define GENERIC_SLOT___hashtable_init , _init #define GENERIC_SLOT___hashtable_init_reserve , _init_reserve #define GENERIC_SLOT___hashtable_clear , _clear -#define GENERIC_SLOT___hashtable_destroy *, _destroy +#define GENERIC_SLOT___hashtable_destroy , _destroy #define GENERIC_SLOT___hashtable_get , _get #define GENERIC_SLOT___hashtable_map , _map #define GENERIC_SLOT___hashtable_map_mut , _map_mut @@ -387,7 +387,7 @@ R"(#define GENERIC_SLOT___hashtable_init , _ #define GENERIC_SLOT___hashtable_rehash *, _rehash #define GENERIC_SLOT___hashtable_rehash_fast , _rehash_fast #define GENERIC_SLOT___hashtable_remove_entry , _remove_entry -#define GENERIC_SLOT___hashtable_set *, _set +#define GENERIC_SLOT___hashtable_set , _set #define GENERIC_SLOT___hashtable_slot , _slot #define GENERIC_SLOT___hashtable__add_entry *, __add_entry diff --git a/project/components/code_serialization.cpp b/project/components/code_serialization.cpp index 369f28e..5369cc6 100644 --- a/project/components/code_serialization.cpp +++ b/project/components/code_serialization.cpp @@ -3,13 +3,15 @@ #include "ast.cpp" #endif -forceinline +inline String attributes_to_string(CodeAttributes attributes) { GEN_ASSERT(attributes); - return {(char*) strc_duplicate( attributes->Content, GlobalAllocator ).Ptr}; + char* raw = ccast(char*, strc_duplicate( attributes->Content, GlobalAllocator ).Ptr); + String result = { raw }; + return result; } -forceinline +inline void attributes_to_string_ref(CodeAttributes attributes, String* result) { GEN_ASSERT(attributes); GEN_ASSERT(result); @@ -77,13 +79,15 @@ void body_to_string_export( CodeBody body, String* result ) string_append_fmt( result, "};\n" ); } -forceinline +inline String comment_to_string(CodeComment comment) { GEN_ASSERT(comment); - return {(char*) strc_duplicate( comment->Content, GlobalAllocator ).Ptr}; + char* raw = ccast(char*, strc_duplicate( comment->Content, GlobalAllocator ).Ptr); + String result = { raw }; + return result; } -forceinline +inline void comment_to_string_ref(CodeComment comment, String* result) { GEN_ASSERT(comment); GEN_ASSERT(result); @@ -184,9 +188,8 @@ void class_to_string_def( CodeClass self, String* result ) if ( self->ParentType ) { - char const* access_level = access_spec_to_str( self->ParentAccess ); - - string_append_fmt( result, "%SC : %s %S", self->Name, access_level, typename_to_string(self->ParentType) ); + StrC access_level = access_spec_to_str( self->ParentAccess ); + string_append_fmt( result, "%SC : %SC %S", self->Name, access_level, typename_to_string(self->ParentType) ); CodeTypename interface = cast(CodeTypename, self->ParentType->Next); if ( interface ) @@ -195,10 +198,10 @@ void class_to_string_def( CodeClass self, String* result ) while ( interface ) { string_append_fmt( result, ", %S", typename_to_string(interface) ); - interface = interface->Next ? cast(CodeTypename, interface->Next) : CodeTypename { nullptr }; + interface = interface->Next ? cast(CodeTypename, interface->Next) : NullCode; } } - else if ( self->Name ) + else if ( self->Name.Len ) { string_append_strc( result, self->Name ); } @@ -263,7 +266,7 @@ String destructor_to_string(CodeDestructor self) void destructor_to_string_def(CodeDestructor self, String* result ) { - if ( self->Name ) + if ( self->Name.Len ) { string_append_fmt( result, "%SC()", self->Name ); } @@ -439,7 +442,10 @@ void enum_to_string_class_fwd(CodeEnum self, String* result ) String exec_to_string(CodeExec exec) { - return {(char*) strc_duplicate( exec->Content, GlobalAllocator ).Ptr}; + GEN_ASSERT(exec); + char* raw = ccast(char*, strc_duplicate( exec->Content, GlobalAllocator ).Ptr); + String result = { raw }; + return result; } void extern_to_string(CodeExtern self, String* result ) @@ -622,10 +628,10 @@ String module_to_string(CodeModule self) void module_to_string_ref(CodeModule self, String* result ) { - if (((u32(ModuleFlag_Export) & u32(self->ModuleFlags)) == u32(ModuleFlag_Export))) + if (((scast(u32, ModuleFlag_Export) & scast(u32, self->ModuleFlags)) == scast(u32, ModuleFlag_Export))) string_append_strc( result, txt("export ")); - if (((u32(ModuleFlag_Import) & u32(self->ModuleFlags)) == u32(ModuleFlag_Import))) + if (((scast(u32, ModuleFlag_Import) & scast(u32, self->ModuleFlags)) == scast(u32, ModuleFlag_Import))) string_append_strc( result, txt("import ")); string_append_fmt( result, "%SC;\n", self->Name ); @@ -796,7 +802,7 @@ void opcast_to_string_def(CodeOpCast self, String* result ) } } - if ( self->Name && self->Name.Len ) + if ( self->Name.Ptr && self->Name.Len ) string_append_fmt( result, "%SC operator %S()", self->Name, typename_to_string(self->ValueType) ); else string_append_fmt( result, "operator %S()", typename_to_string(self->ValueType) ); @@ -814,7 +820,7 @@ void opcast_to_string_def(CodeOpCast self, String* result ) return; } - if ( self->Name && self->Name.Len ) + if ( self->Name.Ptr && self->Name.Len ) string_append_fmt( result, "%SC operator %S()\n{\n%S\n}\n", self->Name, typename_to_string(self->ValueType), body_to_string(self->Body) ); else string_append_fmt( result, "operator %S()\n{\n%S\n}\n", typename_to_string(self->ValueType), body_to_string(self->Body) ); @@ -877,7 +883,7 @@ void params_to_string_ref( CodeParam self, String* result ) // Could also be: ( , ... ) } - if ( self->Name ) + if ( self->Name.Ptr && self->Name.Len ) { if ( self->ValueType == nullptr ) string_append_fmt( result, " %SC", self->Name ); @@ -1036,9 +1042,9 @@ void struct_to_string_def( CodeStruct self, String* result ) if ( self->ParentType ) { - char const* access_level = access_spec_to_str( self->ParentAccess ); + StrC access_level = access_spec_to_str( self->ParentAccess ); - string_append_fmt( result, "%SC : %s %S", self->Name, access_level, typename_to_string(self->ParentType) ); + string_append_fmt( result, "%SC : %SC %S", self->Name, access_level, typename_to_string(self->ParentType) ); CodeTypename interface = cast(CodeTypename, self->ParentType->Next); if ( interface ) @@ -1047,10 +1053,10 @@ void struct_to_string_def( CodeStruct self, String* result ) while ( interface ) { string_append_fmt( result, ", %S", typename_to_string(interface) ); - interface = interface->Next ? cast( CodeTypename, interface->Next) : CodeTypename { nullptr }; + interface = interface->Next ? cast( CodeTypename, interface->Next) : NullCode; } } - else if ( self->Name ) + else if ( self->Name.Len ) { string_append_strc( result, self->Name ); } @@ -1238,7 +1244,7 @@ void union_to_string_def(CodeUnion self, String* result ) if ( self->Attributes ) string_append_fmt( result, "%S ", attributes_to_string(self->Attributes) ); - if ( self->Name ) + if ( self->Name.Len ) { string_append_fmt( result, "%SC\n{\n%S\n}" , self->Name @@ -1269,7 +1275,7 @@ void union_to_string_fwd(CodeUnion self, String* result ) if ( self->Attributes ) string_append_fmt( result, "%S ", attributes_to_string(self->Attributes) ); - if ( self->Name ) + if ( self->Name.Len ) { string_append_fmt( result, "%SC", self->Name); } @@ -1331,7 +1337,7 @@ void using_to_string_ref(CodeUsing self, String* result ) string_append_strc( result, txt("\n")); } -forceinline +inline void using_to_string_ns(CodeUsing self, String* result ) { GEN_ASSERT(self); @@ -1342,7 +1348,7 @@ void using_to_string_ns(CodeUsing self, String* result ) string_append_fmt( result, "using namespace %SC;\n", self->Name ); } -forceinline +inline String var_to_string(CodeVar self) { GEN_ASSERT(self); diff --git a/project/components/interface.cpp b/project/components/interface.cpp index f7a9910..c3c0d5a 100644 --- a/project/components/interface.cpp +++ b/project/components/interface.cpp @@ -101,10 +101,12 @@ void define_constants() access_public->Name = get_cached_string( txt("public:\n") ); code_set_global(access_public); - attrib_api_export = def_attributes( code(GEN_API_Export_Code)); + StrC api_export_str = code(GEN_API_Export_Code); + attrib_api_export = def_attributes( api_export_str ); code_set_global(cast(Code, attrib_api_export)); - attrib_api_import = def_attributes( code(GEN_API_Import_Code)); + StrC api_import_str = code(GEN_API_Import_Code); + attrib_api_import = def_attributes( api_import_str ); code_set_global(cast(Code, attrib_api_import)); module_global_fragment = make_code(); @@ -143,9 +145,14 @@ void define_constants() preprocess_endif->Type = CT_Preprocess_EndIf; code_set_global((Code)preprocess_endif); -# define def_constant_code_type( Type_ ) \ - t_##Type_ = def_type( name(Type_) ); \ - code_set_global( cast(Code, t_##Type_)); +# define def_constant_code_type( Type_ ) \ + do \ + { \ + Opts_def_type ops = {}; \ + StrC name_str = name(Type_); \ + t_##Type_ = def_type( name_str, ops ); \ + code_set_global( cast(Code, t_##Type_)); \ + } while(0) def_constant_code_type( auto ); def_constant_code_type( void ); @@ -237,9 +244,10 @@ void init() { // Setup global allocator { - GlobalAllocator = AllocatorInfo { & Global_Allocator_Proc, nullptr }; + AllocatorInfo becasue_C = { & Global_Allocator_Proc, nullptr }; + GlobalAllocator = becasue_C; - Global_AllocatorBuckets = array_init_reserve( heap(), 128 ); + Global_AllocatorBuckets = array_init_reserve(Arena, heap(), 128 ); if ( Global_AllocatorBuckets == nullptr ) GEN_FATAL( "Failed to reserve memory for Global_AllocatorBuckets"); @@ -273,12 +281,12 @@ void init() // Setup the arrays { - CodePools = array_init_reserve( Allocator_DataArrays, InitSize_DataArrays ); + CodePools = array_init_reserve(Pool, Allocator_DataArrays, InitSize_DataArrays ); if ( CodePools == nullptr ) GEN_FATAL( "gen::init: Failed to initialize the CodePools array" ); - StringArenas = array_init_reserve( Allocator_DataArrays, InitSize_DataArrays ); + StringArenas = array_init_reserve(Arena, Allocator_DataArrays, InitSize_DataArrays ); if ( StringArenas == nullptr ) GEN_FATAL( "gen::init: Failed to initialize the StringArenas array" ); @@ -305,14 +313,14 @@ void init() // Setup the hash tables { - StringCache = hashtable_init(Allocator_StringTable); + StringCache = hashtable_init(StringCached, Allocator_StringTable); if ( StringCache.Entries == nullptr ) GEN_FATAL( "gen::init: Failed to initialize the StringCache"); } // Preprocessor Defines - PreprocessorDefines = array_init_reserve( GlobalAllocator, kilobytes(1) ); + PreprocessorDefines = array_init_reserve(StringCached, GlobalAllocator, kilobytes(1) ); define_constants(); GEN_NS_PARSER init(); @@ -396,7 +404,7 @@ AllocatorInfo get_string_allocator( s32 str_length ) usize size_req = str_length + sizeof(StringHeader) + sizeof(char*); - if ( last->TotalUsed + ssize(size_req) > last->TotalSize ) + if ( last->TotalUsed + scast(ssize, size_req) > last->TotalSize ) { Arena new_arena = arena_init_from_allocator( Allocator_StringArena, SizePer_StringArena ); @@ -424,7 +432,7 @@ StringCached get_cached_string( StrC str ) StrC result = string_to_strc( string_make_strc( get_string_allocator( str.Len ), str )); hashtable_set(StringCache, key, result ); - return { str.Len, result }; + return result; } // Used internally to retireve a Code object form the CodePool. @@ -444,20 +452,8 @@ Code make_code() allocator = array_back( CodePools); } - Code result { rcast( AST*, alloc( pool_allocator_info(allocator), sizeof(AST) )) }; + Code result = { rcast( AST*, alloc( pool_allocator_info(allocator), sizeof(AST) )) }; mem_set( rcast(void*, cast(AST*, result)), 0, sizeof(AST) ); - // result->Type = ECode::Invalid; - - // result->Content = { nullptr }; - // result->Prev = { nullptr }; - // result->Next = { nullptr }; - // result->Token = nullptr; - // result->Parent = { nullptr }; - // result->Name = { nullptr }; - // result->Type = ECode::Invalid; - // result->ModuleFlags = ModuleFlag::Invalid; - // result->NumEntries = 0; - return result; } diff --git a/project/dependencies/macros.hpp b/project/dependencies/macros.hpp index f7accf2..c51057e 100644 --- a/project/dependencies/macros.hpp +++ b/project/dependencies/macros.hpp @@ -16,7 +16,7 @@ #ifndef bit #define bit( Value ) ( 1 << Value ) -#define bitfield_is_equal( Type, Field, Mask ) ( (Type(Mask) & Type(Field)) == Type(Mask) ) +#define bitfield_is_equal( Type, Field, Mask ) ( (scast(Type, Mask) & scast(Type, Field)) == scast(Type, Mask) ) #endif // Mainly intended for forcing the base library to utilize only C-valid constructs or type coercion