First compiling version of operator overloading for C! (on both msvc and clang using -std=c11 flag, using _Generic selection with some helper macros)

Extremely satsified with how unofuscated the generated code is for _Generic.
Still fixing up the templated container code though in the c-codegen
This commit is contained in:
2024-12-05 17:04:17 -05:00
parent 47b9c37e94
commit a3407c14d5
15 changed files with 424 additions and 263 deletions

View File

@ -24,7 +24,7 @@ void* Global_Allocator_Proc( void* allocator_data, AllocType type, ssize size, s
if ( bucket.PhysicalStart == nullptr )
GEN_FATAL( "Failed to create bucket for Global_AllocatorBuckets");
if ( ! array_append( & Global_AllocatorBuckets, bucket ) )
if ( ! array_append( Global_AllocatorBuckets, bucket ) )
GEN_FATAL( "Failed to append bucket to Global_AllocatorBuckets");
last = array_back(Global_AllocatorBuckets);
@ -51,7 +51,7 @@ void* Global_Allocator_Proc( void* allocator_data, AllocType type, ssize size, s
if ( bucket.PhysicalStart == nullptr )
GEN_FATAL( "Failed to create bucket for Global_AllocatorBuckets");
if ( ! array_append( & Global_AllocatorBuckets, bucket ) )
if ( ! array_append( Global_AllocatorBuckets, bucket ) )
GEN_FATAL( "Failed to append bucket to Global_AllocatorBuckets");
last = array_back(Global_AllocatorBuckets);
@ -249,7 +249,7 @@ void init()
if ( bucket.PhysicalStart == nullptr )
GEN_FATAL( "Failed to create first bucket for Global_AllocatorBuckets");
array_append( & Global_AllocatorBuckets, bucket );
array_append( Global_AllocatorBuckets, bucket );
}
// Setup the arrays
@ -272,7 +272,7 @@ void init()
if ( code_pool.PhysicalStart == nullptr )
GEN_FATAL( "gen::init: Failed to initialize the code pool" );
array_append( & CodePools, code_pool );
array_append( CodePools, code_pool );
LexArena = arena_init_from_allocator( Allocator_Lexer, LexAllocator_Size );
@ -281,7 +281,7 @@ void init()
if ( string_arena.PhysicalStart == nullptr )
GEN_FATAL( "gen::init: Failed to initialize the string arena" );
array_append( & StringArenas, string_arena );
array_append( StringArenas, string_arena );
}
// Setup the hash tables
@ -381,7 +381,7 @@ AllocatorInfo get_string_allocator( s32 str_length )
{
Arena new_arena = arena_init_from_allocator( Allocator_StringArena, SizePer_StringArena );
if ( ! array_append( & StringArenas, new_arena ) )
if ( ! array_append( StringArenas, new_arena ) )
GEN_FATAL( "gen::get_string_allocator: Failed to allocate a new string arena" );
last = array_back(StringArenas);
@ -419,7 +419,7 @@ Code make_code()
if ( code_pool.PhysicalStart == nullptr )
GEN_FATAL( "gen::make_code: Failed to allocate a new code pool - CodePool allcoator returned nullptr." );
if ( ! array_append( & CodePools, code_pool ) )
if ( ! array_append( CodePools, code_pool ) )
GEN_FATAL( "gen::make_code: Failed to allocate a new code pool - CodePools failed to append new pool." );
allocator = array_back( CodePools);

View File

@ -236,7 +236,8 @@ forceinline
s32 lex_preprocessor_directive( LexContext* ctx )
{
char const* hash = ctx->scanner;
array_append( & Tokens, { hash, 1, Tok_Preprocess_Hash, ctx->line, ctx->column, TF_Preprocess } );
Token hash_tok = { hash, 1, Tok_Preprocess_Hash, ctx->line, ctx->column, TF_Preprocess };
array_append( Tokens, hash_tok );
move_forward();
SkipWhitespace();
@ -312,14 +313,14 @@ s32 lex_preprocessor_directive( LexContext* ctx )
ctx->token.Length = ctx->token.Length + ctx->token.Text - hash;
ctx->token.Text = hash;
array_append( & Tokens, ctx->token );
array_append( Tokens, ctx->token );
return Lex_Continue; // Skip found token, its all handled here.
}
if ( ctx->token.Type == Tok_Preprocess_Else || ctx->token.Type == Tok_Preprocess_EndIf )
{
ctx->token.Flags |= TF_Preprocess_Cond;
array_append( & Tokens, ctx->token );
array_append( Tokens, ctx->token );
end_line();
return Lex_Continue;
}
@ -328,7 +329,7 @@ s32 lex_preprocessor_directive( LexContext* ctx )
ctx->token.Flags |= TF_Preprocess_Cond;
}
array_append( & Tokens, ctx->token );
array_append( Tokens, ctx->token );
SkipWhitespace();
@ -352,7 +353,7 @@ s32 lex_preprocessor_directive( LexContext* ctx )
name.Length++;
}
array_append( & Tokens, name );
array_append( Tokens, name );
u64 key = crc32( name.Text, name.Length );
hashtable_set(ctx->defines, key, to_str(name) );
@ -398,7 +399,7 @@ s32 lex_preprocessor_directive( LexContext* ctx )
move_forward();
}
array_append( & Tokens, preprocess_content );
array_append( Tokens, preprocess_content );
return Lex_Continue; // Skip found token, its all handled here.
}
@ -461,7 +462,7 @@ s32 lex_preprocessor_directive( LexContext* ctx )
preprocess_content.Length++;
}
array_append( & Tokens, preprocess_content );
array_append( Tokens, preprocess_content );
return Lex_Continue; // Skip found token, its all handled here.
}
@ -470,7 +471,7 @@ void lex_found_token( LexContext* ctx )
{
if ( ctx->token.Type != Tok_Invalid )
{
array_append( & Tokens, ctx->token );
array_append( Tokens, ctx->token );
return;
}
@ -497,7 +498,7 @@ void lex_found_token( LexContext* ctx )
}
ctx->token.Type = type;
array_append( & Tokens, ctx->token );
array_append( Tokens, ctx->token );
return;
}
@ -507,7 +508,7 @@ void lex_found_token( LexContext* ctx )
{
ctx->token.Type = type;
ctx->token.Flags |= TF_Specifier;
array_append( & Tokens, ctx->token );
array_append( Tokens, ctx->token );
return;
}
@ -515,7 +516,7 @@ void lex_found_token( LexContext* ctx )
if ( type != Tok_Invalid )
{
ctx->token.Type = type;
array_append( & Tokens, ctx->token );
array_append( Tokens, ctx->token );
return;
}
@ -569,7 +570,7 @@ void lex_found_token( LexContext* ctx )
ctx->token.Type = Tok_Identifier;
}
array_append( & Tokens, ctx->token );
array_append( Tokens, ctx->token );
}
neverinline
@ -643,7 +644,7 @@ TokArray lex( StrC content )
c.token.Type = Tok_NewLine;
c.token.Length++;
array_append( & Tokens, c.token );
array_append( Tokens, c.token );
continue;
}
}
@ -679,7 +680,7 @@ TokArray lex( StrC content )
c.token.Length++;
move_forward();
array_append( & Tokens, c.token );
array_append( Tokens, c.token );
}
}
@ -1134,7 +1135,7 @@ TokArray lex( StrC content )
move_forward();
c.token.Length++;
}
array_append( & Tokens, c.token );
array_append( Tokens, c.token );
continue;
}
else if ( current == '*' )
@ -1170,7 +1171,7 @@ TokArray lex( StrC content )
move_forward();
c.token.Length++;
}
array_append( & Tokens, c.token );
array_append( Tokens, c.token );
// end_line();
continue;
}
@ -1303,7 +1304,7 @@ TokArray lex( StrC content )
c.token.Length++;
move_forward();
array_append( & Tokens, c.token );
array_append( Tokens, c.token );
continue;
}
}

View File

@ -755,7 +755,7 @@ Code parse_class_struct( TokType which, bool inplace_def = false )
}
Token interface_tok = parse_identifier();
array_append( & interfaces, def_type( to_str(interface_tok) ) );
array_append( interfaces, def_type( to_str(interface_tok) ) );
// <ModuleFlags> <class/struct> <Attributes> <Name> : <Access Specifier> <Name>, ...
}
}