First test works.

This commit is contained in:
Edward R. Gonzalez 2023-04-02 11:53:15 -04:00
parent d66c1e4eb4
commit 5e26d53a12
5 changed files with 56 additions and 37 deletions

View File

@ -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 );

View File

@ -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 );
}
}

View File

@ -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
}

View File

@ -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
}

View File

@ -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;
}