Finished refactoring tests, compiles, but does not generate

This commit is contained in:
Edward R. Gonzalez 2023-07-15 16:13:44 -04:00
parent 8f4a94545c
commit 947b4e3615
9 changed files with 96 additions and 178 deletions

View File

@ -3323,7 +3323,7 @@ namespace gen
CodeEnum def_enum( StrC name
, Code body, CodeType type
, EnumT specifier, Code attributes
, EnumT specifier, CodeAttributes attributes
, ModuleFlag mflags )
{
using namespace ECode;

View File

@ -2701,31 +2701,6 @@ namespace gen
AST* ast;
// operator AST_Body*();
// operator AST_Attributes*();
// operator AST_Comment*();
// operator AST_Class*();
// operator AST_Enum*();
// operator AST_Exec*();
// operator AST_Extern*();
// operator AST_Include*();
// operator AST_Friend*();
// operator AST_Fn*();
// operator AST_Module*();
// operator AST_Namespace*();
// operator AST_Operator*();
// operator AST_OpCast*();
// operator AST_Param*();
// operator AST_Specifier*();
// operator AST_Struct*();
// operator AST_Template*();
// operator AST_Type*();
// operator AST_Typedef*();
// operator AST_Union*();
// operator AST_Using*();
// operator AST_UsingNamespace*();
// operator AST_Var*();
#ifdef GEN_ENFORCE_STRONG_CODE_TYPES
# define operator explicit operator
#endif
@ -2785,7 +2760,7 @@ namespace gen
template< class Type >
Type cast()
{
return (Type) { this };
return (Type)(Code){ this };
}
operator Code();
@ -2827,51 +2802,6 @@ namespace gen
)
/ sizeof(SpecifierT);
#if 0
union {
struct
{
Code Attributes; // Class, Enum, Function, Struct, Typedef, Union, Using, Variable
Code Specs; // Function, Operator, Type symbol, Variable
union {
Code ParentType; // Class, Struct
Code ReturnType; // Function, Operator
Code UnderlyingType; // Enum, Typedef
Code ValueType; // Parameter, Variable
};
Code Params; // Function, Operator, Template
union {
Code ArrExpr; // Type Symbol
Code Body; // Class, Enum, Function, Namespace, Struct, Union
Code Declaration; // Friend, Template
Code Value; // Parameter, Variable
};
};
StringCached Content; // Attributes, Comment, Execution, Include
SpecifierT ArrSpecs[AST::ArrSpecs_Cap]; // Specifiers
};
union {
// Entry Node
struct {
Code Prev;
Code Next;
};
// Body Node
struct {
Code Front;
Code Back;
};
};
Code Parent;
StringCached Name;
CodeT Type;
ModuleFlag ModuleFlags;
union {
OperatorT Op;
AccessSpec ParentAccess;
u32 NumEntries;
};
#else
union {
struct
{
@ -2915,7 +2845,6 @@ namespace gen
AccessSpec ParentAccess;
u32 NumEntries;
};
#endif
};
void assign( AST* field, AST* other )
@ -3717,7 +3646,7 @@ namespace gen
, CodeAttributes attributes = NoCode
, ModuleFlag mflags = ModuleFlag::None );
CodeEnum def_enum( StrC
CodeEnum def_enum( StrC name
, Code body = NoCode, CodeType type = NoCode
, EnumT specifier = EnumRegular, CodeAttributes attributes = NoCode
, ModuleFlag mflags = ModuleFlag::None );
@ -3740,9 +3669,9 @@ namespace gen
, CodeSpecifier specifiers = NoCode, CodeAttributes attributes = NoCode
, ModuleFlag mflags = ModuleFlag::None );
CodeOpCast def_operator_cast( Code type, Code body = NoCode );
CodeOpCast def_operator_cast( CodeType type, Code body = NoCode );
CodeParam def_param ( Code type, StrC name, Code value = NoCode );
CodeParam def_param ( CodeType type, StrC name, Code value = NoCode );
CodeSpecifier def_specifier( SpecifierT specifier );
CodeStruct def_struct( StrC name
@ -4101,17 +4030,17 @@ namespace gen
Code& AST::entry( u32 idx )
{
AST* current = Front;
AST** current = & Front;
while ( idx >= 0 && current != nullptr )
{
if ( idx == 0 )
return * rcast( Code*, & current);
return * rcast( Code*, current);
current = current->Next;
current = & ( * current )->Next;
idx--;
}
return * rcast( Code*, & current);
return * rcast( Code*, current);
}
bool AST::has_entries()
@ -4207,18 +4136,6 @@ namespace gen
return (AST*) ast != other.ast; \
}
// Typename::operator AST*() \
// { \
// return (AST*) ast; \
// }
// Typename& Typename::operator =( AST* other ) \
// { \
// ast = rcast( decltype(ast), other); \
// return * this; \
// } \
Define_CodeImpl( Code );
Define_CodeImpl( CodeBody);
Define_CodeImpl( CodeAttributes );

