From 44d0a9cf9d3449be0b3e3eb3a591992d452ebda5 Mon Sep 17 00:00:00 2001 From: Ed_ Date: Tue, 10 Dec 2024 23:35:47 -0500 Subject: [PATCH] c_library compiles --- base/auxillary/scanner.cpp | 29 ++ base/auxillary/scanner.hpp | 39 +-- base/helpers/misc.hpp | 12 +- gen_c_library/c_library.cpp | 259 ++++++++---------- gen_c_library/c_library.refactor | 42 +-- gen_c_library/components/containers.array.hpp | 3 +- .../components/containers.hashtable.hpp | 3 +- .../components/memory.fixed_arena.hpp | 2 +- gen_c_library/components/misc.hpp | 2 +- gen_c_library/gen.c | 2 +- scripts/build.ci.ps1 | 7 +- 11 files changed, 178 insertions(+), 222 deletions(-) diff --git a/base/auxillary/scanner.cpp b/base/auxillary/scanner.cpp index a7a50f9..70b12f3 100644 --- a/base/auxillary/scanner.cpp +++ b/base/auxillary/scanner.cpp @@ -116,4 +116,33 @@ Code scan_file( char const* path ) return untyped_str( string_to_strc(str) ); } +CodeBody parse_file( const char* path ) { + FileContents file = file_read_contents( GlobalAllocator, true, path ); + StrC content = { file.size, (char const*)file.data }; + CodeBody code = parse_global_body( content ); + log_fmt("\nParsed: %s\n", path); + return code; +} + +CSV_Column parse_csv_one_column(AllocatorInfo allocator, char const* 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, rcast(char*, content.data), allocator, false ); + result.Content = result.ADT.nodes[0].nodes; + return result; +} + +CSV_Columns2 parse_csv_two_columns(AllocatorInfo allocator, char const* 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, rcast(char*, content.data), allocator, false ); + result.Col_1 = result.ADT.nodes[0].nodes; + result.Col_2 = result.ADT.nodes[1].nodes; + return result; +} + #pragma endregion Scanner diff --git a/base/auxillary/scanner.hpp b/base/auxillary/scanner.hpp index 9f2c772..12cc4d3 100644 --- a/base/auxillary/scanner.hpp +++ b/base/auxillary/scanner.hpp @@ -22,14 +22,7 @@ // This is done so that includes can be kept in dependency and component files so that intellisense works. Code scan_file( char const* path ); -inline -CodeBody parse_file( const char* path ) -{ - FileContents file = file_read_contents( GlobalAllocator, true, path ); - CodeBody code = parse_global_body( { file.size, (char const*)file.data } ); - log_fmt("\nParsed: %s\n", path); - return code; -} +CodeBody parse_file( const char* path ); // The follow is basic support for light csv parsing (use it as an example) // Make something robust if its more serious. @@ -37,37 +30,17 @@ CodeBody parse_file( const char* path ) typedef struct CSV_Column CSV_Column; struct CSV_Column { CSV_Object ADT; - Array Content; + Array(ADT_Node) Content; }; typedef struct CSV_Columns2 CSV_Columns2; struct CSV_Columns2 { CSV_Object ADT; - Array Col_1; - Array Col_2; + Array(ADT_Node) Col_1; + Array(ADT_Node) Col_2; }; -inline -CSV_Column parse_csv_one_column(AllocatorInfo allocator, char const* 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, 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) { - 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, rcast(char*, content.data), allocator, false ); - result.Col_1 = result.ADT.nodes[0].nodes; - result.Col_2 = result.ADT.nodes[1].nodes; - return result; -} +CSV_Column parse_csv_one_column(AllocatorInfo allocator, char const* path); +CSV_Columns2 parse_csv_two_columns(AllocatorInfo allocator, char const* path); #pragma endregion Scanner diff --git a/base/helpers/misc.hpp b/base/helpers/misc.hpp index cc4bc1c..f6625f9 100644 --- a/base/helpers/misc.hpp +++ b/base/helpers/misc.hpp @@ -22,7 +22,6 @@ void clang_format_file( char const* path, char const* style_path ) { GEN_ASSERT_NOT_NULL(path); String resolved_path = string_make_strc(GlobalAllocator, to_strc_from_c_str(path)); - String style_arg; if (style_path) { style_arg = string_make_strc(GlobalAllocator, txt("-style=file:")); @@ -38,10 +37,7 @@ void clang_format_file( char const* path, char const* style_path ) string_append_strc( & command, cf_verbose ); string_append_string( & command, style_arg ); string_append_string( & command, resolved_path ); - - log_fmt("\tRunning clang-format:\n"); system( command ); - log_fmt("\tclang-format finished formatting.\n"); } // Will refactor a file with the given script at the provided path. @@ -53,16 +49,12 @@ void refactor_file( char const* path, char const* refactor_script ) GEN_ASSERT_NOT_NULL(refactor_script); String command = string_make_strc(GlobalAllocator, txt("refactor ")); - string_append_strc( & command, txt("-debug ") ); + // string_append_strc( & command, txt("-debug ") ); string_append_strc( & command, txt("-num=1 ") ); string_append_fmt( & command, "-src=%s ", path ); string_append_fmt( & command,"-spec=%s ", refactor_script ); - - log_fmt("\tBeginning refactor:\n"); system(command); - log_fmt("\nRefactoring complete.\n"); - - #undef refactor + log_fmt("\n"); } // Does either of the above or both to the provided code. diff --git a/gen_c_library/c_library.cpp b/gen_c_library/c_library.cpp index 9333e6e..6e2d234 100644 --- a/gen_c_library/c_library.cpp +++ b/gen_c_library/c_library.cpp @@ -3,22 +3,16 @@ #define GEN_DEFINE_LIBRARY_CODE_CONSTANTS #define GEN_ENFORCE_STRONG_CODE_TYPES #define GEN_EXPOSE_BACKEND -#include "../project/gen.cpp" - +#include "gen.cpp" #include "helpers/push_ignores.inline.hpp" -#include "helpers/helper.hpp" + +#include GEN_NS_BEGIN -#include "helpers/push_container_defines.inline.hpp" -#include "dependencies/parsing.cpp" -#include "helpers/pop_container_defines.inline.hpp" +#include "helpers/base_codegen.hpp" +#include "helpers/misc.hpp" GEN_NS_END -#include "auxillary/builder.hpp" -#include "auxillary/builder.cpp" -#include "auxillary/scanner.hpp" - - #include "components/memory.fixed_arena.hpp" #include "components/misc.hpp" #include "components/containers.array.hpp" @@ -52,47 +46,22 @@ constexpr StrC implementation_guard_end = txt(R"( #pragma endregion GENCPP IMPLEMENTATION GUARD )"); -void CHANGE_format_file( char const* path ) -{ - String resolved_path = String::make(GlobalAllocator, to_strc_from_c_str(path)); +#define path_refactor_script "./c_library.refactor" +#define path_format_style "../scripts/.clang-format " +#define scratch_file "gen/scratch.hpp" +#define path_base "../base/" - String style_arg = String::make(GlobalAllocator, txt("-style=file:")); - style_arg.append("../scripts/.clang-format "); - - // Need to execute clang format on the generated file to get it to match the original. - #define clang_format "clang-format " - #define cf_format_inplace "-i " - #define cf_verbose "-verbose " - String command = String::make( GlobalAllocator, clang_format ); - command.append( cf_format_inplace ); - command.append( cf_verbose ); - command.append( style_arg ); - command.append( resolved_path ); - log_fmt("\tRunning clang-format on file:\n"); - system( command ); - log_fmt("\tclang-format finished reformatting.\n"); - #undef cf_cmd - #undef cf_format_inplace - #undef cf_style - #undef cf_verbse +Code refactor( Code code ) { + return code_refactor_and_format(code, scratch_file, path_refactor_script, nullptr ); } - -Code CHANGE_format_code_to_untyped( Code code ) -{ - Builder ecode_file_temp = Builder::open("gen/scratch.hpp"); - ecode_file_temp.print(code); - ecode_file_temp.write(); - format_file("gen/scratch.hpp"); - Code result = scan_file( "gen/scratch.hpp" ); - remove("gen/scratch.hpp"); - return result; +Code refactor_and_format( Code code ) { + return code_refactor_and_format(code, scratch_file, path_refactor_script, path_format_style ); } constexpr bool helper_use_c_definition = true; int gen_main() { -#define project_dir "../project/" gen::init(); PreprocessorDefines.append(txt("GEN_API_C_BEGIN")); @@ -109,22 +78,22 @@ int gen_main() PreprocessorDefines.append(txt("GEN_PARAM_DEFAULT")); //PreprocessorDefines.append(txt("GEN_EXECUTION_EXPRESSION_SUPPORT")); - Code push_ignores = scan_file( project_dir "helpers/push_ignores.inline.hpp" ); - Code pop_ignores = scan_file( project_dir "helpers/pop_ignores.inline.hpp" ); + Code push_ignores = scan_file( path_base "helpers/push_ignores.inline.hpp" ); + Code pop_ignores = scan_file( path_base "helpers/pop_ignores.inline.hpp" ); Code c_library_header_start = scan_file( "components/header_start.hpp" ); // Header Content: Reflection and Generation #pragma region Resolve Dependencies - Code header_platform = scan_file( project_dir "dependencies/platform.hpp" ); - Code header_macros = scan_file( project_dir "dependencies/macros.hpp" ); - Code header_basic_types = scan_file( project_dir "dependencies/basic_types.hpp" ); - Code header_debug = scan_file( project_dir "dependencies/debug.hpp" ); - Code header_string_ops = scan_file( project_dir "dependencies/string_ops.hpp" ); - Code header_hashing = scan_file( project_dir "dependencies/hashing.hpp" ); - Code header_timing = scan_file( project_dir "dependencies/timing.hpp" ); + Code header_platform = scan_file( path_base "dependencies/platform.hpp" ); + Code header_macros = scan_file( path_base "dependencies/macros.hpp" ); + Code header_basic_types = scan_file( path_base "dependencies/basic_types.hpp" ); + Code header_debug = scan_file( path_base "dependencies/debug.hpp" ); + Code header_string_ops = scan_file( path_base "dependencies/string_ops.hpp" ); + Code header_hashing = scan_file( path_base "dependencies/hashing.hpp" ); + Code header_timing = scan_file( path_base "dependencies/timing.hpp" ); - CodeBody parsed_header_memory = parse_file( project_dir "dependencies/memory.hpp" ); + CodeBody parsed_header_memory = parse_file( path_base "dependencies/memory.hpp" ); CodeBody header_memory = def_body(CT_Global_Body); for ( Code entry = parsed_header_memory.begin(); entry != parsed_header_memory.end(); ++ entry ) switch (entry->Type) { @@ -253,7 +222,7 @@ do \ break; } - CodeBody parsed_header_printing = parse_file( project_dir "dependencies/printing.hpp" ); + CodeBody parsed_header_printing = parse_file( path_base "dependencies/printing.hpp" ); CodeBody header_printing = def_body(CT_Global_Body); for ( Code entry = parsed_header_printing.begin(); entry != parsed_header_printing.end(); ++ entry ) switch (entry->Type) { @@ -284,7 +253,7 @@ do \ Code array_ssize = gen_array(txt("gen_ssize"), txt("Array_gen_ssize")); Code array_string_cached = gen_array(txt("gen_StringCached"), txt("Array_gen_StringCached")); - CodeBody parsed_header_strings = parse_file( project_dir "dependencies/strings.hpp" ); + CodeBody parsed_header_strings = parse_file( path_base "dependencies/strings.hpp" ); CodeBody header_strings = def_body(CT_Global_Body); for ( Code entry = parsed_header_strings.begin(); entry != parsed_header_strings.end(); ++ entry ) switch (entry->Type) { @@ -390,7 +359,7 @@ do \ CodeBody array_u8 = gen_array(txt("gen_u8"), txt("Array_gen_u8")); - CodeBody parsed_header_filesystem = parse_file( project_dir "dependencies/filesystem.hpp" ); + CodeBody parsed_header_filesystem = parse_file( path_base "dependencies/filesystem.hpp" ); CodeBody header_filesystem = def_body(CT_Global_Body); for ( Code entry = parsed_header_filesystem.begin(); entry != parsed_header_filesystem.end(); ++ entry ) switch (entry->Type) { @@ -449,7 +418,7 @@ do \ CodeBody array_adt_node = gen_array(txt("gen_ADT_Node"), txt("Array_gen_ADT_Node")); - CodeBody parsed_header_parsing = parse_file( project_dir "dependencies/parsing.hpp" ); + CodeBody parsed_header_parsing = parse_file( path_base "dependencies/parsing.hpp" ); CodeBody header_parsing = def_body(CT_Global_Body); for ( Code entry = parsed_header_parsing.begin(); entry != parsed_header_parsing.end(); ++ entry ) switch (entry->Type) { @@ -544,11 +513,11 @@ do \ // Only has operator overload definitions that C doesn't need. // CodeBody ast_inlines = gen_ast_inlines(); - CodeBody ecode = gen_ecode ( project_dir "enums/ECodeTypes.csv", helper_use_c_definition ); - CodeBody eoperator = gen_eoperator ( project_dir "enums/EOperator.csv", helper_use_c_definition ); - CodeBody especifier = gen_especifier( project_dir "enums/ESpecifier.csv", helper_use_c_definition ); + CodeBody ecode = gen_ecode ( path_base "enums/ECodeTypes.csv", helper_use_c_definition ); + CodeBody eoperator = gen_eoperator ( path_base "enums/EOperator.csv", helper_use_c_definition ); + CodeBody especifier = gen_especifier( path_base "enums/ESpecifier.csv", helper_use_c_definition ); - CodeBody parsed_types = parse_file( project_dir "components/types.hpp" ); + CodeBody parsed_types = parse_file( path_base "components/types.hpp" ); CodeBody types = def_body(CT_Global_Body); for ( Code entry = parsed_types.begin(); entry != parsed_types.end(); ++ entry ) switch(entry->Type) { @@ -620,7 +589,7 @@ do \ // Used to track which functions need generic selectors. Array(CodeFn) code_c_interface = array_init_reserve(GlobalAllocator, 16); - CodeBody parsed_ast = parse_file( project_dir "components/ast.hpp" ); + CodeBody parsed_ast = parse_file( path_base "components/ast.hpp" ); CodeBody ast = def_body(CT_Global_Body); for ( Code entry = parsed_ast.begin(); entry != parsed_ast.end(); ++ entry ) switch (entry->Type) { @@ -789,7 +758,7 @@ R"(#define AST_ArrSpecs_Cap \ txt("CodeVar"), }; - CodeBody parsed_code_types = parse_file( project_dir "components/code_types.hpp" ); + CodeBody parsed_code_types = parse_file( path_base "components/code_types.hpp" ); CodeBody code_types = def_body(CT_Global_Body); for ( Code entry = parsed_code_types.begin(); entry != parsed_code_types.end(); ++ entry ) switch( entry->Type ) { @@ -891,7 +860,7 @@ R"(#define ( code ) _Generic( (code), \ break; } - CodeBody parsed_ast_types = parse_file( project_dir "components/ast_types.hpp" ); + CodeBody parsed_ast_types = parse_file( path_base "components/ast_types.hpp" ); CodeBody ast_types = def_body(CT_Global_Body); for ( Code entry = parsed_ast_types.begin(); entry != parsed_ast_types.end(); ++ entry ) switch( entry->Type ) { @@ -938,7 +907,7 @@ R"(#define ( code ) _Generic( (code), \ break; } - CodeBody parsed_interface = parse_file( project_dir "components/interface.hpp" ); + CodeBody parsed_interface = parse_file( path_base "components/interface.hpp" ); CodeBody interface = def_body(CT_Global_Body); for ( Code entry = parsed_interface.begin(); entry != parsed_interface.end(); ++ entry ) switch( entry->Type ) { @@ -1027,7 +996,7 @@ R"(#define ( code ) _Generic( (code), \ break; } - CodeBody parsed_inlines = parse_file( project_dir "components/inlines.hpp" ); + CodeBody parsed_inlines = parse_file( path_base "components/inlines.hpp" ); CodeBody inlines = def_body(CT_Global_Body); for ( Code entry = parsed_inlines.begin(); entry != parsed_inlines.end(); ++ entry ) switch( entry->Type ) { @@ -1062,7 +1031,7 @@ R"(#define ( code ) _Generic( (code), \ break; } - CodeBody parsed_header_builder = parse_file( project_dir "auxillary/builder.hpp" ); + CodeBody parsed_header_builder = parse_file( path_base "auxillary/builder.hpp" ); CodeBody header_builder = def_body(CT_Global_Body); for ( Code entry = parsed_header_builder.begin(); entry != parsed_header_builder.end(); ++ entry ) switch( entry->Type ) { @@ -1120,7 +1089,7 @@ R"(#define ( code ) _Generic( (code), \ } s32 idx = 0; - CodeBody parsed_header_end = parse_file( project_dir "components/header_end.hpp" ); + CodeBody parsed_header_end = parse_file( path_base "components/header_end.hpp" ); CodeBody header_end = def_body(CT_Global_Body); for ( Code entry = parsed_header_end.begin(); entry != parsed_header_end.end(); ++ entry, ++ idx ) switch( entry->Type ) { @@ -1158,15 +1127,15 @@ R"(#define ( code ) _Generic( (code), \ // Source Content : Reflection and Generation #pragma region Resolve Dependencies - Code src_impl_start = scan_file( project_dir "dependencies/src_start.cpp" ); - Code src_debug = scan_file( project_dir "dependencies/debug.cpp" ); - Code src_string_ops = scan_file( project_dir "dependencies/string_ops.cpp" ); - Code src_printing = scan_file( project_dir "dependencies/printing.cpp" ); - Code src_memory = scan_file( project_dir "dependencies/memory.cpp" ); - Code src_hashing = scan_file( project_dir "dependencies/hashing.cpp" ); - Code src_strings = scan_file( project_dir "dependencies/strings.cpp" ); - Code src_filesystem = scan_file( project_dir "dependencies/filesystem.cpp" ); - Code src_timing = scan_file( project_dir "dependencies/timing.cpp" ); + Code src_impl_start = scan_file( path_base "dependencies/src_start.cpp" ); + Code src_debug = scan_file( path_base "dependencies/debug.cpp" ); + Code src_string_ops = scan_file( path_base "dependencies/string_ops.cpp" ); + Code src_printing = scan_file( path_base "dependencies/printing.cpp" ); + Code src_memory = scan_file( path_base "dependencies/memory.cpp" ); + Code src_hashing = scan_file( path_base "dependencies/hashing.cpp" ); + Code src_strings = scan_file( path_base "dependencies/strings.cpp" ); + Code src_filesystem = scan_file( path_base "dependencies/filesystem.cpp" ); + Code src_timing = scan_file( path_base "dependencies/timing.cpp" ); #pragma endregion Resolve Dependencies #pragma region Resolve Components @@ -1174,14 +1143,14 @@ R"(#define ( code ) _Generic( (code), \ CodeBody array_pool = gen_array(txt("gen_Pool"), txt("Array_gen_Pool")); CodeBody array_token = gen_array(txt("gen_Token"), txt("Array_gen_Token")); - Code src_static_data = scan_file( project_dir "components/static_data.cpp" ); - Code src_ast_case_macros = scan_file( project_dir "components/ast_case_macros.cpp" ); - Code src_code_serialization = scan_file( project_dir "components/code_serialization.cpp" ); - Code src_interface = scan_file( project_dir "components/interface.cpp" ); - Code src_parsing_interface = scan_file( project_dir "components/interface.parsing.cpp" ); - Code src_untyped = scan_file( project_dir "components/interface.untyped.cpp" ); + Code src_static_data = scan_file( path_base "components/static_data.cpp" ); + Code src_ast_case_macros = scan_file( path_base "components/ast_case_macros.cpp" ); + Code src_code_serialization = scan_file( path_base "components/code_serialization.cpp" ); + Code src_interface = scan_file( path_base "components/interface.cpp" ); + Code src_parsing_interface = scan_file( path_base "components/interface.parsing.cpp" ); + Code src_untyped = scan_file( path_base "components/interface.untyped.cpp" ); - CodeBody parsed_src_ast = parse_file( project_dir "components/ast.cpp" ); + CodeBody parsed_src_ast = parse_file( path_base "components/ast.cpp" ); CodeBody src_ast = def_body(CT_Global_Body); for ( Code entry = parsed_src_ast.begin(); entry != parsed_src_ast.end(); ++ entry ) switch( entry ->Type ) { @@ -1216,7 +1185,7 @@ R"(#define ( code ) _Generic( (code), \ break; } - CodeBody parsed_src_upfront = parse_file( project_dir "components/interface.upfront.cpp" ); + CodeBody parsed_src_upfront = parse_file( path_base "components/interface.upfront.cpp" ); CodeBody src_upfront = def_body(CT_Global_Body); for ( Code entry = parsed_src_upfront.begin(); entry != parsed_src_upfront.end(); ++ entry ) switch( entry ->Type ) { @@ -1269,7 +1238,7 @@ R"(#define ( code ) _Generic( (code), \ break; } - CodeBody parsed_src_lexer = parse_file( project_dir "components/lexer.cpp" ); + CodeBody parsed_src_lexer = parse_file( path_base "components/lexer.cpp" ); CodeBody src_lexer = def_body(CT_Global_Body); for ( Code entry = parsed_src_lexer.begin(); entry != parsed_src_lexer.end(); ++ entry ) switch( entry ->Type ) { @@ -1363,7 +1332,7 @@ R"(#define ( code ) _Generic( (code), \ CodeBody array_code_typename = gen_array(txt("gen_CodeTypename"), txt("Array_gen_CodeTypename")); - CodeBody parsed_src_parser = parse_file( project_dir "components/parser.cpp" ); + CodeBody parsed_src_parser = parse_file( path_base "components/parser.cpp" ); CodeBody src_parser = def_body(CT_Global_Body); for ( Code entry = parsed_src_parser.begin(); entry != parsed_src_parser.end(); ++ entry ) switch( entry ->Type ) { @@ -1429,7 +1398,7 @@ R"(#define ( code ) _Generic( (code), \ // Printing : Everything below is jsut serialization & formatting ot a single-file. Builder - header = Builder::open( "gen/gen.h" ); + header = Builder::open( "gen/gen_singleheader.h" ); header.print_fmt( generation_notice ); header.print_fmt("#pragma once\n\n"); header.print( push_ignores ); @@ -1440,24 +1409,24 @@ R"(#define ( code ) _Generic( (code), \ { #pragma region Print Dependencies header.print_fmt( roll_own_dependencies_guard_start ); - header.print( header_platform ); + header.print( refactor(header_platform) ); header.print_fmt( "\nGEN_NS_BEGIN\n" ); - header.print( header_macros ); - header.print( header_basic_types ); - header.print( header_debug ); - header.print( format_code_to_untyped(header_memory) ); - header.print( format_code_to_untyped(header_printing)); - header.print( header_string_ops ); + header.print( refactor(header_macros) ); + header.print( refactor(header_basic_types) ); + header.print( refactor(header_debug) ); + header.print( refactor_and_format(header_memory) ); + header.print( refactor_and_format(header_printing)); + header.print( refactor(header_string_ops) ); header.print( fmt_newline); - header.print( format_code_to_untyped(containers)); - header.print( header_hashing ); - header.print( format_code_to_untyped(header_strings)); - header.print( format_code_to_untyped(header_filesystem)); - header.print( header_timing ); + header.print( refactor_and_format(containers)); + header.print( refactor(header_hashing) ); + header.print( refactor_and_format(header_strings)); + header.print( refactor_and_format(header_filesystem)); + header.print( refactor(header_timing) ); header.print_fmt( "\n#pragma region Parsing\n" ); - header.print( format_code_to_untyped(header_parsing) ); + header.print( refactor_and_format(header_parsing) ); header.print_fmt( "#pragma endregion Parsing\n" ); header.print_fmt( "\nGEN_NS_END\n" ); @@ -1471,36 +1440,35 @@ R"(#define ( code ) _Generic( (code), \ header.print_fmt( "GEN_API_C_BEGIN\n\n" ); header.print_fmt("#pragma region Types\n"); - header.print( format_code_to_untyped(types) ); + header.print( refactor_and_format(types) ); header.print( fmt_newline ); - header.print( format_code_to_untyped( ecode )); + header.print( refactor_and_format( ecode )); header.print( fmt_newline ); - header.print( format_code_to_untyped( eoperator )); + header.print( refactor_and_format( eoperator )); header.print( fmt_newline ); - header.print( format_code_to_untyped( especifier )); + header.print( refactor_and_format( especifier )); header.print_fmt("#pragma endregion Types\n\n"); header.print_fmt("#pragma region AST\n"); - header.print( format_code_to_untyped(ast) ); - header.print( format_code_to_untyped(code_types) ); - header.print( format_code_to_untyped(ast_types) ); + header.print( refactor_and_format(ast) ); + header.print( refactor_and_format(code_types) ); + header.print( refactor_and_format(ast_types) ); header.print_fmt("\n#pragma endregion AST\n"); - header.print( format_code_to_untyped(interface) ); + header.print( refactor_and_format(interface) ); header.print(fmt_newline); header.print_fmt("#pragma region Inlines\n"); - header.print( format_code_to_untyped(inlines) ); + header.print( refactor_and_format(inlines) ); header.print_fmt("#pragma endregion Inlines\n"); header.print(fmt_newline); - header.print( format_code_to_untyped(array_string_cached)); + header.print( refactor_and_format(array_string_cached)); - header.print( format_code_to_untyped(header_end) ); + header.print( refactor_and_format(header_end) ); - header.print_fmt( "\n#pragma region Builder\n" ); - header.print( format_code_to_untyped(header_builder) ); - header.print_fmt( "\n#pragma endregion Builder\n" ); + header.print( refactor_and_format(header_builder) ); + header.print( refactor_and_format( scan_file( path_base "auxillary/scanner.hpp" )) ); header.print_fmt( "\nGEN_API_C_END\n" ); header.print_fmt( "GEN_NS_END\n\n" ); @@ -1516,18 +1484,18 @@ R"(#define ( code ) _Generic( (code), \ header.print_fmt( "GEN_NS_BEGIN\n"); header.print_fmt( "GEN_API_C_BEGIN\n" ); - header.print( src_impl_start ); - header.print( src_debug ); - header.print( src_string_ops ); - header.print( src_printing ); - header.print( src_memory ); - header.print( src_hashing ); - header.print( src_strings ); - header.print( src_filesystem ); - header.print( src_timing ); + header.print( refactor(src_impl_start) ); + header.print( refactor(src_debug) ); + header.print( refactor(src_string_ops) ); + header.print( refactor(src_printing) ); + header.print( refactor(src_memory) ); + header.print( refactor(src_hashing) ); + header.print( refactor(src_strings) ); + header.print( refactor(src_filesystem) ); + header.print( refactor(src_timing) ); header.print_fmt( "\n#pragma region Parsing\n" ); - header.print( scan_file( project_dir "dependencies/parsing.cpp" ) ); + header.print( refactor_and_format( scan_file( path_base "dependencies/parsing.cpp" )) ); header.print_fmt( "\n#pragma endregion Parsing\n\n" ); header.print_fmt( "GEN_NS_END\n"); @@ -1535,46 +1503,41 @@ R"(#define ( code ) _Generic( (code), \ #pragma endregion Print Dependencies #pragma region Print Components - CodeBody etoktype = gen_etoktype( project_dir "enums/ETokType.csv", project_dir "enums/AttributeTokens.csv", helper_use_c_definition ); + CodeBody etoktype = gen_etoktype( path_base "enums/ETokType.csv", path_base "enums/AttributeTokens.csv", helper_use_c_definition ); header.print_fmt( "\nGEN_NS_BEGIN\n"); header.print( fmt_newline); - header.print( format_code_to_untyped(array_arena)); + header.print( refactor_and_format(array_arena)); header.print( fmt_newline); - header.print( format_code_to_untyped(array_pool)); + header.print( refactor_and_format(array_pool)); - header.print( src_static_data ); + header.print( refactor(src_static_data) ); header.print( fmt_newline); header.print_fmt( "#pragma region AST\n\n" ); - header.print( src_ast_case_macros ); - header.print( src_ast ); - header.print( src_code_serialization ); + header.print( refactor(src_ast_case_macros) ); + header.print( refactor(src_ast) ); + header.print( refactor(src_code_serialization) ); header.print_fmt( "#pragma endregion AST\n\n" ); header.print_fmt( "#pragma region Interface\n" ); - header.print( src_interface ); - header.print( format_code_to_untyped(src_upfront) ); + header.print( refactor(src_interface) ); + header.print( refactor_and_format(src_upfront) ); header.print_fmt( "\n#pragma region Parsing\n\n" ); - header.print( format_code_to_untyped(etoktype) ); - header.print( format_code_to_untyped(src_lexer) ); + header.print( refactor_and_format(etoktype) ); + header.print( refactor_and_format(src_lexer) ); header.print( fmt_newline); - header.print( format_code_to_untyped(array_code_typename)); + header.print( refactor_and_format(array_code_typename)); header.print( fmt_newline); - header.print( format_code_to_untyped(src_parser) ); - header.print( src_parsing_interface ); + header.print( refactor_and_format(src_parser) ); + header.print( refactor(src_parsing_interface) ); header.print_fmt( "\n#pragma endregion Parsing\n" ); - header.print( src_untyped ); + header.print( refactor(src_untyped) ); header.print_fmt( "\n#pragma endregion Interface\n\n"); - header.print_fmt( "#pragma region Builder\n" ); - header.print( scan_file( project_dir "auxillary/builder.cpp" ) ); - header.print_fmt( "#pragma endregion Builder\n\n" ); - - header.print_fmt( "\n#pragma region Scanner\n" ); - header.print( scan_file( project_dir "auxillary/scanner.hpp" ) ); - header.print_fmt( "#pragma endregion Scanner\n\n" ); + header.print( refactor_and_format( scan_file( path_base "auxillary/builder.cpp" )) ); + header.print( refactor_and_format( scan_file( path_base "auxillary/scanner.cpp" )) ); header.print_fmt( "GEN_API_C_END\n" ); #pragma endregion Print Components diff --git a/gen_c_library/c_library.refactor b/gen_c_library/c_library.refactor index 3e6569a..c912fa3 100644 --- a/gen_c_library/c_library.refactor +++ b/gen_c_library/c_library.refactor @@ -56,25 +56,29 @@ word hash, gen_hash // Basic Types -word u8, gen_u8 -word s8, gen_s8 -word u16, gen_u16 -word s16, gen_s16 -word u32, gen_u32 -word s32, gen_s32 -word u64, gen_u64 -word s64, gen_s64 -word usize, gen_usize -word ssize, gen_ssize -word sptr, gen_sptr -word uptr, gen_uptr -word f32, gen_f32 -word f64, gen_f64 -word b8, gen_b8 -word b16, gen_b16 -word b32, gen_b32 -word mem_ptr, gen_mem_ptr -word mem_ptr_const, gen_mem_ptr_cnst +word u8, gen_u8 +word s8, gen_s8 +word u16, gen_u16 +word s16, gen_s16 +word u32, gen_u32 +word s32, gen_s32 +word u64, gen_u64 +word s64, gen_s64 +word usize, gen_usize +word ssize, gen_ssize +word sptr, gen_sptr +word uptr, gen_uptr +word f32, gen_f32 +word f64, gen_f64 +word b8, gen_b8 +word b16, gen_b16 +word b32, gen_b32 +word mem_ptr, gen_mem_ptr +word mem_ptr_const, gen_mem_ptr_const +word to_uptr, gen_to_uptr +word to_sptr, gen_to_sptr +word to_mem_ptr, gen_to_mem_ptr +word to_mem_ptr_const, gen_to_mem_ptr_const // Debug diff --git a/gen_c_library/components/containers.array.hpp b/gen_c_library/components/containers.array.hpp index a0beccf..de51628 100644 --- a/gen_c_library/components/containers.array.hpp +++ b/gen_c_library/components/containers.array.hpp @@ -1,6 +1,5 @@ #pragma once - -#include "../project/gen.hpp" +#include "gen.hpp" using namespace gen; diff --git a/gen_c_library/components/containers.hashtable.hpp b/gen_c_library/components/containers.hashtable.hpp index eee83f5..89e7b56 100644 --- a/gen_c_library/components/containers.hashtable.hpp +++ b/gen_c_library/components/containers.hashtable.hpp @@ -1,6 +1,5 @@ #pragma once - -#include "../project/gen.hpp" +#include "gen.hpp" #include "containers.array.hpp" using namespace gen; diff --git a/gen_c_library/components/memory.fixed_arena.hpp b/gen_c_library/components/memory.fixed_arena.hpp index f223d2a..262f06d 100644 --- a/gen_c_library/components/memory.fixed_arena.hpp +++ b/gen_c_library/components/memory.fixed_arena.hpp @@ -1,5 +1,5 @@ #pragma once -#include "../project/gen.hpp" +#include "gen.hpp" using namespace gen; diff --git a/gen_c_library/components/misc.hpp b/gen_c_library/components/misc.hpp index 737505f..2b567a5 100644 --- a/gen_c_library/components/misc.hpp +++ b/gen_c_library/components/misc.hpp @@ -1,5 +1,5 @@ #pragma once -#include "../project/gen.hpp" +#include "gen.hpp" using namespace gen; diff --git a/gen_c_library/gen.c b/gen_c_library/gen.c index a4a7b4d..3c50dea 100644 --- a/gen_c_library/gen.c +++ b/gen_c_library/gen.c @@ -1,5 +1,5 @@ #define GEN_IMPLEMENTATION -#include "gen/gen.h" +#include "gen/gen_singleheader.h" int main() { diff --git a/scripts/build.ci.ps1 b/scripts/build.ci.ps1 index 4f12b46..a3e35ae 100644 --- a/scripts/build.ci.ps1 +++ b/scripts/build.ci.ps1 @@ -4,7 +4,6 @@ $devshell = Join-Path $PSScriptRoot 'helpers/devshell.ps1' $misc = Join-Path $PSScriptRoot 'helpers/misc.psm1' -$refactor_c_library = Join-Path $PSScriptRoot 'refactor_c_library.ps1' $refactor_unreal = Join-Path $PSScriptRoot 'refactor_unreal.ps1' $incremental_checks = Join-Path $PSScriptRoot 'helpers/incremental_checks.ps1' $vendor_toolchain = Join-Path $PSScriptRoot 'helpers/vendor_toolchain.ps1' @@ -222,7 +221,7 @@ if ( $c_library ) New-Item -ItemType Directory -Path $path_gen } - $includes = @( $path_project ) + $includes = @( $path_base ) $unit = join-path $path_c_library "c_library.cpp" $executable = join-path $path_build "c_library.exe" @@ -247,8 +246,6 @@ if ( $c_library ) } Pop-Location - . $refactor_c_library - $unit = join-path $path_c_library "gen.c" $executable = join-path $path_build "gen_c_library_test.exe" @@ -289,7 +286,7 @@ if ( $unreal ) New-Item -ItemType Directory -Path $path_gen } - $includes = @( $path_project ) + $includes = @( $path_base ) $unit = join-path $path_unreal "unreal.cpp" $executable = join-path $path_build "unreal.exe"