Updated readme, added def_body and AST::validate_body

Fixed meson first setup error with missing thirdparty dir (removed it since its no longer used)

Improved SOA test to use newly added funtions.
This commit is contained in:
2023-07-12 15:59:47 -04:00
parent 128b0e17fe
commit 4e61fefc55
13 changed files with 319 additions and 193 deletions

View File

@@ -36,7 +36,7 @@ u32 gen_sanity()
{};
));
empty_body.body()->add_entry( def_comment( txt_StrC("Empty class body") ) );
empty_body->body()->add_entry( def_comment( txt_StrC("Empty class body") ) );
gen_sanity_file.print(fwd);
gen_sanity_file.print(empty_body);
@@ -80,7 +80,7 @@ u32 gen_sanity()
};
));
c_extern.body()->add_entry( empty_comment );
c_extern->body()->add_entry( empty_comment );
gen_sanity_file.print(c_extern);
}
@@ -118,7 +118,7 @@ u32 gen_sanity()
}
));
def.body()->add_entry( def_comment( txt_StrC("Empty function body") ) );
def->body()->add_entry( def_comment( txt_StrC("Empty function body") ) );
gen_sanity_file.print(fwd);
gen_sanity_file.print(def);
@@ -134,7 +134,7 @@ u32 gen_sanity()
}
));
def.body()->add_entry( def_comment( txt_StrC("Empty namespace body") ) );
def->body()->add_entry( def_comment( txt_StrC("Empty namespace body") ) );
gen_sanity_file.print(def);
}
@@ -182,7 +182,7 @@ u32 gen_sanity()
};
));
class_def.body()->add_entry( op_ptr );
class_def->body()->add_entry( op_ptr );
gen_sanity_file.print(class_def);
}
@@ -201,7 +201,7 @@ u32 gen_sanity()
}
));
def.body()->add_entry( def_comment( txt_StrC("Empty function body") ) );
def->body()->add_entry( def_comment( txt_StrC("Empty function body") ) );
gen_sanity_file.print(fwd);
gen_sanity_file.print(def);
@@ -237,7 +237,7 @@ u32 gen_sanity()
{};
));
empty_body.body()->add_entry( def_comment( txt_StrC("Empty struct body") ) );
empty_body->body()->add_entry( def_comment( txt_StrC("Empty struct body") ) );
gen_sanity_file.print(fwd);
gen_sanity_file.print(empty_body);
@@ -253,7 +253,7 @@ u32 gen_sanity()
};
));
empty.body()->add_entry( def_comment( txt_StrC("Empty union body") ) );
empty->body()->add_entry( def_comment( txt_StrC("Empty union body") ) );
gen_sanity_file.print( parse_typedef( code( typedef unsigned short u16; )) );
gen_sanity_file.print( parse_typedef( code( typedef unsigned long u32; )) );

View File

