mirror of
https://github.com/Ed94/gencpp.git
synced 2024-12-22 07:44:45 -08:00
interface.untyped.cpp impl compiles in gnerated c library
This commit is contained in:
parent
cd7548c3d4
commit
0ccffe3f80
@ -1189,7 +1189,7 @@ R"(#define <interface_name>( code ) _Generic( (code), \
|
|||||||
|
|
||||||
for ( CodeParam arr_param : fn->Params )
|
for ( CodeParam arr_param : fn->Params )
|
||||||
if ( fn->Name.starts_with(txt("def_"))
|
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")) )
|
|| arr_param->ValueType->Name.starts_with(txt("Code")) )
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
@ -1508,9 +1508,9 @@ R"(#define <interface_name>( code ) _Generic( (code), \
|
|||||||
header.print( format_code_to_untyped(array_code_typename));
|
header.print( format_code_to_untyped(array_code_typename));
|
||||||
header.print( fmt_newline);
|
header.print( fmt_newline);
|
||||||
header.print( format_code_to_untyped(src_parser) );
|
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_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( "\n#pragma endregion Interface\n\n");
|
||||||
|
|
||||||
// header.print_fmt( "#pragma region Builder\n" );
|
// header.print_fmt( "#pragma region Builder\n" );
|
||||||
|
@ -29,6 +29,11 @@ CodeBody gen_fixed_arenas()
|
|||||||
{
|
{
|
||||||
return arena_size_remaining( & fixed_arena->arena, alignment);
|
return arena_size_remaining( & fixed_arena->arena, alignment);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
void fixed_arena_free_<Name>(FixedArena_<Name>* 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 ));
|
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 \
|
default : gen_generic_selection_fail \
|
||||||
) GEN_RESOLVED_FUNCTION_CALL(expr)
|
) 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), \
|
#define fixed_arena_size_remaining(expr, alignment) _Generic((expr), \
|
||||||
FixedArena_1KB* : fixed_arena_size_remaining_1KB, \
|
FixedArena_1KB* : fixed_arena_size_remaining_1KB, \
|
||||||
FixedArena_4KB* : fixed_arena_size_remaining_4KB, \
|
FixedArena_4KB* : fixed_arena_size_remaining_4KB, \
|
||||||
|
@ -24,8 +24,8 @@
|
|||||||
#ifndef GEN_MAX_UNTYPED_STR_LENGTH
|
#ifndef GEN_MAX_UNTYPED_STR_LENGTH
|
||||||
# define GEN_MAX_UNTYPED_STR_LENGTH megabytes(1)
|
# define GEN_MAX_UNTYPED_STR_LENGTH megabytes(1)
|
||||||
#endif
|
#endif
|
||||||
#ifndef GEN_TOKEN_FMT_TOKEN_MAP_MEM_SIZE
|
#ifndef TokenMap_FixedArena
|
||||||
# define GEN_TOKEN_FMT_TOKEN_MAP_MEM_SIZE kilobytes(8)
|
# define TokenMap_FixedArena FixedArena_8KB
|
||||||
#endif
|
#endif
|
||||||
#ifndef GEN_LEX_ALLOCATOR_SIZE
|
#ifndef GEN_LEX_ALLOCATOR_SIZE
|
||||||
# define GEN_LEX_ALLOCATOR_SIZE megabytes(4)
|
# 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 MaxCommentLineLength = GEN_MAX_COMMENT_LINE_LENGTH;
|
||||||
constexpr s32 MaxNameLength = GEN_MAX_NAME_LENGTH;
|
constexpr s32 MaxNameLength = GEN_MAX_NAME_LENGTH;
|
||||||
constexpr s32 MaxUntypedStrLength = GEN_MAX_UNTYPED_STR_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 LexAllocator_Size = GEN_LEX_ALLOCATOR_SIZE;
|
||||||
constexpr s32 Builder_StrBufferReserve = GEN_BUILDER_STR_BUFFER_RESERVE;
|
constexpr s32 Builder_StrBufferReserve = GEN_BUILDER_STR_BUFFER_RESERVE;
|
||||||
|
|
||||||
|
@ -272,7 +272,7 @@ StrC token_fmt_impl( ssize, ... );
|
|||||||
|
|
||||||
Code untyped_str ( StrC content);
|
Code untyped_str ( StrC content);
|
||||||
Code untyped_fmt ( char const* fmt, ... );
|
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
|
#pragma endregion Untyped text
|
||||||
|
|
||||||
|
@ -35,8 +35,8 @@ CodeConstructor parse_constructor( StrC def )
|
|||||||
|
|
||||||
// TODO(Ed): Constructors can have prefix attributes
|
// TODO(Ed): Constructors can have prefix attributes
|
||||||
|
|
||||||
CodeSpecifiers specifiers;
|
CodeSpecifiers specifiers = NullCode;
|
||||||
Specifier specs_found[ 16 ] { Spec_NumSpecifiers };
|
Specifier specs_found[ 16 ] = { Spec_NumSpecifiers };
|
||||||
s32 NumSpecifiers = 0;
|
s32 NumSpecifiers = 0;
|
||||||
|
|
||||||
while ( left && tok_is_specifier(currtok) )
|
while ( left && tok_is_specifier(currtok) )
|
||||||
|
@ -9,11 +9,11 @@ ssize token_fmt_va( char* buf, usize buf_size, s32 num_tokens, va_list va )
|
|||||||
ssize remaining = buf_size;
|
ssize remaining = buf_size;
|
||||||
|
|
||||||
local_persist
|
local_persist
|
||||||
FixedArena<TokenFmt_TokenMap_MemSize> tok_map_arena;
|
TokenMap_FixedArena tok_map_arena;
|
||||||
fixed_arena_init( & tok_map_arena);
|
fixed_arena_init( & tok_map_arena);
|
||||||
|
|
||||||
local_persist
|
local_persist
|
||||||
HashTable(StrC) tok_map;
|
StringTable tok_map;
|
||||||
{
|
{
|
||||||
tok_map = hashtable_init(StrC, fixed_arena_allocator_info(& tok_map_arena) );
|
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->Type = CT_Untyped;
|
||||||
result->Content = result->Name;
|
result->Content = result->Name;
|
||||||
|
|
||||||
if ( result->Name == nullptr )
|
if ( result->Name.Len == 0 )
|
||||||
{
|
{
|
||||||
log_failure( "untyped_str: could not cache string" );
|
log_failure( "untyped_str: could not cache string" );
|
||||||
return InvalidCode;
|
return InvalidCode;
|
||||||
@ -138,13 +138,16 @@ Code untyped_fmt( char const* fmt, ...)
|
|||||||
ssize length = str_fmt_va(buf, GEN_PRINTF_MAXLEN, fmt, va);
|
ssize length = str_fmt_va(buf, GEN_PRINTF_MAXLEN, fmt, va);
|
||||||
va_end(va);
|
va_end(va);
|
||||||
|
|
||||||
|
StrC buf_str = { str_len_capped(fmt, MaxNameLength), fmt };
|
||||||
|
StrC uncapped_str = { length, buf };
|
||||||
|
|
||||||
Code
|
Code
|
||||||
result = make_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->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" );
|
log_failure( "untyped_fmt: could not cache string" );
|
||||||
return InvalidCode;
|
return InvalidCode;
|
||||||
@ -153,7 +156,7 @@ Code untyped_fmt( char const* fmt, ...)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
Code untyped_token_fmt( s32 num_tokens, ... )
|
Code untyped_token_fmt( s32 num_tokens, char const* fmt, ... )
|
||||||
{
|
{
|
||||||
if ( num_tokens == 0 )
|
if ( num_tokens == 0 )
|
||||||
{
|
{
|
||||||
@ -165,17 +168,19 @@ Code untyped_token_fmt( s32 num_tokens, ... )
|
|||||||
char buf[GEN_PRINTF_MAXLEN] = { 0 };
|
char buf[GEN_PRINTF_MAXLEN] = { 0 };
|
||||||
|
|
||||||
va_list va;
|
va_list va;
|
||||||
va_start(va, num_tokens);
|
va_start(va, fmt);
|
||||||
ssize length = token_fmt_va(buf, GEN_PRINTF_MAXLEN, num_tokens, va);
|
ssize length = token_fmt_va(buf, GEN_PRINTF_MAXLEN, num_tokens, va);
|
||||||
va_end(va);
|
va_end(va);
|
||||||
|
|
||||||
|
StrC buf_str = { length, buf };
|
||||||
|
|
||||||
Code
|
Code
|
||||||
result = make_code();
|
result = make_code();
|
||||||
result->Name = get_cached_string( { length, buf } );
|
result->Name = get_cached_string( buf_str );
|
||||||
result->Type = CT_Untyped;
|
result->Type = CT_Untyped;
|
||||||
result->Content = result->Name;
|
result->Content = result->Name;
|
||||||
|
|
||||||
if ( result->Name == nullptr )
|
if ( result->Name.Len == 0 )
|
||||||
{
|
{
|
||||||
log_failure( "untyped_fmt: could not cache string" );
|
log_failure( "untyped_fmt: could not cache string" );
|
||||||
return InvalidCode;
|
return InvalidCode;
|
||||||
|
@ -150,7 +150,7 @@ void parser_init()
|
|||||||
internal
|
internal
|
||||||
void parser_deinit()
|
void parser_deinit()
|
||||||
{
|
{
|
||||||
Array(Token) null_array = {};
|
Array(Token) null_array = { nullptr };
|
||||||
Lexer_Tokens = null_array;
|
Lexer_Tokens = null_array;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -319,6 +319,7 @@ struct FixedArena;
|
|||||||
template<s32 Size> FixedArena<Size> fixed_arena_init();
|
template<s32 Size> FixedArena<Size> fixed_arena_init();
|
||||||
template<s32 Size> AllocatorInfo fixed_arena_allocator_info(FixedArena<Size>* fixed_arena );
|
template<s32 Size> AllocatorInfo fixed_arena_allocator_info(FixedArena<Size>* fixed_arena );
|
||||||
template<s32 Size> ssize fixed_arena_size_remaining(FixedArena<Size>* fixed_arena, ssize alignment);
|
template<s32 Size> ssize fixed_arena_size_remaining(FixedArena<Size>* fixed_arena, ssize alignment);
|
||||||
|
template<s32 Size> void fixed_arena_free(FixedArena<Size>* fixed_arena);
|
||||||
|
|
||||||
#if GEN_COMPILER_CPP && ! GEN_C_LIKE_CPP
|
#if GEN_COMPILER_CPP && ! GEN_C_LIKE_CPP
|
||||||
template<s32 Size> AllocatorInfo allocator_info( FixedArena<Size>& fixed_arena ) { return allocator_info(& fixed_arena); }
|
template<s32 Size> AllocatorInfo allocator_info( FixedArena<Size>& fixed_arena ) { return allocator_info(& fixed_arena); }
|
||||||
|
Loading…
Reference in New Issue
Block a user