From 0ccffe3f80b7455c158ef3ed2da4e3d492941b43 Mon Sep 17 00:00:00 2001 From: Ed_ Date: Mon, 9 Dec 2024 23:19:19 -0500 Subject: [PATCH] interface.untyped.cpp impl compiles in gnerated c library --- gen_c_library/c_library.cpp | 6 ++--- .../components/memory.fixed_arena.hpp | 21 ++++++++++++++++ project/components/header_end.hpp | 6 ++--- project/components/interface.hpp | 2 +- project/components/interface.parsing.cpp | 4 +-- project/components/interface.untyped.cpp | 25 +++++++++++-------- project/components/parser.cpp | 2 +- project/dependencies/memory.hpp | 1 + 8 files changed, 47 insertions(+), 20 deletions(-) diff --git a/gen_c_library/c_library.cpp b/gen_c_library/c_library.cpp index 7b01b2d..f8ad5b9 100644 --- a/gen_c_library/c_library.cpp +++ b/gen_c_library/c_library.cpp @@ -1189,7 +1189,7 @@ R"(#define ( code ) _Generic( (code), \ for ( CodeParam arr_param : fn->Params ) if ( fn->Name.starts_with(txt("def_")) - && ( arr_param->ValueType->Name.starts_with(txt("Specifier")) + && ( (arr_param->ValueType->Name.starts_with(txt("Specifier")) && fn->Params->NumEntries > 1) || arr_param->ValueType->Name.starts_with(txt("Code")) ) ) { @@ -1508,9 +1508,9 @@ R"(#define ( code ) _Generic( (code), \ header.print( format_code_to_untyped(array_code_typename)); header.print( fmt_newline); header.print( format_code_to_untyped(src_parser) ); - // header.print( parsing_interface ); + header.print( src_parsing_interface ); header.print_fmt( "\n#pragma endregion Parsing\n" ); - // header.print( untyped ); + header.print( src_untyped ); header.print_fmt( "\n#pragma endregion Interface\n\n"); // header.print_fmt( "#pragma region Builder\n" ); diff --git a/gen_c_library/components/memory.fixed_arena.hpp b/gen_c_library/components/memory.fixed_arena.hpp index 0b5061a..f223d2a 100644 --- a/gen_c_library/components/memory.fixed_arena.hpp +++ b/gen_c_library/components/memory.fixed_arena.hpp @@ -29,6 +29,11 @@ CodeBody gen_fixed_arenas() { return arena_size_remaining( & fixed_arena->arena, alignment); } + + inline + void fixed_arena_free_(FixedArena_* fixed_arena) { + arena_free( & fixed_arena->arena); + } ); CodeBody arena_struct_1kb = parse_global_body( token_fmt_impl( 3, "Name", txt("1KB"), "Size", txt("kilobytes(1)"), template_struct )); @@ -105,6 +110,22 @@ CodeBody gen_fixed_arenas() default : gen_generic_selection_fail \ ) GEN_RESOLVED_FUNCTION_CALL(expr) +#define fixed_arena_free(expr) _Generic((expr), \ + FixedArena_1KB* : fixed_arena_free_1KB, \ + FixedArena_4KB* : fixed_arena_free_4KB, \ + FixedArena_8KB* : fixed_arena_free_8KB, \ + FixedArena_16KB* : fixed_arena_free_16KB, \ + FixedArena_32KB* : fixed_arena_free_32KB, \ + FixedArena_64KB* : fixed_arena_free_64KB, \ + FixedArena_128KB* : fixed_arena_free_128KB, \ + FixedArena_256KB* : fixed_arena_free_256KB, \ + FixedArena_512KB* : fixed_arena_free_512KB, \ + FixedArena_1MB* : fixed_arena_free_1MB, \ + FixedArena_2MB* : fixed_arena_free_2MB, \ + FixedArena_4MB* : fixed_arena_free_4MB, \ + default : gen_generic_selection_fail \ +) GEN_RESOLVED_FUNCTION_CALL(expr) + #define fixed_arena_size_remaining(expr, alignment) _Generic((expr), \ FixedArena_1KB* : fixed_arena_size_remaining_1KB, \ FixedArena_4KB* : fixed_arena_size_remaining_4KB, \ diff --git a/project/components/header_end.hpp b/project/components/header_end.hpp index 74d76cc..0bba6a8 100644 --- a/project/components/header_end.hpp +++ b/project/components/header_end.hpp @@ -24,8 +24,8 @@ #ifndef GEN_MAX_UNTYPED_STR_LENGTH # define GEN_MAX_UNTYPED_STR_LENGTH megabytes(1) #endif -#ifndef GEN_TOKEN_FMT_TOKEN_MAP_MEM_SIZE -# define GEN_TOKEN_FMT_TOKEN_MAP_MEM_SIZE kilobytes(8) +#ifndef TokenMap_FixedArena +# define TokenMap_FixedArena FixedArena_8KB #endif #ifndef GEN_LEX_ALLOCATOR_SIZE # define GEN_LEX_ALLOCATOR_SIZE megabytes(4) @@ -49,7 +49,7 @@ constexpr s32 SizePer_StringArena = GEN_SIZE_PER_STRING_ARENA; constexpr s32 MaxCommentLineLength = GEN_MAX_COMMENT_LINE_LENGTH; constexpr s32 MaxNameLength = GEN_MAX_NAME_LENGTH; constexpr s32 MaxUntypedStrLength = GEN_MAX_UNTYPED_STR_LENGTH; -constexpr s32 TokenFmt_TokenMap_MemSize = GEN_TOKEN_FMT_TOKEN_MAP_MEM_SIZE; +// constexpr s32 TokenFmt_TokenMap_MemSize = GEN_TOKEN_FMT_TOKEN_MAP_MEM_SIZE; constexpr s32 LexAllocator_Size = GEN_LEX_ALLOCATOR_SIZE; constexpr s32 Builder_StrBufferReserve = GEN_BUILDER_STR_BUFFER_RESERVE; diff --git a/project/components/interface.hpp b/project/components/interface.hpp index 068dacb..4a5862b 100644 --- a/project/components/interface.hpp +++ b/project/components/interface.hpp @@ -272,7 +272,7 @@ StrC token_fmt_impl( ssize, ... ); Code untyped_str ( StrC content); Code untyped_fmt ( char const* fmt, ... ); -Code untyped_token_fmt( char const* fmt, s32 num_tokens, ... ); +Code untyped_token_fmt( s32 num_tokens, char const* fmt, ... ); #pragma endregion Untyped text diff --git a/project/components/interface.parsing.cpp b/project/components/interface.parsing.cpp index a90870f..15aaa04 100644 --- a/project/components/interface.parsing.cpp +++ b/project/components/interface.parsing.cpp @@ -35,8 +35,8 @@ CodeConstructor parse_constructor( StrC def ) // TODO(Ed): Constructors can have prefix attributes - CodeSpecifiers specifiers; - Specifier specs_found[ 16 ] { Spec_NumSpecifiers }; + CodeSpecifiers specifiers = NullCode; + Specifier specs_found[ 16 ] = { Spec_NumSpecifiers }; s32 NumSpecifiers = 0; while ( left && tok_is_specifier(currtok) ) diff --git a/project/components/interface.untyped.cpp b/project/components/interface.untyped.cpp index 45ecdc1..d430656 100644 --- a/project/components/interface.untyped.cpp +++ b/project/components/interface.untyped.cpp @@ -9,11 +9,11 @@ ssize token_fmt_va( char* buf, usize buf_size, s32 num_tokens, va_list va ) ssize remaining = buf_size; local_persist - FixedArena tok_map_arena; + TokenMap_FixedArena tok_map_arena; fixed_arena_init( & tok_map_arena); local_persist - HashTable(StrC) tok_map; + StringTable tok_map; { tok_map = hashtable_init(StrC, fixed_arena_allocator_info(& tok_map_arena) ); @@ -113,7 +113,7 @@ Code untyped_str( StrC content ) result->Type = CT_Untyped; result->Content = result->Name; - if ( result->Name == nullptr ) + if ( result->Name.Len == 0 ) { log_failure( "untyped_str: could not cache string" ); return InvalidCode; @@ -138,13 +138,16 @@ Code untyped_fmt( char const* fmt, ...) ssize length = str_fmt_va(buf, GEN_PRINTF_MAXLEN, fmt, va); va_end(va); + StrC buf_str = { str_len_capped(fmt, MaxNameLength), fmt }; + StrC uncapped_str = { length, buf }; + Code result = make_code(); - result->Name = get_cached_string( { str_len_capped(fmt, MaxNameLength), fmt } ); + result->Name = get_cached_string( buf_str ); result->Type = CT_Untyped; - result->Content = get_cached_string( { length, buf } ); + result->Content = get_cached_string( uncapped_str ); - if ( result->Name == nullptr ) + if ( result->Name.Len == 0 ) { log_failure( "untyped_fmt: could not cache string" ); return InvalidCode; @@ -153,7 +156,7 @@ Code untyped_fmt( char const* fmt, ...) return result; } -Code untyped_token_fmt( s32 num_tokens, ... ) +Code untyped_token_fmt( s32 num_tokens, char const* fmt, ... ) { if ( num_tokens == 0 ) { @@ -165,17 +168,19 @@ Code untyped_token_fmt( s32 num_tokens, ... ) char buf[GEN_PRINTF_MAXLEN] = { 0 }; va_list va; - va_start(va, num_tokens); + va_start(va, fmt); ssize length = token_fmt_va(buf, GEN_PRINTF_MAXLEN, num_tokens, va); va_end(va); + StrC buf_str = { length, buf }; + Code result = make_code(); - result->Name = get_cached_string( { length, buf } ); + result->Name = get_cached_string( buf_str ); result->Type = CT_Untyped; result->Content = result->Name; - if ( result->Name == nullptr ) + if ( result->Name.Len == 0 ) { log_failure( "untyped_fmt: could not cache string" ); return InvalidCode; diff --git a/project/components/parser.cpp b/project/components/parser.cpp index 2f7062f..7ee8737 100644 --- a/project/components/parser.cpp +++ b/project/components/parser.cpp @@ -150,7 +150,7 @@ void parser_init() internal void parser_deinit() { - Array(Token) null_array = {}; + Array(Token) null_array = { nullptr }; Lexer_Tokens = null_array; } diff --git a/project/dependencies/memory.hpp b/project/dependencies/memory.hpp index 386d0ac..4a80778 100644 --- a/project/dependencies/memory.hpp +++ b/project/dependencies/memory.hpp @@ -319,6 +319,7 @@ struct FixedArena; template FixedArena fixed_arena_init(); template AllocatorInfo fixed_arena_allocator_info(FixedArena* fixed_arena ); template ssize fixed_arena_size_remaining(FixedArena* fixed_arena, ssize alignment); +template void fixed_arena_free(FixedArena* fixed_arena); #if GEN_COMPILER_CPP && ! GEN_C_LIKE_CPP template AllocatorInfo allocator_info( FixedArena& fixed_arena ) { return allocator_info(& fixed_arena); }