WIP Change to code types [ Broken ]

This commit is contained in:
Edward R. Gonzalez 2023-07-13 23:01:20 -04:00
parent a86d6fa0ee
commit 7a2e20bcdb
12 changed files with 744 additions and 418 deletions

View File

@ -1,5 +1,9 @@
root = true root = true
[*.refactor]
indent_style = space
indent_size = 4
[*.md] [*.md]
indent_style = space indent_style = space
indent_size = 4 indent_size = 4
@ -23,3 +27,7 @@ indent_size = 4
[*.ps1] [*.ps1]
indent_style = tab indent_style = tab
indent_size = 4 indent_size = 4
[*.natvis]
indent_style = tab
indent_size = 4

View File

@ -17,7 +17,8 @@
"xmemory": "cpp", "xmemory": "cpp",
"algorithm": "cpp", "algorithm": "cpp",
"limits": "cpp", "limits": "cpp",
"concepts": "cpp" "concepts": "cpp",
"*.rh": "cpp"
}, },
"C_Cpp.intelliSenseEngineFallback": "disabled", "C_Cpp.intelliSenseEngineFallback": "disabled",
"mesonbuild.configureOnOpen": true, "mesonbuild.configureOnOpen": true,

View File

@ -121,7 +121,6 @@
<ClInclude Include="test\Upfront\Sanity.Upfront.hpp" /> <ClInclude Include="test\Upfront\Sanity.Upfront.hpp" />
<ClInclude Include="test\Parsed\Array.Parsed.hpp" /> <ClInclude Include="test\Parsed\Array.Parsed.hpp" />
<ClInclude Include="test\Parsed\Sanity.Parsed.hpp" /> <ClInclude Include="test\Parsed\Sanity.Parsed.hpp" />
<ClInclude Include="thirdparty\zpl.h" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="project\Bloat.cpp" /> <ClCompile Include="project\Bloat.cpp" />

View File

@ -30,17 +30,16 @@ Major enum definitions and their associated functions used with the AST data
* `ESpecifier` : Used with specifier ASTs for all specifiers the user may tag an associated * `ESpecifier` : Used with specifier ASTs for all specifiers the user may tag an associated
AST with. AST with.
* `AccessSpec` : Used with class and struct ASTs to denote the public, protected, or private fields. * `AccessSpec` : Used with class and struct ASTs to denote the public, protected, or private fields.
* `EnumT` : Used with def_enum to determine if constructing a regular enum or an enum class.
* `ModuleFlag` : Used with any valid definition that can have export or import related keywords assoicated with it. * `ModuleFlag` : Used with any valid definition that can have export or import related keywords assoicated with it.
#### Data Structures #### Data Structures
`StringTable` : Hash table for cached strings. (`StringCached` typedef used to denote strings managed by it) `StringCache` : Hash table for cached strings. (`StringCached` typedef used to denote strings managed by it)
`AST` : The node data strucuture for the code. `AST` : The node data strucuture for the code.
`Code` : Wrapper for `AST` with functionality for handling it appropriately. `Code` : Wrapper for `AST` with functionality for handling it appropriately.
`TypeTable` : Hash table for cached typename ASTs.
#### Gen Interface #### Gen Interface
First set of fowards are either backend functions used for various aspects of AST generation or configurating allocators used for different containers. First set of fowards are either backend functions used for various aspects of AST generation or configurating allocators used for different containers.

View File

