mirror of
https://github.com/Ed94/gencpp.git
synced 2024-12-22 15:54:45 -08:00
Ed_
47c15e7af2
There shouldn't be much more changes design wise. Anything else is based on what needs to be done for it to work.
87 lines
1.7 KiB
C++
87 lines
1.7 KiB
C++
#pragma once
|
|
|
|
#include "Bloat.hpp"
|
|
#include "gen.hpp"
|
|
|
|
#ifdef gen_time
|
|
using namespace gen;
|
|
|
|
char* sprintf_buf[ZPL_PRINTF_MAXLEN];
|
|
|
|
/*
|
|
What it should generate:
|
|
|
|
inline
|
|
type square( type value )
|
|
{
|
|
return value * value;
|
|
}
|
|
*/
|
|
#define gen_square( Type_ ) gen__square( #Type_ )
|
|
Code gen__square( char const* type )
|
|
{
|
|
Code t_integral_type = def_type( type );
|
|
|
|
#ifndef GEN_DEFINE_DSL
|
|
string name = string_sprintf( g_allocator, (char*)sprintf_buf, ZPL_PRINTF_MAXLEN, "square", type );
|
|
|
|
#if 1
|
|
Code square;
|
|
{
|
|
Code params = def_params( 1, integral_type, "value" );
|
|
Code specifiers = def_specifiers( 1, SpecifierT::Inline );
|
|
Code ret_stmt = untyped_str( txt( return value * value; ));
|
|
|
|
square = def_function( name, specifiers, params, integral_type, ret_stmt );
|
|
}
|
|
|
|
#else
|
|
// Test of token template str.
|
|
char const* tmpl = txt(
|
|
{type} square( {type} value )
|
|
{
|
|
return value * value;
|
|
}
|
|
);
|
|
char const* gen_code = token_fmt( tmpl, 1, "type", type );
|
|
|
|
Code square = parse_function(gen_code, strlen(gen_code));
|
|
#endif
|
|
|
|
#else
|
|
Code square = function( square, params( integral_type, value), integral_type, __,
|
|
code_str(return value * value)
|
|
);
|
|
#endif
|
|
|
|
if ( ! square )
|
|
fatal( "Failed to generate square function for: %s", type );
|
|
|
|
return square;
|
|
}
|
|
|
|
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 );
|
|
|
|
Builder
|
|
mathgen;
|
|
mathgen.open( "math.gen.hpp" );
|
|
mathgen.print( fadd_u8 );
|
|
mathgen.print( fadd_u16 );
|
|
mathgen.print( fadd_u32 );
|
|
mathgen.print( fadd_u64 );
|
|
mathgen.write();
|
|
return 0;
|
|
}
|
|
#endif
|
|
|
|
#ifndef gen_time
|
|
# include "math.gen.hpp"
|
|
# undef square
|
|
|
|
#endif
|