mirror of
https://github.com/Ed94/gencpp.git
synced 2025-06-14 18:51:47 -07:00
WIP: Design is almost done, impl this weekend.
This commit is contained in:
@ -16,7 +16,7 @@
|
||||
#ifndef GEN_DEFINE_DSL
|
||||
using namespace gen;
|
||||
|
||||
Code t_allocator = def_type( txt(allocator) );
|
||||
Code t_allocator = def_type( txt(allocator) );
|
||||
|
||||
Code header;
|
||||
{
|
||||
@ -64,7 +64,6 @@
|
||||
return ArrayBase;
|
||||
}
|
||||
|
||||
#define gen_array( Type_ ) gen__array( #Type_, sizeof(Type_), a_base )
|
||||
Code gen__array( char const* type_str, s32 type_size, Code parent )
|
||||
{
|
||||
#ifndef GEN_DEFINE_DSL
|
||||
@ -155,6 +154,7 @@
|
||||
Code append = make_proc( "append" );
|
||||
{
|
||||
append->add( def_params( 1, type, "value") );
|
||||
append->add( t_bool );
|
||||
|
||||
Code
|
||||
body = append.body();
|
||||
@ -172,6 +172,8 @@
|
||||
|
||||
return true;
|
||||
)));
|
||||
|
||||
append->check();
|
||||
}
|
||||
|
||||
Code back;
|
||||
@ -295,7 +297,7 @@
|
||||
}
|
||||
|
||||
Code set_capacity = parse_proc( txt_with_length(
|
||||
bool set_capacity( new_capacity )
|
||||
bool set_capacity( sw new_capacity )
|
||||
{
|
||||
Header& header = get_header();
|
||||
|
||||
@ -305,7 +307,7 @@
|
||||
if ( capacity < header.Num )
|
||||
header.Num = capacity;
|
||||
|
||||
uw size = sizeof(Header) + sizeof(Type) * capacity;
|
||||
sw size = sizeof(Header) + sizeof(Type) * capacity;
|
||||
Header* new_header = rcast( Header* alloc( header.Allocator, size ));
|
||||
|
||||
if ( new_header == nullptr )
|
||||
@ -591,18 +593,58 @@
|
||||
return array_def;
|
||||
}
|
||||
|
||||
struct ArrayRequest
|
||||
{
|
||||
char const* Name;
|
||||
sw Size;
|
||||
};
|
||||
|
||||
array(ArrayRequest) UserArrayGenQueue;
|
||||
|
||||
#define gen_array( Type_ ) add_gen_array_request( #Type_, sizeof(Type_) )
|
||||
|
||||
void add_gen_array_request( const char* type_str, sw type_size )
|
||||
{
|
||||
ArrayRequest request = { type_str, type_size };
|
||||
|
||||
array_append( UserArrayGenQueue, request );
|
||||
}
|
||||
|
||||
u32 gen_array_file()
|
||||
{
|
||||
Code a_base = gen__array_base();
|
||||
|
||||
Code a_u32 = gen_array( u32 );
|
||||
Code a_cstr = gen_array( char const* );
|
||||
add_gen_array_request( "u32", sizeof(u32) );
|
||||
gen_array( char const* );
|
||||
|
||||
array(Code) array_asts;
|
||||
array_init( array_asts, g_allocator );
|
||||
|
||||
sw left = array_count( UserArrayGenQueue );
|
||||
sw index = 0;
|
||||
while( left -- )
|
||||
{
|
||||
ArrayRequest request = UserArrayGenQueue[index];
|
||||
|
||||
Code result = gen__array( request.Name, request.Size, a_base );
|
||||
|
||||
array_append( array_asts, result );
|
||||
}
|
||||
|
||||
Builder
|
||||
arraygen;
|
||||
arraygen.open( "Array.gen.hpp" );
|
||||
arraygen.print( a_u32 );
|
||||
arraygen.print( a_cstr );
|
||||
|
||||
left = array_count( array_asts );
|
||||
index = 0;
|
||||
|
||||
while( left-- )
|
||||
{
|
||||
Code code = array_asts[index];
|
||||
|
||||
arraygen.print( code );
|
||||
}
|
||||
|
||||
arraygen.write();
|
||||
return 0;
|
||||
}
|
||||
|
22
test/c99/meson.build
Normal file
22
test/c99/meson.build
Normal file
@ -0,0 +1,22 @@
|
||||
project( 'test', 'c', default_options : ['buildtype=debug'] )
|
||||
|
||||
# add_global_arguments('-E', language : 'cpp')
|
||||
|
||||
includes = include_directories(
|
||||
[
|
||||
'../gen',
|
||||
'../../singleheader'
|
||||
])
|
||||
|
||||
# get_sources = files('./get_sources.ps1')
|
||||
# sources = files(run_command('powershell', get_sources, check: true).stdout().strip().split('\n'))
|
||||
|
||||
sources = [ 'test.c99.c' ]
|
||||
|
||||
if get_option('buildtype').startswith('debug')
|
||||
|
||||
add_project_arguments('-DBuild_Debug', language : ['c' ])
|
||||
|
||||
endif
|
||||
|
||||
executable( 'test_c99', sources, include_directories : includes )
|
79
test/c99/table.h
Normal file
79
test/c99/table.h
Normal file
@ -0,0 +1,79 @@
|
||||
#include "gen.h"
|
||||
|
||||
#define Table( Type_ ) Table_##Type_
|
||||
|
||||
typedef u64(*)(void*) HashingFn;
|
||||
|
||||
#if gen_time
|
||||
# define gen_table( Type_, HashingFn_ ) gen_request_table( #Type_, sizeof(Type_), HashingFn_ )
|
||||
|
||||
u64 table_default_hash_fn( void* address )
|
||||
{
|
||||
return crc32( address, 4 );
|
||||
}
|
||||
|
||||
Code gen_table_code( char const* type_str, sw type_size, HashingFn hash_fn )
|
||||
{
|
||||
Code table;
|
||||
|
||||
return table;
|
||||
}
|
||||
|
||||
struct TableRequest
|
||||
{
|
||||
char const* Type;
|
||||
sw Size;
|
||||
HashingFn HashFn;
|
||||
};
|
||||
|
||||
array(TableRequest) TableRequests;
|
||||
|
||||
void gen_request_table( const char* type_str, sw type_size, HashingFn hash_fn )
|
||||
{
|
||||
TableRequest request = { type_str, type_size, hash_fn };
|
||||
|
||||
array_append( TableRequests, request );
|
||||
}
|
||||
|
||||
u32 gen_table_file()
|
||||
{
|
||||
gen_table( u32 );
|
||||
gen_table( char const* );
|
||||
|
||||
array(Code) array_asts;
|
||||
array_init( array_asts, g_allocator );
|
||||
|
||||
sw left = array_count( TableRequests );
|
||||
sw index = 0;
|
||||
while( left -- )
|
||||
{
|
||||
ArrayRequest request = TableRequests[index];
|
||||
|
||||
Code result = gen_table_code( request.Name, request.Size, request.HashFn );
|
||||
|
||||
array_append( array_asts, result );
|
||||
}
|
||||
|
||||
Builder
|
||||
arraygen;
|
||||
arraygen.open( "table.gen.h" );
|
||||
|
||||
left = array_count( array_asts );
|
||||
index = 0;
|
||||
|
||||
while( left-- )
|
||||
{
|
||||
Code code = array_asts[index];
|
||||
|
||||
arraygen.print( code );
|
||||
}
|
||||
|
||||
arraygen.write();
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef gen_time
|
||||
# include "table.gen.h"
|
||||
#endif
|
||||
|
40
test/c99/test.c99.c
Normal file
40
test/c99/test.c99.c
Normal file
@ -0,0 +1,40 @@
|
||||
#define GENC_IMPLEMENTATION
|
||||
#include "genc.h"
|
||||
#include "table.h"
|
||||
|
||||
|
||||
struct Test
|
||||
{
|
||||
u64 A;
|
||||
u64 B;
|
||||
};
|
||||
|
||||
|
||||
|
||||
#if gen_time
|
||||
|
||||
|
||||
u64 hash_struct( void* test )
|
||||
{
|
||||
return crc32( ((Test)test).A, sizeof(u64) );
|
||||
}
|
||||
|
||||
|
||||
int gen_main()
|
||||
{
|
||||
gen_table( Test, & hash_struct )
|
||||
|
||||
gen_table_file();
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#if runtime
|
||||
int main()
|
||||
{
|
||||
Table(Test) test_table;
|
||||
|
||||
|
||||
}
|
||||
#endif
|
@ -25,7 +25,7 @@
|
||||
#ifndef GEN_DEFINE_DSL
|
||||
string name = string_sprintf( g_allocator, (char*)sprintf_buf, ZPL_PRINTF_MAXLEN, "square", type );
|
||||
|
||||
#if 1
|
||||
#if 0
|
||||
Code square;
|
||||
{
|
||||
Code params = def_params( 1, integral_type, "value" );
|
||||
@ -43,9 +43,9 @@
|
||||
return value * value;
|
||||
}
|
||||
);
|
||||
char const* gen_code = token_fmt( tmpl, 1, type );
|
||||
char const* gen_code = token_fmt( tmpl, 1, "type", type );
|
||||
|
||||
Code square = parse_proc(gen_code);
|
||||
Code square = parse_proc(gen_code, strlen(gen_code));
|
||||
#endif
|
||||
|
||||
#else
|
||||
|
0
test/test.singleheader.cpp
Normal file
0
test/test.singleheader.cpp
Normal file
Reference in New Issue
Block a user