@ -1722,33 +1722,33 @@ namespace gen
} }
#pragma region Constants #pragma region Constants
global Code t_auto; global CodeType t_auto;
global Code t_void; global CodeType t_void;
global Code t_int; global CodeType t_int;
global Code t_bool; global CodeType t_bool;
global Code t_char; global CodeType t_char;
global Code t_wchar_t; global CodeType t_wchar_t;
global Code t_class; global CodeType t_class;
global Code t_typename; global CodeType t_typename;
#ifdef GEN_DEFINE_LIBRARY_CODE_CONSTANTS #ifdef GEN_DEFINE_LIBRARY_CODE_CONSTANTS
global Code t_b32; global CodeType t_b32;
global Code t_s8; global CodeType t_s8;
global Code t_s16; global CodeType t_s16;
global Code t_s32; global CodeType t_s32;
global Code t_s64; global CodeType t_s64;
global Code t_u8; global CodeType t_u8;
global Code t_u16; global CodeType t_u16;
global Code t_u32; global CodeType t_u32;
global Code t_u64; global CodeType t_u64;
global Code t_sw; global CodeType t_sw;
global Code t_uw; global CodeType t_uw;
global Code t_f32; global CodeType t_f32;
global Code t_f64; global CodeType t_f64;
#endif #endif
global Code access_public; global Code access_public;
@ -1760,23 +1760,23 @@ namespace gen
global Code pragma_once; global Code pragma_once;
global Code spec_const; global CodeSpecifiers spec_const;
global Code spec_consteval; global CodeSpecifiers spec_consteval;
global Code spec_constexpr; global CodeSpecifiers spec_constexpr;
global Code spec_constinit; global CodeSpecifiers spec_constinit;
global Code spec_extern_linkage; global CodeSpecifiers spec_extern_linkage;
global Code spec_global; global CodeSpecifiers spec_global;
global Code spec_inline; global CodeSpecifiers spec_inline;
global Code spec_internal_linkage; global CodeSpecifiers spec_internal_linkage;
global Code spec_local_persist; global CodeSpecifiers spec_local_persist;
global Code spec_mutable; global CodeSpecifiers spec_mutable;
global Code spec_ptr; global CodeSpecifiers spec_ptr;
global Code spec_ref; global CodeSpecifiers spec_ref;
global Code spec_register; global CodeSpecifiers spec_register;
global Code spec_rvalue; global CodeSpecifiers spec_rvalue;
global Code spec_static_member; global CodeSpecifiers spec_static_member;
global Code spec_thread_local; global CodeSpecifiers spec_thread_local;
global Code spec_volatile; global CodeSpecifiers spec_volatile;
#pragma endregion Constants #pragma endregion Constants
#pragma region AST Body Case Macros #pragma region AST Body Case Macros
@ -3184,7 +3184,7 @@ namespace gen
}; };
inline inline
OpValidateResult operator__validate( OperatorT op, Code params_code, Code ret_type, Code specifier ) OpValidateResult operator__validate( OperatorT op, CodeParams params_code, Code ret_type, Code specifier )
{ {
using namespace EOperator; using namespace EOperator;
@ -3208,7 +3208,7 @@ namespace gen
} }
# define check_param_eq_ret() \ # define check_param_eq_ret() \
if ( ! is_member_symbol && params_code->param_type() != ret_type ) \ if ( ! is_member_symbol && params_code.type() != ret_type ) \
{ \ { \
log_failure("gen_def_operator: operator%s requires first parameter to equal return type\n" \ log_failure("gen_def_operator: operator%s requires first parameter to equal return type\n" \
"param types: %s\n" \ "param types: %s\n" \
@ -3240,7 +3240,7 @@ namespace gen
case Assign: case Assign:
check_params(); check_params();
if ( params_code->param_count() > 1 ) if ( params_code.num() > 1 )
{ {
log_failure("gen::def_operator: " log_failure("gen::def_operator: "
"operator%s does not support non-member definition (more than one parameter provided) - %s", "operator%s does not support non-member definition (more than one parameter provided) - %s",
@ -3265,17 +3265,17 @@ namespace gen
case Assign_RShift: case Assign_RShift:
check_params(); check_params();
if ( params_code->param_count() == 1 ) if ( params_code.num() == 1 )
is_member_symbol = true; is_member_symbol = true;
else else
check_param_eq_ret(); check_param_eq_ret();
if (params_code->param_count() > 2 ) if (params_code.num() > 2 )
{ {
log_failure("gen::def_operator: operator%s may not be defined with more than two parametes - param count; %d\n%s" log_failure("gen::def_operator: operator%s may not be defined with more than two parametes - param count; %d\n%s"
, to_str(op) , to_str(op)
, params_code->param_count() , params_code.num()
, params_code->debug_str() , params_code->debug_str()
); );
return OpValidateResult::Fail; return OpValidateResult::Fail;
@ -3296,10 +3296,10 @@ namespace gen
return OpValidateResult::Fail; return OpValidateResult::Fail;
} }
switch ( params_code->param_count() ) switch ( params_code.num() )
{ {
case 1: case 1:
if ( params_code->param_type()->is_equal( t_int ) ) if ( params_code.type()->is_equal( t_int ) )
is_member_symbol = true; is_member_symbol = true;
else else
@ -3309,7 +3309,7 @@ namespace gen
case 2: case 2:
check_param_eq_ret(); check_param_eq_ret();
if ( ! params_code->get_param(1)->is_equal( t_int ) ) if ( ! params_code.get(1)->is_equal( t_int ) )
{ {
log_failure("gen::def_operator: " log_failure("gen::def_operator: "
"operator%s requires second parameter of non-member definition to be int for post-decrement", "operator%s requires second parameter of non-member definition to be int for post-decrement",
@ -3320,9 +3320,9 @@ namespace gen
break; break;
default: default:
log_failure("gen::def_operator: operator%s recieved unexpected number of paramters recived %d instead of 0-2" log_failure("gen::def_operator: operator%s recieved unexpected number of parameters recived %d instead of 0-2"
, to_str(op) , to_str(op)
, params_code->param_count() , params_code.num()
); );
return OpValidateResult::Fail; return OpValidateResult::Fail;
} }
@ -3343,7 +3343,7 @@ namespace gen
return OpValidateResult::Fail; return OpValidateResult::Fail;
} }
if ( params_code->param_type()->is_equal( ret_type ) ) if ( params_code.type()->is_equal( ret_type ) )
{ {
log_failure("gen::def_operator: " log_failure("gen::def_operator: "
"operator%s is non-member symbol yet first paramter does not equal return type\n" "operator%s is non-member symbol yet first paramter does not equal return type\n"
@ -3355,11 +3355,11 @@ namespace gen
return OpValidateResult::Fail; return OpValidateResult::Fail;
} }
if ( params_code->param_count() > 1 ) if ( params_code.num() > 1 )
{ {
log_failure("gen::def_operator: operator%s may not have more than one parameter - param count: %d" log_failure("gen::def_operator: operator%s may not have more than one parameter - param count: %d"
, to_str(op) , to_str(op)
, params_code->param_count() , params_code.num()
); );
return OpValidateResult::Fail; return OpValidateResult::Fail;
} }
@ -3378,14 +3378,14 @@ namespace gen
case RShift: case RShift:
check_params(); check_params();
switch ( params_code->param_count() ) switch ( params_code.num() )
{ {
case 1: case 1:
is_member_symbol = true; is_member_symbol = true;
break; break;
case 2: case 2:
if ( ! params_code->param_type()->is_equal( ret_type ) ) if ( ! params_code.type()->is_equal( ret_type ) )
{ {
log_failure("gen::def_operator: " log_failure("gen::def_operator: "
"operator%s is non-member symbol yet first paramter does not equal return type\n" "operator%s is non-member symbol yet first paramter does not equal return type\n"
@ -3401,7 +3401,7 @@ namespace gen
default: default:
log_failure("gen::def_operator: operator%s recieved unexpected number of paramters recived %d instead of 0-2" log_failure("gen::def_operator: operator%s recieved unexpected number of paramters recived %d instead of 0-2"
, to_str(op) , to_str(op)
, params_code->param_count() , params_code.num()
); );
return OpValidateResult::Fail; return OpValidateResult::Fail;
} }
@ -3588,7 +3588,7 @@ namespace gen
The largest of the functions is related to operator overload definitions. The largest of the functions is related to operator overload definitions.
The library validates a good protion of their form and thus the argument processing for is quite a bit. The library validates a good protion of their form and thus the argument processing for is quite a bit.
*/ */
Code def_attributes( StrC content ) CodeAttributes def_attributes( StrC content )
{ {
if ( content.Len <= 0 || content.Ptr == nullptr ) if ( content.Len <= 0 || content.Ptr == nullptr )
{ {
@ -3605,7 +3605,7 @@ namespace gen
return result; return result;
} }
Code def_comment( StrC content ) CodeComment def_comment( StrC content )
{ {
if ( content.Len <= 0 || content.Ptr == nullptr ) if ( content.Len <= 0 || content.Ptr == nullptr )
{ {
@ -3622,7 +3622,7 @@ namespace gen
return result; return result;
} }
Code def_class( StrC name CodeClass def_class( StrC name
, Code body , Code body
, Code parent, AccessSpec parent_access , Code parent, AccessSpec parent_access
, Code attributes , Code attributes
@ -3682,7 +3682,7 @@ namespace gen
return result; return result;
} }
Code def_enum( StrC name CodeEnum def_enum( StrC name
, Code body, Code type , Code body, Code type
, EnumT specifier, Code attributes , EnumT specifier, Code attributes
, ModuleFlag mflags ) , ModuleFlag mflags )
@ -3748,7 +3748,7 @@ namespace gen
return result; return result;
} }
Code def_execution( StrC content ) CodeExec def_execution( StrC content )
{ {
if ( content.Len <= 0 || content.Ptr == nullptr ) if ( content.Len <= 0 || content.Ptr == nullptr )
{ {
@ -3765,7 +3765,7 @@ namespace gen
return result; return result;
} }
Code def_extern_link( StrC name, Code body, ModuleFlag mflags ) CodeExtern def_extern_link( StrC name, Code body, ModuleFlag mflags )
{ {
using namespace ECode; using namespace ECode;
@ -3784,12 +3784,12 @@ namespace gen
result->Name = get_cached_string( name ); result->Name = get_cached_string( name );
result->ModuleFlags = mflags; result->ModuleFlags = mflags;
result->add_entry( body ); result->entry( AST::Entry_Body ) = body;
return result; return result;
} }
Code def_friend( Code declaration ) CodeFriend def_friend( Code declaration )
{ {
using namespace ECode; using namespace ECode;
@ -5773,7 +5773,7 @@ namespace gen
untyped_tok.Length = ( (sptr)prevtok.Text + prevtok.Length ) - (sptr)untyped_tok.Text; untyped_tok.Length = ( (sptr)prevtok.Text + prevtok.Length ) - (sptr)untyped_tok.Text;
Code array_expr = untyped_str( untyped_tok ); Code array_expr = code_str( untyped_tok );
if ( left == 0 ) if ( left == 0 )
{ {
@ -6297,7 +6297,7 @@ namespace gen
} }
expr_tok.Length = ( (sptr)currtok.Text + currtok.Length ) - (sptr)expr_tok.Text; expr_tok.Length = ( (sptr)currtok.Text + currtok.Length ) - (sptr)expr_tok.Text;
expr = untyped_str( expr_tok ); expr = code_str( expr_tok );
} }
eat( TokType::Statement_End ); eat( TokType::Statement_End );
@ -6352,7 +6352,7 @@ namespace gen
eat( currtok.Type ); eat( currtok.Type );
} }
expr = untyped_str( expr_tok ); expr = code_str( expr_tok );
} }
return expr; return expr;
@ -6585,7 +6585,7 @@ namespace gen
eat( currtok.Type ); eat( currtok.Type );
} }
member = untyped_str( untyped_tok ); member = code_str( untyped_tok );
break; break;
} }
@ -7006,7 +7006,7 @@ namespace gen
{ {
// mem_copy( entries_code, body.Text, body.Length ); // mem_copy( entries_code, body.Text, body.Length );
Code untyped_body = untyped_str( body ); Code untyped_body = code_str( body );
result->Type = is_enum_class ? Enum_Class : Enum; result->Type = is_enum_class ? Enum_Class : Enum;
result->add_entry( untyped_body ); result->add_entry( untyped_body );
@ -7370,7 +7370,7 @@ namespace gen
body_str.Length = ( (sptr)prevtok.Text + prevtok.Length ) - (sptr)body_str.Text; body_str.Length = ( (sptr)prevtok.Text + prevtok.Length ) - (sptr)body_str.Text;
body = untyped_str( body_str ); body = code_str( body_str );
eat( TokType::BraceCurly_Close ); eat( TokType::BraceCurly_Close );
} }
@ -8093,7 +8093,7 @@ namespace gen
return result; return result;
} }
Code untyped_str( StrC content ) Code code_str( StrC content )
{ {
Code Code
result = make_code(); result = make_code();
@ -8104,7 +8104,7 @@ namespace gen
return result; return result;
} }
Code untyped_fmt( char const* fmt, ...) Code code_fmt( char const* fmt, ...)
{ {
local_persist thread_local local_persist thread_local
char buf[GEN_PRINTF_MAXLEN] = { 0 }; char buf[GEN_PRINTF_MAXLEN] = { 0 };

File diff suppressed because it is too large Load Diff

View File

@ -240,7 +240,6 @@
// word StringTable new_name // word StringTable new_name
// word UsingRegular new_name // word UsingRegular new_name
// word UsingNamespace new_name // word UsingNamespace new_name
// word UsingT new_name
// gencpp Data // gencpp Data

View File

@ -27,16 +27,16 @@ u32 gen_sanity()
// Class // Class
{ {
Code fwd = parse_class( code( CodeClass fwd = parse_class( code(
class TestEmptyClass; class TestEmptyClass;
)); ));
Code empty_body = parse_class( code( CodeClass empty_body = parse_class( code(
class TestEmptyClass class TestEmptyClass
{}; {};
)); ));
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(fwd);
gen_sanity_file.print(empty_body); gen_sanity_file.print(empty_body);
@ -72,15 +72,15 @@ u32 gen_sanity()
// External Linkage // External Linkage
{ {
Code empty_comment = def_comment( txt_StrC("Empty external linkage") ); CodeComment empty_comment = def_comment( txt_StrC("Empty external linkage") );
Code c_extern = parse_extern_link( code( CodeExtern c_extern = parse_extern_link( code(
extern "C" extern "C"
{ {
}; };
)); ));
c_extern->body()->add_entry( empty_comment ); c_extern.body()->add_entry( empty_comment );
gen_sanity_file.print(c_extern); gen_sanity_file.print(c_extern);
} }
@ -108,17 +108,17 @@ u32 gen_sanity()
// Function // Function
{ {
Code fwd = parse_function( code( CodeFn fwd = parse_function( code(
void test_function(); void test_function();
)); ));
Code def = parse_function( code( CodeFn def = parse_function( code(
void test_function() void test_function()
{ {
} }
)); ));
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(fwd);
gen_sanity_file.print(def); gen_sanity_file.print(def);
@ -128,13 +128,13 @@ u32 gen_sanity()
// Namespace // Namespace
{ {
Code def = parse_namespace( code( CodeNamespace def = parse_namespace( code(
namespace TestNamespace namespace TestNamespace
{ {
} }
)); ));
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); gen_sanity_file.print(def);
} }
@ -172,17 +172,17 @@ u32 gen_sanity()
// Operator cast // Operator cast
{ {
Code op_ptr = parse_operator_cast( code( CodeClass op_ptr = parse_operator_cast( code(
operator u8* (); operator u8* ();
)); ));
Code class_def = parse_class( code( CodeClass class_def = parse_class( code(
class TestClass class TestClass
{ {
}; };
)); ));
class_def->body()->add_entry( op_ptr ); class_def.body()->add_entry( op_ptr );
gen_sanity_file.print(class_def); gen_sanity_file.print(class_def);
} }
@ -191,17 +191,17 @@ u32 gen_sanity()
// Parameters // Parameters
{ {
Code fwd = parse_function( code( CodeFn fwd = parse_function( code(
void test_function_param( int a ); void test_function_param( int a );
)); ));
Code def = parse_function( code( CodeFn def = parse_function( code(
void test_function_param2( int a, int b ) void test_function_param2( int a, int b )
{ {
} }
)); ));
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(fwd);
gen_sanity_file.print(def); gen_sanity_file.print(def);
@ -228,16 +228,16 @@ u32 gen_sanity()
// Struct // Struct
{ {
Code fwd = parse_struct( code( CodeStruct fwd = parse_struct( code(
struct TestEmptyStruct; struct TestEmptyStruct;
)); ));
Code empty_body = parse_struct( code( CodeStruct empty_body = parse_struct( code(
struct TestEmptyStruct struct TestEmptyStruct
{}; {};
)); ));
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(fwd);
gen_sanity_file.print(empty_body); gen_sanity_file.print(empty_body);
@ -247,13 +247,13 @@ u32 gen_sanity()
// Union // Union
{ {
Code empty = parse_union( code( CodeUnion empty = parse_union( code(
union TestEmptyUnion union TestEmptyUnion
{ {
}; };
)); ));
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 short u16; )) );
gen_sanity_file.print( parse_typedef( code( typedef unsigned long u32; )) ); gen_sanity_file.print( parse_typedef( code( typedef unsigned long u32; )) );

View File

@ -4,7 +4,7 @@
#include "gen.hpp" #include "gen.hpp"
using namespace gen; using namespace gen;
Code gen_SOA( Code struct_def, s32 num_entries = 0 ) Code gen_SOA( CodeStruct struct_def, s32 num_entries = 0 )
{ {
StringCached name = get_cached_string( token_fmt( "name", (StrC)struct_def->Name, StringCached name = get_cached_string( token_fmt( "name", (StrC)struct_def->Name,
stringize( SOA_<name> ) stringize( SOA_<name> )
@ -22,22 +22,18 @@ Code gen_SOA( Code struct_def, s32 num_entries = 0 )
var_arena = Arena::init_from_memory( var_memory, kilobytes(Num_Vars_Cap) ); var_arena = Arena::init_from_memory( var_memory, kilobytes(Num_Vars_Cap) );
do_once_end do_once_end
Array<Code> vars = Array<Code>::init( var_arena );; Array<CodeVar> vars = Array<CodeVar>::init( var_arena );;
Code soa = def_struct( name, def_body( ECode::Struct_Body )); CodeStruct soa = def_struct( name, def_body( ECode::Struct_Body ));
{ {
Code body = *struct_def->body(); for ( Code struct_mem : struct_def.body() )
for ( s32 idx = 0; idx < body->num_entries(); idx++ )
{ {
Code struct_mem = { body->entry( idx ) };
if ( struct_mem->Type == ECode::Variable ) if ( struct_mem->Type == ECode::Variable )
{ {
Code var_type = { struct_mem->entry(0) }; CodeType var_type = CodeVar(struct_mem).type();
StrC num_entries_str = to_StrC( str_fmt_buf( "%d", num_entries ) );
StrC num_entries_str = to_StrC( str_fmt_buf( "%d", num_entries ) ); CodeVar entry_arr = { nullptr };
Code entry_arr = { nullptr };
if ( ! num_entries) if ( ! num_entries)
{ {
entry_arr = parse_variable( token_fmt( "type", (StrC)var_type->Name, "name", (StrC)struct_mem->Name, entry_arr = parse_variable( token_fmt( "type", (StrC)var_type->Name, "name", (StrC)struct_mem->Name,
@ -52,12 +48,12 @@ Code gen_SOA( Code struct_def, s32 num_entries = 0 )
} }
vars.append( entry_arr ); vars.append( entry_arr );
soa->body()->add_entry( entry_arr ); soa.body()->add_entry( entry_arr );
} }
} }
} }
Code make; CodeFn make;
{ {
make = parse_function( token_fmt("SOA_Type", (StrC)name, make = parse_function( token_fmt("SOA_Type", (StrC)name,
stringize( stringize(
@ -71,22 +67,20 @@ Code gen_SOA( Code struct_def, s32 num_entries = 0 )
if ( ! num_entries ) if ( ! num_entries )
{ {
for ( s32 idx = 0; idx < vars.num(); idx++ ) for ( CodeVar member : vars )
{ {
Code member = vars[idx];
Code arr_init = def_execution( token_fmt( "var_name", (StrC)member->Name, "var_type", (StrC)member->entry(0)->Name, Code arr_init = def_execution( token_fmt( "var_name", (StrC)member->Name, "var_type", (StrC)member->entry(0)->Name,
stringize( soa.<var_name> = <var_type>::init( allocator ); ) 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; CodeFn get;
{ {
get = parse_function( code( get = parse_function( code(
Entry get( s32 idx ) Entry get( s32 idx )
@ -96,10 +90,8 @@ Code gen_SOA( Code struct_def, s32 num_entries = 0 )
String content = String::make( Memory::GlobalAllocator, "return\n{\n" ); String content = String::make( Memory::GlobalAllocator, "return\n{\n" );
for ( s32 idx = 0; idx < vars.num(); idx ++ ) for ( CodeVar member : vars )
{ {
Code member = vars[idx];
content.append_fmt( token_fmt( "var_name", (StrC)member->Name, content.append_fmt( token_fmt( "var_name", (StrC)member->Name,
"<var_name>[idx]," "<var_name>[idx],"
)); ));
@ -107,14 +99,14 @@ Code gen_SOA( Code struct_def, s32 num_entries = 0 )
content.append( "};" ); content.append( "};" );
Code ret = def_execution( content ); CodeExec ret = def_execution( content );
get->body()->add_entry( ret ); get.body()->add_entry( ret );
} }
soa->body()->add_entry( make ); soa.body()->add_entry( make );
soa->body()->add_entry( get ); soa.body()->add_entry( get );
soa->body()->validate_body(); soa.body()->validate_body();
vars.free(); vars.free();
return soa; return soa;

View File

@ -27,14 +27,14 @@ Code gen__array_base()
Code gen__array( StrC type ) Code gen__array( StrC type )
{ {
static Code t_allocator_info = def_type( name(AllocatorInfo) ); static Code t_allocator_info = def_type( name(AllocatorInfo) );
static Code v_nullptr = untyped_str( code(nullptr)); static Code v_nullptr = code_str( code(nullptr));
static Code spec_ct_member = def_specifiers( 2, ESpecifier::Constexpr, ESpecifier::Static_Member ); static Code spec_ct_member = def_specifiers( 2, ESpecifier::Constexpr, ESpecifier::Static_Member );
static Code spec_static_inline = def_specifiers( 2, ESpecifier::Static_Member, ESpecifier::Inline ); static Code spec_static_inline = def_specifiers( 2, ESpecifier::Static_Member, ESpecifier::Inline );
static Code spec_static = def_specifier( ESpecifier::Static_Member ); static Code spec_static = def_specifier( ESpecifier::Static_Member );
static Code using_header = def_using( name(Header), def_type( name(ArrayHeader) ) ); static Code using_header = def_using( name(Header), def_type( name(ArrayHeader) ) );
static Code ct_grow_formula = def_variable( t_auto, name(grow_formula), untyped_str( code( & array_grow_formula )), spec_ct_member ); static Code ct_grow_formula = def_variable( t_auto, name(grow_formula), code_str( code( & array_grow_formula )), spec_ct_member );
StrC name; StrC name;
{ {
@ -134,7 +134,7 @@ Code gen__array( StrC type )
, def_param( t_alias, name(value) ) , def_param( t_alias, name(value) )
); );
Code body = untyped_str( code( Code body = code_str( code(
Header& header = * get_header(); Header& header = * get_header();
if ( begin < 0 || end >= header.Num ) if ( begin < 0 || end >= header.Num )

View File

@ -140,7 +140,7 @@ Code gen__hashtable( StrC type )
char const* tmpl = stringize( char const* tmpl = stringize(
void (*) ( u64 key, <type> value ) void (*) ( u64 key, <type> value )
); );
Code value = untyped_str( token_fmt( "type", (StrC)t_type->to_string(), tmpl ) ); Code value = code_str( token_fmt( "type", (StrC)t_type->to_string(), tmpl ) );
using_map_proc = def_using ( name(MapProc), value); using_map_proc = def_using ( name(MapProc), value);
} }
@ -166,7 +166,7 @@ Code gen__hashtable( StrC type )
char const* tmpl = stringize( char const* tmpl = stringize(
void (*) ( u64 key, <type> value ) void (*) ( u64 key, <type> value )
); );
Code value = untyped_str( token_fmt( "type", (StrC)t_type_ptr->to_string(), tmpl ) ); Code value = code_str( token_fmt( "type", (StrC)t_type_ptr->to_string(), tmpl ) );
using_map_mut_proc = def_using ( name(MapMutProc), value); using_map_mut_proc = def_using ( name(MapMutProc), value);
} }

View File

@ -54,7 +54,7 @@ u32 gen_sanity_upfront()
Code fwd = def_enum( name(ETestEnum), NoCode, t_u8 ); Code fwd = def_enum( name(ETestEnum), NoCode, t_u8 );
Code def; Code def;
{ {
Code body = untyped_str( code( Code body = code_str( code(
A, A,
B, B,
C C
@ -160,7 +160,7 @@ u32 gen_sanity_upfront()
Code bitflagtest; Code bitflagtest;
{ {
Code body = def_enum_body( 1, untyped_str( code( Code body = def_enum_body( 1, code_str( code(
A = 1 << 0, A = 1 << 0,
B = 1 << 1, B = 1 << 1,
C = 1 << 2 C = 1 << 2
@ -177,7 +177,7 @@ u32 gen_sanity_upfront()
); );
op_fwd = def_operator( EOperator::BOr, params, t_bitflag ); op_fwd = def_operator( EOperator::BOr, params, t_bitflag );
op_or = def_operator( EOperator::BOr, params, t_bitflag, untyped_str( code( op_or = def_operator( EOperator::BOr, params, t_bitflag, code_str( code(
return EBitFlagtest( (u8)a | (u8)b ); return EBitFlagtest( (u8)a | (u8)b );
))); )));
} }
@ -299,7 +299,7 @@ u32 gen_sanity_upfront()
// Variable // Variable
{ {
Code bss = def_variable( t_u8, name(test_variable) ); Code bss = def_variable( t_u8, name(test_variable) );
Code data = def_variable( t_u8, name(test_variable2), untyped_str( code( 0x12 )) ); Code data = def_variable( t_u8, name(test_variable2), code_str( code( 0x12 )) );
gen_sanity_file.print(bss); gen_sanity_file.print(bss);
gen_sanity_file.print(data); gen_sanity_file.print(data);