test.cpp gen_time compiles (has memory issues though)

This commit is contained in:
2023-04-02 01:07:44 -04:00
parent f09fe6aa15
commit d66c1e4eb4
13 changed files with 238 additions and 264 deletions

View File

@ -1,13 +0,0 @@
// Handwritten generated code:
#pragma region gen_array
#pragma endregion gen_array
#define Array( Type_ ) Array_##Type_

View File

@ -1,164 +0,0 @@
#include "gen.hpp"
#include "bloat.hpp"
#if tt
#define gen_array( Type_ ) gen__array( #Type_ )
Code* gen__array( char const* type )
{
Code codegen;
Code
data;
data.add( "%type* data" );
Code header;
header.define_struct( "Header",
"uw Num;"
"uw Capacity;"
"allocator Allocator;"
);
Code grow_formula;
grow_formula.define_function( "grow_formula", "static", "forceinline",
"return 2 * value * 8"
);
codegen.define_struct( "Array",
data
, header
, grow_formula
);
codegen.define
R"(
%type* data;
struct Header
{
uw Num;
uw Capacity;
allocator Allocator;
};
static forceinline
sw grow_formula ( sw value )
{
return 2 * value * 8;
}
static
bool init ( %Array& array, allocator mem_handler )
{
return init_reserve( array, mem_handler, grow_formula(0) );
}
static
bool init_reserve( %Array& array, allocator mem_handler, uw capacity )
{
Header*
header = nullptr;
header = rcast( Header*, alloc( mem_handler, size_of( Header ) + sizeof(type) * capacity ));
if (header == nullptr)
return false;
header->Num = 0;
header->Capacity = capacity;
header->Allocator = mem_handler;
array.data = rcast( %type*, header + 1 );
return true;
}
void append( %type value )
{
}
type back()
{
Header& header = get_header();
return data[ header.Num - 1 ];
}
void clear()
{
get_header().Num = 0;
}
void fill( uw begin, uw end, type value )
{
Header& header = get_header();
if ( begin < 0 || end >= header.Num )
{
fatal( "Range out of bounds" );
}
}
void free()
{
Header& header = get_header();
::free( header.Allocator, & get_header() );
}
bool grow( uw min_capacity )
{
Header& header = get_header();
uw new_capacity = grow_formula( header.Capacity );
if ( new_capacity < min_capacity )
new_capacity = min_capacity;
return set_capacity( new_capacity );
}
forceinline
Header& get_header()
{
return vcast( Header, data - 1 );
}
void pop()
{
}
void reserve()
{
}
void resize()
{
}
bool set_capacity( uw capacity )
{
Header& header = get_header();
if ( capacity == header.Capacity )
{
}
}
)"
, type
);
};
#endif
void tt_run()
{
gen_array( u32 );
}
#endif tt
#if !tt
#include "array.gen.manual.hpp"
#endif

0
test/gen/math.gen.hpp Normal file
View File

View File

@ -4,15 +4,14 @@ project( 'test', 'c', 'cpp', default_options : ['buildtype=debug'] )
includes = include_directories(
[
'../test'
'../project'
, '../thirdparty'
'../../project',
'../../thirdparty'
])
# get_sources = files('./get_sources.ps1')
# sources = files(run_command('powershell', get_sources, check: true).stdout().strip().split('\n'))
sources = [ 'test.cpp' ]
sources = [ '../test.cpp' ]
if get_option('buildtype').startswith('debug')
@ -20,6 +19,6 @@ if get_option('buildtype').startswith('debug')
endif
add_project_arguments('-Dgen_time', langauge : ['c', 'cpp'])
add_project_arguments('-Dgen_time', language : ['c', 'cpp'])
executable( '', sources, include_directories : includes )
executable( 'gencpp', sources, include_directories : includes )

View File

@ -1,9 +1,9 @@
#pragma once
#ifdef gen_time
#include "Bloat.hpp"
#include "gen.hpp"
#include "Bloat.hpp"
#include "gen.hpp"
#ifdef gen_time
using namespace gen;
/*
@ -15,8 +15,8 @@
return value * value;
}
*/
#define gen_square( Type_ ) gen__squre( #Type_ )
Code gen__squre( char const* type )
#define gen_square( Type_ ) gen__square( #Type_ )
Code gen__square( char const* type )
{
Code integral_type = make_type( type );
@ -41,17 +41,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 );
File
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;
}

View File

@ -1,17 +1,28 @@
#include "Bloat.cpp"
#include "math.hpp"
#ifdef gen_time
u32 gen_main()
{
return gen_math();
}
#include "gen.cpp"
int gen_main()
{
Memory::setup();
zpl_printf("\nPress any key after attaching to process\n");
getchar();
int result = gen_math();
Memory::cleanup();
return result;
}
#endif
#ifndef gen_time
#include "math.hpp"
int main()
{
u32 result = square(5);