mirror of
https://github.com/Ed94/gencpp.git
synced 2025-06-15 03:01:47 -07:00
C-library gen progress: Header files mostly done, starting dep c impl and fixes to generic selection generation
This commit is contained in:
@ -21,8 +21,9 @@ CodeBody gen_array_base()
|
||||
|
||||
Code grow_formula = untyped_str( txt( "#define array_grow_formula( value ) ( 2 * value + 8 )\n" ));
|
||||
Code get_header = untyped_str( txt( "#define array_get_header( self ) ( (ArrayHeader*)( self ) - 1)\n" ));
|
||||
Code type_define = untyped_str( txt( "#define Array(Type) Array_##Type\n"));
|
||||
|
||||
return def_global_body( args( fmt_newline, td_header, header, grow_formula, get_header, fmt_newline ) );
|
||||
return def_global_body( args( fmt_newline, td_header, header, type_define, grow_formula, get_header, fmt_newline ) );
|
||||
};
|
||||
|
||||
CodeBody gen_array( StrC type, StrC array_name )
|
||||
@ -68,7 +69,7 @@ CodeBody gen_array( StrC type, StrC array_name )
|
||||
<array_type> <fn>_init( AllocatorInfo allocator )
|
||||
{
|
||||
size_t initial_size = array_grow_formula(0);
|
||||
return array_init_reserve( <array_type>, allocator, initial_size );
|
||||
return array_init_reserve( <type>, allocator, initial_size );
|
||||
}
|
||||
|
||||
inline
|
||||
@ -362,24 +363,24 @@ CodeBody gen_array( StrC type, StrC array_name )
|
||||
++ Array_DefinitionCounter;
|
||||
StrC slot_str = String::fmt_buf(GlobalAllocator, "%d", Array_DefinitionCounter).to_strc();
|
||||
|
||||
Code generic_interface_slot = untyped_str(token_fmt( "type_delimiter", (StrC)array_type, "slot", (StrC)slot_str,
|
||||
R"(#define GENERIC_SLOT_<slot>__array_init <type_delimiter>, <type_delimiter>_init
|
||||
#define GENERIC_SLOT_<slot>__array_init_reserve <type_delimiter>, <type_delimiter>_init_reserve
|
||||
#define GENERIC_SLOT_<slot>__array_append <type_delimiter>, <type_delimiter>_append
|
||||
#define GENERIC_SLOT_<slot>__array_append_items <type_delimiter>, <type_delimiter>_append_items
|
||||
#define GENERIC_SLOT_<slot>__array_append_at <type_delimiter>, <type_delimiter>_append_at
|
||||
#define GENERIC_SLOT_<slot>__array_append_items_at <type_delimiter>, <type_delimiter>_append_items_at
|
||||
#define GENERIC_SLOT_<slot>__array_back <type_delimiter>, <type_delimiter>_back
|
||||
#define GENERIC_SLOT_<slot>__array_clear <type_delimiter>, <type_delimiter>_clear
|
||||
#define GENERIC_SLOT_<slot>__array_fill <type_delimiter>, <type_delimiter>_fill
|
||||
#define GENERIC_SLOT_<slot>__array_free <type_delimiter>, <type_delimiter>_free
|
||||
#define GENERIC_SLOT_<slot>__array_grow <type_delimiter>*, <type_delimiter>_grow
|
||||
#define GENERIC_SLOT_<slot>__array_num <type_delimiter>, <type_delimiter>_num
|
||||
#define GENERIC_SLOT_<slot>__array_pop <type_delimiter>, <type_delimiter>_pop
|
||||
#define GENERIC_SLOT_<slot>__array_remove_at <type_delimiter>, <type_delimiter>_remove_at
|
||||
#define GENERIC_SLOT_<slot>__array_reserve <type_delimiter>, <type_delimiter>_reserve
|
||||
#define GENERIC_SLOT_<slot>__array_resize <type_delimiter>, <type_delimiter>_resize
|
||||
#define GENERIC_SLOT_<slot>__array_set_capacity <type_delimiter>*, <type_delimiter>_set_capacity
|
||||
Code generic_interface_slot = untyped_str(token_fmt( "type", type, "array_type", (StrC)array_type, "slot", (StrC)slot_str,
|
||||
R"(#define GENERIC_SLOT_<slot>__array_init <type>, <array_type>_init
|
||||
#define GENERIC_SLOT_<slot>__array_init_reserve <type>, <array_type>_init_reserve
|
||||
#define GENERIC_SLOT_<slot>__array_append <array_type>, <array_type>_append
|
||||
#define GENERIC_SLOT_<slot>__array_append_items <array_type>, <array_type>_append_items
|
||||
#define GENERIC_SLOT_<slot>__array_append_at <array_type>, <array_type>_append_at
|
||||
#define GENERIC_SLOT_<slot>__array_append_items_at <array_type>, <array_type>_append_items_at
|
||||
#define GENERIC_SLOT_<slot>__array_back <array_type>, <array_type>_back
|
||||
#define GENERIC_SLOT_<slot>__array_clear <array_type>, <array_type>_clear
|
||||
#define GENERIC_SLOT_<slot>__array_fill <array_type>, <array_type>_fill
|
||||
#define GENERIC_SLOT_<slot>__array_free <array_type>, <array_type>_free
|
||||
#define GENERIC_SLOT_<slot>__array_grow <array_type>*, <array_type>_grow
|
||||
#define GENERIC_SLOT_<slot>__array_num <array_type>, <array_type>_num
|
||||
#define GENERIC_SLOT_<slot>__array_pop <array_type>, <array_type>_pop
|
||||
#define GENERIC_SLOT_<slot>__array_remove_at <array_type>, <array_type>_remove_at
|
||||
#define GENERIC_SLOT_<slot>__array_reserve <array_type>, <array_type>_reserve
|
||||
#define GENERIC_SLOT_<slot>__array_resize <array_type>, <array_type>_resize
|
||||
#define GENERIC_SLOT_<slot>__array_set_capacity <array_type>*, <array_type>_set_capacity
|
||||
)"
|
||||
));
|
||||
|
||||
|
@ -109,19 +109,19 @@ CodeBody gen_hashtable( StrC type, StrC hashtable_name )
|
||||
|
||||
<tbl_type> <fn>init( AllocatorInfo allocator )
|
||||
{
|
||||
<tbl_type> result = hashtable_init_reserve(<tbl_type>, allocator, 8);
|
||||
<tbl_type> result = hashtable_init_reserve(<type>, allocator, 8);
|
||||
return result;
|
||||
}
|
||||
|
||||
<tbl_type> <fn>_init_reserve( AllocatorInfo allocator, ssize num )
|
||||
{
|
||||
<tbl_type> result = { NULL, NULL };
|
||||
result.Hashes = array_init_reserve(Array_ssize, allocator, num );
|
||||
result.Hashes = array_init_reserve(ssize, allocator, num );
|
||||
array_get_header(result.Hashes)->Num = num;
|
||||
array_resize(result.Hashes, num);
|
||||
array_fill(result.Hashes, 0, num, -1);
|
||||
|
||||
result.Entries = array_init_reserve(<array_entry>, allocator, num );
|
||||
result.Entries = array_init_reserve(<entry_type>, allocator, num );
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -199,7 +199,7 @@ CodeBody gen_hashtable( StrC type, StrC hashtable_name )
|
||||
ArrayHeader* old_hash_header = array_get_header( self->Hashes );
|
||||
ArrayHeader* old_entries_header = array_get_header( self->Entries );
|
||||
|
||||
<tbl_type> new_tbl = hashtable_init_reserve( <tbl_type>, old_hash_header->Allocator, old_hash_header->Num );
|
||||
<tbl_type> new_tbl = hashtable_init_reserve( <type>, old_hash_header->Allocator, old_hash_header->Num );
|
||||
|
||||
ArrayHeader* new_hash_header = array_get_header( new_tbl.Hashes );
|
||||
|
||||
@ -375,24 +375,24 @@ CodeBody gen_hashtable( StrC type, StrC hashtable_name )
|
||||
++ HashTable_DefinitionCounter;
|
||||
StrC slot_str = String::fmt_buf(GlobalAllocator, "%d", Array_DefinitionCounter).to_strc();
|
||||
|
||||
Code generic_interface_slot = untyped_str(token_fmt( "type_delimiter", (StrC)tbl_type, "slot", (StrC)slot_str,
|
||||
R"(#define GENERIC_SLOT_<slot>__hashtable_init <type_delimiter>, <type_delimiter>_init
|
||||
#define GENERIC_SLOT_<slot>__hashtable_init_reserve <type_delimiter>, <type_delimiter>_init_reserve
|
||||
#define GENERIC_SLOT_<slot>__hashtable_clear <type_delimiter>, <type_delimiter>_clear
|
||||
#define GENERIC_SLOT_<slot>__hashtable_destroy <type_delimiter>*, <type_delimiter>_destroy
|
||||
#define GENERIC_SLOT_<slot>__hashtable_get <type_delimiter>, <type_delimiter>_get
|
||||
#define GENERIC_SLOT_<slot>__hashtable_map <type_delimiter>, <type_delimiter>_map
|
||||
#define GENERIC_SLOT_<slot>__hashtable_map_mut <type_delimiter>, <type_delimiter>_map_mut
|
||||
#define GENERIC_SLOT_<slot>__hashtable_grow <type_delimiter>*, <type_delimiter>_grow
|
||||
#define GENERIC_SLOT_<slot>__hashtable_rehash <type_delimiter>*, <type_delimiter>_rehash
|
||||
#define GENERIC_SLOT_<slot>__hashtable_rehash_fast <type_delimiter>, <type_delimiter>_rehash_fast
|
||||
#define GENERIC_SLOT_<slot>__hashtable_remove_entry <type_delimiter>, <type_delimiter>_remove_entry
|
||||
#define GENERIC_SLOT_<slot>__hashtable_set <type_delimiter>*, <type_delimiter>_set
|
||||
#define GENERIC_SLOT_<slot>__hashtable_slot <type_delimiter>, <type_delimiter>_slot
|
||||
Code generic_interface_slot = untyped_str(token_fmt( "type", type, "tbl_type", (StrC)tbl_type, "slot", (StrC)slot_str,
|
||||
R"(#define GENERIC_SLOT_<slot>__hashtable_init <type>, <tbl_type>_init
|
||||
#define GENERIC_SLOT_<slot>__hashtable_init_reserve <type>, <tbl_type>_init_reserve
|
||||
#define GENERIC_SLOT_<slot>__hashtable_clear <tbl_type>, <tbl_type>_clear
|
||||
#define GENERIC_SLOT_<slot>__hashtable_destroy <tbl_type>*, <tbl_type>_destroy
|
||||
#define GENERIC_SLOT_<slot>__hashtable_get <tbl_type>, <tbl_type>_get
|
||||
#define GENERIC_SLOT_<slot>__hashtable_map <tbl_type>, <tbl_type>_map
|
||||
#define GENERIC_SLOT_<slot>__hashtable_map_mut <tbl_type>, <tbl_type>_map_mut
|
||||
#define GENERIC_SLOT_<slot>__hashtable_grow <tbl_type>*, <tbl_type>_grow
|
||||
#define GENERIC_SLOT_<slot>__hashtable_rehash <tbl_type>*, <tbl_type>_rehash
|
||||
#define GENERIC_SLOT_<slot>__hashtable_rehash_fast <tbl_type>, <tbl_type>_rehash_fast
|
||||
#define GENERIC_SLOT_<slot>__hashtable_remove_entry <tbl_type>, <tbl_type>_remove_entry
|
||||
#define GENERIC_SLOT_<slot>__hashtable_set <tbl_type>*, <tbl_type>_set
|
||||
#define GENERIC_SLOT_<slot>__hashtable_slot <tbl_type>, <tbl_type>_slot
|
||||
|
||||
#define GENERIC_SLOT_<slot>__hashtable__add_entry <type_delimiter>*, <type_delimiter>__add_entry
|
||||
#define GENERIC_SLOT_<slot>__hashtable__find <type_delimiter>, <type_delimiter>__find
|
||||
#define GENERIC_SLOT_<slot>__hashtable__full <type_delimiter>, <type_delimiter>__full
|
||||
#define GENERIC_SLOT_<slot>__hashtable__add_entry <tbl_type>*, <tbl_type>__add_entry
|
||||
#define GENERIC_SLOT_<slot>__hashtable__find <tbl_type>, <tbl_type>__find
|
||||
#define GENERIC_SLOT_<slot>__hashtable__full <tbl_type>, <tbl_type>__full
|
||||
)"
|
||||
));
|
||||
|
||||
|
@ -4,16 +4,20 @@
|
||||
See Readme.md for more information from the project repository.
|
||||
|
||||
Public Address:
|
||||
https://github.com/Ed94/gencpp
|
||||
|
||||
This is a single header C-Library variant.
|
||||
Define GEN_IMPLEMENTATION before including this file in a single compilation unit.
|
||||
|
||||
! ----------------------------------------------------------------------- VERSION: v0.20-Alpha !
|
||||
! ============================================================================================ !
|
||||
! WARNING: THIS IS AN ALPHA VERSION OF THE LIBRARY, USE AT YOUR OWN DISCRETION !
|
||||
! NEVER DO CODE GENERATION WITHOUT AT LEAST HAVING CONTENT IN A CODEBASE UNDER VERSION CONTROL !
|
||||
! ============================================================================================ !
|
||||
https://github.com/Ed94/gencpp ---------------------------------------------------------------.
|
||||
| _____ _____ _ _ ___ __ __ |
|
||||
| / ____) / ____} | | | / ,__} / | / | |
|
||||
| | / ___ ___ _ __ ___ _ __ _ __ | {___ | l_ __ _ __ _, ___ __| | | | '-l | '-l | |
|
||||
| | |{_ \/ __\ '_ \ / __} '_ l| '_ l \___ \| __/ _` |/ _` |/ __\/ _` | | | | | | | |
|
||||
| | l__j | ___/ | | | {__; ;_l } ;_l } ____} | l| (_} | {_| | ___j {_; | | l___ _J l_ _J l_ |
|
||||
| \_____|\___}_l |_|\___} .__/| .__/ {_____/ \__\__/_l\__. |\___/\__,_l \____}{_____}{_____} |
|
||||
| | | | | __} | |
|
||||
| l_l l_l {___/ |
|
||||
! ----------------------------------------------------------------------- VERSION: v0.20-Alpha |
|
||||
! ============================================================================================= |
|
||||
! WARNING: THIS IS AN ALPHA VERSION OF THE LIBRARY, USE AT YOUR OWN DISCRETION |
|
||||
! NEVER DO CODE GENERATION WITHOUT AT LEAST HAVING CONTENT IN A CODEBASE UNDER VERSION CONTROL |
|
||||
! ============================================================================================= /
|
||||
*/
|
||||
#if ! defined(GEN_DONT_ENFORCE_GEN_TIME_GUARD) && ! defined(GEN_TIME)
|
||||
# error Gen.hpp : GEN_TIME not defined
|
||||
|
@ -24,7 +24,7 @@ b32 ignore_preprocess_cond_block( StrC cond_sig, Code& entry_iter, CodeBody& par
|
||||
CodePreprocessCond cond = cast(CodePreprocessCond, entry_iter);
|
||||
if ( cond->Content.is_equal(cond_sig) )
|
||||
{
|
||||
log_fmt("Preprocess cond found: %SC\n", cond->Content);
|
||||
//log_fmt("Preprocess cond found: %SC\n", cond->Content);
|
||||
found = true;
|
||||
|
||||
s32 depth = 1;
|
||||
@ -105,7 +105,7 @@ R"(#define <macro_name>(selector_arg, ...) _Generic( (selector_arg), \
|
||||
for ( s32 slot = 1; slot <= num_slots; ++ slot )
|
||||
{
|
||||
StrC slot_str = String::fmt_buf(GlobalAllocator, "%d", slot).to_strc();
|
||||
if (slot == num_slots)
|
||||
if (slot == num_slots && false)
|
||||
{
|
||||
define_builder.append( token_fmt( "macro_name", macro_name, "slot", slot_str,
|
||||
R"( GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT_LAST( GENERIC_SLOT_<slot>__<macro_name> ) \
|
||||
@ -128,6 +128,8 @@ R"( GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( GENERIC_SLOT_<slot>__<macro_name> )
|
||||
));
|
||||
}
|
||||
|
||||
define_builder.append( txt("default: gen_generic_selection_fail") );
|
||||
|
||||
if ( ! one_arg )
|
||||
{
|
||||
if (opts == GenericSel_By_Ref)
|
||||
|
Reference in New Issue
Block a user