@@ -4,21 +4,29 @@
#include "gen.hpp"
using namespace gen;
Code gen_SOA( Code struct_def, bool use_dynamic = false )
Code gen_SOA( Code struct_def, s32 num_entries = 0 )
{
StrC name;
name.Ptr = str_fmt_buf( "SOA_%s", (char const*) struct_def->Name );
name.Len = str_len( name );
StringCached name = get_cached_string( token_fmt( "name", (StrC)struct_def->Name,
stringize( SOA_<name> )
));
Code
soa_entry = { struct_def->duplicate() };
soa_entry->Name = get_cached_string( name(Entry) );
Array<Code> vars = Array<Code>::init( Memory::GlobalAllocator );;
constexpr s32 Num_Vars_Cap = 128;
Code soa = def_struct( name, def_struct_body( 1, soa_entry ) );
local_persist Code var_memory[Num_Vars_Cap];
local_persist Arena var_arena;
do_once_start
var_arena = Arena::init_from_memory( var_memory, kilobytes(Num_Vars_Cap) );
do_once_end
Array<Code> vars = Array<Code>::init( var_arena );;
Code soa = def_struct( name, def_body( ECode::Struct_Body ));
{
Code body = struct_def.body();
Code body = *struct_def->body();
for ( s32 idx = 0; idx < body->num_entries(); idx++ )
{
Code struct_mem = { body->entry( idx ) };
@@ -27,8 +35,10 @@ Code gen_SOA( Code struct_def, bool use_dynamic = false )
{
Code var_type = { struct_mem->entry(0) };
StrC num_entries_str = to_StrC( str_fmt_buf( "%d", num_entries ) );
Code entry_arr = { nullptr };
if ( use_dynamic)
if ( ! num_entries)
{
entry_arr = parse_variable( token_fmt( "type", (StrC)var_type->Name, "name", (StrC)struct_mem->Name,
stringize( Array<<type>> <name>; )
@@ -36,20 +46,20 @@ Code gen_SOA( Code struct_def, bool use_dynamic = false )
}
else
{
entry_arr = parse_variable( token_fmt( "type", (StrC)var_type->Name, "name", (StrC)struct_mem->Name,
stringize( <type> <name>[100]; )
entry_arr = parse_variable( token_fmt( "type", (StrC)var_type->Name, "name", (StrC)struct_mem->Name, "num", num_entries_str,
stringize( <type> <name>[<num>]; )
));
}
vars.append( entry_arr );
soa.body()->add_entry( entry_arr );
soa->body()->add_entry( entry_arr );
}
}
}
Code make;
{
make = parse_function( token_fmt("SOA_Type", name,
make = parse_function( token_fmt("SOA_Type", (StrC)name,
stringize(
static
<SOA_Type> make( AllocatorInfo allocator )
@@ -59,7 +69,7 @@ Code gen_SOA( Code struct_def, bool use_dynamic = false )
)
));
if ( use_dynamic )
if ( ! num_entries )
{
for ( s32 idx = 0; idx < vars.num(); idx++ )
{
@@ -69,11 +79,11 @@ Code gen_SOA( Code struct_def, bool use_dynamic = false )
stringize( soa.<var_name> = <var_type>::init( allocator ); )
));
make.body()->add_entry( arr_init );
make->body()->add_entry( arr_init );
}
}
make.body()->add_entry( def_execution( code( return soa; ) ));
make->body()->add_entry( def_execution( code( return soa; ) ));
}
Code get;
@@ -99,11 +109,14 @@ Code gen_SOA( Code struct_def, bool use_dynamic = false )
Code ret = def_execution( content );
get.body()->add_entry( ret );
get->body()->add_entry( ret );
}
soa.body()->add_entry( make );
soa.body()->add_entry( get );
soa->body()->add_entry( make );
soa->body()->add_entry( get );
soa->body()->validate_body();
vars.free();
return soa;
}
#endif

View File

@@ -51,7 +51,7 @@ Code gen__buffer( StrC type, sw type_size )
Code init;
{
Code params = def_params( args(
, def_param( t_allocator_info, name(allocator))
def_param( t_allocator_info, name(allocator))
, def_param( t_sw, name(capacity))
));

View File

@@ -140,7 +140,7 @@ Code gen__hashtable( StrC type )
char const* tmpl = stringize(
void (*) ( u64 key, <type> value )
);
Code value = untyped_str( token_fmt( "type", (StrC)t_type.to_string(), tmpl ) );
Code value = untyped_str( token_fmt( "type", (StrC)t_type->to_string(), tmpl ) );
using_map_proc = def_using ( name(MapProc), value);
}
@@ -166,7 +166,7 @@ Code gen__hashtable( StrC type )
char const* tmpl = stringize(
void (*) ( u64 key, <type> value )
);
Code value = untyped_str( token_fmt( "type", (StrC)t_type_ptr.to_string(), tmpl ) );
Code value = untyped_str( token_fmt( "type", (StrC)t_type_ptr->to_string(), tmpl ) );
using_map_mut_proc = def_using ( name(MapMutProc), value);
}
@@ -373,7 +373,7 @@ Code gen__hashtable( StrC type )
);
hashtable = def_struct( name, def_struct_body( args(
, using_entry
using_entry
, using_array_entry
, using_find_result
, using_map_proc

View File

@@ -46,7 +46,7 @@ Code gen__ring( StrC type )
Code init;
{
Code params = def_params( args(
, def_param( t_allocator_info, name(allocator) )
def_param( t_allocator_info, name(allocator) )
, def_param( t_uw, name(max_size) )
));

View File

@@ -3,7 +3,7 @@
using namespace gen;
u32 gen_sanity()
u32 gen_sanity_upfront()
{
Builder
gen_sanity_file;
@@ -27,7 +27,8 @@ u32 gen_sanity()
Code empty_body;
{
Code cmt = def_comment( txt_StrC("Empty class body") );
Code body = def_class_body( 1, cmt );
Code body = def_class_body( args( cmt ) );
empty_body = def_class( name(TestEmptyClass), body );
}
@@ -87,9 +88,7 @@ u32 gen_sanity()
// Friend
{
Code fwd = def_class( name(TestFriendFwd));
Code body = def_class_body( 1
, def_friend( fwd )
);
Code body = def_class_body( args( def_friend( fwd ) ) );
gen_sanity_file.print( def_class( name(TestFriend), body ) );
}
@@ -196,7 +195,7 @@ u32 gen_sanity()
Code op_ptr = def_operator_cast( t_u8_ptr, __ );
Code op_class = def_class( name(TestOperatorCast), def_class_body( 1, op_ptr ) );
Code op_class = def_class( name(TestOperatorCast), def_class_body( args( op_ptr) ) );
gen_sanity_file.print(op_class);
}
@@ -245,7 +244,7 @@ u32 gen_sanity()
{
Code fwd_fn = def_function( name(test_function_specifiers), __, __, __, spec_inline );
// TODO: Need an op overload here
// TODO : Need an op overload here
Code u8_ptr = def_type( name(u8), __, spec_ptr );
Code typedef_u8_ptr = def_typedef( name(ConstExprTest), u8_ptr );
@@ -262,7 +261,7 @@ u32 gen_sanity()
Code empty_body;
{
Code cmt = def_comment( txt_StrC("Empty struct body") );
Code body = def_class_body( 1, cmt );
Code body = def_class_body( args( cmt ) );
empty_body = def_class( name(TestEmptyStruct), body );
}

View File

@@ -5,7 +5,7 @@ project( 'test', 'c', 'cpp', default_options : ['buildtype=debug'] )
includes = include_directories(
[
'../../project',
'../../thirdparty'
# '../../thirdparty'
])
# get_sources = files('./get_sources.ps1')

View File

@@ -6,7 +6,7 @@ includes = include_directories(
[
'./gen',
'../project',
'../thirdparty'
# '../thirdparty'
])
# get_sources = files('./get_sources.ps1')

View File

@@ -1,6 +1,7 @@
#ifdef gen_time
#define GEN_DEFINE_LIBRARY_CODE_CONSTANTS
#define GEN_FEATURE_PARSING
#include "Upfront\Sanity.Upfront.hpp"
#include "Parsed\Array.Parsed.hpp"
#include "Parsed\Buffer.Parsed.hpp"
#include "Parsed\HashTable.Parsed.hpp"
@@ -55,7 +56,7 @@ int gen_main()
u64 D;
};
)),
false
128
));
soa_test.write();