Templates, test changes (prob not working), progress on parsing bodies and operators.

This time, really not touching for a couple of weeks.
This commit is contained in:
2023-07-10 01:15:25 -04:00
parent 9df177edf4
commit ed6a1d0f95
14 changed files with 1343 additions and 503 deletions

View File

@@ -114,7 +114,6 @@ Code gen__array( StrC type, sw type_size )
Header& header = get_header();
return Data[ header.Num - 1 ];
))
, spec_inline
);
Code clear = def_function( name(clear), __, t_void
@@ -122,7 +121,6 @@ Code gen__array( StrC type, sw type_size )
Header& header = get_header();
header.Num = 0;
))
, spec_inline
);
Code fill;
@@ -155,14 +153,12 @@ Code gen__array( StrC type, sw type_size )
Header& header = get_header();
zpl::free( header.Allocator, & header );
))
, spec_inline
);
Code get_header = def_function( name(get_header), __, t_header_ref
, def_execution( code(
return * ( rcast( Header*, Data ) - 1 );
))
, spec_inline
);
Code grow = def_function( name(grow), def_param( t_uw, name(min_capacity)), t_bool
@@ -182,7 +178,6 @@ Code gen__array( StrC type, sw type_size )
, def_execution( code(
return get_header().Num;
))
, spec_inline
);
Code pop = def_function( name(pop), __, t_bool
@@ -192,7 +187,6 @@ Code gen__array( StrC type, sw type_size )
ZPL_ASSERT( header.Num > 0 );
header.Num--;
))
, spec_inline
);
Code remove_at = def_function( name(remove_at), def_param( t_uw, name(idx)), t_void
@@ -203,7 +197,6 @@ Code gen__array( StrC type, sw type_size )
mem_move( header + idx, header + idx + 1, sizeof( Type ) * ( header->Num - idx - 1 ) );
header->Num--;
))
, spec_inline
);
Code reserve = def_function( name(reserve), def_param( t_uw, name(new_capacity)), t_bool
@@ -316,7 +309,7 @@ Array(GenArrayRequest) GenArrayRequests;
void gen__array_request( StrC type, sw size, StrC dep = {} )
{
do_once_start
array_init( GenArrayRequests, g_allocator );
array_init( GenArrayRequests, Memory::GlobalAllocator );
do_once_end
// Make sure we don't already have a request for the type.

View File

@@ -101,7 +101,6 @@ Code gen__buffer( StrC type, sw type_size )
Data[ header.Num ] = value;
header.Num++;
))
, spec_inline
);
Code appendv;
@@ -121,7 +120,6 @@ Code gen__buffer( StrC type, sw type_size )
header.Num += num;
))
, spec_inline
);
}
@@ -130,7 +128,6 @@ Code gen__buffer( StrC type, sw type_size )
Header& header = get_header();
header.Num = 0;
))
, spec_inline
);
Code end = def_function( name(end), __, t_type_ref
@@ -138,7 +135,6 @@ Code gen__buffer( StrC type, sw type_size )
Header& header = get_header();
return Data[ header.Num - 1 ];
))
, spec_inline
);
Code free = def_function( name(free), __, t_void
@@ -146,21 +142,18 @@ Code gen__buffer( StrC type, sw type_size )
Header& header = get_header();
zpl::free( header.Backing, & header );
))
, spec_inline
);
Code get_header = def_function( name(get_header), __, t_header_ref
, def_execution( code(
return * ( rcast( Header*, Data ) - 1 );
))
, spec_inline
);
Code num = def_function( name(num), __, t_sw
, def_execution( code(
return get_header().Num;
))
, spec_inline
);
Code pop = def_function( name(pop), __, t_type
@@ -169,7 +162,6 @@ Code gen__buffer( StrC type, sw type_size )
header.Num--;
return Data[ header.Num ];
))
, spec_inline
);
Code wipe = def_function( name(wipe), __, t_void
@@ -178,7 +170,6 @@ Code gen__buffer( StrC type, sw type_size )
header.Num = 0;
mem_set( Data, 0, header.Capacity * sizeof( Type ) );
))
, spec_inline
);
Code op_type_ptr = untyped_str( code(
@@ -223,7 +214,7 @@ Array(GenBufferRequest) GenBufferRequests;
void gen__buffer_request( StrC type, sw size, StrC dep = {} )
{
do_once_start
array_init( GenBufferRequests, g_allocator );
array_init( GenBufferRequests, Memory::GlobalAllocator );
do_once_end
// Make sure we don't already have a request for the type.

View File

@@ -90,7 +90,7 @@ Code gen__hashtable( StrC type, sw type_size )
Code clear = def_function( name(clear), __, t_void
, def_execution( code(
if ( s32 idx = 0; idx < Hashes.num(), idx++ )
for ( s32 idx = 0; idx < Hashes.num(), idx++ )
Hashes[ idx ] = -1;
Entries.clear();
@@ -100,11 +100,10 @@ Code gen__hashtable( StrC type, sw type_size )
Code destroy = def_function( name(destroy), __, t_void
, def_execution( code(
if ( Hashes )
Hashes .free();
Hashes.free();
if ( Entries )
Entries.free();
))
, spec_inline
);
Code get = def_function( name(get), def_param( t_u64, name(key)), t_type_ptr
@@ -174,7 +173,6 @@ Code gen__hashtable( StrC type, sw type_size )
sw new_num = array_grow_formula( Entries.num() );
rehash( new_num );
))
, spec_inline
);
Code rehash;
@@ -214,7 +212,6 @@ Code gen__hashtable( StrC type, sw type_size )
new_ht.Entries[ last_added_index ].Value = entry.Value;
}
// <type>* old_ht = this;
// *this = new_ht;
// old_ht.destroy();
@@ -320,7 +317,6 @@ Code gen__hashtable( StrC type, sw type_size )
return -1;
))
, spec_inline
);
Code add_entry = def_function( name(add_entry), def_param( t_u64, name(key)), t_sw
@@ -332,7 +328,6 @@ Code gen__hashtable( StrC type, sw type_size )
Entries.append( entry );
return idx;
))
, spec_inline
);
Code find = def_function( name(find), def_param( t_u64, name(key)), t_find_result
@@ -362,7 +357,6 @@ Code gen__hashtable( StrC type, sw type_size )
, def_execution( code(
return 0.75f * Hashes.num() < Entries.num();
))
, spec_inline
);
hashtable = def_struct( name, def_struct_body( 24
@@ -411,7 +405,7 @@ Array(GenHashTableRequest) GenHashTableRequests;
void gen__hashtable_request( StrC type, sw size, StrC dep = {} )
{
do_once_start
array_init( GenHashTableRequests, g_allocator );
array_init( GenHashTableRequests, Memory::GlobalAllocator );
gen_array( sw );
do_once_end

View File

@@ -80,7 +80,6 @@ Code gen__ring( StrC type, sw type_size )
if ( Head == Tail )
Tail = ( Tail + 1 ) % Capacity;
))
, spec_inline
);
Code appendv;
@@ -102,21 +101,18 @@ Code gen__ring( StrC type, sw type_size )
, def_execution( code(
return Head == Tail;
))
, spec_inline
);
Code free = def_function( name(free), __, t_void
, def_execution( code(
Buffer.free();
))
, spec_inline
);
Code full = def_function( name(full), __, t_bool
, def_execution( code(
return (Head + 1) % Capacity == Tail;
))
, spec_inline
);
Code get = def_function( name(get), __, t_type_ref
@@ -134,7 +130,6 @@ Code gen__ring( StrC type, sw type_size )
Tail = 0;
Buffer.wipe();
))
, spec_inline
);
ring = def_struct( name, def_struct_body( 14,
@@ -172,7 +167,7 @@ Array(GenRingRequest) GenRingRequests;
void gen__ring_request( StrC type, sw size, StrC dep = {} )
{
do_once_start
array_init( GenRingRequests, g_allocator );
array_init( GenRingRequests, Memory::GlobalAllocator );
do_once_end
// Make sure we don't already have a request for the type.

View File

@@ -78,13 +78,13 @@ Code gen__array( StrC type, sw type_size )
return true;
}
inline Type& back( void )
Type& back( void )
{
Header& header = get_header();
return Data[ header.Num - 1 ];
}
inline void clear( void )
void clear( void )
{
Header& header = get_header();
header.Num = 0;
@@ -105,13 +105,13 @@ Code gen__array( StrC type, sw type_size )
return true;
}
inline void free( void )
void free( void )
{
Header& header = get_header();
zpl::free( header.Allocator, &header );
}
inline Header& get_header( void )
Header& get_header( void )
{
return *( reinterpret_cast< Header* >( Data ) - 1 );
}
@@ -127,12 +127,12 @@ Code gen__array( StrC type, sw type_size )
return set_capacity( new_capacity );
}
inline uw num( void )
uw num( void )
{
return get_header().Num;
}
inline bool pop( void )
bool pop( void )
{
Header& header = get_header();
@@ -140,7 +140,7 @@ Code gen__array( StrC type, sw type_size )
header.Num--;
}
inline void remove_at( uw idx )
void remove_at( uw idx )
{
Header* header = &get_header();
ZPL_ASSERT( idx < header->Num );
@@ -233,7 +233,7 @@ Array(GenArrayRequest) GenArrayRequests;
void gen__array_request( StrC type, sw size, StrC dep = {} )
{
do_once_start
array_init( GenArrayRequests, g_allocator );
array_init( GenArrayRequests, Memory::GlobalAllocator );
do_once_end
// Make sure we don't already have a request for the type.

View File

@@ -192,7 +192,6 @@ u32 gen_sanity()
gen_sanity_file.print_fmt("\n");
// Specifiers
if (0)
{
Code fwd_fn = parse_function( code(
inline

View File

@@ -2,10 +2,11 @@
The following tests focus on attempting to generate some math, containers, and the memory module of zpl.
Not all the files are written how I would practically use the librarry,
Not all the files are written how I would practically use the librarry, the containers for example would
be better on in c++ as templates, since the templates they generate are trivial symbols to inspect or debug.
There will be down the line a proper container, and memory libraries made with this gen library
once the stress test files are complete.
An exmaple of a non-trival generation is a container for elements with SOA or AOS policy for layout.
(If a unified element syntax is desired)
The test is divided between two major sets of tests: Parsed and Nonparsed.

View File

@@ -25,5 +25,5 @@ endif
add_project_arguments('-Dgen_time', language : ['c', 'cpp'])
# executable( 'gencpp', sources, include_directories : includes )
executable( 'gencpp', sources, include_directories : includes )
executable( 'gencpp_parsed', sources_parsed, include_directories : includes )