mirror of
https://github.com/Ed94/gencpp.git
synced 2025-07-30 00:46:59 -07:00
Started to move over zpl depndencies and use templated containers.
Still have a ways to go.
This commit is contained in:
@@ -300,16 +300,16 @@ struct GenArrayRequest
|
||||
StrC Dependency;
|
||||
StrC Type;
|
||||
};
|
||||
Array(GenArrayRequest) GenArrayRequests;
|
||||
Array<GenArrayRequest> GenArrayRequests;
|
||||
|
||||
void gen__array_request( StrC type, StrC dep = {} )
|
||||
{
|
||||
do_once_start
|
||||
array_init( GenArrayRequests, Memory::GlobalAllocator );
|
||||
GenArrayRequests = Array<GenArrayRequest>::init( Memory::GlobalAllocator );
|
||||
do_once_end
|
||||
|
||||
// Make sure we don't already have a request for the type.
|
||||
for ( sw idx = 0; idx < array_count( GenArrayRequests ); ++idx )
|
||||
for ( sw idx = 0; idx < GenArrayRequests.num(); ++idx )
|
||||
{
|
||||
StrC const reqest_type = GenArrayRequests[ idx ].Type;
|
||||
|
||||
@@ -321,7 +321,7 @@ void gen__array_request( StrC type, StrC dep = {} )
|
||||
}
|
||||
|
||||
GenArrayRequest request = { dep, type };
|
||||
array_append( GenArrayRequests, request );
|
||||
GenArrayRequests.append( request );
|
||||
}
|
||||
#define gen_array( type ) gen__array_request( { txt_to_StrC(type) } )
|
||||
|
||||
@@ -338,7 +338,7 @@ u32 gen_array_file()
|
||||
gen_array_file.print( array_base );
|
||||
|
||||
GenArrayRequest* current = GenArrayRequests;
|
||||
s32 left = array_count( GenArrayRequests );
|
||||
s32 left = GenArrayRequests.num();
|
||||
while (left--)
|
||||
{
|
||||
GenArrayRequest const& request = * current;
|
||||
|
@@ -206,16 +206,16 @@ struct GenBufferRequest
|
||||
StrC Type;
|
||||
sw TypeSize;
|
||||
};
|
||||
Array(GenBufferRequest) GenBufferRequests;
|
||||
Array<GenBufferRequest> GenBufferRequests;
|
||||
|
||||
void gen__buffer_request( StrC type, sw size, StrC dep = {} )
|
||||
{
|
||||
do_once_start
|
||||
array_init( GenBufferRequests, Memory::GlobalAllocator );
|
||||
GenBufferRequests = Array<GenBufferRequest>::init( Memory::GlobalAllocator );
|
||||
do_once_end
|
||||
|
||||
// Make sure we don't already have a request for the type.
|
||||
for ( sw idx = 0; idx < array_count( GenBufferRequests ); ++idx )
|
||||
for ( sw idx = 0; idx < GenBufferRequests.num(); ++idx )
|
||||
{
|
||||
StrC const reqest_type = GenBufferRequests[ idx ].Type;
|
||||
|
||||
@@ -227,7 +227,7 @@ void gen__buffer_request( StrC type, sw size, StrC dep = {} )
|
||||
}
|
||||
|
||||
GenBufferRequest request = { dep, type, size};
|
||||
array_append( GenBufferRequests, request );
|
||||
GenBufferRequests.append( request );
|
||||
}
|
||||
#define gen_buffer( type ) gen__buffer_request( { txt_to_StrC(type) }, sizeof( type ))
|
||||
|
||||
@@ -241,7 +241,7 @@ u32 gen_buffer_file()
|
||||
gen_buffer_file.print( gen__buffer_base() );
|
||||
|
||||
GenBufferRequest* current = GenBufferRequests;
|
||||
s32 left = array_count( GenBufferRequests );
|
||||
s32 left = GenBufferRequests.num();
|
||||
while (left--)
|
||||
{
|
||||
GenBufferRequest const& request = * current;
|
||||
|
@@ -21,7 +21,7 @@ Code gen__hashtable_base()
|
||||
return find_result;
|
||||
}
|
||||
|
||||
Code gen__hashtable( StrC type, sw type_size )
|
||||
Code gen__hashtable( StrC type )
|
||||
{
|
||||
static Code t_allocator_info = def_type( name(AllocatorInfo) );
|
||||
|
||||
@@ -397,20 +397,19 @@ struct GenHashTableRequest
|
||||
{
|
||||
StrC Dependency;
|
||||
StrC Type;
|
||||
sw TypeSize;
|
||||
};
|
||||
Array(GenHashTableRequest) GenHashTableRequests;
|
||||
Array<GenHashTableRequest> GenHashTableRequests;
|
||||
|
||||
void gen__hashtable_request( StrC type, sw size, StrC dep = {} )
|
||||
void gen__hashtable_request( StrC type, StrC dep = {} )
|
||||
{
|
||||
do_once_start
|
||||
array_init( GenHashTableRequests, Memory::GlobalAllocator );
|
||||
GenHashTableRequests = Array<GenHashTableRequest>::init( Memory::GlobalAllocator );
|
||||
|
||||
gen_array( sw );
|
||||
do_once_end
|
||||
|
||||
// Make sure we don't already have a request for the type.
|
||||
for ( sw idx = 0; idx < array_count( GenHashTableRequests ); ++idx )
|
||||
for ( sw idx = 0; idx < GenHashTableRequests.num(); ++idx )
|
||||
{
|
||||
StrC const reqest_type = GenHashTableRequests[ idx ].Type;
|
||||
|
||||
@@ -421,10 +420,10 @@ void gen__hashtable_request( StrC type, sw size, StrC dep = {} )
|
||||
return;
|
||||
}
|
||||
|
||||
GenHashTableRequest request = { dep, type, size};
|
||||
array_append( GenHashTableRequests, request );
|
||||
GenHashTableRequest request = { dep, type };
|
||||
GenHashTableRequests.append( request );
|
||||
}
|
||||
#define gen_hashtable( type ) gen__hashtable_request( { txt_to_StrC(type) }, sizeof( type ))
|
||||
#define gen_hashtable( type ) gen__hashtable_request( { txt_to_StrC(type) } )
|
||||
|
||||
u32 gen_hashtable_file()
|
||||
{
|
||||
@@ -439,12 +438,12 @@ u32 gen_hashtable_file()
|
||||
gen_buffer_file.print( gen__hashtable_base());
|
||||
|
||||
GenHashTableRequest* current = GenHashTableRequests;
|
||||
s32 left = array_count( GenHashTableRequests );
|
||||
s32 left = GenHashTableRequests.num();
|
||||
while (left--)
|
||||
{
|
||||
GenHashTableRequest const& request = * current;
|
||||
|
||||
Code generated_buffer = gen__hashtable( current->Type, current->TypeSize );
|
||||
Code generated_buffer = gen__hashtable( current->Type );
|
||||
|
||||
if ( request.Dependency )
|
||||
{
|
||||
|
@@ -162,16 +162,16 @@ struct GenRingRequest
|
||||
StrC Type;
|
||||
sw TypeSize;
|
||||
};
|
||||
Array(GenRingRequest) GenRingRequests;
|
||||
Array<GenRingRequest> GenRingRequests;
|
||||
|
||||
void gen__ring_request( StrC type, sw size, StrC dep = {} )
|
||||
{
|
||||
do_once_start
|
||||
array_init( GenRingRequests, Memory::GlobalAllocator );
|
||||
GenRingRequests = Array<GenRingRequest>::init( Memory::GlobalAllocator );
|
||||
do_once_end
|
||||
|
||||
// Make sure we don't already have a request for the type.
|
||||
for ( sw idx = 0; idx < array_count( GenRingRequests ); ++idx )
|
||||
for ( sw idx = 0; idx < GenRingRequests.num(); ++idx )
|
||||
{
|
||||
StrC const reqest_type = GenRingRequests[ idx ].Type;
|
||||
|
||||
@@ -186,7 +186,7 @@ void gen__ring_request( StrC type, sw size, StrC dep = {} )
|
||||
gen__buffer_request( type, size, dep );
|
||||
|
||||
GenRingRequest request = { dep, type, size};
|
||||
array_append( GenRingRequests, request );
|
||||
GenRingRequests.append( request );
|
||||
}
|
||||
#define gen_ring( type ) gen__ring_request( { txt_to_StrC(type) }, sizeof( type ))
|
||||
|
||||
@@ -201,7 +201,7 @@ u32 gen_ring_file()
|
||||
// gen_ring_file.print( gen__ring_base() );
|
||||
|
||||
GenRingRequest* current = GenRingRequests;
|
||||
s32 left = array_count( GenRingRequests );
|
||||
s32 left = GenRingRequests.num();
|
||||
while (left--)
|
||||
{
|
||||
GenRingRequest const& request = * current;
|
||||
|
@@ -224,16 +224,16 @@ struct GenArrayRequest
|
||||
StrC Dependency;
|
||||
StrC Type;
|
||||
};
|
||||
Array(GenArrayRequest) GenArrayRequests;
|
||||
Array<GenArrayRequest> GenArrayRequests;
|
||||
|
||||
void gen__array_request( StrC type, sw size, StrC dep = {} )
|
||||
{
|
||||
do_once_start
|
||||
array_init( GenArrayRequests, Memory::GlobalAllocator );
|
||||
GenArrayRequests = Array<GenArrayRequest>::init( Memory::GlobalAllocator );
|
||||
do_once_end
|
||||
|
||||
// Make sure we don't already have a request for the type.
|
||||
for ( sw idx = 0; idx < array_count( GenArrayRequests ); ++idx )
|
||||
for ( sw idx = 0; idx < GenArrayRequests.num(); ++idx )
|
||||
{
|
||||
StrC const reqest_type = GenArrayRequests[ idx ].Type;
|
||||
|
||||
@@ -245,7 +245,7 @@ void gen__array_request( StrC type, sw size, StrC dep = {} )
|
||||
}
|
||||
|
||||
GenArrayRequest request = { dep, type };
|
||||
array_append( GenArrayRequests, request );
|
||||
GenArrayRequests.append( request );
|
||||
}
|
||||
#define gen_array( type ) gen__array_request( { txt_to_StrC(type) }, sizeof(type) )
|
||||
|
||||
@@ -262,7 +262,7 @@ u32 gen_array_file()
|
||||
gen_array_file.print( array_base );
|
||||
|
||||
GenArrayRequest* current = GenArrayRequests;
|
||||
s32 left = array_count( GenArrayRequests );
|
||||
s32 left = GenArrayRequests.num();
|
||||
while (left--)
|
||||
{
|
||||
GenArrayRequest const& request = * current;
|
||||
|
@@ -137,16 +137,16 @@ struct GenBufferRequest
|
||||
StrC Dependency;
|
||||
StrC Type;
|
||||
};
|
||||
Array(GenBufferRequest) GenBufferRequests;
|
||||
Array<GenBufferRequest> GenBufferRequests;
|
||||
|
||||
void gen__buffer_request( StrC type, StrC dep = {} )
|
||||
{
|
||||
do_once_start
|
||||
array_init( GenBufferRequests, Memory::GlobalAllocator );
|
||||
GenBufferRequests = Array<GenBufferRequest>::init( Memory::GlobalAllocator );
|
||||
do_once_end
|
||||
|
||||
// Make sure we don't already have a request for the type.
|
||||
for ( sw idx = 0; idx < array_count( GenBufferRequests ); ++idx )
|
||||
for ( sw idx = 0; idx < GenBufferRequests.num(); ++idx )
|
||||
{
|
||||
StrC const reqest_type = GenBufferRequests[ idx ].Type;
|
||||
|
||||
@@ -158,7 +158,7 @@ void gen__buffer_request( StrC type, StrC dep = {} )
|
||||
}
|
||||
|
||||
GenBufferRequest request = { dep, type };
|
||||
array_append( GenBufferRequests, request );
|
||||
GenBufferRequests.append( request );
|
||||
}
|
||||
#define gen_buffer( type ) gen__buffer_request( { txt_to_StrC(type) } )
|
||||
|
||||
@@ -172,7 +172,7 @@ u32 gen_buffer_file()
|
||||
gen_buffer_file.print( gen__buffer_base() );
|
||||
|
||||
GenBufferRequest* current = GenBufferRequests;
|
||||
s32 left = array_count( GenBufferRequests );
|
||||
s32 left = GenBufferRequests.num();
|
||||
while (left--)
|
||||
{
|
||||
GenBufferRequest const& request = * current;
|
||||
|
@@ -290,18 +290,18 @@ struct GenHashTableRequest
|
||||
StrC Type;
|
||||
sw TypeSize;
|
||||
};
|
||||
Array(GenHashTableRequest) GenHashTableRequests;
|
||||
Array<GenHashTableRequest> GenHashTableRequests;
|
||||
|
||||
void gen__hashtable_request( StrC type, sw size, StrC dep = {} )
|
||||
{
|
||||
do_once_start
|
||||
array_init( GenHashTableRequests, Memory::GlobalAllocator );
|
||||
GenHashTableRequests = Array<GenHashTableRequest>::init( Memory::GlobalAllocator );
|
||||
|
||||
gen_array( sw );
|
||||
do_once_end
|
||||
|
||||
// Make sure we don't already have a request for the type.
|
||||
for ( sw idx = 0; idx < array_count( GenHashTableRequests ); ++idx )
|
||||
for ( sw idx = 0; idx < GenHashTableRequests.num(); ++idx )
|
||||
{
|
||||
StrC const reqest_type = GenHashTableRequests[ idx ].Type;
|
||||
|
||||
@@ -313,7 +313,7 @@ void gen__hashtable_request( StrC type, sw size, StrC dep = {} )
|
||||
}
|
||||
|
||||
GenHashTableRequest request = { dep, type, size};
|
||||
array_append( GenHashTableRequests, request );
|
||||
GenHashTableRequests.append( request );
|
||||
}
|
||||
#define gen_hashtable( type ) gen__hashtable_request( { txt_to_StrC(type) }, sizeof( type ))
|
||||
|
||||
@@ -329,7 +329,7 @@ u32 gen_hashtable_file()
|
||||
gen_buffer_file.print( gen__hashtable_base());
|
||||
|
||||
GenHashTableRequest* current = GenHashTableRequests;
|
||||
s32 left = array_count( GenHashTableRequests );
|
||||
s32 left = GenHashTableRequests.num();
|
||||
while (left--)
|
||||
{
|
||||
GenHashTableRequest const& request = * current;
|
||||
|
@@ -102,16 +102,16 @@ struct GenRingRequest
|
||||
StrC Dependency;
|
||||
StrC Type;
|
||||
};
|
||||
Array(GenRingRequest) GenRingRequests;
|
||||
Array<GenRingRequest> GenRingRequests;
|
||||
|
||||
void gen__ring_request( StrC type, sw size, StrC dep = {} )
|
||||
{
|
||||
do_once_start
|
||||
array_init( GenRingRequests, Memory::GlobalAllocator );
|
||||
GenRingRequests = Array<GenRingRequest>::init( Memory::GlobalAllocator );
|
||||
do_once_end
|
||||
|
||||
// Make sure we don't already have a request for the type.
|
||||
for ( sw idx = 0; idx < array_count( GenRingRequests ); ++idx )
|
||||
for ( sw idx = 0; idx < GenRingRequests.num(); ++idx )
|
||||
{
|
||||
StrC const reqest_type = GenRingRequests[ idx ].Type;
|
||||
|
||||
@@ -126,7 +126,7 @@ void gen__ring_request( StrC type, sw size, StrC dep = {} )
|
||||
gen__buffer_request( type, dep );
|
||||
|
||||
GenRingRequest request = { dep, type };
|
||||
array_append( GenRingRequests, request );
|
||||
GenRingRequests.append( request );
|
||||
}
|
||||
#define gen_ring( type ) gen__ring_request( { txt_to_StrC(type) }, sizeof( type ))
|
||||
|
||||
@@ -141,7 +141,7 @@ u32 gen_ring_file()
|
||||
// gen_ring_file.print( gen__ring_base() );
|
||||
|
||||
GenRingRequest* current = GenRingRequests;
|
||||
s32 left = array_count( GenRingRequests );
|
||||
s32 left = GenRingRequests.num();
|
||||
while (left--)
|
||||
{
|
||||
GenRingRequest const& request = * current;
|
||||
|
113
test/SOA.hpp
Normal file
113
test/SOA.hpp
Normal file
@@ -0,0 +1,113 @@
|
||||
#pragma once
|
||||
|
||||
#ifdef gen_time
|
||||
#include "gen.hpp"
|
||||
using namespace gen;
|
||||
|
||||
Code gen_SOA( Code struct_def, bool use_dynamic = false )
|
||||
{
|
||||
StrC name;
|
||||
name.Ptr = str_fmt_buf( "SOA_%s", (char const*) struct_def->Name );
|
||||
name.Len = str_len( name );
|
||||
|
||||
Code
|
||||
soa_entry = { struct_def->duplicate() };
|
||||
soa_entry->Name = get_cached_string( name(Entry) );
|
||||
|
||||
Array<Code> vars = Array<Code>::init( Memory::GlobalAllocator );;
|
||||
|
||||
Code soa = def_struct( name, def_struct_body( 1, soa_entry ) );
|
||||
{
|
||||
Code body = struct_def.body();
|
||||
for ( s32 idx = 0; idx < body->num_entries(); idx++ )
|
||||
{
|
||||
Code struct_mem = { body->entry( idx ) };
|
||||
|
||||
if ( struct_mem->Type == ECode::Variable )
|
||||
{
|
||||
Code var_type = { struct_mem->entry(0) };
|
||||
|
||||
Code entry_arr = { nullptr };
|
||||
if ( use_dynamic)
|
||||
{
|
||||
entry_arr = parse_variable( token_fmt( "Array<<type>> <name>;", 2
|
||||
, "type", (char const*)var_type->Name
|
||||
, "name", (char const*)struct_mem->Name )
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
entry_arr = parse_variable( token_fmt( "<type> <name>[100];", 2
|
||||
, "type", (char const*)var_type->Name
|
||||
, "name", (char const*)struct_mem->Name )
|
||||
);
|
||||
}
|
||||
|
||||
vars.append( entry_arr );
|
||||
soa.body()->add_entry( entry_arr );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Code make;
|
||||
{
|
||||
make = parse_function( token_fmt(
|
||||
txt(
|
||||
static
|
||||
<SOA_Type> make( AllocatorInfo allocator )
|
||||
{
|
||||
<SOA_Type> soa = {};
|
||||
}
|
||||
),
|
||||
1, "SOA_Type", (char const*)name
|
||||
));
|
||||
|
||||
if ( use_dynamic )
|
||||
{
|
||||
for ( s32 idx = 0; idx < vars.num(); idx++ )
|
||||
{
|
||||
Code member = vars[idx];
|
||||
|
||||
Code arr_init = def_execution( token_fmt( "soa.<var_name> = <var_type>::init( allocator );", 2
|
||||
, "var_name", (char const*)member->Name
|
||||
, "var_type", (char const*)member->entry(0)->Name
|
||||
));
|
||||
|
||||
make.body()->add_entry( arr_init );
|
||||
}
|
||||
}
|
||||
|
||||
make.body()->add_entry( def_execution( code( return soa; ) ));
|
||||
}
|
||||
|
||||
Code get;
|
||||
{
|
||||
get = parse_function( code(
|
||||
Entry get( s32 idx )
|
||||
{
|
||||
}
|
||||
));
|
||||
|
||||
String content = String::make( Memory::GlobalAllocator, "return\n{\n" );
|
||||
|
||||
for ( s32 idx = 0; idx < vars.num(); idx ++ )
|
||||
{
|
||||
Code member = vars[idx];
|
||||
|
||||
content.append_fmt( token_fmt( "<var_name>[idx],", 1
|
||||
, "var_name", (char const*)member->Name
|
||||
));
|
||||
}
|
||||
|
||||
content.append( "};" );
|
||||
|
||||
Code ret = def_execution( content );
|
||||
|
||||
get.body()->add_entry( ret );
|
||||
}
|
||||
|
||||
soa.body()->add_entry( make );
|
||||
soa.body()->add_entry( get );
|
||||
return soa;
|
||||
}
|
||||
#endif
|
@@ -4,6 +4,7 @@
|
||||
#include "Parsed\HashTable.Parsed.hpp"
|
||||
#include "Parsed\Ring.Parsed.hpp"
|
||||
#include "Parsed\Sanity.Parsed.hpp"
|
||||
#include "SOA.hpp"
|
||||
|
||||
|
||||
#ifdef gen_time
|
||||
@@ -34,6 +35,31 @@ int gen_main()
|
||||
gen_hashtable_file();
|
||||
gen_ring_file();
|
||||
|
||||
Builder soa_test; soa_test.open( "SOA.gen.hpp" );
|
||||
|
||||
soa_test.print( parse_using( code(
|
||||
using u16 = unsigned short;
|
||||
)));
|
||||
|
||||
soa_test.print( def_include( StrC::from("Bloat.hpp")));
|
||||
|
||||
soa_test.print( def_using_namespace( name(gen) ) );
|
||||
|
||||
soa_test.print( gen_SOA(
|
||||
parse_struct( code(
|
||||
struct TestStruct
|
||||
{
|
||||
u8 A;
|
||||
u16 B;
|
||||
u32 C;
|
||||
u64 D;
|
||||
};
|
||||
)),
|
||||
true
|
||||
));
|
||||
|
||||
soa_test.write();
|
||||
|
||||
gen::deinit();
|
||||
Memory::cleanup();
|
||||
return 0;
|
||||
|
Reference in New Issue
Block a user