mirror of
https://github.com/Ed94/gencpp.git
synced 2025-06-15 03:01:47 -07:00
gencpp : General refactors to dependencies
Mostly just cleanup and renaming of certain stuff (mostly in dependencies). * Changed uw and sw to usize and ssize. * Removed zpl_cast usage throughout dependencies * No longer using GEN_DEF_INLINE & GEN_IMPL_INLINE * header_start.hpp renamed to platform.hpp for depdendencies header.
This commit is contained in:
@ -15,11 +15,11 @@ Code gen__array_base()
|
||||
struct ArrayHeader
|
||||
{
|
||||
AllocatorInfo Allocator;
|
||||
uw Capacity;
|
||||
uw Num;
|
||||
usize Capacity;
|
||||
usize Num;
|
||||
};
|
||||
|
||||
static inline uw array_grow_formula( uw value )
|
||||
static inline usize array_grow_formula( usize value )
|
||||
{
|
||||
return 2 * value * 8;
|
||||
}
|
||||
@ -52,7 +52,7 @@ Code gen__array( StrC type )
|
||||
}
|
||||
|
||||
static
|
||||
<ArrayType> init_reserve( AllocatorInfo allocator, sw capacity )
|
||||
<ArrayType> init_reserve( AllocatorInfo allocator, ssize capacity )
|
||||
{
|
||||
Header* header = rcast( Header*, alloc( allocator, sizeof(Header) + sizeof(Type) ));
|
||||
|
||||
@ -94,14 +94,14 @@ Code gen__array( StrC type )
|
||||
header.Num = 0;
|
||||
}
|
||||
|
||||
bool fill( uw begin, uw end, Type value )
|
||||
bool fill( usize begin, usize end, Type value )
|
||||
{
|
||||
Header& header = get_header();
|
||||
|
||||
if ( begin < 0 || end >= header.Num )
|
||||
return false;
|
||||
|
||||
for ( sw idx = begin; idx < end; idx++ )
|
||||
for ( ssize idx = begin; idx < end; idx++ )
|
||||
{
|
||||
Data[ idx ] = value;
|
||||
}
|
||||
@ -120,10 +120,10 @@ Code gen__array( StrC type )
|
||||
return *( reinterpret_cast< Header* >( Data ) - 1 );
|
||||
}
|
||||
|
||||
bool grow( uw min_capacity )
|
||||
bool grow( usize min_capacity )
|
||||
{
|
||||
Header& header = get_header();
|
||||
uw new_capacity = grow_formula( header.Capacity );
|
||||
usize new_capacity = grow_formula( header.Capacity );
|
||||
|
||||
if ( new_capacity < min_capacity )
|
||||
new_capacity = 8;
|
||||
@ -131,7 +131,7 @@ Code gen__array( StrC type )
|
||||
return set_capacity( new_capacity );
|
||||
}
|
||||
|
||||
uw num( void )
|
||||
usize num( void )
|
||||
{
|
||||
return get_header().Num;
|
||||
}
|
||||
@ -144,7 +144,7 @@ Code gen__array( StrC type )
|
||||
header.Num--;
|
||||
}
|
||||
|
||||
void remove_at( uw idx )
|
||||
void remove_at( usize idx )
|
||||
{
|
||||
Header* header = &get_header();
|
||||
GEN_ASSERT( idx < header->Num );
|
||||
@ -153,7 +153,7 @@ Code gen__array( StrC type )
|
||||
header->Num--;
|
||||
}
|
||||
|
||||
bool reserve( uw new_capacity )
|
||||
bool reserve( usize new_capacity )
|
||||
{
|
||||
Header& header = get_header();
|
||||
|
||||
@ -163,7 +163,7 @@ Code gen__array( StrC type )
|
||||
return true;
|
||||
}
|
||||
|
||||
bool resize( uw num )
|
||||
bool resize( usize num )
|
||||
{
|
||||
Header& header = get_header();
|
||||
|
||||
@ -177,7 +177,7 @@ Code gen__array( StrC type )
|
||||
return true;
|
||||
}
|
||||
|
||||
bool set_capacity( uw new_capacity )
|
||||
bool set_capacity( usize new_capacity )
|
||||
{
|
||||
Header& header = get_header();
|
||||
|
||||
@ -187,7 +187,7 @@ Code gen__array( StrC type )
|
||||
if ( new_capacity < header.Num )
|
||||
header.Num = new_capacity;
|
||||
|
||||
sw size = sizeof( Header ) + sizeof( Type ) * new_capacity;
|
||||
ssize size = sizeof( Header ) + sizeof( Type ) * new_capacity;
|
||||
Header* new_header = rcast( Header*, alloc( header.Allocator, size ) );
|
||||
|
||||
if ( new_header == nullptr )
|
||||
@ -233,7 +233,7 @@ void gen__array_request( StrC type, StrC dep = {} )
|
||||
do_once_end
|
||||
|
||||
// Make sure we don't already have a request for the type.
|
||||
for ( sw idx = 0; idx < GenArrayRequests.num(); ++idx )
|
||||
for ( ssize idx = 0; idx < GenArrayRequests.num(); ++idx )
|
||||
{
|
||||
StrC const reqest_type = GenArrayRequests[ idx ].Type;
|
||||
|
||||
|
@ -15,8 +15,8 @@ Code gen__buffer_base()
|
||||
struct BufferHeader
|
||||
{
|
||||
AllocatorInfo Backing;
|
||||
uw Capacity;
|
||||
uw Num;
|
||||
usize Capacity;
|
||||
usize Num;
|
||||
};
|
||||
));
|
||||
}
|
||||
@ -38,7 +38,7 @@ Code gen__buffer( StrC type )
|
||||
using Header = BufferHeader;
|
||||
using Type = <type>;
|
||||
|
||||
static <BufferName> init( AllocatorInfo allocator, sw capacity )
|
||||
static <BufferName> init( AllocatorInfo allocator, ssize capacity )
|
||||
{
|
||||
Header* header = rcast( Header*, alloc( allocator, sizeof( Header ) + capacity * sizeof( Type ) ) );
|
||||
|
||||
@ -76,7 +76,7 @@ Code gen__buffer( StrC type )
|
||||
header.Num++;
|
||||
}
|
||||
|
||||
void append( Type* values, sw num )
|
||||
void append( Type* values, ssize num )
|
||||
{
|
||||
Header& header = get_header();
|
||||
GEN_ASSERT( header.Num + num <= header.Capacity);
|
||||
@ -108,7 +108,7 @@ Code gen__buffer( StrC type )
|
||||
return *( rcast( Header*, Data ) - 1 );
|
||||
}
|
||||
|
||||
sw num( void )
|
||||
ssize num( void )
|
||||
{
|
||||
return get_header().Num;
|
||||
}
|
||||
@ -147,7 +147,7 @@ void gen__buffer_request( StrC type, StrC dep = {} )
|
||||
do_once_end
|
||||
|
||||
// Make sure we don't already have a request for the type.
|
||||
for ( sw idx = 0; idx < GenBufferRequests.num(); ++idx )
|
||||
for ( ssize idx = 0; idx < GenBufferRequests.num(); ++idx )
|
||||
{
|
||||
StrC const reqest_type = GenBufferRequests[ idx ].Type;
|
||||
|
||||
|
@ -15,9 +15,9 @@ Code gen__hashtable_base()
|
||||
return parse_global_body( code(
|
||||
struct HashTable_FindResult
|
||||
{
|
||||
sw HashIndex;
|
||||
sw PrevIndex;
|
||||
sw EntryIndex;
|
||||
ssize HashIndex;
|
||||
ssize PrevIndex;
|
||||
ssize EntryIndex;
|
||||
};
|
||||
));
|
||||
}
|
||||
@ -37,7 +37,7 @@ Code gen__hashtable( StrC type )
|
||||
struct <HashTableName>_Entry
|
||||
{
|
||||
u64 Key;
|
||||
sw Next;
|
||||
ssize Next;
|
||||
<type> Value;
|
||||
};
|
||||
)
|
||||
@ -86,7 +86,7 @@ Code gen__hashtable( StrC type )
|
||||
|
||||
Type* get( u64 key )
|
||||
{
|
||||
sw idx = find( key ).EntryIndex;
|
||||
ssize idx = find( key ).EntryIndex;
|
||||
|
||||
if ( idx > 0 )
|
||||
return &Entries[ idx ].Value;
|
||||
@ -96,7 +96,7 @@ Code gen__hashtable( StrC type )
|
||||
|
||||
void grow( void )
|
||||
{
|
||||
sw new_num = array_grow_formula( Entries.num() );
|
||||
ssize new_num = array_grow_formula( Entries.num() );
|
||||
|
||||
rehash( new_num );
|
||||
}
|
||||
@ -105,7 +105,7 @@ Code gen__hashtable( StrC type )
|
||||
{
|
||||
GEN_ASSERT_NOT_NULL( map_proc );
|
||||
|
||||
for ( sw idx = 0; idx < Entries.num(); idx++ )
|
||||
for ( ssize idx = 0; idx < Entries.num(); idx++ )
|
||||
{
|
||||
map_proc( Entries[ idx ].Key, Entries[ idx ].Value );
|
||||
}
|
||||
@ -115,16 +115,16 @@ Code gen__hashtable( StrC type )
|
||||
{
|
||||
GEN_ASSERT_NOT_NULL( map_proc );
|
||||
|
||||
for ( sw idx = 0; idx < Entries.num(); idx++ )
|
||||
for ( ssize idx = 0; idx < Entries.num(); idx++ )
|
||||
{
|
||||
map_proc( Entries[ idx ].Key, &Entries[ idx ].Value );
|
||||
}
|
||||
}
|
||||
|
||||
void rehash( sw new_num )
|
||||
void rehash( ssize new_num )
|
||||
{
|
||||
sw idx;
|
||||
sw last_added_index;
|
||||
ssize idx;
|
||||
ssize last_added_index;
|
||||
HashTable_u32 new_ht = HashTable_u32::init( Hashes.get_header().Allocator );
|
||||
|
||||
new_ht.Hashes.resize( new_num );
|
||||
@ -163,7 +163,7 @@ Code gen__hashtable( StrC type )
|
||||
|
||||
void rehash_fast( void )
|
||||
{
|
||||
sw idx;
|
||||
ssize idx;
|
||||
|
||||
for ( idx = 0; idx < Entries.num(); idx++ )
|
||||
Entries[ idx ].Next = -1;
|
||||
@ -189,14 +189,14 @@ Code gen__hashtable( StrC type )
|
||||
}
|
||||
}
|
||||
|
||||
void remove_entry( sw idx )
|
||||
void remove_entry( ssize idx )
|
||||
{
|
||||
Entries.remove_at( idx );
|
||||
}
|
||||
|
||||
void set( u64 key, Type value )
|
||||
{
|
||||
sw idx;
|
||||
ssize idx;
|
||||
FindResult find_result;
|
||||
|
||||
if ( Hashes.num() == 0 )
|
||||
@ -228,9 +228,9 @@ Code gen__hashtable( StrC type )
|
||||
grow();
|
||||
}
|
||||
|
||||
sw slot( u64 key )
|
||||
ssize slot( u64 key )
|
||||
{
|
||||
for ( sw idx = 0; idx < Hashes.num(); ++idx )
|
||||
for ( ssize idx = 0; idx < Hashes.num(); ++idx )
|
||||
if ( Hashes[ idx ] == key )
|
||||
return idx;
|
||||
|
||||
@ -242,9 +242,9 @@ Code gen__hashtable( StrC type )
|
||||
|
||||
protected:
|
||||
|
||||
sw add_entry( u64 key )
|
||||
ssize add_entry( u64 key )
|
||||
{
|
||||
sw idx;
|
||||
ssize idx;
|
||||
Entry entry = { key, -1 };
|
||||
idx = Entries.num();
|
||||
Entries.append( entry );
|
||||
@ -294,11 +294,11 @@ void gen__hashtable_request( StrC type, StrC dep = {} )
|
||||
do_once_start
|
||||
GenHashTableRequests = Array<GenHashTableRequest>::init( GlobalAllocator );
|
||||
|
||||
gen_array( sw );
|
||||
gen_array( ssize );
|
||||
do_once_end
|
||||
|
||||
// Make sure we don't already have a request for the type.
|
||||
for ( sw idx = 0; idx < GenHashTableRequests.num(); ++idx )
|
||||
for ( ssize idx = 0; idx < GenHashTableRequests.num(); ++idx )
|
||||
{
|
||||
StrC const reqest_type = GenHashTableRequests[ idx ].Type;
|
||||
|
||||
|
@ -30,7 +30,7 @@ Code gen__ring( StrC type )
|
||||
{
|
||||
using Type = <type>;
|
||||
|
||||
static <RingName> init( AllocatorInfo allocator, uw max_size )
|
||||
static <RingName> init( AllocatorInfo allocator, usize max_size )
|
||||
{
|
||||
<RingName> result = { 0 };
|
||||
|
||||
@ -52,9 +52,9 @@ Code gen__ring( StrC type )
|
||||
Tail = ( Tail + 1 ) % Capacity;
|
||||
}
|
||||
|
||||
inline void append( Type* values, sw num )
|
||||
inline void append( Type* values, ssize num )
|
||||
{
|
||||
for ( sw idx = 0; idx < num; idx++ )
|
||||
for ( ssize idx = 0; idx < num; idx++ )
|
||||
append( values[ idx ] );
|
||||
}
|
||||
|
||||
@ -88,9 +88,9 @@ Code gen__ring( StrC type )
|
||||
}
|
||||
|
||||
AllocatorInfo Backing;
|
||||
uw Capacity;
|
||||
uw Head;
|
||||
uw Tail;
|
||||
usize Capacity;
|
||||
usize Head;
|
||||
usize Tail;
|
||||
<BufferName> Buffer;
|
||||
};
|
||||
)
|
||||
@ -113,7 +113,7 @@ void gen__ring_request( StrC type, StrC dep = {} )
|
||||
do_once_end
|
||||
|
||||
// Make sure we don't already have a request for the type.
|
||||
for ( sw idx = 0; idx < GenRingRequests.num(); ++idx )
|
||||
for ( ssize idx = 0; idx < GenRingRequests.num(); ++idx )
|
||||
{
|
||||
StrC const reqest_type = GenRingRequests[ idx ].Type;
|
||||
|
||||
|
@ -23,14 +23,14 @@ int gen_main()
|
||||
gen_sanity();
|
||||
|
||||
gen_array( u8 );
|
||||
gen_array( sw );
|
||||
gen_array( ssize );
|
||||
|
||||
gen_buffer( u8 );
|
||||
|
||||
gen_hashtable( u32 );
|
||||
|
||||
gen_ring( s16 );
|
||||
gen_ring( uw );
|
||||
gen_ring( usize );
|
||||
|
||||
gen_array_file();
|
||||
gen_buffer_file();
|
||||
|
@ -142,7 +142,7 @@ Code gen__array( StrC type )
|
||||
if ( begin < 0 || end >= header.Num )
|
||||
return false;
|
||||
|
||||
for ( sw idx = begin; idx < end; idx++ )
|
||||
for ( ssize idx = begin; idx < end; idx++ )
|
||||
{
|
||||
Data[ idx ] = value;
|
||||
}
|
||||
@ -170,7 +170,7 @@ Code gen__array( StrC type )
|
||||
, def_execution( code(
|
||||
Header& header = * get_header();
|
||||
|
||||
uw new_capacity = grow_formula( header.Capacity );
|
||||
usize new_capacity = grow_formula( header.Capacity );
|
||||
|
||||
if ( new_capacity < min_capacity )
|
||||
new_capacity = 8;
|
||||
@ -243,7 +243,7 @@ Code gen__array( StrC type )
|
||||
if ( new_capacity < header.Num )
|
||||
header.Num = new_capacity;
|
||||
|
||||
sw size = sizeof(Header) + sizeof(Type) * new_capacity;
|
||||
ssize size = sizeof(Header) + sizeof(Type) * new_capacity;
|
||||
Header* new_header = rcast( Header*, alloc( header.Allocator, size ));
|
||||
|
||||
if ( new_header == nullptr )
|
||||
@ -314,7 +314,7 @@ void gen__array_request( StrC type, StrC dep = {} )
|
||||
do_once_end
|
||||
|
||||
// Make sure we don't already have a request for the type.
|
||||
for ( sw idx = 0; idx < GenArrayRequests.num(); ++idx )
|
||||
for ( ssize idx = 0; idx < GenArrayRequests.num(); ++idx )
|
||||
{
|
||||
StrC const reqest_type = GenArrayRequests[ idx ].Type;
|
||||
|
||||
|
@ -19,7 +19,7 @@ Code gen__buffer_base()
|
||||
return def_global_body( 1, header );
|
||||
}
|
||||
|
||||
Code gen__buffer( StrC type, sw type_size )
|
||||
Code gen__buffer( StrC type, ssize type_size )
|
||||
{
|
||||
static CodeType t_allocator_info = def_type( name(AllocatorInfo));
|
||||
|
||||
@ -206,7 +206,7 @@ struct GenBufferRequest
|
||||
{
|
||||
StrC Dependency;
|
||||
StrC Type;
|
||||
sw TypeSize;
|
||||
ssize TypeSize;
|
||||
};
|
||||
Array<GenBufferRequest> GenBufferRequests;
|
||||
|
||||
@ -217,7 +217,7 @@ void gen__buffer_request( StrC type, StrC dep = {} )
|
||||
do_once_end
|
||||
|
||||
// Make sure we don't already have a request for the type.
|
||||
for ( sw idx = 0; idx < GenBufferRequests.num(); ++idx )
|
||||
for ( ssize idx = 0; idx < GenBufferRequests.num(); ++idx )
|
||||
{
|
||||
StrC const reqest_type = GenBufferRequests[ idx ].Type;
|
||||
|
||||
|
@ -128,7 +128,7 @@ Code gen__hashtable( StrC type )
|
||||
|
||||
CodeFn get = def_function( name(get), def_param( t_u64, name(key)), t_type_ptr
|
||||
, def_execution( code(
|
||||
sw idx = find( key ).EntryIndex;
|
||||
ssize idx = find( key ).EntryIndex;
|
||||
if ( idx >= 0 )
|
||||
return & Entries[ idx ].Value;
|
||||
|
||||
@ -153,7 +153,7 @@ Code gen__hashtable( StrC type )
|
||||
Code body = def_execution( code(
|
||||
GEN_ASSERT_NOT_NULL( map_proc );
|
||||
|
||||
for ( sw idx = 0; idx < Entries.num(); idx++ )
|
||||
for ( ssize idx = 0; idx < Entries.num(); idx++ )
|
||||
{
|
||||
map_proc( Entries[ idx ].Key, Entries[ idx ].Value );
|
||||
}
|
||||
@ -179,7 +179,7 @@ Code gen__hashtable( StrC type )
|
||||
Code body = def_execution( code(
|
||||
GEN_ASSERT_NOT_NULL( map_proc );
|
||||
|
||||
for ( sw idx = 0; idx < Entries.num(); idx++ )
|
||||
for ( ssize idx = 0; idx < Entries.num(); idx++ )
|
||||
{
|
||||
map_proc( Entries[ idx ].Key, & Entries[ idx ].Value );
|
||||
}
|
||||
@ -190,7 +190,7 @@ Code gen__hashtable( StrC type )
|
||||
|
||||
CodeFn grow = def_function( name(grow), __, t_void
|
||||
, def_execution( code(
|
||||
sw new_num = array_grow_formula( Entries.num() );
|
||||
ssize new_num = array_grow_formula( Entries.num() );
|
||||
rehash( new_num );
|
||||
))
|
||||
);
|
||||
@ -198,8 +198,8 @@ Code gen__hashtable( StrC type )
|
||||
CodeFn rehash;
|
||||
{
|
||||
char const* tmpl = stringize(
|
||||
sw idx;
|
||||
sw last_added_index;
|
||||
ssize idx;
|
||||
ssize last_added_index;
|
||||
|
||||
<type> new_ht = init_reserve( Hashes.get_header()->Allocator, new_num );
|
||||
|
||||
@ -242,7 +242,7 @@ Code gen__hashtable( StrC type )
|
||||
CodeFn rehash_fast;
|
||||
{
|
||||
char const* tmpl = stringize(
|
||||
sw idx;
|
||||
ssize idx;
|
||||
|
||||
for ( idx = 0; idx < Entries.num(); idx++ )
|
||||
Entries[ idx ].Next = -1;
|
||||
@ -288,7 +288,7 @@ Code gen__hashtable( StrC type )
|
||||
));
|
||||
|
||||
Code body = def_execution( code(
|
||||
sw idx;
|
||||
ssize idx;
|
||||
FindResult find_result;
|
||||
|
||||
if ( Hashes.num() == 0 )
|
||||
@ -325,7 +325,7 @@ Code gen__hashtable( StrC type )
|
||||
|
||||
CodeFn slot = def_function( name(slot), def_param( t_u64, name(key)), t_sw
|
||||
, def_execution( code(
|
||||
for ( sw idx = 0; idx < Hashes.num(); ++idx )
|
||||
for ( ssize idx = 0; idx < Hashes.num(); ++idx )
|
||||
if ( Hashes[ idx ] == key )
|
||||
return idx;
|
||||
|
||||
@ -335,7 +335,7 @@ Code gen__hashtable( StrC type )
|
||||
|
||||
CodeFn add_entry = def_function( name(add_entry), def_param( t_u64, name(key)), t_sw
|
||||
, def_execution( code(
|
||||
sw idx;
|
||||
ssize idx;
|
||||
Entry entry = { key, -1 };
|
||||
|
||||
idx = Entries.num();
|
||||
@ -421,11 +421,11 @@ void gen__hashtable_request( StrC type, StrC dep = {} )
|
||||
do_once_start
|
||||
GenHashTableRequests = Array<GenHashTableRequest>::init( GlobalAllocator );
|
||||
|
||||
gen_array( sw );
|
||||
gen_array( ssize );
|
||||
do_once_end
|
||||
|
||||
// Make sure we don't already have a request for the type.
|
||||
for ( sw idx = 0; idx < GenHashTableRequests.num(); ++idx )
|
||||
for ( ssize idx = 0; idx < GenHashTableRequests.num(); ++idx )
|
||||
{
|
||||
StrC const reqest_type = GenHashTableRequests[ idx ].Type;
|
||||
|
||||
|
@ -87,7 +87,7 @@ Code gen__ring( StrC type )
|
||||
);
|
||||
|
||||
Code body = def_execution( code(
|
||||
for ( sw idx = 0; idx < num; idx++ )
|
||||
for ( ssize idx = 0; idx < num; idx++ )
|
||||
append( values[ idx ] );
|
||||
));
|
||||
|
||||
@ -167,7 +167,7 @@ void gen__ring_request( StrC type, StrC dep = {} )
|
||||
do_once_end
|
||||
|
||||
// Make sure we don't already have a request for the type.
|
||||
for ( sw idx = 0; idx < GenRingRequests.num(); ++idx )
|
||||
for ( ssize idx = 0; idx < GenRingRequests.num(); ++idx )
|
||||
{
|
||||
StrC const reqest_type = GenRingRequests[ idx ].Type;
|
||||
|
||||
|
@ -22,7 +22,7 @@ int gen_main()
|
||||
gen_sanity_upfront();
|
||||
|
||||
gen_array( u8 );
|
||||
gen_array( sw );
|
||||
gen_array( ssize );
|
||||
|
||||
gen_buffer( u8 );
|
||||
|
||||
|
Reference in New Issue
Block a user