From 5e26d53a12c39e9e6b093ba7ab065c1e67be2816 Mon Sep 17 00:00:00 2001 From: Ed_ Date: Sun, 2 Apr 2023 11:53:15 -0400 Subject: [PATCH] First test works. --- project/Bloat.hpp | 3 ++- project/gen.cpp | 33 ++++++++++++--------------------- scripts/clean.ps1 | 14 +++++++------- test/gen/math.gen.hpp | 24 ++++++++++++++++++++++++ test/math.hpp | 19 +++++++++++-------- 5 files changed, 56 insertions(+), 37 deletions(-) diff --git a/project/Bloat.hpp b/project/Bloat.hpp index 802e2d6..dde36a2 100644 --- a/project/Bloat.hpp +++ b/project/Bloat.hpp @@ -87,7 +87,8 @@ namespace Memory ct uw Initial_Reserve = megabytes(10); extern arena Global_Arena; - #define g_allocator arena_allocator( & Memory::Global_Arena) + // #define g_allocator arena_allocator( & Memory::Global_Arena) + #define g_allocator heap() void setup(); void resize( uw new_size ); diff --git a/project/gen.cpp b/project/gen.cpp index f903b88..c771b65 100644 --- a/project/gen.cpp +++ b/project/gen.cpp @@ -1,5 +1,5 @@ #include "Bloat.hpp" -// #define gen_time +#define gen_time #include "gen.hpp" #ifdef gen_time @@ -10,18 +10,6 @@ namespace gen return { Code::Invalid, nullptr, nullptr, { nullptr } }; } - #if 0 - static Code Unused() - { - static Code value = { - Code::Unused, - string_make( g_allocator, "Unused" ) - }; - - return value; - } - #endif - Code decl_type( char const* name, Code specifiers, Code type ) { Code @@ -85,6 +73,8 @@ namespace gen param = make(); param.Name = string_make( g_allocator, va_arg(va, char const*) ); + array_init( param.Entries, g_allocator ); + type = va_arg(va, Code); param.add( type ); @@ -126,7 +116,7 @@ namespace gen result.Name = string_make( g_allocator, name ); result.Type = Code::Function; - array_init( result.Content, g_allocator ); + array_init( result.Entries, g_allocator ); if ( specifiers ) result.add( specifiers ); @@ -234,7 +224,7 @@ namespace gen if ( left && Entries[index].Type == Parameters ) { - result = string_append_fmt( result, "%s, ", Entries[index].to_string() ); + result = string_append_fmt( result, "%s", Entries[index].to_string() ); index++; left--; } @@ -247,10 +237,10 @@ namespace gen { result = string_append_fmt( result, "%s %s", Entries[0].to_string(), Name ); - u32 index = 1; - u32 left = array_count( Entries ) - 1; + s32 index = 1; + s32 left = array_count( Entries ) - 1; - while ( left-- ) + while ( left--, left > 0 ) result = string_append_fmt( result, ", %s %s" , Entries[index].Entries[0].to_string() , Entries[index].Name @@ -272,7 +262,7 @@ namespace gen if ( Entries[index].Type == Specifiers ) { - result = string_append_fmt( result, "%s\n", Entries[index].to_string() ); + result = string_append_fmt( result, "%s", Entries[index].to_string() ); index++; left--; } @@ -286,7 +276,7 @@ namespace gen if ( left && Entries[index].Type == Parameters ) { - result = string_append_fmt( result, "%s, ", Entries[index].to_string() ); + result = string_append_fmt( result, "%s", Entries[index].to_string() ); index++; left--; } @@ -313,7 +303,7 @@ namespace gen void Builder::print( Code code ) { - Buffer = string_append( Buffer, code.to_string() ); + Buffer = string_append_fmt( Buffer, "%s\n\n", code.to_string() ); } bool Builder::open( char const* path ) @@ -338,6 +328,7 @@ namespace gen if ( result == false ) fatal("gen::File::write - Failed to write to file: %s", file_name( & File ) ); + // file_seek( & File, 0 ); file_close( & File ); } } diff --git a/scripts/clean.ps1 b/scripts/clean.ps1 index 5d6fe4e..7155f7f 100644 --- a/scripts/clean.ps1 +++ b/scripts/clean.ps1 @@ -20,12 +20,12 @@ if ( Test-Path $path_gen_build ) Remove-Item $path_gen_build -Recurse } -# [string[]] $include = '*.h', '*.hpp', '*.cpp' -# [string[]] $exclude = +[string[]] $include = '*.h', '*.hpp', '*.cpp' +[string[]] $exclude = -# $files = Get-ChildItem -Recurse -Path $path_test -Include $include -Exclude $exclude +$files = Get-ChildItem -Recurse -Path $path_gen -Include $include -Exclude $exclude -# if ( $files ) -# { -# Remove-Item $files -# } +if ( $files ) +{ + Remove-Item $files +} diff --git a/test/gen/math.gen.hpp b/test/gen/math.gen.hpp index e69de29..a74c1a1 100644 --- a/test/gen/math.gen.hpp +++ b/test/gen/math.gen.hpp @@ -0,0 +1,24 @@ +inline +u8 square_u8(u8 value) +{ + return value * value +} + +inline +u16 square_u16(u16 value) +{ + return value * value +} + +inline +u32 square_u32(u32 value) +{ + return value * value +} + +inline +u64 square_u64(u64 value) +{ + return value * value +} + diff --git a/test/math.hpp b/test/math.hpp index 682793b..853dcf7 100644 --- a/test/math.hpp +++ b/test/math.hpp @@ -1,11 +1,14 @@ #pragma once +#define gen_time #include "Bloat.hpp" #include "gen.hpp" #ifdef gen_time using namespace gen; + char* sprintf_buf[ZPL_PRINTF_MAXLEN]; + /* What it should generate: @@ -20,10 +23,10 @@ { Code integral_type = make_type( type ); - string name = string_sprintf_buf( g_allocator, "square_%s", type ); + string name = string_sprintf( g_allocator, (char*)sprintf_buf, ZPL_PRINTF_MAXLEN, "square_%s", type ); Code specifiers = make_specifiers( 1, Specifier::Inline ); Code params = make_parameters( 1, "value", integral_type ); - Code ret_stmt = make_fmt( "return value * value" ); + Code ret_stmt = make_fmt( "\treturn value * value" ); Code result = make_function( name, specifiers, @@ -41,17 +44,17 @@ u32 gen_math() { Code fadd_u8 = gen_square( u8 ); - // Code fadd_u16 = gen_square( u16 ); - // Code fadd_u32 = gen_square( u32 ); - // Code fadd_u64 = gen_square( u64 ); + Code fadd_u16 = gen_square( u16 ); + Code fadd_u32 = gen_square( u32 ); + Code fadd_u64 = gen_square( u64 ); Builder mathgen; mathgen.open( "math.gen.hpp" ); mathgen.print( fadd_u8 ); - // mathgen.print( fadd_u16 ); - // mathgen.print( fadd_u32 ); - // mathgen.print( fadd_u64 ); + mathgen.print( fadd_u16 ); + mathgen.print( fadd_u32 ); + mathgen.print( fadd_u64 ); mathgen.write(); return 0; }