base works

This commit is contained in:
Edward R. Gonzalez 2024-12-10 21:35:46 -05:00
parent ef78772278
commit 0e32838da1
5 changed files with 41 additions and 43 deletions

View File

@ -49,26 +49,22 @@ struct CSV_Columns2 {
inline
CSV_Column parse_csv_one_column(AllocatorInfo allocator, char const* path) {
char scratch_mem[kilobytes(32)];
Arena scratch = arena_init_from_memory( scratch_mem, sizeof(scratch_mem) );
file_read_contents( arena_allocator_info( & scratch), file_zero_terminate, path );
FileContents content = file_read_contents( allocator, file_zero_terminate, path );
Arena csv_arena = arena_init_from_memory(content.data, content.size);
CSV_Column result;
csv_parse( & result.ADT, scratch_mem, allocator, false );
csv_parse( & result.ADT, rcast(char*, content.data), allocator, false );
result.Content = result.ADT.nodes[0].nodes;
return result;
}
inline
CSV_Columns2 parse_csv_two_columns(AllocatorInfo allocator, char const* path) {
char scratch_mem[kilobytes(32)];
Arena scratch = arena_init_from_memory( scratch_mem, sizeof(scratch_mem) );
file_read_contents( arena_allocator_info( & scratch), file_zero_terminate, path );
FileContents content = file_read_contents( allocator, file_zero_terminate, path );
Arena csv_arena = arena_init_from_memory(content.data, content.size);
CSV_Columns2 result;
csv_parse( & result.ADT, scratch_mem, allocator, false );
csv_parse( & result.ADT, rcast(char*, content.data), allocator, false );
result.Col_1 = result.ADT.nodes[0].nodes;
result.Col_2 = result.ADT.nodes[1].nodes;
return result;

View File

@ -16,7 +16,7 @@ GEN_NS_END
using namespace gen;
constexpr char const* path_format_style = "../scripts/.clang-format";
constexpr char const* scratch_file = "gen/scratch.hpp";
constexpr char const* scratch_file = "build/scratch.hpp";
Code format( Code code ) {
return code_refactor_and_format(code, scratch_file, nullptr, path_format_style );
@ -26,20 +26,18 @@ constexpr char const* generation_notice =
"// This file was generated automatially by gencpp's bootstrap.cpp "
"(See: https://github.com/Ed94/gencpp)\n\n";
CodeBody gen_component_header = def_global_body( args(
int gen_main()
{
gen::init();
CodeBody gen_component_header = def_global_body( args(
def_preprocess_cond( PreprocessCond_IfDef, txt("GEN_INTELLISENSE_DIRECTIVES") ),
pragma_once,
def_include(txt("components/types.hpp")),
preprocess_endif,
fmt_newline,
untyped_str( to_strc_from_c_str(generation_notice) )
));
int gen_main()
{
gen::init();
__debugbreak();
));
CodeBody ecode = gen_ecode ( "enums/ECodeTypes.csv" );
CodeBody eoperator = gen_eoperator ( "enums/EOperator.csv" );

View File

@ -9,8 +9,10 @@ using namespace gen;
CodeBody gen_ecode( char const* path, bool use_c_definition = false )
{
CSV_Columns2 csv_enum = parse_csv_two_columns(GlobalAllocator, path );
FixedArena_32KB scratch; fixed_arena_init(& scratch);
AllocatorInfo scratch_info = fixed_arena_allocator_info(& scratch);
CSV_Columns2 csv_enum = parse_csv_two_columns( scratch_info, path );
String enum_entries = string_make_reserve( GlobalAllocator, kilobytes(1) );
String to_str_entries = string_make_reserve( GlobalAllocator, kilobytes(1) );
String to_keyword_str_entries = string_make_reserve( GlobalAllocator, kilobytes(1) );
@ -91,10 +93,12 @@ CodeBody gen_ecode( char const* path, bool use_c_definition = false )
CodeBody gen_eoperator( char const* path, bool use_c_definition = false )
{
CSV_Columns2 csv_enum = parse_csv_two_columns(GlobalAllocator, path);
FixedArena_16KB scratch; fixed_arena_init(& scratch);
AllocatorInfo scratch_info = fixed_arena_allocator_info(& scratch);
String enum_entries = string_make_reserve( GlobalAllocator, kilobytes(1) );
String to_str_entries = string_make_reserve( GlobalAllocator, kilobytes(1) );
CSV_Columns2 csv_enum = parse_csv_two_columns( scratch_info, path );
String enum_entries = string_make_reserve( GlobalAllocator, 32 );
String to_str_entries = string_make_reserve( GlobalAllocator, 32 );
for (usize idx = 0; idx < array_num(csv_enum.Col_1); idx++) {
char const* enum_str = csv_enum.Col_1[idx].string;
@ -175,10 +179,12 @@ CodeBody gen_eoperator( char const* path, bool use_c_definition = false )
CodeBody gen_especifier( char const* path, bool use_c_definition = false )
{
CSV_Columns2 csv_enum = parse_csv_two_columns(GlobalAllocator, path);
FixedArena_16KB scratch; fixed_arena_init(& scratch);
AllocatorInfo scratch_info = fixed_arena_allocator_info(& scratch);
String enum_entries = string_make_reserve( GlobalAllocator, kilobytes(1) );
String to_str_entries = string_make_reserve( GlobalAllocator, kilobytes(1) );
CSV_Columns2 csv_enum = parse_csv_two_columns( scratch_info, path );
String enum_entries = string_make_reserve( scratch_info, kilobytes(1) );
String to_str_entries = string_make_reserve( scratch_info, kilobytes(1) );
for (usize idx = 0; idx < array_num(csv_enum.Col_1); idx++)
{
@ -314,31 +320,29 @@ CodeBody gen_especifier( char const* path, bool use_c_definition = false )
CodeBody gen_etoktype( char const* etok_path, char const* attr_path, bool use_c_definition = false )
{
char scratch_mem[kilobytes(16)];
Arena scratch = arena_init_from_memory( scratch_mem, sizeof(scratch_mem) );
AllocatorInfo scratch_info = arena_allocator_info(& scratch);
FixedArena_32KB scratch; fixed_arena_init(& scratch);
AllocatorInfo scratch_info = fixed_arena_allocator_info(& scratch);
FileContents enum_content = file_read_contents( scratch_info, file_zero_terminate, etok_path );
CSV_Object csv_enum_nodes;
csv_parse( &csv_enum_nodes, rcast(char*, enum_content.data), GlobalAllocator, false );
csv_parse( &csv_enum_nodes, rcast(char*, enum_content.data), scratch_info, false );
FileContents attrib_content = file_read_contents( scratch_info, file_zero_terminate, attr_path );
CSV_Object csv_attr_nodes;
csv_parse( &csv_attr_nodes, rcast(char*, attrib_content.data), GlobalAllocator, false );
csv_parse( &csv_attr_nodes, rcast(char*, attrib_content.data), scratch_info, false );
Array<ADT_Node> enum_strs = csv_enum_nodes.nodes[0].nodes;
Array<ADT_Node> enum_str_strs = csv_enum_nodes.nodes[1].nodes;
Array<ADT_Node> attribute_strs = csv_attr_nodes.nodes[0].nodes;
Array<ADT_Node> attribute_str_strs = csv_attr_nodes.nodes[1].nodes;
String enum_entries = string_make_reserve( GlobalAllocator, kilobytes(2) );
String to_str_entries = string_make_reserve( GlobalAllocator, kilobytes(4) );
String attribute_entries = string_make_reserve( GlobalAllocator, kilobytes(2) );
String to_str_attributes = string_make_reserve( GlobalAllocator, kilobytes(4) );
String attribute_define_entries = string_make_reserve( GlobalAllocator, kilobytes(4) );
String enum_entries = string_make_reserve( scratch_info, kilobytes(2) );
String to_str_entries = string_make_reserve( scratch_info, kilobytes(4) );
String attribute_entries = string_make_reserve( scratch_info, kilobytes(2) );
String to_str_attributes = string_make_reserve( scratch_info, kilobytes(4) );
String attribute_define_entries = string_make_reserve( scratch_info, kilobytes(4) );
for (usize idx = 0; idx < array_num(enum_strs); idx++)
{

View File

@ -71,7 +71,7 @@ Code code_refactor_and_format( Code code, char const* scratch_path, char const*
{
GEN_ASSERT(code);
GEN_ASSERT_NOT_NULL(scratch_path);
Builder scratch_file = builder_open("gen/scratch.hpp");
Builder scratch_file = builder_open( scratch_path );
builder_print( & scratch_file, code);
builder_write(& scratch_file);

View File

@ -115,13 +115,13 @@ if ( $base )
$flag_link_win_subsystem_console
)
$includes = @( $path_project)
$includes = @( $path_base)
$unit = join-path $path_base "base.cpp"
$executable = join-path $path_build "base.exe"
$result = build-simple $path_build $includes $compiler_args $linker_args $unit $executable
Push-Location $path_project
Push-Location $path_base
if ( Test-Path( $executable ) ) {
write-host "`nRunning base"
$time_taken = Measure-Command { & $executable
@ -129,7 +129,7 @@ if ( $base )
write-host `t $_ -ForegroundColor Green
}
}
write-host "`bbase completed in $($time_taken.TotalMilliseconds) ms"
write-host "`nbase completed in $($time_taken.TotalMilliseconds) ms"
}
Pop-Location
}