mirror of
https://github.com/Ed94/gencpp.git
synced 2024-12-22 15:54:45 -08:00
First test works.
This commit is contained in:
parent
d66c1e4eb4
commit
5e26d53a12
@ -87,7 +87,8 @@ namespace Memory
|
|||||||
ct uw Initial_Reserve = megabytes(10);
|
ct uw Initial_Reserve = megabytes(10);
|
||||||
|
|
||||||
extern arena Global_Arena;
|
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 setup();
|
||||||
void resize( uw new_size );
|
void resize( uw new_size );
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#include "Bloat.hpp"
|
#include "Bloat.hpp"
|
||||||
// #define gen_time
|
#define gen_time
|
||||||
#include "gen.hpp"
|
#include "gen.hpp"
|
||||||
|
|
||||||
#ifdef gen_time
|
#ifdef gen_time
|
||||||
@ -10,18 +10,6 @@ namespace gen
|
|||||||
return { Code::Invalid, nullptr, nullptr, { nullptr } };
|
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 decl_type( char const* name, Code specifiers, Code type )
|
||||||
{
|
{
|
||||||
Code
|
Code
|
||||||
@ -85,6 +73,8 @@ namespace gen
|
|||||||
param = make();
|
param = make();
|
||||||
param.Name = string_make( g_allocator, va_arg(va, char const*) );
|
param.Name = string_make( g_allocator, va_arg(va, char const*) );
|
||||||
|
|
||||||
|
array_init( param.Entries, g_allocator );
|
||||||
|
|
||||||
type = va_arg(va, Code);
|
type = va_arg(va, Code);
|
||||||
param.add( type );
|
param.add( type );
|
||||||
|
|
||||||
@ -126,7 +116,7 @@ namespace gen
|
|||||||
result.Name = string_make( g_allocator, name );
|
result.Name = string_make( g_allocator, name );
|
||||||
result.Type = Code::Function;
|
result.Type = Code::Function;
|
||||||
|
|
||||||
array_init( result.Content, g_allocator );
|
array_init( result.Entries, g_allocator );
|
||||||
|
|
||||||
if ( specifiers )
|
if ( specifiers )
|
||||||
result.add( specifiers );
|
result.add( specifiers );
|
||||||
@ -234,7 +224,7 @@ namespace gen
|
|||||||
|
|
||||||
if ( left && Entries[index].Type == Parameters )
|
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++;
|
index++;
|
||||||
left--;
|
left--;
|
||||||
}
|
}
|
||||||
@ -247,10 +237,10 @@ namespace gen
|
|||||||
{
|
{
|
||||||
result = string_append_fmt( result, "%s %s", Entries[0].to_string(), Name );
|
result = string_append_fmt( result, "%s %s", Entries[0].to_string(), Name );
|
||||||
|
|
||||||
u32 index = 1;
|
s32 index = 1;
|
||||||
u32 left = array_count( Entries ) - 1;
|
s32 left = array_count( Entries ) - 1;
|
||||||
|
|
||||||
while ( left-- )
|
while ( left--, left > 0 )
|
||||||
result = string_append_fmt( result, ", %s %s"
|
result = string_append_fmt( result, ", %s %s"
|
||||||
, Entries[index].Entries[0].to_string()
|
, Entries[index].Entries[0].to_string()
|
||||||
, Entries[index].Name
|
, Entries[index].Name
|
||||||
@ -272,7 +262,7 @@ namespace gen
|
|||||||
|
|
||||||
if ( Entries[index].Type == Specifiers )
|
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++;
|
index++;
|
||||||
left--;
|
left--;
|
||||||
}
|
}
|
||||||
@ -286,7 +276,7 @@ namespace gen
|
|||||||
|
|
||||||
if ( left && Entries[index].Type == Parameters )
|
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++;
|
index++;
|
||||||
left--;
|
left--;
|
||||||
}
|
}
|
||||||
@ -313,7 +303,7 @@ namespace gen
|
|||||||
|
|
||||||
void Builder::print( Code code )
|
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 )
|
bool Builder::open( char const* path )
|
||||||
@ -338,6 +328,7 @@ namespace gen
|
|||||||
if ( result == false )
|
if ( result == false )
|
||||||
fatal("gen::File::write - Failed to write to file: %s", file_name( & File ) );
|
fatal("gen::File::write - Failed to write to file: %s", file_name( & File ) );
|
||||||
|
|
||||||
|
// file_seek( & File, 0 );
|
||||||
file_close( & File );
|
file_close( & File );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,12 +20,12 @@ if ( Test-Path $path_gen_build )
|
|||||||
Remove-Item $path_gen_build -Recurse
|
Remove-Item $path_gen_build -Recurse
|
||||||
}
|
}
|
||||||
|
|
||||||
# [string[]] $include = '*.h', '*.hpp', '*.cpp'
|
[string[]] $include = '*.h', '*.hpp', '*.cpp'
|
||||||
# [string[]] $exclude =
|
[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 )
|
if ( $files )
|
||||||
# {
|
{
|
||||||
# Remove-Item $files
|
Remove-Item $files
|
||||||
# }
|
}
|
||||||
|
@ -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
|
||||||
|
}
|
||||||
|
|
@ -1,11 +1,14 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#define gen_time
|
||||||
#include "Bloat.hpp"
|
#include "Bloat.hpp"
|
||||||
#include "gen.hpp"
|
#include "gen.hpp"
|
||||||
|
|
||||||
#ifdef gen_time
|
#ifdef gen_time
|
||||||
using namespace gen;
|
using namespace gen;
|
||||||
|
|
||||||
|
char* sprintf_buf[ZPL_PRINTF_MAXLEN];
|
||||||
|
|
||||||
/*
|
/*
|
||||||
What it should generate:
|
What it should generate:
|
||||||
|
|
||||||
@ -20,10 +23,10 @@
|
|||||||
{
|
{
|
||||||
Code integral_type = make_type( type );
|
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 specifiers = make_specifiers( 1, Specifier::Inline );
|
||||||
Code params = make_parameters( 1, "value", integral_type );
|
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,
|
Code result = make_function( name,
|
||||||
specifiers,
|
specifiers,
|
||||||
@ -41,17 +44,17 @@
|
|||||||
u32 gen_math()
|
u32 gen_math()
|
||||||
{
|
{
|
||||||
Code fadd_u8 = gen_square( u8 );
|
Code fadd_u8 = gen_square( u8 );
|
||||||
// Code fadd_u16 = gen_square( u16 );
|
Code fadd_u16 = gen_square( u16 );
|
||||||
// Code fadd_u32 = gen_square( u32 );
|
Code fadd_u32 = gen_square( u32 );
|
||||||
// Code fadd_u64 = gen_square( u64 );
|
Code fadd_u64 = gen_square( u64 );
|
||||||
|
|
||||||
Builder
|
Builder
|
||||||
mathgen;
|
mathgen;
|
||||||
mathgen.open( "math.gen.hpp" );
|
mathgen.open( "math.gen.hpp" );
|
||||||
mathgen.print( fadd_u8 );
|
mathgen.print( fadd_u8 );
|
||||||
// mathgen.print( fadd_u16 );
|
mathgen.print( fadd_u16 );
|
||||||
// mathgen.print( fadd_u32 );
|
mathgen.print( fadd_u32 );
|
||||||
// mathgen.print( fadd_u64 );
|
mathgen.print( fadd_u64 );
|
||||||
mathgen.write();
|
mathgen.write();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user