View File

@ -30,7 +30,7 @@ Code gen_SOA( CodeStruct struct_def, s32 num_entries = 0 )
{
if ( struct_mem->Type == ECode::Variable )
{
CodeType var_type = struct_mem->cast<CodeVar>()->ValueType;
CodeType var_type = struct_mem.cast<CodeVar>()->ValueType;
StrC num_entries_str = to_StrC( str_fmt_buf( "%d", num_entries ) );
CodeVar entry_arr = { nullptr };

View File

@ -71,9 +71,9 @@ Code gen__buffer( StrC type, sw type_size )
init = def_function( name(init), params, t_buffer_type, body, spec_static_member );
}
Code init_copy;
CodeFn init_copy;
{
Code params = def_params( args(
CodeParam params = def_params( args(
def_param( t_allocator_info, name(allocator))
, def_param( t_buffer_type, name(other))
));
@ -96,7 +96,7 @@ Code gen__buffer( StrC type, sw type_size )
);
}
Code append = def_function( name(append), def_param( t_type, name(value)), t_void
CodeFn append = def_function( name(append), def_param( t_type, name(value)), t_void
, def_execution( code(
Header& header = get_header();
Data[ header.Num ] = value;
@ -104,9 +104,9 @@ Code gen__buffer( StrC type, sw type_size )
))
);
Code appendv;
CodeFn appendv;
{
Code params = def_params( args(
CodeParam params = def_params( args(
def_param( t_type_ptr, name( values))
, def_param( t_sw, name( num))
));
@ -124,40 +124,40 @@ Code gen__buffer( StrC type, sw type_size )
);
}
Code clear = def_function( name(clear), __, t_void
CodeFn clear = def_function( name(clear), __, t_void
, def_execution( code(
Header& header = get_header();
header.Num = 0;
))
);
Code end = def_function( name(end), __, t_type_ref
CodeFn end = def_function( name(end), __, t_type_ref
, def_execution( code(
Header& header = get_header();
return Data[ header.Num - 1 ];
))
);
Code free = def_function( name(free), __, t_void
CodeFn free = def_function( name(free), __, t_void
, def_execution( code(
Header& header = get_header();
zpl::free( header.Backing, & header );
))
);
Code get_header = def_function( name(get_header), __, t_header_ref
CodeFn get_header = def_function( name(get_header), __, t_header_ref
, def_execution( code(
return * ( rcast( Header*, Data ) - 1 );
))
);
Code num = def_function( name(num), __, t_sw
CodeFn num = def_function( name(num), __, t_sw
, def_execution( code(
return get_header().Num;
))
);
Code pop = def_function( name(pop), __, t_type
CodeFn pop = def_function( name(pop), __, t_type
, def_execution( code(
Header& header = get_header();
header.Num--;
@ -165,7 +165,7 @@ Code gen__buffer( StrC type, sw type_size )
))
);
Code wipe = def_function( name(wipe), __, t_void
CodeFn wipe = def_function( name(wipe), __, t_void
, def_execution( code(
Header& header = get_header();
header.Num = 0;
@ -173,7 +173,7 @@ Code gen__buffer( StrC type, sw type_size )
))
);
Code op_type_ptr = def_operator_cast( t_type_ptr, def_execution( code(
CodeOpCast op_type_ptr = def_operator_cast( t_type_ptr, def_execution( code(
return Data;
)));

View File

@ -8,11 +8,11 @@ using namespace gen;
Code gen__hashtable_base()
{
Code hashIndex = def_variable( t_sw, name(HashIndex) );
Code entry_prev = def_variable( t_sw, name(PrevIndex) );
Code entry_index = def_variable( t_sw, name(EntryIndex) );
CodeVar hashIndex = def_variable( t_sw, name(HashIndex) );
CodeVar entry_prev = def_variable( t_sw, name(PrevIndex) );
CodeVar entry_index = def_variable( t_sw, name(EntryIndex) );
Code find_result = def_struct( name(HashTable_FindResult), def_struct_body( 3
CodeStruct find_result = def_struct( name(HashTable_FindResult), def_struct_body( 3
, hashIndex
, entry_prev
, entry_index
@ -23,9 +23,9 @@ Code gen__hashtable_base()
Code gen__hashtable( StrC type )
{
static Code t_allocator_info = def_type( name(AllocatorInfo) );
static CodeType t_allocator_info = def_type( name(AllocatorInfo) );
Code t_find_result = def_type( name(HashTable_FindResult) );
CodeType t_find_result = def_type( name(HashTable_FindResult) );
StringCached name;
{
@ -35,14 +35,15 @@ Code gen__hashtable( StrC type )
name = get_cached_string({ len, name_str });
}
Code t_ht_type = def_type( name );
CodeType t_ht_type = def_type( name );
Code t_type = def_type( type );
Code t_type_ptr = def_type( type, __, spec_ptr );
Code t_type_ref = def_type( type, __, spec_ref );
CodeType t_type = def_type( type );
CodeType t_type_ptr = def_type( type, __, spec_ptr );
CodeType t_type_ref = def_type( type, __, spec_ref );
// Hash table depends on array container for its entry structure.
Code t_ht_entry, ht_entry, array_ht_entry, t_array_ht_entry;
CodeType t_ht_entry, t_array_ht_entry;
CodeStruct ht_entry, array_ht_entry;
{
char const* name_str = str_fmt_buf( "HashTable_%s_Entry", type.Ptr );
s32 len = str_len( name_str );
@ -60,19 +61,19 @@ Code gen__hashtable( StrC type )
t_array_ht_entry = def_type( array_ht_entry->Name );
}
Code hashtable = {0};
CodeStruct 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 );
Code using_find_result = def_using( name(FindResult), t_find_result );
CodeUsing using_entry = def_using( name(Entry), t_ht_entry );
CodeUsing using_array_entry = def_using( name(Array_Entry), t_array_ht_entry );
CodeUsing using_find_result = def_using( name(FindResult), t_find_result );
Code t_array_sw = def_type( name(Array_sw) );
Code t_array_entry = def_type( name(Array_Entry) );
CodeType t_array_sw = def_type( name(Array_sw) );
CodeType t_array_entry = def_type( name(Array_Entry) );
Code hashes = def_variable( t_array_sw, name(Hashes) );
Code entries = def_variable( t_array_entry, name(Entries));
CodeVar hashes = def_variable( t_array_sw, name(Hashes) );
CodeVar entries = def_variable( t_array_entry, name(Entries));
Code init;
CodeFn init;
{
char const* tmpl = stringize(
<type> result = { 0 };
@ -88,7 +89,7 @@ Code gen__hashtable( StrC type )
}
Code init_reserve;
CodeFn init_reserve;
{
char const* tmpl = stringize(
<type> result = { { nullptr }, { nullptr } };
@ -102,12 +103,12 @@ Code gen__hashtable( StrC type )
);
Code body = def_execution( token_fmt( "type", (StrC)name, tmpl ) );
Code params = def_params( args( def_param( t_allocator_info, name(allocator)), def_param( t_sw, name(num))));
CodeParam params = def_params( args( def_param( t_allocator_info, name(allocator)), def_param( t_sw, name(num))));
init_reserve = def_function( name(init_reserve), params, t_ht_type, body, spec_static_member );
}
Code clear = def_function( name(clear), __, t_void
CodeFn clear = def_function( name(clear), __, t_void
, def_execution( code(
for ( s32 idx = 0; idx < Hashes.num(); idx++ )
Hashes[ idx ] = -1;
@ -116,7 +117,7 @@ Code gen__hashtable( StrC type )
))
);
Code destroy = def_function( name(destroy), __, t_void
CodeFn destroy = def_function( name(destroy), __, t_void
, def_execution( code(
if ( Hashes && Hashes.get_header()->Capacity )
Hashes.free();
@ -125,7 +126,7 @@ Code gen__hashtable( StrC type )
))
);
Code get = def_function( name(get), def_param( t_u64, name(key)), t_type_ptr
CodeFn get = def_function( name(get), def_param( t_u64, name(key)), t_type_ptr
, def_execution( code(
sw idx = find( key ).EntryIndex;
if ( idx >= 0 )
@ -135,19 +136,19 @@ Code gen__hashtable( StrC type )
))
);
Code using_map_proc;
CodeUsing using_map_proc;
{
char const* tmpl = stringize(
void (*) ( u64 key, <type> value )
);
Code value = untyped_str( token_fmt( "type", (StrC)t_type->to_string(), tmpl ) );
CodeType value = def_type( token_fmt( "type", (StrC)t_type.to_string(), tmpl ) );
using_map_proc = def_using ( name(MapProc), value);
}
Code map;
CodeFn map;
{
Code t_map_proc = def_type( name(MapProc) );
CodeType t_map_proc = def_type( name(MapProc) );
Code body = def_execution( code(
ZPL_ASSERT_NOT_NULL( map_proc );
@ -161,19 +162,19 @@ Code gen__hashtable( StrC type )
map = def_function( name(map), def_param( t_map_proc, name(map_proc) ), t_void, body );
}
Code using_map_mut_proc;
CodeUsing using_map_mut_proc;
{
char const* tmpl = stringize(
void (*) ( u64 key, <type> value )
);
Code value = untyped_str( token_fmt( "type", (StrC)t_type_ptr->to_string(), tmpl ) );
CodeType value = def_type( token_fmt( "type", (StrC)t_type_ptr.to_string(), tmpl ) );
using_map_mut_proc = def_using ( name(MapMutProc), value);
}
Code map_mut;
CodeFn map_mut;
{
Code t_map_mut_proc = def_type( name(MapMutProc));
CodeType t_map_mut_proc = def_type( name(MapMutProc));
Code body = def_execution( code(
ZPL_ASSERT_NOT_NULL( map_proc );
@ -187,14 +188,14 @@ Code gen__hashtable( StrC type )
map_mut = def_function( name(map_mut), def_param( t_map_mut_proc, name(map_proc)), t_void, body );
}
Code grow = def_function( name(grow), __, t_void
CodeFn grow = def_function( name(grow), __, t_void
, def_execution( code(
sw new_num = array_grow_formula( Entries.num() );
rehash( new_num );
))
);
Code rehash;
CodeFn rehash;
{
char const* tmpl = stringize(
sw idx;
@ -238,7 +239,7 @@ Code gen__hashtable( StrC type )
rehash = def_function( name(rehash), def_param( t_sw, name(new_num)), t_void, body );
}
Code rehash_fast;
CodeFn rehash_fast;
{
char const* tmpl = stringize(
sw idx;
@ -261,7 +262,7 @@ Code gen__hashtable( StrC type )
rehash_fast = def_function( name(rehash_fast), __, t_void, body );
}
Code remove = def_function( name(remove), def_param( t_u64, name(key)), t_void
CodeFn remove = def_function( name(remove), def_param( t_u64, name(key)), t_void
, def_execution( code(
FindResult find_result = find( key);
@ -273,15 +274,15 @@ Code gen__hashtable( StrC type )
))
);
Code remove_entry = def_function( name(remove_entry), def_param( t_sw, name(idx)), t_void
CodeFn remove_entry = def_function( name(remove_entry), def_param( t_sw, name(idx)), t_void
, def_execution( code(
Entries.remove_at( idx );
))
);
Code set;
CodeFn set;
{
Code params = def_params( args(
CodeParam params = def_params( args(
def_param( t_u64, name(key))
, def_param( t_type, name(value))
));
@ -322,7 +323,7 @@ Code gen__hashtable( StrC type )
set = def_function( name(set), params, t_void, body );
}
Code slot = def_function( name(slot), def_param( t_u64, name(key)), t_sw
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 )
if ( Hashes[ idx ] == key )
@ -332,7 +333,7 @@ Code gen__hashtable( StrC type )
))
);
Code add_entry = def_function( name(add_entry), def_param( t_u64, name(key)), t_sw
CodeFn add_entry = def_function( name(add_entry), def_param( t_u64, name(key)), t_sw
, def_execution( code(
sw idx;
Entry entry = { key, -1 };
@ -343,7 +344,7 @@ Code gen__hashtable( StrC type )
))
);
Code find = def_function( name(find), def_param( t_u64, name(key)), t_find_result
CodeFn find = def_function( name(find), def_param( t_u64, name(key)), t_find_result
, def_execution( code(
FindResult result = { -1, -1, -1 };
@ -366,7 +367,7 @@ Code gen__hashtable( StrC type )
))
);
Code full = def_function( name(full), __, t_b32
CodeFn full = def_function( name(full), __, t_b32
, def_execution( code(
return 0.75f * Hashes.num() < Entries.num();
))

View File

@ -8,7 +8,7 @@ using namespace gen;
Code gen__ring( StrC type )
{
static Code t_allocator_info = def_type( name(AllocatorInfo) );
static CodeType t_allocator_info = def_type( name(AllocatorInfo) );
String name;
{
@ -18,14 +18,14 @@ Code gen__ring( StrC type )
name = get_cached_string({ name_len, name_str });
};
Code t_ring_type = def_type( name );
Code t_ring_type_ptr = def_type( name, __, spec_ptr );
CodeType t_ring_type = def_type( name );
CodeType t_ring_type_ptr = def_type( name, __, spec_ptr );
Code t_type = def_type( type );
Code t_type_ptr = def_type( type, __, spec_ptr );
Code t_type_ref = def_type( type, __, spec_ref );
CodeType t_type = def_type( type );
CodeType t_type_ptr = def_type( type, __, spec_ptr );
CodeType t_type_ref = def_type( type, __, spec_ref );
Code t_buffer_type;
CodeType t_buffer_type;
{
char const* name_str = str_fmt_buf( "Buffer_%s\0", type.Ptr );
s32 len = str_len( name_str );
@ -33,19 +33,19 @@ Code gen__ring( StrC type )
t_buffer_type = def_type( { len, name_str } );
}
Code ring = {0};
CodeStruct ring = {0};
{
Code using_type = def_using( name(Type), t_type );
CodeUsing using_type = def_using( name(Type), t_type );
Code backing = def_variable( t_allocator_info, name(Backing) );
Code capacity = def_variable( t_uw, name(Capacity) );
Code head = def_variable( t_uw, name(Head) );
Code tail = def_variable( t_uw, name(Tail) );
Code buffer = def_variable( t_buffer_type, name(Buffer) );
CodeVar backing = def_variable( t_allocator_info, name(Backing) );
CodeVar capacity = def_variable( t_uw, name(Capacity) );
CodeVar head = def_variable( t_uw, name(Head) );
CodeVar tail = def_variable( t_uw, name(Tail) );
CodeVar buffer = def_variable( t_buffer_type, name(Buffer) );
Code init;
CodeFn init;
{
Code params = def_params( args(
CodeParam params = def_params( args(
def_param( t_allocator_info, name(allocator) )
, def_param( t_uw, name(max_size) )
));
@ -69,7 +69,7 @@ Code gen__ring( StrC type )
init = def_function( name(init), params, t_ring_type, body, spec_static_member );
}
Code append = def_function( name(append), def_param( t_type, name(value)), t_void
CodeFn append = def_function( name(append), def_param( t_type, name(value)), t_void
, def_execution( code(
Buffer[ Head ] = value;
Head = ( Head + 1 ) % Capacity;
@ -79,9 +79,9 @@ Code gen__ring( StrC type )
))
);
Code appendv;
CodeFn appendv;
{
Code params = def_params( 2
CodeParam params = def_params( 2
, def_param( t_type_ptr, name(values))
, def_param( t_sw, name(num))
);
@ -94,25 +94,25 @@ Code gen__ring( StrC type )
appendv = def_function( name(append), params, t_void, body, spec_inline );
}
Code empty = def_function( name(empty), __, t_bool
CodeFn empty = def_function( name(empty), __, t_bool
, def_execution( code(
return Head == Tail;
))
);
Code free = def_function( name(free), __, t_void
CodeFn free = def_function( name(free), __, t_void
, def_execution( code(
Buffer.free();
))
);
Code full = def_function( name(full), __, t_bool
CodeFn full = def_function( name(full), __, t_bool
, def_execution( code(
return (Head + 1) % Capacity == Tail;
))
);
Code get = def_function( name(get), __, t_type_ref
CodeFn get = def_function( name(get), __, t_type_ref
, def_execution( code(
Type& data = Buffer[ Tail ];
Tail = ( Tail + 1 ) % Capacity;
@ -121,7 +121,7 @@ Code gen__ring( StrC type )
))
);
Code wipe = def_function( name(wipe), __, t_void
CodeFn wipe = def_function( name(wipe), __, t_void
, def_execution( code(
Head = 0;
Tail = 0;

View File

@ -190,7 +190,7 @@ u32 gen_sanity_upfront()
// Operator cast
{
Code t_u8_ptr = def_type( name(u8), __, spec_ptr );
CodeType t_u8_ptr = def_type( name(u8), __, spec_ptr );
Code op_ptr = def_operator_cast( t_u8_ptr, __ );

View File

@ -11,7 +11,7 @@ includes = include_directories(
# get_sources = files('./get_sources.ps1')
# sources = files(run_command('powershell', get_sources, check: true).stdout().strip().split('\n'))
sources = [ '../test.cpp' ]
sources = [ '../test.Upfront.cpp' ]
if get_option('buildtype').startswith('debug')

View File

@ -18,7 +18,7 @@ int gen_main()
Memory::setup();
gen::init();
gen_sanity();
gen_sanity_upfront();
gen_array( u8 );
gen_array( sw );