mirror of
https://github.com/Ed94/gencpp.git
synced 2025-06-30 19:01:02 -07:00
Removed readonly ast option. Removed indentation from serialization. Updates to readme.
- Readonly overcompilcates things for the scope of this project. I'm avoding const correctness to avoid mental overhead. - Indentation was removed as it still required a formatting pass after, and the only significant thing needed was the newlines. - Removed some opinionated takes from readme, trying to keep it straight to the point. - Used def_execution more in array and ring defs (was using untyped_str when could have been using execution...)
This commit is contained in:
@ -16,7 +16,7 @@ Code gen__array_base()
|
||||
));
|
||||
|
||||
Code grow_formula = def_function( name(array_grow_formula), def_param( t_uw, name(value)), t_uw
|
||||
, untyped_str( code( return 2 * value * 8; ) )
|
||||
, def_execution( code( return 2 * value * 8; ) )
|
||||
, def_specifiers( 2, ESpecifier::Static_Member, ESpecifier::Inline )
|
||||
);
|
||||
|
||||
@ -57,20 +57,17 @@ Code gen__array( StrC type, sw type_size )
|
||||
Code t_header_ptr = def_type( name(Header), __, spec_ptr );
|
||||
Code t_header_ref = def_type( name(Header), __, spec_ref );
|
||||
|
||||
Code array;
|
||||
Code array = {0};
|
||||
{
|
||||
Code using_type = def_using( name(Type), t_type );
|
||||
Code data = def_variable( t_alias_ptr, name(Data) );
|
||||
|
||||
Code init;
|
||||
{
|
||||
Code params = def_param( t_allocator_info, name(allocator) );
|
||||
Code body = untyped_str( code(
|
||||
Code init = def_function( name(init), def_param( t_allocator_info, name(allocator) ), t_array_type
|
||||
, def_execution( code(
|
||||
return init_reserve( allocator, grow_formula(0) );
|
||||
));
|
||||
|
||||
init = def_function( name(init), params, t_array_type, body, spec_static );
|
||||
}
|
||||
))
|
||||
, spec_static
|
||||
);
|
||||
|
||||
Code init_reserve;
|
||||
{
|
||||
@ -79,7 +76,7 @@ Code gen__array( StrC type, sw type_size )
|
||||
, def_param( t_sw, name(capacity) )
|
||||
);
|
||||
|
||||
Code body = untyped_str( code(
|
||||
Code body = def_execution( code(
|
||||
Header* header = rcast( Header*, alloc( allocator, sizeof(Header) + sizeof(Type) ));
|
||||
|
||||
if ( header == nullptr )
|
||||
@ -95,44 +92,33 @@ Code gen__array( StrC type, sw type_size )
|
||||
init_reserve = def_function( name(init_reserve), params, t_array_type, body, spec_static );
|
||||
}
|
||||
|
||||
Code append;
|
||||
{
|
||||
// Code param_type;
|
||||
// if ( type_size <= 64 )
|
||||
// param_type = t_type;
|
||||
// else
|
||||
// param_type = t_type_ref;
|
||||
Code append = def_function( name(append), def_param(t_alias, name(value)), t_bool
|
||||
, def_execution( code(
|
||||
Header& header = get_header();
|
||||
|
||||
append = def_function( name(append), def_param(t_alias, name(value)), t_bool
|
||||
, untyped_str( code(
|
||||
Header& header = get_header();
|
||||
if ( header.Num == header.Capacity )
|
||||
{
|
||||
if ( ! grow( header.Capacity ))
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( header.Num == header.Capacity )
|
||||
{
|
||||
if ( ! grow( header.Capacity ))
|
||||
return false;
|
||||
}
|
||||
Data[ header.Num ] = value;
|
||||
header.Num++;
|
||||
|
||||
Data[ header.Num ] = value;
|
||||
header.Num++;
|
||||
return true;
|
||||
))
|
||||
);
|
||||
|
||||
return true;
|
||||
))
|
||||
);
|
||||
}
|
||||
|
||||
Code back;
|
||||
{
|
||||
Code body = untyped_str( code(
|
||||
Code back = def_function( name(back), __, t_alias_ref
|
||||
, def_execution( code(
|
||||
Header& header = get_header();
|
||||
return Data[ header.Num - 1 ];
|
||||
));
|
||||
|
||||
back = def_function( name(back), __, t_alias_ref, body, spec_inline );
|
||||
}
|
||||
))
|
||||
, spec_inline
|
||||
);
|
||||
|
||||
Code clear = def_function( name(clear), __, t_void
|
||||
, untyped_str( code(
|
||||
, def_execution( code(
|
||||
Header& header = get_header();
|
||||
header.Num = 0;
|
||||
))
|
||||
@ -165,19 +151,22 @@ Code gen__array( StrC type, sw type_size )
|
||||
}
|
||||
|
||||
Code free = def_function( name(free), __, t_void
|
||||
, untyped_str( code(
|
||||
, def_execution( code(
|
||||
Header& header = get_header();
|
||||
zpl::free( header.Allocator, & header );
|
||||
))
|
||||
, spec_inline
|
||||
);
|
||||
|
||||
Code get_header = def_function( name(get_header), __, t_header_ref, untyped_str( code(
|
||||
return * ( rcast( Header*, Data ) - 1 );
|
||||
)));
|
||||
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
|
||||
, untyped_str( code(
|
||||
, def_execution( code(
|
||||
Header& header = get_header();
|
||||
|
||||
uw new_capacity = grow_formula( header.Capacity );
|
||||
@ -190,23 +179,21 @@ Code gen__array( StrC type, sw type_size )
|
||||
);
|
||||
|
||||
Code num = def_function( name(num), __, t_uw
|
||||
, untyped_str( code(
|
||||
, def_execution( code(
|
||||
return get_header().Num;
|
||||
))
|
||||
, spec_inline
|
||||
);
|
||||
|
||||
Code pop;
|
||||
{
|
||||
Code body = untyped_str( code(
|
||||
Code pop = def_function( name(pop), __, t_bool
|
||||
, def_execution( code(
|
||||
Header& header = get_header();
|
||||
|
||||
ZPL_ASSERT( header.Num > 0 );
|
||||
header.Num--;
|
||||
));
|
||||
|
||||
pop = def_function( name(pop), __, t_bool, body, spec_inline );
|
||||
}
|
||||
))
|
||||
, spec_inline
|
||||
);
|
||||
|
||||
Code remove_at = def_function( name(remove_at), def_param( t_uw, name(idx)), t_void
|
||||
, def_execution( code(
|
||||
@ -220,7 +207,7 @@ Code gen__array( StrC type, sw type_size )
|
||||
);
|
||||
|
||||
Code reserve = def_function( name(reserve), def_param( t_uw, name(new_capacity)), t_bool
|
||||
, untyped_str( code(
|
||||
, def_execution( code(
|
||||
Header& header = get_header();
|
||||
|
||||
if ( header.Capacity < new_capacity )
|
||||
@ -231,7 +218,7 @@ Code gen__array( StrC type, sw type_size )
|
||||
);
|
||||
|
||||
Code resize = def_function( name(resize), def_param( t_uw, name(num)), t_bool
|
||||
, untyped_str( code(
|
||||
, def_execution( code(
|
||||
Header& header = get_header();
|
||||
|
||||
if ( num > header.Capacity )
|
||||
@ -247,7 +234,7 @@ Code gen__array( StrC type, sw type_size )
|
||||
|
||||
Code set_capacity;
|
||||
{
|
||||
Code body = untyped_str( code(
|
||||
Code body = def_execution( code(
|
||||
Header& header = get_header();
|
||||
|
||||
if ( new_capacity == header.Capacity )
|
||||
|
@ -42,7 +42,7 @@ Code gen__buffer( StrC type, sw type_size )
|
||||
Code t_header_ptr = def_type( name(Header), __, spec_ptr );
|
||||
Code t_header_ref = def_type( name(Header), __, spec_ref );
|
||||
|
||||
Code buffer;
|
||||
Code buffer = {0};
|
||||
{
|
||||
Code using_type = def_using( name(Type), t_type );
|
||||
Code data = def_variable( t_type_ptr, name(Data) );
|
||||
@ -54,7 +54,7 @@ Code gen__buffer( StrC type, sw type_size )
|
||||
, def_param( t_sw, name(capacity))
|
||||
);
|
||||
|
||||
Code body = untyped_str( code(
|
||||
Code body = def_execution( code(
|
||||
Header* header = rcast( Header*, alloc( allocator, sizeof(Header) + capacity * sizeof(Type) ) );
|
||||
|
||||
if ( header == nullptr )
|
||||
@ -78,7 +78,7 @@ Code gen__buffer( StrC type, sw type_size )
|
||||
);
|
||||
|
||||
init_copy = def_function( name(init), params, t_buffer_type
|
||||
, untyped_str( code(
|
||||
, def_execution( code(
|
||||
Header& other_header = other.get_header();
|
||||
Header* header = rcast( Header*, alloc( allocator, sizeof(Header) + other_header.Capacity * sizeof(Type) ) );
|
||||
|
||||
@ -95,23 +95,14 @@ Code gen__buffer( StrC type, sw type_size )
|
||||
);
|
||||
}
|
||||
|
||||
Code append;
|
||||
{
|
||||
// Code param_type;
|
||||
// if ( type_size <= 64 )
|
||||
// param_type = t_type;
|
||||
// else
|
||||
// param_type = t_type_ref;
|
||||
|
||||
append = def_function( name(append), def_param( t_type, name(value)), t_void
|
||||
, untyped_str( code(
|
||||
Header& header = get_header();
|
||||
Data[ header.Num ] = value;
|
||||
header.Num++;
|
||||
))
|
||||
, spec_inline
|
||||
);
|
||||
}
|
||||
Code append = def_function( name(append), def_param( t_type, name(value)), t_void
|
||||
, def_execution( code(
|
||||
Header& header = get_header();
|
||||
Data[ header.Num ] = value;
|
||||
header.Num++;
|
||||
))
|
||||
, spec_inline
|
||||
);
|
||||
|
||||
Code appendv;
|
||||
{
|
||||
@ -121,7 +112,7 @@ Code gen__buffer( StrC type, sw type_size )
|
||||
);
|
||||
|
||||
appendv = def_function( name(append), params, t_void
|
||||
, untyped_str( code(
|
||||
, def_execution( code(
|
||||
Header& header = get_header();
|
||||
|
||||
ZPL_ASSERT( header.Num + num <= header.Capacity);
|
||||
@ -135,7 +126,7 @@ Code gen__buffer( StrC type, sw type_size )
|
||||
}
|
||||
|
||||
Code clear = def_function( name(clear), __, t_void
|
||||
, untyped_str( code(
|
||||
, def_execution( code(
|
||||
Header& header = get_header();
|
||||
header.Num = 0;
|
||||
))
|
||||
@ -143,7 +134,7 @@ Code gen__buffer( StrC type, sw type_size )
|
||||
);
|
||||
|
||||
Code end = def_function( name(end), __, t_type_ref
|
||||
, untyped_str( code(
|
||||
, def_execution( code(
|
||||
Header& header = get_header();
|
||||
return Data[ header.Num - 1 ];
|
||||
))
|
||||
@ -151,7 +142,7 @@ Code gen__buffer( StrC type, sw type_size )
|
||||
);
|
||||
|
||||
Code free = def_function( name(free), __, t_void
|
||||
, untyped_str( code(
|
||||
, def_execution( code(
|
||||
Header& header = get_header();
|
||||
zpl::free( header.Backing, & header );
|
||||
))
|
||||
@ -159,21 +150,21 @@ Code gen__buffer( StrC type, sw type_size )
|
||||
);
|
||||
|
||||
Code get_header = def_function( name(get_header), __, t_header_ref
|
||||
, untyped_str( code(
|
||||
, def_execution( code(
|
||||
return * ( rcast( Header*, Data ) - 1 );
|
||||
))
|
||||
, spec_inline
|
||||
);
|
||||
|
||||
Code num = def_function( name(num), __, t_sw
|
||||
, untyped_str( code(
|
||||
, def_execution( code(
|
||||
return get_header().Num;
|
||||
))
|
||||
, spec_inline
|
||||
);
|
||||
|
||||
Code pop = def_function( name(pop), __, t_type
|
||||
, untyped_str( code(
|
||||
, def_execution( code(
|
||||
Header& header = get_header();
|
||||
header.Num--;
|
||||
return Data[ header.Num ];
|
||||
@ -182,7 +173,7 @@ Code gen__buffer( StrC type, sw type_size )
|
||||
);
|
||||
|
||||
Code wipe = def_function( name(wipe), __, t_void
|
||||
, untyped_str( code(
|
||||
, def_execution( code(
|
||||
Header& header = get_header();
|
||||
header.Num = 0;
|
||||
mem_set( Data, 0, header.Capacity * sizeof( Type ) );
|
||||
|
@ -12,7 +12,7 @@ Code gen__hashtable_base()
|
||||
Code entry_prev = def_variable( t_sw, name(PrevIndex) );
|
||||
Code entry_index = def_variable( t_sw, name(EntryIndex) );
|
||||
|
||||
Code find_result = def_struct( name(HashTableFindResult), def_struct_body( 3
|
||||
Code find_result = def_struct( name(HashTable_FindResult), def_struct_body( 3
|
||||
, hashIndex
|
||||
, entry_prev
|
||||
, entry_index
|
||||
@ -25,7 +25,7 @@ Code gen__hashtable( StrC type, sw type_size )
|
||||
{
|
||||
static Code t_allocator_info = def_type( name(AllocatorInfo) );
|
||||
|
||||
Code t_find_result = def_type( name(HashTableFindResult) );
|
||||
Code t_find_result = def_type( name(HashTable_FindResult) );
|
||||
|
||||
StringCached name;
|
||||
{
|
||||
@ -61,7 +61,7 @@ Code gen__hashtable( StrC type, sw type_size )
|
||||
t_array_ht_entry = def_type( array_ht_entry->Name );
|
||||
}
|
||||
|
||||
Code hashtable;
|
||||
Code hashtable = {0};
|
||||
{
|
||||
Code using_entry = def_using( name(Entry), t_ht_entry );
|
||||
Code using_array_entry = def_using( name(Array_Entry), t_array_ht_entry );
|
||||
|
@ -33,7 +33,7 @@ Code gen__ring( StrC type, sw type_size )
|
||||
t_buffer_type = def_type( { len, name_str } );
|
||||
}
|
||||
|
||||
Code ring;
|
||||
Code ring = {0};
|
||||
{
|
||||
Code using_type = def_using( name(Type), t_type );
|
||||
|
||||
@ -64,7 +64,7 @@ Code gen__ring( StrC type, sw type_size )
|
||||
|
||||
return result;
|
||||
);
|
||||
Code body = untyped_str( token_fmt( tmpl, 2
|
||||
Code body = def_execution( token_fmt( tmpl, 2
|
||||
, "type", (char const*)name
|
||||
, "data_type", (char const*)type
|
||||
));
|
||||
@ -73,7 +73,7 @@ Code gen__ring( StrC type, sw type_size )
|
||||
}
|
||||
|
||||
Code append = def_function( name(append), def_param( t_type, name(value)), t_void
|
||||
, untyped_str( code(
|
||||
, def_execution( code(
|
||||
Buffer[ Head ] = value;
|
||||
Head = ( Head + 1 ) % Capacity;
|
||||
|
||||
@ -90,7 +90,7 @@ Code gen__ring( StrC type, sw type_size )
|
||||
, def_param( t_sw, name(num))
|
||||
);
|
||||
|
||||
Code body = untyped_str( code(
|
||||
Code body = def_execution( code(
|
||||
for ( sw idx = 0; idx < num; idx++ )
|
||||
append( values[ idx ] );
|
||||
));
|
||||
|
Reference in New Issue
Block a user