mirror of
https://github.com/Ed94/gencpp.git
synced 2024-11-10 02:54:53 -08:00
WIP : Design for V1 finalization
There shouldn't be much more changes design wise. Anything else is based on what needs to be done for it to work.
This commit is contained in:
parent
a4cb0c12ef
commit
47c15e7af2
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
@ -9,5 +9,6 @@
|
|||||||
"xutility": "cpp",
|
"xutility": "cpp",
|
||||||
"initializer_list": "cpp",
|
"initializer_list": "cpp",
|
||||||
"table.h": "c"
|
"table.h": "c"
|
||||||
}
|
},
|
||||||
|
"C_Cpp.intelliSenseEngineFallback": "disabled"
|
||||||
}
|
}
|
@ -10,7 +10,7 @@ namespace Global
|
|||||||
namespace Memory
|
namespace Memory
|
||||||
{
|
{
|
||||||
arena Global_Arena {};
|
arena Global_Arena {};
|
||||||
|
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
arena_init_from_allocator( & Global_Arena, heap(), Initial_Reserve );
|
arena_init_from_allocator( & Global_Arena, heap(), Initial_Reserve );
|
||||||
@ -20,16 +20,16 @@ namespace Memory
|
|||||||
assert_crash( "Failed to reserve memory for Tests:: Global_Arena" );
|
assert_crash( "Failed to reserve memory for Tests:: Global_Arena" );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void resize( uw new_size )
|
void resize( uw new_size )
|
||||||
{
|
{
|
||||||
void* new_memory = resize( heap(), Global_Arena.physical_start, Global_Arena.total_size, new_size );
|
void* new_memory = resize( heap(), Global_Arena.physical_start, Global_Arena.total_size, new_size );
|
||||||
|
|
||||||
if ( new_memory == nullptr )
|
if ( new_memory == nullptr )
|
||||||
{
|
{
|
||||||
fatal("Failed to resize global arena!");
|
fatal("Failed to resize global arena!");
|
||||||
}
|
}
|
||||||
|
|
||||||
Global_Arena.physical_start = new_memory;
|
Global_Arena.physical_start = new_memory;
|
||||||
Global_Arena.total_size = new_size;
|
Global_Arena.total_size = new_size;
|
||||||
}
|
}
|
||||||
@ -37,14 +37,14 @@ namespace Memory
|
|||||||
void cleanup()
|
void cleanup()
|
||||||
{
|
{
|
||||||
arena_free( & Global_Arena);
|
arena_free( & Global_Arena);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
struct TokEntry
|
struct TokEntry
|
||||||
{
|
{
|
||||||
char const* Str;
|
char const* Str;
|
||||||
s32 Length;
|
sw Length;
|
||||||
};
|
};
|
||||||
|
|
||||||
ZPL_TABLE( static, TokMap, tokmap_, TokEntry )
|
ZPL_TABLE( static, TokMap, tokmap_, TokEntry )
|
||||||
@ -65,10 +65,10 @@ sw token_fmt_va( char* buf, uw buf_size, char const* fmt, s32 num_tokens, va_lis
|
|||||||
char const* token = va_arg( va, char const* );
|
char const* token = va_arg( va, char const* );
|
||||||
char const* value = va_arg( va, char const* );
|
char const* value = va_arg( va, char const* );
|
||||||
|
|
||||||
TokEntry entry
|
TokEntry entry
|
||||||
{
|
{
|
||||||
value,
|
value,
|
||||||
zpl_strnlen(value, 128)
|
zpl_strnlen(value, (sw)128)
|
||||||
};
|
};
|
||||||
|
|
||||||
u32 key = crc32( token, zpl_strnlen(token, 32) );
|
u32 key = crc32( token, zpl_strnlen(token, 32) );
|
||||||
@ -84,7 +84,7 @@ sw token_fmt_va( char* buf, uw buf_size, char const* fmt, s32 num_tokens, va_lis
|
|||||||
{
|
{
|
||||||
sw len = 0;
|
sw len = 0;
|
||||||
|
|
||||||
while ( current && current != '{' && remaining )
|
while ( current && current != '{' && remaining )
|
||||||
{
|
{
|
||||||
*buf = *fmt;
|
*buf = *fmt;
|
||||||
buf++;
|
buf++;
|
||||||
@ -119,7 +119,7 @@ sw token_fmt_va( char* buf, uw buf_size, char const* fmt, s32 num_tokens, va_lis
|
|||||||
}
|
}
|
||||||
|
|
||||||
scanner++;
|
scanner++;
|
||||||
fmt = scanner;
|
fmt = scanner;
|
||||||
current = *fmt;
|
current = *fmt;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
This contians all definitions not directly related to the project.
|
This contians all definitions not directly related to the project.
|
||||||
*/
|
*/
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#ifdef BLOAT_IMPL
|
#ifdef BLOAT_IMPL
|
||||||
# define ZPL_IMPLEMENTATION
|
# define ZPL_IMPLEMENTATION
|
||||||
@ -12,7 +12,7 @@
|
|||||||
|
|
||||||
#pragma region ZPL INCLUDE
|
#pragma region ZPL INCLUDE
|
||||||
#if __clang__
|
#if __clang__
|
||||||
# pragma clang diagnostic push
|
# pragma clang diagnostic push
|
||||||
# pragma clang diagnostic ignored "-Wmissing-braces"
|
# pragma clang diagnostic ignored "-Wmissing-braces"
|
||||||
# pragma clang diagnostic ignored "-Wbraced-scalar-init"
|
# pragma clang diagnostic ignored "-Wbraced-scalar-init"
|
||||||
#endif
|
#endif
|
||||||
@ -46,32 +46,48 @@
|
|||||||
# pragma clang diagnostic ignored "-Wswitch"
|
# pragma clang diagnostic ignored "-Wswitch"
|
||||||
# pragma clang diagnostic ignored "-Wunused-variable"
|
# pragma clang diagnostic ignored "-Wunused-variable"
|
||||||
# pragma clang diagnostic ignored "-Wunknown-pragmas"
|
# pragma clang diagnostic ignored "-Wunknown-pragmas"
|
||||||
|
# pragma clang diagnostic ignored "-Wvarargs"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#if defined(__GNUC__) || defined(__clang__) || 1
|
#if defined(__GNUC__) || defined(__clang__) || true
|
||||||
// Supports 0-10 arguments
|
// Supports 0-10 arguments
|
||||||
#define VA_NARGS_IMPL( _0, \
|
#define macro_num_args_impl( _0, \
|
||||||
_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, \
|
_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, \
|
||||||
_11, _12, _13, _14, _15, _16, _17, _18, _19, _20, \
|
_11, _12, _13, _14, _15, _16, _17, _18, _19, _20, \
|
||||||
_21, _22, _23, _24, _25, _26, _27, _28, _29, _30, \
|
N, ... \
|
||||||
_31, _32, _33, _34, _35, _36, _37, _38, _39, _40, \
|
) N
|
||||||
_41, _42, _43, _44, _45, _46, _47, _48, _49, _50, \
|
// _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, \
|
||||||
N, ...) N
|
// _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, \
|
||||||
// ## deletes preceding comma if _VA_ARGS__ is empty (GCC, Clang)
|
// _41, _42, _43, _44, _45, _46, _47, _48, _49, _50,
|
||||||
#define VA_NARGS(...) VA_NARGS_IMPL(_, ## __VA_ARGS__, \
|
|
||||||
50, 49, 48, 47, 46, 45, 44, 43, 42, 41, \
|
// ## deletes preceding comma if _VA_ARGS__ is empty (GCC, Clang)
|
||||||
40, 39, 38, 37, 36, 35, 34, 33, 32, 31, \
|
#define macro_num_args(...) \
|
||||||
30, 29, 28, 27, 26, 25, 24, 23, 22, 21, \
|
macro_num_args_impl(_, ## __VA_ARGS__, \
|
||||||
20, 19, 18, 17, 16, 15, 14, 13, 12, 11, \
|
20, 19, 18, 17, 16, 15, 14, 13, 12, 11, \
|
||||||
10, 9, 8, 7, 6, 5, 4, 3, 2, 1, \
|
10, 9, 8, 7, 6, 5, 4, 3, 2, 1, \
|
||||||
0)
|
0 \
|
||||||
|
)
|
||||||
|
// 50, 49, 48, 47, 46, 45, 44, 43, 42, 41, \
|
||||||
|
// 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, \
|
||||||
|
// 30, 29, 28, 27, 26, 25, 24, 23, 22, 21,
|
||||||
#else
|
#else
|
||||||
// Supports 1-10 arguments
|
// Supports 1-10 arguments
|
||||||
#define VA_NARGS_IMPL(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, N, ...) N
|
#define macro_num_args_impl( \
|
||||||
#define VA_NARGS(...) VA_NARGS_IMPL(__VA_ARGS__, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1)
|
_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, \
|
||||||
|
_11, _12, _13, _14, _15, _16, _17, _18, _19, _20, \
|
||||||
|
N, ... \
|
||||||
|
) N
|
||||||
|
|
||||||
|
#define macro_num_args(...) \
|
||||||
|
macro_num_args_impl( __VA_ARGS__, \
|
||||||
|
20, 19, 18, 17, 16, 15, 14, 13, 12, 11, \
|
||||||
|
10, 9, 8, 7, 6, 5, 4, 3, 2, 1 \
|
||||||
|
)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define macro_expand( Expanded_ ) Expanded_
|
||||||
|
|
||||||
#define bit( Value_ ) ( 1 << Value_ )
|
#define bit( Value_ ) ( 1 << Value_ )
|
||||||
#define bitfield_is_equal( Field_, Mask_ ) ( ( (Mask_) & (Field_) ) == (Mask_) )
|
#define bitfield_is_equal( Field_, Mask_ ) ( ( (Mask_) & (Field_) ) == (Mask_) )
|
||||||
#define ct constexpr
|
#define ct constexpr
|
||||||
@ -83,8 +99,7 @@
|
|||||||
#define pcast( Type_, Value_ ) ( * (Type_*)( & (Value_) ) )
|
#define pcast( Type_, Value_ ) ( * (Type_*)( & (Value_) ) )
|
||||||
#define txt_impl( Value_ ) #Value_
|
#define txt_impl( Value_ ) #Value_
|
||||||
#define txt( Value_ ) txt_impl( Value_ )
|
#define txt( Value_ ) txt_impl( Value_ )
|
||||||
#define txt_with_length( Value_ ) txt_impl( Value_ ), sizeof( txt_impl( Value_ ) )
|
#define txt_n_len( Value_ ) sizeof( txt_impl( Value_ ) ), txt_impl( Value_ )
|
||||||
|
|
||||||
#define do_once() \
|
#define do_once() \
|
||||||
do \
|
do \
|
||||||
{ \
|
{ \
|
||||||
@ -136,7 +151,7 @@ sw token_fmt_va( char* buf, uw buf_size, char const* fmt, s32 num_tokens, va_lis
|
|||||||
inline
|
inline
|
||||||
char const* token_fmt( char const* fmt, sw num_tokens, ... )
|
char const* token_fmt( char const* fmt, sw num_tokens, ... )
|
||||||
{
|
{
|
||||||
local_persist thread_local
|
local_persist thread_local
|
||||||
char buf[ZPL_PRINTF_MAXLEN] = { 0 };
|
char buf[ZPL_PRINTF_MAXLEN] = { 0 };
|
||||||
|
|
||||||
va_list va;
|
va_list va;
|
||||||
@ -148,25 +163,25 @@ char const* token_fmt( char const* fmt, sw num_tokens, ... )
|
|||||||
}
|
}
|
||||||
|
|
||||||
inline
|
inline
|
||||||
sw log_fmt(char const *fmt, ...)
|
sw log_fmt(char const *fmt, ...)
|
||||||
{
|
{
|
||||||
if ( Global::ShouldShowDebug == false )
|
if ( Global::ShouldShowDebug == false )
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
sw res;
|
sw res;
|
||||||
va_list va;
|
va_list va;
|
||||||
|
|
||||||
va_start(va, fmt);
|
va_start(va, fmt);
|
||||||
res = zpl_printf_va(fmt, va);
|
res = zpl_printf_va(fmt, va);
|
||||||
va_end(va);
|
va_end(va);
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline
|
inline
|
||||||
sw fatal(char const *fmt, ...)
|
sw fatal(char const *fmt, ...)
|
||||||
{
|
{
|
||||||
local_persist thread_local
|
local_persist thread_local
|
||||||
char buf[ZPL_PRINTF_MAXLEN] = { 0 };
|
char buf[ZPL_PRINTF_MAXLEN] = { 0 };
|
||||||
|
|
||||||
va_list va;
|
va_list va;
|
||||||
|
4
project/Bloat.redef.hpp
Normal file
4
project/Bloat.redef.hpp
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
/*
|
||||||
|
Redefine any macros.
|
||||||
|
Used if you have some code thats getting parsed and don't want it ot get preprocessed.
|
||||||
|
*/
|
420
project/gen.cpp
420
project/gen.cpp
@ -9,22 +9,77 @@ namespace gen
|
|||||||
|
|
||||||
namespace StaticData
|
namespace StaticData
|
||||||
{
|
{
|
||||||
|
#ifndef GEN_CODE_USE_SOA
|
||||||
static array(CodePOD) CodePool = nullptr;
|
static array(CodePOD) CodePool = nullptr;
|
||||||
|
|
||||||
|
#else
|
||||||
|
using DataUnion = union
|
||||||
|
{
|
||||||
|
array(AST*) Entries;
|
||||||
|
string Content;
|
||||||
|
};
|
||||||
|
|
||||||
|
namespace CodePool
|
||||||
|
{
|
||||||
|
array(CodeT) Type;
|
||||||
|
array(bool) Readonly;
|
||||||
|
array(AST*) Parent;
|
||||||
|
array(string) Name;
|
||||||
|
array(string) Comment;
|
||||||
|
array(DataUnion) Data;
|
||||||
|
|
||||||
|
forceinline
|
||||||
|
CodeT& type( sw index )
|
||||||
|
{
|
||||||
|
return Type[index];
|
||||||
|
}
|
||||||
|
|
||||||
|
forceinline
|
||||||
|
bool& readonly( sw index )
|
||||||
|
{
|
||||||
|
return Readonly[index];
|
||||||
|
}
|
||||||
|
|
||||||
|
forceinline
|
||||||
|
AST*& parent( sw index )
|
||||||
|
{
|
||||||
|
return Parent[index];
|
||||||
|
}
|
||||||
|
|
||||||
|
forceinline
|
||||||
|
string& name( sw index )
|
||||||
|
{
|
||||||
|
return Name[index];
|
||||||
|
}
|
||||||
|
|
||||||
|
forceinline
|
||||||
|
string& comment( sw index )
|
||||||
|
{
|
||||||
|
return Comment[index];
|
||||||
|
}
|
||||||
|
|
||||||
|
forceinline
|
||||||
|
DataUnion& data( sw index )
|
||||||
|
{
|
||||||
|
return Data[index];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
static array(arena) StringArenas = nullptr;
|
static array(arena) StringArenas = nullptr;
|
||||||
|
|
||||||
static StringTable StringMap;
|
static StringTable StringMap;
|
||||||
static TypeTable TypeMap;
|
static TypeTable TypeMap;
|
||||||
|
|
||||||
static sw InitSize_CodePool = megabytes(64);
|
static sw InitSize_CodePool = megabytes(64);
|
||||||
static sw InitSize_StringArena = megabytes(32);
|
static sw InitSize_StringArena = megabytes(32);
|
||||||
static sw InitSize_StringTable = megabytes(4);
|
static sw InitSize_StringTable = megabytes(4);
|
||||||
static sw InitSize_TypeTable = megabytes(4);
|
static sw InitSize_TypeTable = megabytes(4);
|
||||||
|
|
||||||
static allocator Allocator_CodePool = zpl_heap();
|
static allocator Allocator_CodePool = heap();
|
||||||
static allocator Allocator_StringArena = zpl_heap();
|
static allocator Allocator_StringArena = heap();
|
||||||
static allocator Allocator_StringTable = zpl_heap();
|
static allocator Allocator_StringTable = heap();
|
||||||
static allocator Allocator_TypeTable = zpl_heap();
|
static allocator Allocator_TypeTable = heap();
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma region CONSTANTS
|
#pragma region CONSTANTS
|
||||||
@ -63,29 +118,50 @@ namespace gen
|
|||||||
{
|
{
|
||||||
using namespace StaticData;
|
using namespace StaticData;
|
||||||
|
|
||||||
|
# ifndef GEN_CODE_USE_SOA
|
||||||
ct CodePOD Invalid = { ECode::Invalid, false, nullptr, nullptr, nullptr, { nullptr } };
|
ct CodePOD Invalid = { ECode::Invalid, false, nullptr, nullptr, nullptr, { nullptr } };
|
||||||
|
|
||||||
array_append( CodePool, Invalid );
|
array_append( CodePool, Invalid );
|
||||||
|
|
||||||
return pcast( Code, array_back( CodePool ));
|
return pcast( Code, array_back( CodePool ));
|
||||||
|
# else
|
||||||
|
|
||||||
|
array_append( CodePool::Type, ECode::Invalid );
|
||||||
|
array_append( CodePool::Readonly, false );
|
||||||
|
array_append( CodePool::Name, nullptr );
|
||||||
|
array_append( CodePool::Comment, nullptr );
|
||||||
|
array_append( CodePool::Data, { nullptr } );
|
||||||
|
|
||||||
|
Code code { array_count( CodePool::Type) - 1 };
|
||||||
|
|
||||||
|
return code;
|
||||||
|
# endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void init()
|
void init()
|
||||||
{
|
{
|
||||||
array_init( StaticData::CodePool, g_allocator );
|
array_init( StaticData::CodePool, StaticData::Allocator_CodePool );
|
||||||
|
array_init( StaticData::StringArenas, heap() );
|
||||||
|
|
||||||
Code&
|
arena string_arena;
|
||||||
InvalidCode_write = ccast( Code, InvalidCode );
|
arena_init_from_allocator( & string_arena, StaticData::Allocator_StringArena, StaticData::InitSize_StringArena );
|
||||||
|
|
||||||
|
str_tbl_init( & StaticData::StringMap, StaticData::Allocator_StringTable );
|
||||||
|
type_tbl_init( & StaticData::TypeMap, StaticData::Allocator_TypeTable );
|
||||||
|
|
||||||
|
Code&
|
||||||
|
InvalidCode_write = ccast( Code, Code::Invalid );
|
||||||
InvalidCode_write = make_code();
|
InvalidCode_write = make_code();
|
||||||
|
|
||||||
#ifdef GEN_DEFINE_LIBRARY_CODE_CONSTANTS
|
#ifdef GEN_DEFINE_LIBRARY_CODE_CONSTANTS
|
||||||
Code&
|
Code&
|
||||||
t_bool_write = ccast( Code, t_void );
|
t_bool_write = ccast( Code, t_void );
|
||||||
t_bool_write = def_type( txt(void) );
|
t_bool_write = def_type( txt(void) );
|
||||||
|
|
||||||
# define def_constant_code_type( Type_ ) \
|
# define def_constant_code_type( Type_ ) \
|
||||||
Code& \
|
Code& \
|
||||||
t_##Type_ = def_type( txt(Type_) )
|
t_##Type_ = def_type( txt(Type_) ); \
|
||||||
|
t_##Type_.lock()
|
||||||
|
|
||||||
def_constant_code_type( bool );
|
def_constant_code_type( bool );
|
||||||
def_constant_code_type( char );
|
def_constant_code_type( char );
|
||||||
@ -106,23 +182,21 @@ namespace gen
|
|||||||
|
|
||||||
def_constant_code_type( f32 );
|
def_constant_code_type( f32 );
|
||||||
def_constant_code_type( f64 );
|
def_constant_code_type( f64 );
|
||||||
|
|
||||||
# undef def_constant_code_type
|
# undef def_constant_code_type
|
||||||
|
#endif
|
||||||
|
|
||||||
Code&
|
Code&
|
||||||
spec_constexpr_write = ccast( Code, spec_constexpr );
|
spec_constexpr_write = ccast( Code, spec_constexpr );
|
||||||
spec_constexpr_write = def_specifiers( 1, ESpecifier::Constexpr );
|
spec_constexpr_write = def_specifiers( 1, ESpecifier::Constexpr );
|
||||||
|
|
||||||
# define def_constant_spec( Type_, ... ) \
|
# define def_constant_spec( Type_, ... ) \
|
||||||
Code& \
|
Code& \
|
||||||
spec_##Type_##_write = ccast( Code, spec_##Type_ ); \
|
spec_##Type_ = def_specifiers( macro_num_args(__VA_ARGS__), __VA_ARGS__); \
|
||||||
spec_##Type_##_write = def_specifiers( VA_NARGS(__VA_ARGS__), __VA_ARGS__)
|
spec_##Type_.lock();
|
||||||
|
|
||||||
|
def_constant_spec( const, ESpecifier::Const );
|
||||||
def_constant_spec( inline, ESpecifier::Inline );
|
def_constant_spec( inline, ESpecifier::Inline );
|
||||||
|
|
||||||
# undef def_constant_spec
|
# undef def_constant_spec
|
||||||
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void clear_code_pool()
|
void clear_code_pool()
|
||||||
@ -211,70 +285,11 @@ namespace gen
|
|||||||
}
|
}
|
||||||
|
|
||||||
# pragma region Upfront Constructors
|
# pragma region Upfront Constructors
|
||||||
Code def_params( s32 num, ... )
|
Code def_function( char const* name
|
||||||
{
|
|
||||||
using namespace ECode;
|
|
||||||
|
|
||||||
if (num <= 0)
|
|
||||||
{
|
|
||||||
log_failure( "TT::make_paramters: num cannot be zero or neg" );
|
|
||||||
return InvalidCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
Code
|
|
||||||
result = make_code();
|
|
||||||
result->Type = Parameters;
|
|
||||||
|
|
||||||
va_list va;
|
|
||||||
va_start(va, num);
|
|
||||||
|
|
||||||
result->Name = string_make( g_allocator, va_arg(va, char const*) );
|
|
||||||
|
|
||||||
array_init( result->Entries, g_allocator );
|
|
||||||
|
|
||||||
Code type = va_arg(va, Code);
|
|
||||||
|
|
||||||
if ( type->Type != Typename )
|
|
||||||
{
|
|
||||||
log_failure( "gen::def_parameters: type of param %d is not a Typename", num - num + 1 );
|
|
||||||
return InvalidCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
result->add( type );
|
|
||||||
|
|
||||||
while( num -= 2, num && num % 2 == 0 )
|
|
||||||
{
|
|
||||||
type = va_arg(va, Code);
|
|
||||||
|
|
||||||
Code
|
|
||||||
param = make_code();
|
|
||||||
param->Type = Parameters;
|
|
||||||
param->Name = string_make( g_allocator, va_arg(va, char const*) );
|
|
||||||
|
|
||||||
array_init( param->Entries, g_allocator );
|
|
||||||
|
|
||||||
if ( type->Type != Typename )
|
|
||||||
{
|
|
||||||
log_failure( "gen::def_parameters: type of param %d is not a Typename", num - num + 1 );
|
|
||||||
return InvalidCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
param->add( type );
|
|
||||||
param.lock();
|
|
||||||
|
|
||||||
result->add(param);
|
|
||||||
}
|
|
||||||
va_end(va);
|
|
||||||
|
|
||||||
result.lock();
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
Code def_proc( char const* name
|
|
||||||
, Code specifiers
|
, Code specifiers
|
||||||
, Code params
|
, Code params
|
||||||
, Code ret_type
|
, Code ret_type
|
||||||
, Code body
|
, Code body
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
using namespace ECode;
|
using namespace ECode;
|
||||||
@ -282,40 +297,42 @@ namespace gen
|
|||||||
if ( specifiers && specifiers->Type != Specifiers )
|
if ( specifiers && specifiers->Type != Specifiers )
|
||||||
{
|
{
|
||||||
log_failure( "gen::def_function: specifiers was not a `Specifiers` type" );
|
log_failure( "gen::def_function: specifiers was not a `Specifiers` type" );
|
||||||
return InvalidCode;
|
return Code::Invalid;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( params && params->Type != Parameters )
|
if ( params && params->Type != Parameters )
|
||||||
{
|
{
|
||||||
log_failure( "gen::def_function: params was not a `Parameters` type" );
|
log_failure( "gen::def_function: params was not a `Parameters` type" );
|
||||||
return InvalidCode;
|
return Code::Invalid;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ret_type == nullptr || ret_type->Type != Typename )
|
if ( ret_type == nullptr || ret_type->Type != Typename )
|
||||||
{
|
{
|
||||||
log_failure( "gen::def_function: ret_type was not a Typename" );
|
log_failure( "gen::def_function: ret_type was not a Typename" );
|
||||||
return InvalidCode;
|
return Code::Invalid;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch ( body->Type )
|
switch ( body->Type )
|
||||||
{
|
{
|
||||||
case Proc_Body:
|
case Function_Body:
|
||||||
case Untyped:
|
case Untyped:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
log_failure("gen::def_function: body must be either of Function_Body or Untyped type.");
|
log_failure("gen::def_function: body must be either of Function_Body or Untyped type.");
|
||||||
return InvalidCode;
|
return Code::Invalid;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Code
|
s32 name_length = zpl_strnlen( name, MaxNameLength );
|
||||||
|
|
||||||
|
Code
|
||||||
result = make_code();
|
result = make_code();
|
||||||
result->Name = string_make( g_allocator, name );
|
result->Name = code_string( name, name_length );
|
||||||
result->Type = Proc;
|
result->Type = Function;
|
||||||
|
|
||||||
array_init( result->Entries, g_allocator );
|
array_init( result->Entries, StaticData::Allocator_CodePool );
|
||||||
|
|
||||||
result->add( body );
|
result->add( body );
|
||||||
|
|
||||||
@ -331,14 +348,14 @@ namespace gen
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
Code def_proc_body( s32 num, ... )
|
Code def_function_body( s32 num, ... )
|
||||||
{
|
{
|
||||||
using namespace ECode;
|
using namespace ECode;
|
||||||
|
|
||||||
if ( num <= 0 )
|
if ( num <= 0 )
|
||||||
{
|
{
|
||||||
log_failure("gen::def_function_body: num cannot zero or neg");
|
log_failure("gen::def_function_body: num cannot zero or neg");
|
||||||
return InvalidCode;
|
return Code::Invalid;
|
||||||
}
|
}
|
||||||
|
|
||||||
Code result = make_code();
|
Code result = make_code();
|
||||||
@ -354,12 +371,12 @@ namespace gen
|
|||||||
if ( ! entry )
|
if ( ! entry )
|
||||||
{
|
{
|
||||||
log_failure("gen::def_function_body: Provided an invalid entry!");
|
log_failure("gen::def_function_body: Provided an invalid entry!");
|
||||||
return InvalidCode;
|
return Code::Invalid;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch ( entry->Type )
|
switch ( entry->Type )
|
||||||
{
|
{
|
||||||
case Proc_Forward:
|
case Function_Forward:
|
||||||
case Namespace:
|
case Namespace:
|
||||||
case Namespace_Body:
|
case Namespace_Body:
|
||||||
case Parameters:
|
case Parameters:
|
||||||
@ -368,7 +385,7 @@ namespace gen
|
|||||||
case Typename:
|
case Typename:
|
||||||
{
|
{
|
||||||
log_failure("gen::def_function_body: Entry type is not allowed: %s", entry->type_str() );
|
log_failure("gen::def_function_body: Entry type is not allowed: %s", entry->type_str() );
|
||||||
return InvalidCode;
|
return Code::Invalid;
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@ -376,27 +393,27 @@ namespace gen
|
|||||||
}
|
}
|
||||||
|
|
||||||
result->add( entry );
|
result->add( entry );
|
||||||
}
|
}
|
||||||
while ( num--, num > 0 );
|
while ( num--, num > 0 );
|
||||||
va_end(va);
|
va_end(va);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
Code def_proc_body( s32 num, Code* codes )
|
Code def_function_body( s32 num, Code* codes )
|
||||||
{
|
{
|
||||||
using namespace ECode;
|
using namespace ECode;
|
||||||
|
|
||||||
if ( num <= 0 )
|
if ( num <= 0 )
|
||||||
{
|
{
|
||||||
log_failure("gen::def_function_body: num cannot zero or neg");
|
log_failure("gen::def_function_body: num cannot zero or neg");
|
||||||
return InvalidCode;
|
return Code::Invalid;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( codes == nullptr )
|
if ( codes == nullptr )
|
||||||
{
|
{
|
||||||
log_failure("gen::def_function_body: Provided a null array of codes!");
|
log_failure("gen::def_function_body: Provided a null array of codes!");
|
||||||
return InvalidCode;
|
return Code::Invalid;
|
||||||
}
|
}
|
||||||
|
|
||||||
Code result = make_code();
|
Code result = make_code();
|
||||||
@ -409,12 +426,12 @@ namespace gen
|
|||||||
if ( ! entry )
|
if ( ! entry )
|
||||||
{
|
{
|
||||||
log_failure("gen::def_function_body: Provided an invalid entry!");
|
log_failure("gen::def_function_body: Provided an invalid entry!");
|
||||||
return InvalidCode;
|
return Code::Invalid;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch ( entry->Type )
|
switch ( entry->Type )
|
||||||
{
|
{
|
||||||
case Proc_Forward:
|
case Function_Forward:
|
||||||
case Namespace:
|
case Namespace:
|
||||||
case Namespace_Body:
|
case Namespace_Body:
|
||||||
case Parameters:
|
case Parameters:
|
||||||
@ -423,7 +440,7 @@ namespace gen
|
|||||||
case Typename:
|
case Typename:
|
||||||
{
|
{
|
||||||
log_failure("gen::def_function_body: Entry type is not allowed: %s", entry->type_str() );
|
log_failure("gen::def_function_body: Entry type is not allowed: %s", entry->type_str() );
|
||||||
return InvalidCode;
|
return Code::Invalid;
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@ -431,17 +448,83 @@ namespace gen
|
|||||||
}
|
}
|
||||||
|
|
||||||
result->add( entry );
|
result->add( entry );
|
||||||
}
|
}
|
||||||
while ( num--, num > 0 );
|
while ( num--, num > 0 );
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Code def_params( s32 num, ... )
|
||||||
|
{
|
||||||
|
using namespace ECode;
|
||||||
|
|
||||||
|
if (num <= 0)
|
||||||
|
{
|
||||||
|
log_failure( "TT::make_paramters: num cannot be zero or neg" );
|
||||||
|
return Code::Invalid;
|
||||||
|
}
|
||||||
|
|
||||||
|
Code
|
||||||
|
result = make_code();
|
||||||
|
result->Type = Parameters;
|
||||||
|
|
||||||
|
va_list va;
|
||||||
|
va_start(va, num);
|
||||||
|
|
||||||
|
Code type = va_arg(va, Code);
|
||||||
|
|
||||||
|
char const* name = va_arg(va, char const*);
|
||||||
|
s32 name_length = zpl_strnlen(name, MaxNameLength);
|
||||||
|
|
||||||
|
result->Name = code_string( name, name_length );
|
||||||
|
|
||||||
|
array_init( result->Entries, g_allocator );
|
||||||
|
|
||||||
|
if ( type->Type != Typename )
|
||||||
|
{
|
||||||
|
log_failure( "gen::def_parameters: type of param %d is not a Typename", num - num + 1 );
|
||||||
|
return Code::Invalid;
|
||||||
|
}
|
||||||
|
|
||||||
|
result->add( type );
|
||||||
|
|
||||||
|
while( num -= 2, num && num % 2 == 0 )
|
||||||
|
{
|
||||||
|
type = va_arg(va, Code);
|
||||||
|
|
||||||
|
name = va_arg(va, char const*);
|
||||||
|
name_length = zpl_strnlen(name, MaxNameLength);
|
||||||
|
|
||||||
|
Code
|
||||||
|
param = make_code();
|
||||||
|
param->Type = Parameters;
|
||||||
|
param->Name = code_string(name, name_length);
|
||||||
|
|
||||||
|
array_init( param->Entries, StaticData::Allocator_CodePool );
|
||||||
|
|
||||||
|
if ( type->Type != Typename )
|
||||||
|
{
|
||||||
|
log_failure( "gen::def_parameters: type of param %d is not a Typename", num - num + 1 );
|
||||||
|
return Code::Invalid;
|
||||||
|
}
|
||||||
|
|
||||||
|
param->add( type );
|
||||||
|
param.lock();
|
||||||
|
|
||||||
|
result->add(param);
|
||||||
|
}
|
||||||
|
va_end(va);
|
||||||
|
|
||||||
|
result.lock();
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Code def_namespace( char const* name, Code body )
|
Code def_namespace( char const* name, Code body )
|
||||||
{
|
{
|
||||||
using namespace ECode;
|
using namespace ECode;
|
||||||
|
|
||||||
Code
|
Code
|
||||||
result = make_code();
|
result = make_code();
|
||||||
result->Type = Namespace;
|
result->Type = Namespace;
|
||||||
|
|
||||||
@ -450,7 +533,7 @@ namespace gen
|
|||||||
if ( body->Type != Namespace_Body || body->Type != Untyped )
|
if ( body->Type != Namespace_Body || body->Type != Untyped )
|
||||||
{
|
{
|
||||||
log_failure("gen::def_namespace: body is not of namespace or untyped type");
|
log_failure("gen::def_namespace: body is not of namespace or untyped type");
|
||||||
return InvalidCode;
|
return Code::Invalid;
|
||||||
}
|
}
|
||||||
|
|
||||||
result->add( body );
|
result->add( body );
|
||||||
@ -465,7 +548,7 @@ namespace gen
|
|||||||
if ( num <= 0 )
|
if ( num <= 0 )
|
||||||
{
|
{
|
||||||
log_failure("gen::make_specifier: num cannot be zero or less");
|
log_failure("gen::make_specifier: num cannot be zero or less");
|
||||||
return InvalidCode;
|
return Code::Invalid;
|
||||||
}
|
}
|
||||||
|
|
||||||
Code
|
Code
|
||||||
@ -477,7 +560,7 @@ namespace gen
|
|||||||
do
|
do
|
||||||
{
|
{
|
||||||
Code entry = va_arg(va, Code);
|
Code entry = va_arg(va, Code);
|
||||||
|
|
||||||
switch ( entry->Type )
|
switch ( entry->Type )
|
||||||
{
|
{
|
||||||
case Namespace_Body:
|
case Namespace_Body:
|
||||||
@ -486,14 +569,14 @@ namespace gen
|
|||||||
case Struct_Body:
|
case Struct_Body:
|
||||||
case Typename:
|
case Typename:
|
||||||
log_failure("gen::def_function_body: Entry type is not allowed: %s", ECode::str(entry->Type) );
|
log_failure("gen::def_function_body: Entry type is not allowed: %s", ECode::str(entry->Type) );
|
||||||
return InvalidCode;
|
return Code::Invalid;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
result->add( entry );
|
result->add( entry );
|
||||||
}
|
}
|
||||||
while ( num--, num > 0 );
|
while ( num--, num > 0 );
|
||||||
va_end(va);
|
va_end(va);
|
||||||
|
|
||||||
@ -505,7 +588,7 @@ namespace gen
|
|||||||
if ( num <= 0 )
|
if ( num <= 0 )
|
||||||
fatal("gen::make_specifier: num cannot be zero or less");
|
fatal("gen::make_specifier: num cannot be zero or less");
|
||||||
|
|
||||||
Code
|
Code
|
||||||
result = make_code();
|
result = make_code();
|
||||||
result->Type = ECode::Specifiers;
|
result->Type = ECode::Specifiers;
|
||||||
result->Content = string_make( g_allocator, "" );
|
result->Content = string_make( g_allocator, "" );
|
||||||
@ -542,19 +625,19 @@ namespace gen
|
|||||||
if ( specifiers && specifiers->Type != Specifiers )
|
if ( specifiers && specifiers->Type != Specifiers )
|
||||||
{
|
{
|
||||||
log_failure( "gen::def_struct: specifiers was not a `Specifiers` type" );
|
log_failure( "gen::def_struct: specifiers was not a `Specifiers` type" );
|
||||||
return InvalidCode;
|
return Code::Invalid;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( parent && parent->Type != Struct )
|
if ( parent && parent->Type != Struct )
|
||||||
{
|
{
|
||||||
log_failure( "gen::def_struct: parent was not a `Struct` type" );
|
log_failure( "gen::def_struct: parent was not a `Struct` type" );
|
||||||
return InvalidCode;
|
return Code::Invalid;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( body && body->Type != Struct_Body )
|
if ( body && body->Type != Struct_Body )
|
||||||
{
|
{
|
||||||
log_failure( "gen::def_struct: body was not a Struct_Body type" );
|
log_failure( "gen::def_struct: body was not a Struct_Body type" );
|
||||||
return InvalidCode;
|
return Code::Invalid;
|
||||||
}
|
}
|
||||||
|
|
||||||
Code
|
Code
|
||||||
@ -583,7 +666,7 @@ namespace gen
|
|||||||
if ( num == 0 )
|
if ( num == 0 )
|
||||||
{
|
{
|
||||||
log_failure("gen::def_struct_body: num cannot be zero");
|
log_failure("gen::def_struct_body: num cannot be zero");
|
||||||
return InvalidCode;
|
return Code::Invalid;
|
||||||
}
|
}
|
||||||
|
|
||||||
Code result = make_code();
|
Code result = make_code();
|
||||||
@ -606,15 +689,15 @@ namespace gen
|
|||||||
case Typename:
|
case Typename:
|
||||||
{
|
{
|
||||||
log_failure("gen::def_struct_body: Entry type is not allowed: %s", ECode::str(entry->Type) );
|
log_failure("gen::def_struct_body: Entry type is not allowed: %s", ECode::str(entry->Type) );
|
||||||
return InvalidCode;
|
return Code::Invalid;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
result->add( entry );
|
result->add( entry );
|
||||||
}
|
}
|
||||||
while ( num--, num > 0 );
|
while ( num--, num > 0 );
|
||||||
va_end(va);
|
va_end(va);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -623,26 +706,26 @@ namespace gen
|
|||||||
if ( specifiers && specifiers->Type != ECode::Specifiers )
|
if ( specifiers && specifiers->Type != ECode::Specifiers )
|
||||||
{
|
{
|
||||||
log_failure( "gen::def_variable: specifiers was not a `Specifiers` type" );
|
log_failure( "gen::def_variable: specifiers was not a `Specifiers` type" );
|
||||||
return InvalidCode;
|
return Code::Invalid;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( type->Type != ECode::Typename )
|
if ( type->Type != ECode::Typename )
|
||||||
{
|
{
|
||||||
log_failure( "gen::def_variable: type was not a Typename" );
|
log_failure( "gen::def_variable: type was not a Typename" );
|
||||||
return InvalidCode;
|
return Code::Invalid;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( value && value->Type != ECode::Untyped )
|
if ( value && value->Type != ECode::Untyped )
|
||||||
{
|
{
|
||||||
log_failure( "gen::def_variable: value was not a `Untyped` type" );
|
log_failure( "gen::def_variable: value was not a `Untyped` type" );
|
||||||
return InvalidCode;
|
return Code::Invalid;
|
||||||
}
|
}
|
||||||
|
|
||||||
Code
|
Code
|
||||||
result = make_code();
|
result = make_code();
|
||||||
result->Name = string_make( g_allocator, name );
|
result->Name = string_make( g_allocator, name );
|
||||||
result->Type = ECode::Variable;
|
result->Type = ECode::Variable;
|
||||||
|
|
||||||
array_init( result->Entries, g_allocator );
|
array_init( result->Entries, g_allocator );
|
||||||
|
|
||||||
if ( specifiers )
|
if ( specifiers )
|
||||||
@ -658,7 +741,7 @@ namespace gen
|
|||||||
|
|
||||||
Code def_type( char const* name, Code specifiers )
|
Code def_type( char const* name, Code specifiers )
|
||||||
{
|
{
|
||||||
Code
|
Code
|
||||||
result = make_code();
|
result = make_code();
|
||||||
result->Name = string_make( g_allocator, name );
|
result->Name = string_make( g_allocator, name );
|
||||||
result->Type = ECode::Typename;
|
result->Type = ECode::Typename;
|
||||||
@ -683,7 +766,7 @@ namespace gen
|
|||||||
# pragma endregion Upfront Constructors
|
# pragma endregion Upfront Constructors
|
||||||
|
|
||||||
# pragma region Incremetnal Constructors
|
# pragma region Incremetnal Constructors
|
||||||
Code make_proc( char const* name
|
Code make_function( char const* name
|
||||||
, Code specifiers
|
, Code specifiers
|
||||||
, Code params
|
, Code params
|
||||||
, Code ret_type
|
, Code ret_type
|
||||||
@ -694,26 +777,26 @@ namespace gen
|
|||||||
if ( specifiers && specifiers->Type != Specifiers )
|
if ( specifiers && specifiers->Type != Specifiers )
|
||||||
{
|
{
|
||||||
log_failure( "gen::def_function: specifiers was not a `Specifiers` type" );
|
log_failure( "gen::def_function: specifiers was not a `Specifiers` type" );
|
||||||
return InvalidCode;
|
return Code::Invalid;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( params && params->Type != Parameters )
|
if ( params && params->Type != Parameters )
|
||||||
{
|
{
|
||||||
log_failure( "gen::def_function: params was not a `Parameters` type" );
|
log_failure( "gen::def_function: params was not a `Parameters` type" );
|
||||||
return InvalidCode;
|
return Code::Invalid;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ret_type == nullptr || ret_type->Type != Typename )
|
if ( ret_type == nullptr || ret_type->Type != Typename )
|
||||||
{
|
{
|
||||||
log_failure( "gen::def_function: ret_type was not a Typename" );
|
log_failure( "gen::def_function: ret_type was not a Typename" );
|
||||||
return InvalidCode;
|
return Code::Invalid;
|
||||||
}
|
}
|
||||||
|
|
||||||
Code
|
Code
|
||||||
result = make_code();
|
result = make_code();
|
||||||
result->Name = string_make( g_allocator, name );
|
result->Name = string_make( g_allocator, name );
|
||||||
result->Type = Proc;
|
result->Type = Function;
|
||||||
|
|
||||||
array_init( result->Entries, g_allocator );
|
array_init( result->Entries, g_allocator );
|
||||||
|
|
||||||
// Making body at entry 0.
|
// Making body at entry 0.
|
||||||
@ -731,20 +814,20 @@ namespace gen
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
Code make_struct( char const* name, Code parent = UnusedCode, Code specifiers = UnusedCode )
|
Code make_struct( char const* name, Code parent, Code specifiers )
|
||||||
{
|
{
|
||||||
using namespace ECode;
|
using namespace ECode;
|
||||||
|
|
||||||
if ( specifiers && specifiers->Type != Specifiers )
|
if ( specifiers && specifiers->Type != Specifiers )
|
||||||
{
|
{
|
||||||
log_failure( "gen::def_struct: specifiers was not a `Specifiers` type" );
|
log_failure( "gen::def_struct: specifiers was not a `Specifiers` type" );
|
||||||
return InvalidCode;
|
return Code::Invalid;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( parent && parent->Type != Struct )
|
if ( parent && parent->Type != Struct )
|
||||||
{
|
{
|
||||||
log_failure( "gen::def_struct: parent was not a `Struct` type" );
|
log_failure( "gen::def_struct: parent was not a `Struct` type" );
|
||||||
return InvalidCode;
|
return Code::Invalid;
|
||||||
}
|
}
|
||||||
|
|
||||||
Code
|
Code
|
||||||
@ -788,7 +871,7 @@ namespace gen
|
|||||||
if ( def == nullptr )
|
if ( def == nullptr )
|
||||||
{
|
{
|
||||||
log_failure("gen::parse_proc: def is null!");
|
log_failure("gen::parse_proc: def is null!");
|
||||||
return InvalidCode;
|
return Code::Invalid;
|
||||||
}
|
}
|
||||||
|
|
||||||
arena mem;
|
arena mem;
|
||||||
@ -806,13 +889,13 @@ namespace gen
|
|||||||
// Making all significant tokens have a max length of 128 for this parser.
|
// Making all significant tokens have a max length of 128 for this parser.
|
||||||
ct sw LengthID = 128;
|
ct sw LengthID = 128;
|
||||||
|
|
||||||
struct Param
|
struct Param
|
||||||
{
|
{
|
||||||
char const Type[LengthID];
|
char const Type[LengthID];
|
||||||
char const Name[LengthID];
|
char const Name[LengthID];
|
||||||
};
|
};
|
||||||
|
|
||||||
static
|
static
|
||||||
Param Params[ 64 ] { 0 };
|
Param Params[ 64 ] { 0 };
|
||||||
|
|
||||||
// Zero out params before a run of this func.
|
// Zero out params before a run of this func.
|
||||||
@ -848,7 +931,7 @@ namespace gen
|
|||||||
|
|
||||||
s32 length = 0;
|
s32 length = 0;
|
||||||
char const* spec_or_type = scanner;
|
char const* spec_or_type = scanner;
|
||||||
|
|
||||||
while ( char_is_alpha( * scanner) || * scanner == '_')
|
while ( char_is_alpha( * scanner) || * scanner == '_')
|
||||||
{
|
{
|
||||||
length++;
|
length++;
|
||||||
@ -870,7 +953,7 @@ namespace gen
|
|||||||
ret_length = length;
|
ret_length = length;
|
||||||
scanner++;
|
scanner++;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
while( left );
|
while( left );
|
||||||
|
|
||||||
SkipWhitespace();
|
SkipWhitespace();
|
||||||
@ -887,13 +970,13 @@ namespace gen
|
|||||||
|
|
||||||
// Parameters
|
// Parameters
|
||||||
SkipWhitespace();
|
SkipWhitespace();
|
||||||
|
|
||||||
if ( * scanner != '(' )
|
if ( * scanner != '(' )
|
||||||
{
|
{
|
||||||
log_failure("gen::parse_proc: Error, expected a ( in %s", string_make_length( g_allocator, scanner - 4, 100) );
|
log_failure("gen::parse_proc: Error, expected a ( in %s", string_make_length( g_allocator, scanner - 4, 100) );
|
||||||
return InvalidCode;
|
return Code::Invalid;
|
||||||
}
|
}
|
||||||
|
|
||||||
scanner++;
|
scanner++;
|
||||||
|
|
||||||
do
|
do
|
||||||
@ -909,7 +992,7 @@ namespace gen
|
|||||||
|
|
||||||
// get end specifiers
|
// get end specifiers
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if ( * scanner != '{')
|
if ( * scanner != '{')
|
||||||
@ -919,16 +1002,16 @@ namespace gen
|
|||||||
}
|
}
|
||||||
|
|
||||||
Code specifiers = def_specifiers( num_specifiers, specs_found );
|
Code specifiers = def_specifiers( num_specifiers, specs_found );
|
||||||
|
|
||||||
Code params = make_code();
|
Code params = make_code();
|
||||||
Code ret_type = def_type( ret_type_str );
|
Code ret_type = def_type( ret_type_str );
|
||||||
Code body = untyped_str( body_str, body_length );
|
Code body = untyped_str( body_length, body_str );
|
||||||
|
|
||||||
Code
|
Code
|
||||||
result = make_code();
|
result = make_code();
|
||||||
result->Name = string_make( g_allocator, name );
|
result->Name = string_make( g_allocator, name );
|
||||||
result->Type = ECode::Proc;
|
result->Type = ECode::Function;
|
||||||
|
|
||||||
array_init( result->Entries, g_allocator );
|
array_init( result->Entries, g_allocator );
|
||||||
|
|
||||||
result->add( body );
|
result->add( body );
|
||||||
@ -970,7 +1053,7 @@ namespace gen
|
|||||||
# pragma region Untyped Constructors
|
# pragma region Untyped Constructors
|
||||||
Code untyped_str(char const* fmt)
|
Code untyped_str(char const* fmt)
|
||||||
{
|
{
|
||||||
Code
|
Code
|
||||||
result = make_code();
|
result = make_code();
|
||||||
result->Name = string_make( g_allocator, fmt );
|
result->Name = string_make( g_allocator, fmt );
|
||||||
result->Type = ECode::Untyped;
|
result->Type = ECode::Untyped;
|
||||||
@ -981,15 +1064,15 @@ namespace gen
|
|||||||
|
|
||||||
Code untyped_fmt(char const* fmt, ...)
|
Code untyped_fmt(char const* fmt, ...)
|
||||||
{
|
{
|
||||||
local_persist thread_local
|
local_persist thread_local
|
||||||
char buf[ZPL_PRINTF_MAXLEN] = { 0 };
|
char buf[ZPL_PRINTF_MAXLEN] = { 0 };
|
||||||
|
|
||||||
va_list va;
|
va_list va;
|
||||||
va_start(va, fmt);
|
va_start(va, fmt);
|
||||||
zpl_snprintf_va(buf, ZPL_PRINTF_MAXLEN, fmt, va);
|
zpl_snprintf_va(buf, ZPL_PRINTF_MAXLEN, fmt, va);
|
||||||
va_end(va);
|
va_end(va);
|
||||||
|
|
||||||
Code
|
Code
|
||||||
result = make_code();
|
result = make_code();
|
||||||
result->Name = string_make( g_allocator, fmt );
|
result->Name = string_make( g_allocator, fmt );
|
||||||
result->Type = ECode::Untyped;
|
result->Type = ECode::Untyped;
|
||||||
@ -1000,7 +1083,7 @@ namespace gen
|
|||||||
|
|
||||||
Code untyped_token_fmt( char const* fmt, s32 num_tokens, ... )
|
Code untyped_token_fmt( char const* fmt, s32 num_tokens, ... )
|
||||||
{
|
{
|
||||||
local_persist thread_local
|
local_persist thread_local
|
||||||
char buf[ZPL_PRINTF_MAXLEN] = { 0 };
|
char buf[ZPL_PRINTF_MAXLEN] = { 0 };
|
||||||
|
|
||||||
va_list va;
|
va_list va;
|
||||||
@ -1033,13 +1116,13 @@ namespace gen
|
|||||||
case Global_Body:
|
case Global_Body:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Proc:
|
case Function:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Proc_Body:
|
case Function_Body:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Proc_Forward:
|
case Function_Forward:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Namespace:
|
case Namespace:
|
||||||
@ -1103,7 +1186,7 @@ namespace gen
|
|||||||
result = string_append_length( result, Content, string_length(Content) );
|
result = string_append_length( result, Content, string_length(Content) );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Proc_Forward:
|
case Function_Forward:
|
||||||
{
|
{
|
||||||
u32 index = 0;
|
u32 index = 0;
|
||||||
u32 left = array_count( Entries );
|
u32 left = array_count( Entries );
|
||||||
@ -1136,7 +1219,7 @@ namespace gen
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Proc:
|
case Function:
|
||||||
{
|
{
|
||||||
u32 index = 0;
|
u32 index = 0;
|
||||||
u32 left = array_count( Entries );
|
u32 left = array_count( Entries );
|
||||||
@ -1169,7 +1252,7 @@ namespace gen
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Proc_Body:
|
case Function_Body:
|
||||||
fatal("NOT SUPPORTED YET");
|
fatal("NOT SUPPORTED YET");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -1181,7 +1264,7 @@ namespace gen
|
|||||||
fatal("NOT SUPPORTED YET");
|
fatal("NOT SUPPORTED YET");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Parameters:
|
case Parameters:
|
||||||
{
|
{
|
||||||
result = string_append_fmt( result, "%s %s", Entries[0]->to_string(), Name );
|
result = string_append_fmt( result, "%s %s", Entries[0]->to_string(), Name );
|
||||||
|
|
||||||
@ -1191,7 +1274,7 @@ namespace gen
|
|||||||
while ( left--, left > 0 )
|
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
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -1227,9 +1310,12 @@ namespace gen
|
|||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const Code Code::Invalid;
|
||||||
# pragma endregion AST
|
# pragma endregion AST
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# pragma region Builder
|
# pragma region Builder
|
||||||
void Builder::print( Code code )
|
void Builder::print( Code code )
|
||||||
{
|
{
|
||||||
@ -1247,7 +1333,7 @@ namespace gen
|
|||||||
}
|
}
|
||||||
|
|
||||||
Buffer = string_make( g_allocator, "" );
|
Buffer = string_make( g_allocator, "" );
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
557
project/gen.hpp
557
project/gen.hpp
@ -1,18 +1,21 @@
|
|||||||
/*
|
/*
|
||||||
gencpp: A simple staged metaprogramming library for C++.
|
gencpp: A simple staged metaprogramming library for C++.
|
||||||
|
|
||||||
|
The library is mostly a compositon of code element constructors.
|
||||||
|
These build up a code AST to then serialize with a file builder.
|
||||||
|
|
||||||
This library is intended for small-to midsize projects.
|
This library is intended for small-to midsize projects.
|
||||||
|
|
||||||
AST type checking supports only a small subset of c++.
|
AST type checking supports only a small subset of c++.
|
||||||
See the 'ECode' namespace and 'gen API' region to see what is supported.
|
See the 'ECode' namespace and 'gen API' region to see what is supported.
|
||||||
|
|
||||||
### *WHAT IS NOT PROVIDED*
|
### *WHAT IS NOT PROVIDED*
|
||||||
|
|
||||||
* Macro or template generation : This library is to avoid those, adding support for them adds unnecessary complexity.
|
* Macro or template generation : This library is to avoid those, adding support for them adds unnecessary complexity.
|
||||||
If you desire define them outside the gen_time scopes.
|
If you desire define them outside the gen_time scopes.
|
||||||
* Expression validation : Execution expressions are defined using the untyped string API.
|
* Expression validation : Execution expressions are defined using the untyped string API.
|
||||||
There is no parse API for validating expression (possibly will add in the future)
|
There is no parse API for validating expression (possibly will add in the future)
|
||||||
* Complete file parser DSL : This isn't like the unreal header tool.
|
* Complete file parser DSL : This isn't like the unreal header tool.
|
||||||
Code injection to file or based off a file contents is not supported by the api. However nothing is stopping you using the library for that purpose.
|
Code injection to file or based off a file contents is not supported by the api. However nothing is stopping you using the library for that purpose.
|
||||||
* Modern c++ (STL library) features
|
* Modern c++ (STL library) features
|
||||||
|
|
||||||
@ -21,17 +24,17 @@
|
|||||||
Notes:
|
Notes:
|
||||||
|
|
||||||
* The allocator definitions used are exposed to the user incase they want to dictate memory usage
|
* The allocator definitions used are exposed to the user incase they want to dictate memory usage
|
||||||
* ASTs are wrapped for the user in a Code struct which essentially a warpper for a AST* type.
|
* ASTs are wrapped for the user in a Code struct which essentially a warpper for a AST* type.
|
||||||
* Both AST and Code have member symbols but their data layout is enforced to be POD types.
|
* Both AST and Code have member symbols but their data layout is enforced to be POD types.
|
||||||
|
|
||||||
Data layout of AST struct:
|
Data layout of AST struct:
|
||||||
|
|
||||||
CodeT Type;
|
CodeT Type;
|
||||||
bool Readonly;
|
bool Readonly;
|
||||||
AST* Parent;
|
AST* Parent;
|
||||||
string Name;
|
string Name;
|
||||||
string Comment;
|
string Comment;
|
||||||
union {
|
union {
|
||||||
array(AST*) Entries;
|
array(AST*) Entries;
|
||||||
string Content;
|
string Content;
|
||||||
};
|
};
|
||||||
@ -39,7 +42,7 @@
|
|||||||
*`CodeT` is a typedef for `ECode::Type` which is the type of the enum.*
|
*`CodeT` is a typedef for `ECode::Type` which is the type of the enum.*
|
||||||
|
|
||||||
ASTs can be set to readonly by calling Code's lock() member function.
|
ASTs can be set to readonly by calling Code's lock() member function.
|
||||||
Adding comments is always available even if the AST is set to readonly.
|
Adding comments is always available even if the AST is set to readonly.
|
||||||
|
|
||||||
### There are four sets of interfaces for Code AST generation the library provides
|
### There are four sets of interfaces for Code AST generation the library provides
|
||||||
|
|
||||||
@ -57,25 +60,21 @@
|
|||||||
|
|
||||||
* def_class
|
* def_class
|
||||||
* def_class_body
|
* def_class_body
|
||||||
* def_class_fwd
|
|
||||||
* def_enum
|
* def_enum
|
||||||
* def_enum_class
|
* def_enum_class
|
||||||
* def_enum_body
|
* def_enum_body
|
||||||
|
* def_function
|
||||||
|
* def_function_body
|
||||||
* def_global_body
|
* def_global_body
|
||||||
* def_namespace
|
* def_namespace
|
||||||
* def_namespace_body
|
* def_namespace_body
|
||||||
* def_operator
|
* def_operator
|
||||||
* def_operator_fwd
|
|
||||||
* def_param
|
* def_param
|
||||||
* def_params
|
* def_params
|
||||||
* def_proc
|
|
||||||
* def_proc_body
|
|
||||||
* def_proc_fwd
|
|
||||||
* def_specifier
|
* def_specifier
|
||||||
* def_specifiers
|
* def_specifiers
|
||||||
* def_struct
|
* def_struct
|
||||||
* def_struct_body
|
* def_struct_body
|
||||||
* def_struct_fwd
|
|
||||||
* def_variable
|
* def_variable
|
||||||
* def_type
|
* def_type
|
||||||
* def_typedef
|
* def_typedef
|
||||||
@ -97,17 +96,13 @@
|
|||||||
* make_class
|
* make_class
|
||||||
* make_enum
|
* make_enum
|
||||||
* make_enum_class
|
* make_enum_class
|
||||||
|
* make_function
|
||||||
* make_global_body
|
* make_global_body
|
||||||
* make_namespace
|
* make_namespace
|
||||||
* make_operator
|
* make_operator
|
||||||
* make_params
|
* make_params
|
||||||
* make_proc
|
|
||||||
* make_specifiers
|
* make_specifiers
|
||||||
* make_struct
|
* make_struct
|
||||||
* make_variable
|
|
||||||
* make_type
|
|
||||||
* make_typedef
|
|
||||||
* make_using
|
|
||||||
|
|
||||||
### Parse construction
|
### Parse construction
|
||||||
|
|
||||||
@ -119,13 +114,13 @@
|
|||||||
* parse_classes
|
* parse_classes
|
||||||
* parse_enum
|
* parse_enum
|
||||||
* parse_enums
|
* parse_enums
|
||||||
|
* parse_function
|
||||||
|
* parse_functions
|
||||||
* parse_global_body
|
* parse_global_body
|
||||||
* parse_namespace
|
* parse_namespace
|
||||||
* parse_namespaces
|
* parse_namespaces
|
||||||
* parse_operator
|
* parse_operator
|
||||||
* parse_operators
|
* parse_operators
|
||||||
* parse_proc
|
|
||||||
* parse_procs
|
|
||||||
* parse_struct
|
* parse_struct
|
||||||
* parse_strucs
|
* parse_strucs
|
||||||
* parse_variable
|
* parse_variable
|
||||||
@ -139,7 +134,7 @@
|
|||||||
The parse API treats any execution scope definitions with no validation and are turned into untyped Code ASTs.
|
The parse API treats any execution scope definitions with no validation and are turned into untyped Code ASTs.
|
||||||
This includes the assignmetn of variables; due to the library not yet supporting c/c++ expression parsing.
|
This includes the assignmetn of variables; due to the library not yet supporting c/c++ expression parsing.
|
||||||
|
|
||||||
The plural variants provide an array of codes, its up to the user to add them to a body AST
|
The plural variants provide an array of codes, its up to the user to add them to a body AST
|
||||||
(they are not auto-added to a body)
|
(they are not auto-added to a body)
|
||||||
|
|
||||||
### Untyped constructions
|
### Untyped constructions
|
||||||
@ -152,7 +147,7 @@
|
|||||||
* untyped_fmt
|
* untyped_fmt
|
||||||
* untyped_token_fmt
|
* untyped_token_fmt
|
||||||
|
|
||||||
During serialization any untyped Code AST is has its string value directly injected inline of
|
During serialization any untyped Code AST is has its string value directly injected inline of
|
||||||
whatever context the content existed as an entry within.
|
whatever context the content existed as an entry within.
|
||||||
Even though thse are not validated from somewhat correct c/c++ syntax or components, it doesn't mean that
|
Even though thse are not validated from somewhat correct c/c++ syntax or components, it doesn't mean that
|
||||||
Untyped code can be added as any component of a Code AST:
|
Untyped code can be added as any component of a Code AST:
|
||||||
@ -169,53 +164,56 @@
|
|||||||
|
|
||||||
// Temporarily here for debugging purposes.
|
// Temporarily here for debugging purposes.
|
||||||
#define gen_time
|
#define gen_time
|
||||||
|
|
||||||
|
|
||||||
|
#define GEN_BAN_CPP_TEMPLATES
|
||||||
#define GEN_ENFORCE_READONLY_AST
|
#define GEN_ENFORCE_READONLY_AST
|
||||||
// #define GEN_DEFINE_DSL
|
#define GEN_DEFINE_DSL
|
||||||
#define GEN_DEFINE_LIBRARY_CODE_CONSTANTS
|
#define GEN_DEFINE_LIBRARY_CODE_CONSTANTS
|
||||||
// #define GEN_BAN_CPP_TEMPLATES
|
|
||||||
#define GEN_USE_FATAL
|
#define GEN_USE_FATAL
|
||||||
|
|
||||||
|
|
||||||
#ifdef gen_time
|
#ifdef gen_time
|
||||||
namespace gen
|
namespace gen
|
||||||
{
|
{
|
||||||
using LogFailType = sw(*)(char const*, ...);
|
using LogFailType = sw(*)(char const*, ...);
|
||||||
|
|
||||||
#ifdef GEN_BAN_CPP_TEMPLATES
|
# ifdef GEN_BAN_CPP_TEMPLATES
|
||||||
#define template static_assert("Templates are banned within gen_time scope blocks")
|
#define template static_assert("Templates are banned within gen_time scope blocks")
|
||||||
#endif
|
# endif
|
||||||
|
|
||||||
#ifdef GEN_USE_FATAL
|
# ifdef GEN_USE_FATAL
|
||||||
ct LogFailType log_failure = fatal;
|
ct LogFailType log_failure = fatal;
|
||||||
#else
|
# else
|
||||||
ct LogFailType log_failure = log_fmt;
|
ct LogFailType log_failure = log_fmt;
|
||||||
#endif
|
# endif
|
||||||
|
|
||||||
namespace ECode
|
namespace ECode
|
||||||
{
|
{
|
||||||
enum Type : u8
|
enum Type : u8
|
||||||
{
|
{
|
||||||
Invalid,
|
Invalid,
|
||||||
Untyped,
|
Untyped,
|
||||||
Access_Public,
|
Access_Public,
|
||||||
Access_Private,
|
Access_Private,
|
||||||
Access_Protected,
|
Access_Protected,
|
||||||
Class,
|
Class,
|
||||||
Enum,
|
Enum,
|
||||||
Enum_Body,
|
Enum_Body,
|
||||||
Global_Body,
|
Global_Body,
|
||||||
Namespace,
|
Namespace,
|
||||||
Namespace_Body,
|
Namespace_Body,
|
||||||
Parameters,
|
Parameters,
|
||||||
Proc,
|
Function,
|
||||||
Proc_Body,
|
Function_Body,
|
||||||
Proc_Forward,
|
Function_Forward,
|
||||||
Specifiers,
|
Specifiers,
|
||||||
Struct,
|
Struct,
|
||||||
Struct_Body,
|
Struct_Body,
|
||||||
Variable,
|
Variable,
|
||||||
Typedef,
|
Typedef,
|
||||||
Typename,
|
Typename,
|
||||||
Using,
|
Using,
|
||||||
|
|
||||||
Num_Types
|
Num_Types
|
||||||
};
|
};
|
||||||
@ -223,7 +221,7 @@ namespace gen
|
|||||||
local_persist
|
local_persist
|
||||||
char const* str( Type type )
|
char const* str( Type type )
|
||||||
{
|
{
|
||||||
static
|
static
|
||||||
char const* lookup[Num_Types] = {
|
char const* lookup[Num_Types] = {
|
||||||
"Invalid",
|
"Invalid",
|
||||||
"Untyped",
|
"Untyped",
|
||||||
@ -267,7 +265,7 @@ namespace gen
|
|||||||
Num_Ops
|
Num_Ops
|
||||||
};
|
};
|
||||||
|
|
||||||
inline
|
inline
|
||||||
char const* str( Type op )
|
char const* str( Type op )
|
||||||
{
|
{
|
||||||
local_persist
|
local_persist
|
||||||
@ -287,23 +285,23 @@ namespace gen
|
|||||||
{
|
{
|
||||||
enum Type : u8
|
enum Type : u8
|
||||||
{
|
{
|
||||||
Attribute,
|
Attribute,
|
||||||
Alignas,
|
Alignas,
|
||||||
Constexpr,
|
Constexpr,
|
||||||
Const,
|
Const,
|
||||||
Inline,
|
Inline,
|
||||||
Pointer,
|
Pointer,
|
||||||
Reference,
|
Reference,
|
||||||
RValue,
|
RValue,
|
||||||
|
|
||||||
C_Linkage,
|
C_Linkage,
|
||||||
API_Import,
|
API_Import,
|
||||||
API_Export,
|
API_Export,
|
||||||
External_Linkage,
|
External_Linkage,
|
||||||
Internal_Linkage,
|
Internal_Linkage,
|
||||||
Static_Member,
|
Static_Member,
|
||||||
Local_Persist,
|
Local_Persist,
|
||||||
Thread_Local,
|
Thread_Local,
|
||||||
|
|
||||||
Invalid,
|
Invalid,
|
||||||
Num_Specifiers,
|
Num_Specifiers,
|
||||||
@ -325,13 +323,13 @@ namespace gen
|
|||||||
|
|
||||||
"extern \"C\"",
|
"extern \"C\"",
|
||||||
|
|
||||||
#if defined(ZPL_SYSTEM_WINDOWS)
|
# if defined(ZPL_SYSTEM_WINDOWS)
|
||||||
"__declspec(dllexport)",
|
"__declspec(dllexport)",
|
||||||
"__declspec(dllimport)",
|
"__declspec(dllimport)",
|
||||||
#elif defined(ZPL_SYSTEM_MACOS)
|
# elif defined(ZPL_SYSTEM_MACOS)
|
||||||
"__attribute__ ((visibility (\"default\")))",
|
"__attribute__ ((visibility (\"default\")))",
|
||||||
"__attribute__ ((visibility (\"default\")))",
|
"__attribute__ ((visibility (\"default\")))",
|
||||||
#endif
|
# endif
|
||||||
|
|
||||||
"extern",
|
"extern",
|
||||||
"static",
|
"static",
|
||||||
@ -342,7 +340,7 @@ namespace gen
|
|||||||
|
|
||||||
return lookup[ specifier ];
|
return lookup[ specifier ];
|
||||||
}
|
}
|
||||||
|
|
||||||
Type to_type( char const* str, s32 length )
|
Type to_type( char const* str, s32 length )
|
||||||
{
|
{
|
||||||
local_persist
|
local_persist
|
||||||
@ -371,7 +369,7 @@ namespace gen
|
|||||||
|
|
||||||
#pragma region Data Structures
|
#pragma region Data Structures
|
||||||
// TODO: If perf needs it, convert layout an SOA format.
|
// TODO: If perf needs it, convert layout an SOA format.
|
||||||
/*
|
/*
|
||||||
Simple AST POD with functionality to seralize into C++ syntax.
|
Simple AST POD with functionality to seralize into C++ syntax.
|
||||||
|
|
||||||
ASTs are currently stored as an AOS. They are always reconstructed on demand.
|
ASTs are currently stored as an AOS. They are always reconstructed on demand.
|
||||||
@ -467,7 +465,7 @@ namespace gen
|
|||||||
/*
|
/*
|
||||||
AST* typedef as to not constantly have to add the '*' as this is written often..
|
AST* typedef as to not constantly have to add the '*' as this is written often..
|
||||||
|
|
||||||
If GEN_ENFORCE_READONLY_AST is defined, readonly assertions will be done on any member dreference,
|
If GEN_ENFORCE_READONLY_AST is defined, readonly assertions will be done on any member dreference,
|
||||||
and the 'gen API' related functions. will set their created ASTs to readonly before returning.
|
and the 'gen API' related functions. will set their created ASTs to readonly before returning.
|
||||||
|
|
||||||
Casting to AST* will bypass.
|
Casting to AST* will bypass.
|
||||||
@ -481,22 +479,22 @@ namespace gen
|
|||||||
if ( ast->Type == ECode::Invalid )
|
if ( ast->Type == ECode::Invalid )
|
||||||
{
|
{
|
||||||
log_failure("Code::body: Type is invalid, cannot get");
|
log_failure("Code::body: Type is invalid, cannot get");
|
||||||
return InvalidCode;
|
return Invalid;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ast->Entries == nullptr || array_count(ast->Entries) == 0 )
|
if ( ast->Entries == nullptr || array_count(ast->Entries) == 0 )
|
||||||
{
|
{
|
||||||
log_failure("Code::body: Entries of ast not properly setup.");
|
log_failure("Code::body: Entries of ast not properly setup.");
|
||||||
return InvalidCode;
|
return Invalid;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef GEN_ENFORCE_READONLY_AST
|
# ifdef GEN_ENFORCE_READONLY_AST
|
||||||
if ( ast->Readonly )
|
if ( ast->Readonly )
|
||||||
{
|
{
|
||||||
log_failure("Attempted to a body AST from a readonly AST!");
|
log_failure("Attempted to a body AST from a readonly AST!");
|
||||||
return InvalidCode;
|
return Invalid;
|
||||||
}
|
}
|
||||||
#endif
|
# endif
|
||||||
|
|
||||||
return * (Code*)( ast->body() );
|
return * (Code*)( ast->body() );
|
||||||
}
|
}
|
||||||
@ -522,7 +520,7 @@ namespace gen
|
|||||||
{
|
{
|
||||||
return ast;
|
return ast;
|
||||||
}
|
}
|
||||||
|
|
||||||
Code& operator =( Code other )
|
Code& operator =( Code other )
|
||||||
{
|
{
|
||||||
if ( ast == nullptr )
|
if ( ast == nullptr )
|
||||||
@ -531,10 +529,10 @@ namespace gen
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef GEN_ENFORCE_READONLY_AST
|
#ifdef GEN_ENFORCE_READONLY_AST
|
||||||
if ( ast->Readonly )
|
if ( ast->Readonly )
|
||||||
{
|
{
|
||||||
log_failure("Attempted to set a readonly AST!");
|
log_failure("Attempted to set a readonly AST!");
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -545,7 +543,7 @@ namespace gen
|
|||||||
}
|
}
|
||||||
|
|
||||||
forceinline
|
forceinline
|
||||||
AST* operator ->()
|
AST* operator ->()
|
||||||
{
|
{
|
||||||
if ( ast == nullptr )
|
if ( ast == nullptr )
|
||||||
{
|
{
|
||||||
@ -553,24 +551,25 @@ namespace gen
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef GEN_ENFORCE_READONLY_AST
|
# ifdef GEN_ENFORCE_READONLY_AST
|
||||||
if ( ast->Readonly )
|
if ( ast->Readonly )
|
||||||
{
|
{
|
||||||
log_failure("Attempted to access a member from a readonly AST!");
|
log_failure("Attempted to access a member from a readonly AST!");
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
#endif
|
# endif
|
||||||
|
|
||||||
return ast;
|
return ast;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Used internally for the most part to identify invaidly generated code.
|
||||||
|
static const Code Invalid;
|
||||||
};
|
};
|
||||||
static_assert( sizeof(Code) == sizeof(AST*), "ERROR: Code is not POD" );
|
static_assert( sizeof(Code) == sizeof(AST*), "ERROR: Code is not POD" );
|
||||||
|
|
||||||
// Used when the its desired when omission is allowed in a definition.
|
// Used when the its desired when omission is allowed in a definition.
|
||||||
ct Code UnusedCode = { nullptr };
|
ct Code NoCode = { nullptr };
|
||||||
|
// extern const Code InvalidCode;
|
||||||
// Used internally for the most part to identify invaidly generated code.
|
|
||||||
extern const Code InvalidCode;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*/
|
*/
|
||||||
@ -590,10 +589,10 @@ namespace gen
|
|||||||
/*
|
/*
|
||||||
Initialize the library.
|
Initialize the library.
|
||||||
This currently just initializes the CodePool.
|
This currently just initializes the CodePool.
|
||||||
*/
|
*/
|
||||||
void init();
|
void init();
|
||||||
|
|
||||||
// Use this only if you know you generated the code you needed to a file
|
// Use this only if you know you generated the code you needed to a file.
|
||||||
// And rather get rid of current code asts instead of growing the pool memory.
|
// And rather get rid of current code asts instead of growing the pool memory.
|
||||||
void clear_code_pool();
|
void clear_code_pool();
|
||||||
|
|
||||||
@ -610,186 +609,100 @@ namespace gen
|
|||||||
void set_allocator_type_table ( allocator type_reg_allocator );
|
void set_allocator_type_table ( allocator type_reg_allocator );
|
||||||
|
|
||||||
# pragma region Upfront
|
# pragma region Upfront
|
||||||
Code def_class ( char const* name, Code body, Code parent = UnusedCode, Code specifiers = UnusedCode );
|
Code def_class ( char const* name, Code parent = NoCode, Code specifiers = NoCode, Code body = NoCode );
|
||||||
Code def_class_body( s32 num, ... );
|
Code def_class ( s32 length, char const* name, Code parent = NoCode, Code specifiers = NoCode, Code body = NoCode );
|
||||||
Code def_class_fwd ( char const* name );
|
Code def_enum ( char const* name, Code type = NoCode, Code body = NoCode);
|
||||||
|
Code def_enum ( s32 length, char const* name, Code type = NoCode, Code body = NoCode );
|
||||||
|
Code def_function ( char const* name, Code params = NoCode, Code ret_type = NoCode, Code Specifiers = NoCode, Code body = NoCode );
|
||||||
|
Code def_function ( s32 length, char const* name, Code params = NoCode, Code ret_type = NoCode, Code Specifiers = NoCode, Code body = NoCode );
|
||||||
|
Code def_namespace ( char const* name, Code body );
|
||||||
|
Code def_namespace ( s32 length, char const* name, Code body );
|
||||||
|
Code def_operator ( OperatorT op, Code params = NoCode, Code ret_type = NoCode, Code Specifiers = NoCode, Code body = NoCode );
|
||||||
|
|
||||||
Code def_enum( char const* name, Code type, Code body );
|
Code def_param ( Code type, char const* name );
|
||||||
|
Code def_param ( Code type, s32 length, char const* name );
|
||||||
|
|
||||||
Code def_global_body( s32 num, ... );
|
Code def_specifier ( SpecifierT* specifier );
|
||||||
|
|
||||||
Code def_namespace ( char const* name, Code body );
|
Code def_struct ( char const* name, Code parent = NoCode, Code specifiers = NoCode, Code body = NoCode );
|
||||||
Code def_namespace_body( s32 num, ... );
|
Code def_struct ( s32 length, char const* name, Code parent = NoCode, Code specifiers = NoCode, Code body = NoCode );
|
||||||
|
Code def_type ( char const* name, Code specifiers = NoCode );
|
||||||
|
Code def_type ( s32 length, char const* name, Code specifiers = NoCode );
|
||||||
|
Code def_using ( char const* name, Code type );
|
||||||
|
Code def_using ( s32 length, char const* name, Code type );
|
||||||
|
Code def_using_namespace( char const* name );
|
||||||
|
Code def_using_namespace( s32 length, char const* name );
|
||||||
|
|
||||||
Code def_operator( OperatorT op
|
Code def_variable ( Code type, char const* name, Code value = NoCode, Code specifiers = NoCode );
|
||||||
, Code specifiers
|
Code def_variable ( Code type, s32 length, char const* name, Code value = NoCode, Code specifiers = NoCode );
|
||||||
, Code params
|
|
||||||
, Code ret_type
|
|
||||||
, Code body
|
|
||||||
);
|
|
||||||
Code def_operator_fwd( OperatorT op, Code specifiers, Code params, Code ret_type );
|
|
||||||
|
|
||||||
Code def_param( Code type, char const* name );
|
Code def_class_body ( s32 num, ... );
|
||||||
Code def_params( s32 num, ... );
|
Code def_enum_body ( u32 num, ... );
|
||||||
Code def_params( s32 num, Code* params );
|
Code def_enum_body ( u32 num, Code* Values );
|
||||||
|
Code def_global_body ( s32 num, ... );
|
||||||
Code def_proc( char const* name
|
Code def_function_body ( s32 num, ... );
|
||||||
, Code specifiers
|
Code def_function_body ( s32 num, Code* codes );
|
||||||
, Code params
|
Code def_namespace_body ( s32 num, ... );
|
||||||
, Code ret_type
|
Code def_operator_body ( s32 num, ... );
|
||||||
, Code body
|
Code def_params ( s32 num, ... );
|
||||||
);
|
Code def_params ( s32 num, Code* params );
|
||||||
|
Code def_specifiers ( s32 num , ... );
|
||||||
Code def_proc_body( s32 num, ... );
|
Code def_specifiers ( s32 num, SpecifierT* specs );
|
||||||
Code def_proc_body( s32 num, Code* codes );
|
Code def_struct_body ( s32 num, ... );
|
||||||
|
Code def_struct_body ( s32 num, Code* codes );
|
||||||
Code def_proc_fwd( char const* name
|
|
||||||
, Code specifiers
|
|
||||||
, Code params
|
|
||||||
, Code ret_type
|
|
||||||
);
|
|
||||||
|
|
||||||
Code def_specifier( SpecifierT* specifier );
|
|
||||||
Code def_specifiers( s32 num , ... );
|
|
||||||
Code def_specifiers( s32 num, SpecifierT* specs );
|
|
||||||
|
|
||||||
Code def_struct( char const* name, Code body, Code parent = UnusedCode, Code specifiers = UnusedCode );
|
|
||||||
|
|
||||||
Code def_struct_body( s32 num, ... );
|
|
||||||
Code def_struct_body( s32 num, Code* codes );
|
|
||||||
|
|
||||||
Code def_sturct_fwd();
|
|
||||||
|
|
||||||
Code def_variable( Code type, char const* name, Code value = UnusedCode, Code specifiers = UnusedCode );
|
|
||||||
|
|
||||||
Code def_type( char const* name, Code specifiers = UnusedCode );
|
|
||||||
|
|
||||||
Code def_using ( char const* name, Code type );
|
|
||||||
Code def_using_namespace( char const* name );
|
|
||||||
# pragma endregion Upfront
|
# pragma endregion Upfront
|
||||||
|
|
||||||
# pragma region Incremental
|
# pragma region Incremental
|
||||||
Code make_class( char const* name, Code parent = UnusedCode, Code specifiers = UnusedCode );
|
Code make_class ( char const* name, Code parent = NoCode, Code specifiers = NoCode );
|
||||||
|
Code make_class ( s32 length, char const* name, Code parent = NoCode, Code specifiers = NoCode );
|
||||||
|
Code make_enum ( s32 length, char const* name, Code type = NoCode, Code body = NoCode );
|
||||||
|
Code make_enum ( char const* name, Code type = NoCode, Code body = NoCode );
|
||||||
|
Code make_enum_class ( s32 length, char const* name, Code type = NoCode, Code body = NoCode );
|
||||||
|
Code make_function ( s32 length, char const* name, Code params = NoCode, Code ret_type = NoCode, Code specifiers = NoCode );
|
||||||
|
Code make_function ( char const* name, Code params = NoCode, Code ret_type = NoCode, Code specifiers = NoCode );
|
||||||
|
Code make_global_body ( char const* name = "", s32 num = 0, ... );
|
||||||
|
Code make_global_body ( s32 length, char const* name = "", s32 num = 0, ... );
|
||||||
|
Code make_namespace ( char const* name );
|
||||||
|
Code make_namespace ( s32 length, char const* name );
|
||||||
|
Code make_operator ( OperatorT op, Code params = NoCode, Code ret_type = NoCode, Code specifiers = NoCode );
|
||||||
|
Code make_struct ( char const* name, Code parent = NoCode, Code specifiers = NoCode );
|
||||||
|
Code make_struct ( s32 length, char const* name, Code parent = NoCode, Code specifiers = NoCode );
|
||||||
|
|
||||||
Code make_enum ( char const* name, Code type = UnusedCode, Code body = UnusedCode );
|
Code make_params ( s32 num, ... );
|
||||||
Code make_enum_class( char const* name, Code type = UnusedCode, Code body = UnusedCode );
|
Code make_params_macro( s32 num, ... );
|
||||||
|
Code make_params ( s32 num, Code* params );
|
||||||
Code make_global_body( char const* name = "", s32 num = 0, ... );
|
Code make_specifiers ( s32 num, ... );
|
||||||
|
Code make_specifiers ( s32 num, SpecifierT* specs );
|
||||||
Code make_namespace( char const* name );
|
|
||||||
|
|
||||||
Code make_operator( OperatorT op
|
|
||||||
, Code specifiers = UnusedCode
|
|
||||||
, Code params = UnusedCode
|
|
||||||
, Code ret_type = UnusedCode
|
|
||||||
, Code body = UnusedCode
|
|
||||||
);
|
|
||||||
|
|
||||||
Code make_params( s32 num, ... );
|
|
||||||
|
|
||||||
Code make_proc( char const* name
|
|
||||||
, Code specifiers = UnusedCode
|
|
||||||
, Code params = UnusedCode
|
|
||||||
, Code ret_type = UnusedCode
|
|
||||||
);
|
|
||||||
|
|
||||||
Code make_specifiers( s32 num , ... );
|
|
||||||
Code make_specifiers( s32 num, SpecifierT* specs );
|
|
||||||
|
|
||||||
Code make_struct( char const* name, Code parent = UnusedCode, Code specifiers = UnusedCode );
|
|
||||||
|
|
||||||
Code make_variable( char const* name, Code type = UnusedCode, Code value = UnusedCode, Code specifiers = UnusedCode );
|
|
||||||
|
|
||||||
Code make_type( char const* name, Code specifiers = UnusedCode );
|
|
||||||
|
|
||||||
Code make_using( char const* name, Code type = UnusedCode, Code specifiers = UnusedCode );
|
|
||||||
# pragma endregion Incremental
|
# pragma endregion Incremental
|
||||||
|
|
||||||
# pragma region Parsing
|
# pragma region Parsing
|
||||||
Code parse_class( char const* class_def, s32 length );
|
Code parse_class ( s32 length, char const* class_def );
|
||||||
s32 parse_classes( char const* class_defs, s32 length, Code* out_classes );
|
Code parse_enum ( s32 length, char const* enum_def );
|
||||||
|
Code parse_function ( s32 length, char const* fn_def );
|
||||||
|
Code parse_global_body( s32 length, char const* body_def );
|
||||||
|
Code parse_operator ( s32 length, char const* operator_def );
|
||||||
|
Code parse_struct ( s32 length, char const* struct_def );
|
||||||
|
Code parse_variable ( s32 length, char const* var_def );
|
||||||
|
Code parse_type ( s32 length, char const* type_def );
|
||||||
|
Code parse_typedef ( s32 length, char const* typedef_def );
|
||||||
|
Code parse_using ( s32 length, char const* using_def );
|
||||||
|
|
||||||
Code parse_enum( char const* enum_def, s32 length);
|
s32 parse_classes ( s32 length, char const* class_defs, Code* out_classes );
|
||||||
s32 parse_enums( char const* enum_defs, s32 length, Code* out_enums );
|
s32 parse_enums ( s32 length, char const* enum_defs, Code* out_enums );
|
||||||
|
s32 parse_functions( s32 length, char const* fn_defs, Code* out_fn_codes );
|
||||||
Code parse_global_body( char const* body_def, s32 length );
|
s32 parse_structs ( s32 length, char const* struct_defs, Code* out_struct_codes );
|
||||||
|
s32 parse_variables( s32 length, char const* vars_def, Code* out_var_codes );
|
||||||
Code parse_operator( char const* operator_def, s32 length );
|
s32 parse_typedef ( s32 length, char const* typedef_def, Code* out_typedef_codes );
|
||||||
|
s32 parse_usings ( s32 length, char const* usings_def, Code* out_using_codes );
|
||||||
Code parse_proc( char const* proc_def, s32 length );
|
|
||||||
s32 parse_procs( char const* proc_defs, s32 length, Code* out_procs );
|
|
||||||
|
|
||||||
Code parse_struct( char const* struct_def, s32 length );
|
|
||||||
s32 parse_structs( char const* struct_defs, s32 length, Code* out_struct_codes );
|
|
||||||
|
|
||||||
Code parse_variable( char const* var_def, s32 length );
|
|
||||||
s32 parse_variables( char const* vars_def, s32 length, Code* out_var_codes );
|
|
||||||
|
|
||||||
Code parse_type( char const* type_def, s32 length );
|
|
||||||
|
|
||||||
Code parse_typedef( char const* typedef_def, s32 length );
|
|
||||||
s32 parse_typedef( char const* typedef_def, s32 length, Code* out_typedef_codes );
|
|
||||||
|
|
||||||
Code parse_using ( char const* using_def, s32 length );
|
|
||||||
s32 parse_usings( char const* usings_def, s32 length, Code* out_using_codes );
|
|
||||||
# pragma endregion Parsing
|
# pragma endregion Parsing
|
||||||
|
|
||||||
# pragma region Untyped text
|
# pragma region Untyped text
|
||||||
/*
|
Code untyped_str ( char const* str );
|
||||||
Define an untyped code string.
|
Code untyped_str ( s32 length, char const* str);
|
||||||
|
Code untyped_fmt ( char const* fmt, ... );
|
||||||
Untyped code may be used in bodies of functions, namespaces, or structs
|
Code untyped_token_fmt( char const* fmt, s32 num_tokens, ... );
|
||||||
or the in places where expressions may be placed.
|
|
||||||
|
|
||||||
Because the code within it is untyped, errors will naturally not be provided.
|
|
||||||
Consider this an a preprocessor define.
|
|
||||||
*/
|
|
||||||
Code untyped_str( char const* str );
|
|
||||||
Code untyped_str( char const* str, s32 length);
|
|
||||||
|
|
||||||
/*
|
|
||||||
Define an untyped code string using traditional 'printf'.
|
|
||||||
|
|
||||||
Untyped code may be used in bodies of functions, namespaces, or structs
|
|
||||||
or the in places where expressions may be placed.
|
|
||||||
|
|
||||||
Because the code within it is untyped, errors will naturally not be provided.
|
|
||||||
Consider this an a preprocessor define.
|
|
||||||
*/
|
|
||||||
Code untyped_fmt( char const* fmt, ... );
|
|
||||||
|
|
||||||
/*
|
|
||||||
Define an untyped code string using token formatting:
|
|
||||||
... { <ID> } ... Will be repalced with value of token ID.
|
|
||||||
|
|
||||||
Values are to provided as: <char const* ID>, <char const* Value>, ...
|
|
||||||
|
|
||||||
num_tokens : The number of ID-Value pairs provided.
|
|
||||||
|
|
||||||
Untyped code may be used in bodies of functions, namespaces, or structs
|
|
||||||
or the in places where expressions may be placed.
|
|
||||||
|
|
||||||
Because the code within it is untyped, errors will naturally not be provided.
|
|
||||||
Consider this an a preprocessor define.
|
|
||||||
*/
|
|
||||||
Code untyped_token_fmt( char const* fmt, s32 num_tokens, ... );
|
|
||||||
# pragma endregion Untyped text
|
# pragma endregion Untyped text
|
||||||
|
|
||||||
/*
|
|
||||||
Used to generate the files.
|
|
||||||
This is inspired by jai's usage of the string_builder with #insert.
|
|
||||||
|
|
||||||
Its expected when using this library that Code ast will be serialized with the:
|
|
||||||
Builder::print() proc
|
|
||||||
|
|
||||||
The seralized content of the Code ast will be appended to Buffer within an empty line
|
|
||||||
prepared for a another definition or to add an empty newline to the end of the file.
|
|
||||||
|
|
||||||
Builder::write() should be called when all Code has been seralized for that file.
|
|
||||||
|
|
||||||
The #insert directive is thus represented by an #include of the generated file at your desired line
|
|
||||||
of any file in the target project.
|
|
||||||
*/
|
|
||||||
struct Builder
|
struct Builder
|
||||||
{
|
{
|
||||||
zpl_file File;
|
zpl_file File;
|
||||||
@ -805,7 +718,9 @@ namespace gen
|
|||||||
|
|
||||||
#pragma region MACROS
|
#pragma region MACROS
|
||||||
# define gen_main main
|
# define gen_main main
|
||||||
# define __ UnusedCode
|
|
||||||
|
# define __ NoCode
|
||||||
|
# define spec_alignas( Value_ ) ESpecifier::Alignas, Value
|
||||||
|
|
||||||
/*
|
/*
|
||||||
gen's Domain Specific Langauge.
|
gen's Domain Specific Langauge.
|
||||||
@ -827,45 +742,99 @@ namespace gen
|
|||||||
The code macros are used to embed c/c++ to insert into the desired lcoation.
|
The code macros are used to embed c/c++ to insert into the desired lcoation.
|
||||||
*/
|
*/
|
||||||
#ifdef GEN_DEFINE_DSL
|
#ifdef GEN_DEFINE_DSL
|
||||||
# define untyped_code( Name_, Value_ ) Code Name_ = gen::untyped_str( txt(Value_) )
|
|
||||||
# define typename( Name_, Value_ ) Code t_##Name_ = gen::def_type( txt(Value_) )
|
|
||||||
# define typename_fmt( Name_, Fmt_, ... ) Code t_##Name_ = gen::def_type( bprintf( Fmt_, __VA_ARGS__ ) )
|
|
||||||
# define using_type( Name_, Type_ ) Code Name_ = gen::def_using( #Name_, t_##Type_ )
|
|
||||||
# define variable( Type_, Name_, ... ) Code Name_ = gen::def_variable( t_##Type_, #Name_, __VA_ARGS__ )
|
|
||||||
|
|
||||||
# define untyped( Value_ ) gen::untyped_str( txt_with_length(Value_) )
|
// Boilerplate
|
||||||
# define code_token( Fmt_, ... ) gen::untyped_token_fmt( Fmt_, VA_NARGS( __VA_ARGS__), __VA_ARGS__ )
|
|
||||||
# define code_fmt( Fmt_, ... ) gen::untyped_fmt( Fmt_, __VA_ARGS__ )
|
|
||||||
# define specifiers( ... ) gen::def_specifiers( VA_NARGS( __VA_ARGS__ ), __VA_ARGS__ )
|
|
||||||
# define type( Value_ ) gen::def_type( txt(Value_) )
|
|
||||||
# define type_fmt( Fmt_, ... ) gen::def_type( bprintf( Fmt_, __VA_ARGS__ ) )
|
|
||||||
# define using( Name_, Type_ ) gen::def_using( #Name_, Type_ )
|
|
||||||
# define var( Type_, Name_, ... ) gen::def_variable( Type_, #Name_, __VA_ARGS__ )
|
|
||||||
|
|
||||||
# define make( Type_, Name_, ... ) Code Name_ = make_##Type_( #Name_, __VA_ARGS__ );
|
/*
|
||||||
# define enum( Name_, Type_, Body_ ) gen::def_enum( #Name_, t_##Type_, Body_ )
|
In order to provide some convient syntax sugar this polymoprhic macro boilerplate is needed for:
|
||||||
# define proc( Name_, Specifiers_, RetType_, Parameters_, Body_ ) Name_ = gen::def_proc( #Name_, Specifiers_, Parameters_, RetType_, Body_ )
|
* function( ... )
|
||||||
# define proc_body( ... ) gen::def_proc_body( VA_NARGS( __VA_ARS__ ), __VA_ARGS__ )
|
* operator( ... )
|
||||||
# define params( ... ) gen::def_params( VA_NARGS( __VA_ARGS__ ) / 2, __VA_ARGS__ )
|
* params( ... )
|
||||||
# define struct( Name_, Parent_, Specifiers_, Body_ ) Name_ = gen::def_struct( #Name_, Body_, Parent_, Specifiers_ )
|
|
||||||
# define struct_body( ... ) gen::def_struct_body( VA_NARGS( __VA_ARGS__ ), __VA_ARGS__ )
|
|
||||||
|
|
||||||
# define add_var( Value_ ) add( gen::parse_variable( txt_with_length(Value_)) )
|
macrofn based off of: https://stackoverflow.com/questions/3046889/optional-parameters-with-c-macros
|
||||||
# define add_untyped( Value_ ) add( gen::untyped_str( txt_with_length( Value_ ) ) )
|
specifically: https://stackoverflow.com/a/56038661
|
||||||
# define add_type( Value_ ) add( gen::parse_type( txt_with_length(Value_)) )
|
*/
|
||||||
# define add_params( Value_ ) add( gen::parse_params( txt_with_length(Value_) ))
|
|
||||||
|
|
||||||
# define enum_code( Def_ ) gen::parse_enum( txt( Def_ ), sizeof( txt( Def_ )) )
|
#define macrofn_chooser(_f0, _f1, _f2, _f3, _f4, _f5, _f6, _f7, _f8, _f9, _f10, _f11, _f12, _f13, _f14, _f15, _f16, ...) _f16
|
||||||
# define global_code( Def_ ) gen::parse_global_body( txt_with_length( Def_ ))
|
#define macrofn_recomposer(ArgsWithParentheses_) macrofn_chooser ArgsWithParentheses_
|
||||||
# define namespace_code( Def_ ) gen::parse_namespace( txt(Def_), sizeof( txt(Def_)) )
|
#define macrofn_chose_from_arg_num(F, ...) macrofn_recomposer((__VA_ARGS__, F##_16, F##_15, F##_14, F##_13, F##_12, F##_11, F##_10, F##_9, F##_8, F##_7, F##_6, F##_5, F##_4, F##_3, F##_2, F##_1, ))
|
||||||
# define proc_code( Def_ ) gen::parse_proc( txt( Def_ ), sizeof( txt( Def_ )) )
|
#define marcofn_no_arg_expander(Func) ,,,,,,,,,,,,,,,,Func_ ## _0
|
||||||
# define struct_code( Def_ ) gen::parse_struct( txt( Def_ ), sizeof( txt( Def_ )) )
|
#define macrofn_finder(Func_, ...) macrofn_chose_from_arg_num(Func_, NO_ARG_EXPANDER __VA_ARGS__ (Func_))
|
||||||
# define variable_code( Def_ ) gen::parse_variable( txt_with_length( Def_ ) )
|
#define macrofn_polymorphic(Func_, ...) macrofn_finder(Func_, __VA_ARGS__)(__VA_ARGS__)
|
||||||
|
|
||||||
|
#define function_5( Name_, Params_, RetType_, Specifiers_, Body_ ) gen::def_function( txt_n_len( Name_ ), macro_expand( Params_ ), t_##RetType_, Specifiers_, Body_ )
|
||||||
|
#define function_4( Name_, Params_, RetType_, Specifiers_ ) gen::def_function( txt_n_len( Name_ ), macro_expand( Params_ ), t_##RetType_, Specifiers_ )
|
||||||
|
#define function_3( Name_, Params_, RetType_ ) gen::def_function( txt_n_len( Name_ ), macro_expand( Params_ ), t_##RetType_ )
|
||||||
|
#define function_2( Name_, Params_ ) gen::def_function( txt_n_len( Name_ ), macro_expand( Params_ ) )
|
||||||
|
#define function_1( Name_ ) gen::def_function( txt_n_len( Name_ ) )
|
||||||
|
|
||||||
|
#define params_12( T_1, V_1, T_2, V_2, T_3, V_3, T_4, V_4, T_5, V_5, T_6, V_6 ) gen::def_params( 6, t_##T_1, txt_n_len( V_1), t_##T_2, txt_n_len( V_2), t_##T_3, txt_n_len( V_3), t_##T_4, txt_n_len( V_4), t_##T_5, txt_n_len( V_5))
|
||||||
|
#define params_10( T_1, V_1, T_2, V_2, T_3, V_3, T_4, V_4, T_5, V_5 ) gen::def_params( 5, t_##T_1, txt_n_len( V_1), t_##T_2, txt_n_len( V_2), t_##T_3, txt_n_len( V_3), t_##T_4, txt_n_len( V_4), t_##T_5, txt_n_len( V_5))
|
||||||
|
#define params_8( T_1, V_1, T_2, V_2, T_3, V_3, T_4, V_4 ) gen::def_params( 4, t_##T_1, txt_n_len( V_1), t_##T_2, txt_n_len( V_2), t_##T_3, txt_n_len( V_3), t_##T_4, txt_n_len( V_4) )
|
||||||
|
#define params_6( T_1, V_1, T_2, V_2, T_3, V_3 ) gen::def_params( 3, t_##T_1, txt_n_len( V_1), t_##T_2, txt_n_len( V_2), t_##T_3, txt_n_len( V_3))
|
||||||
|
#define params_4( T_1, V_1, T_2, V_2 ) gen::def_params( 2, t_##T_1, txt_n_len( V_1), t_##T_2, txt_n_len( V_2))
|
||||||
|
#define params_2( T_1, V_1 ) gen::def_params( 1, t_##T_1, txt_n_len( V_1))
|
||||||
|
#define params_bad static_assert("params(...): Invalid number of parameters provided.")
|
||||||
|
#define params_11 params_bad
|
||||||
|
#define params_9 params_bad
|
||||||
|
#define params_7 params_bad
|
||||||
|
#define params_5 params_bad
|
||||||
|
#define params_3 params_bad
|
||||||
|
#define params_1 params_bad
|
||||||
|
|
||||||
|
// Upfront
|
||||||
|
|
||||||
|
# define class( Name_, ... ) gen::def_class( txt_n_len(Name_), __VA_ARGS__ )
|
||||||
|
# define enum( Name_, Type_, Body_ ) gen::def_enum ( txt_n_len(Name_), t_##Type_, Body_ )
|
||||||
|
|
||||||
|
# define function( ... ) macrofn_polymorphic( function, __VA_ARGS__ )
|
||||||
|
# define namespace( Name_, Body_ ) gen::def_namespace ( txt_n_len(Name_), Body_ )
|
||||||
|
# define operator( Op_, ... ) macrofn_polymorphic( operator, __VA_ARGS__ )
|
||||||
|
# define params( ... ) macrofn_polymorphic( params, __VA_ARGS__ )
|
||||||
|
# define specifiers( ... ) gen::def_specifiers ( macro_num_args( __VA_ARGS__ ), __VA_ARGS__ )
|
||||||
|
# define struct( Name_, ... ) gen::def_struct ( txt_n_len(Name_), ## __VA_ARGS__ )
|
||||||
|
# define variable( Type_, Name_, ... ) gen::def_variable ( t_##Type_, txt_n_len(Name_), __VA_ARGS__ )
|
||||||
|
# define type( Value_, ... ) gen::def_type ( txt_n_len(Value_), __VA_ARGS__ )
|
||||||
|
# define type_fmt( Fmt_, ... ) gen::def_type ( bprintf( Fmt_, __VA_ARGS__ ) )
|
||||||
|
# define using( Name_, Type_ ) gen::def_using ( txt_n_len(Name_), t_##Type_ )
|
||||||
|
# define using_namespace( Name_ ) gen::def_using_namespace( txt_n_len(Name_) )
|
||||||
|
|
||||||
|
# define class_body( ... ) gen::def_class_body ( macro_num_args( __VA_ARGS__ ), __VA_ARGS__ )
|
||||||
|
# define enum_body( ... ) gen::def_enum_body ( macro_num_args( __VA_ARGS__ ), __VA_ARGS__ )
|
||||||
|
# define global_body( ... ) gen::def_global_body ( macro_num_args( __VA_ARGS__ ), __VA_ARGS__ )
|
||||||
|
# define function_body( ... ) gen::def_function_body ( macro_num_args( __VA_ARGS__ ), __VA_ARGS__ )
|
||||||
|
# define namespace_body( ... ) gen::def_namespace_body ( macro_num_args( __VA_ARGS__ ), __VA_ARGS__ )
|
||||||
|
# define operator_body( ... ) gen::def_operator_body ( macro_num_args( __VA_ARGS__ ), __VA_ARGS__ )
|
||||||
|
# define struct_body( ... ) gen::def_struct_body ( macro_num_args( __VA_ARGS__ ), __VA_ARGS__ )
|
||||||
|
|
||||||
|
// Incremental
|
||||||
|
|
||||||
|
# define make( ConstructType_, Name_, ... ) Code Name_ = make_##ConstructType_( #Name_, ## __VA_ARGS__ );
|
||||||
|
|
||||||
|
// Parsing
|
||||||
|
|
||||||
|
# define class_code( ... ) gen::parse_class ( txt_n_len( __VA_ARGS__ ))
|
||||||
|
# define enum_code( ... ) gen::parse_enum ( txt_n_len( __VA_ARGS__ ))
|
||||||
|
# define function_code( ... ) gen::parse_function ( txt_n_len( __VA_ARGS__ ))
|
||||||
|
# define global_body_code( ... ) gen::parse_global_body( txt_n_len( __VA_ARGS__ ))
|
||||||
|
# define operator_code( ... ) gen::parse_operator ( txt_n_len( __VA_ARGS__ ))
|
||||||
|
# define namespace_code( ... ) gen::parse_namespace ( txt_n_len( __VA_ARGS__ ))
|
||||||
|
# define struct_code( ... ) gen::parse_struct ( txt_n_len( __VA_ARGS__ ))
|
||||||
|
# define variable_code( ... ) gen::parse_variable ( txt_n_len( __VA_ARGS__ ))
|
||||||
|
# define type_code( ... ) gen::parse_type ( txt_n_len( __VA_ARGS__ ))
|
||||||
|
# define typedef_code( ... ) gen::parse_typedef ( txt_n_len( __VA_ARGS__ ))
|
||||||
|
# define using_code( ... ) gen::parse_code ( txt_n_len( __VA_ARGS__ ))
|
||||||
|
|
||||||
|
// Untyped
|
||||||
|
|
||||||
|
# define code_str( ... ) gen::untyped_str ( txt_n_len(__VA_ARGS__) )
|
||||||
|
# define code_fmt( Fmt_, ... ) gen::untyped_fmt ( Fmt_, __VA_ARGS__ )
|
||||||
|
# define code_token( Fmt_, ... ) gen::untyped_token_fmt( Fmt_, macro_num_args( __VA_ARGS__), __VA_ARGS__ )
|
||||||
#endif
|
#endif
|
||||||
#pragma endregion MACROS
|
#pragma endregion MACROS
|
||||||
|
|
||||||
#pragma region CONSTANTS
|
#pragma region CONSTANTS
|
||||||
#ifdef GEN_DEFINE_LIBRARY_CODE_CONSTANTS
|
#ifdef GEN_DEFINE_LIBRARY_CODE_CONSTANTS
|
||||||
namespace gen
|
namespace gen
|
||||||
{
|
{
|
||||||
// Predefined typename codes.
|
// Predefined typename codes.
|
||||||
@ -895,12 +864,18 @@ namespace gen
|
|||||||
extern Code t_f64;
|
extern Code t_f64;
|
||||||
|
|
||||||
extern Code spec_constexpr;
|
extern Code spec_constexpr;
|
||||||
|
extern Code spec_const;
|
||||||
extern Code spec_inline;
|
extern Code spec_inline;
|
||||||
|
extern Code spec_ptr;
|
||||||
|
extern Code spec_ref;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace gen
|
namespace gen
|
||||||
{
|
{
|
||||||
|
ct s32 MaxNameLength = 128;
|
||||||
|
ct s32 StringTable_MaxHashLength = kilobytes(1);
|
||||||
|
|
||||||
extern Code access_public;
|
extern Code access_public;
|
||||||
extern Code access_protected;
|
extern Code access_protected;
|
||||||
extern Code access_private;
|
extern Code access_private;
|
||||||
|
@ -189,7 +189,7 @@ Code make_log_failure()
|
|||||||
R"(#ifdef GEN_USE_FATAL)"
|
R"(#ifdef GEN_USE_FATAL)"
|
||||||
));
|
));
|
||||||
|
|
||||||
result->add( proc_code(
|
result->add( function_code(
|
||||||
inline
|
inline
|
||||||
sw genc_log_failure(char const *fmt, ...)
|
sw genc_log_failure(char const *fmt, ...)
|
||||||
{
|
{
|
||||||
@ -211,32 +211,31 @@ Code make_log_failure()
|
|||||||
R"(#else)"
|
R"(#else)"
|
||||||
));
|
));
|
||||||
|
|
||||||
result->add( parse_proc(
|
result->add( proc_code(
|
||||||
R"(inline
|
inline
|
||||||
sw genc_log_failure(char const *fmt, ...)
|
sw genc_log_failure(char const *fmt, ...)
|
||||||
{
|
{
|
||||||
local_persist thread_local
|
local_persist thread_local
|
||||||
char buf[ZPL_PRINTF_MAXLEN] = { 0 };
|
char buf[ZPL_PRINTF_MAXLEN] = { 0 };
|
||||||
|
|
||||||
va_list va;
|
va_list va;
|
||||||
|
|
||||||
#if Build_Debug
|
#if Build_Debug
|
||||||
va_start(va, fmt);
|
va_start(va, fmt);
|
||||||
zpl_snprintf_va(buf, ZPL_PRINTF_MAXLEN, fmt, va);
|
zpl_snprintf_va(buf, ZPL_PRINTF_MAXLEN, fmt, va);
|
||||||
va_end(va);
|
va_end(va);
|
||||||
|
|
||||||
assert_crash(buf);
|
assert_crash(buf);
|
||||||
return -1;
|
return -1;
|
||||||
#else
|
#else
|
||||||
va_start(va, fmt);
|
va_start(va, fmt);
|
||||||
zpl_printf_err_va( fmt, va);
|
zpl_printf_err_va( fmt, va);
|
||||||
va_end(va);
|
va_end(va);
|
||||||
|
|
||||||
zpl_exit(1);
|
zpl_exit(1);
|
||||||
return -1;
|
return -1;
|
||||||
#endif
|
#endif
|
||||||
})"
|
}
|
||||||
, 372
|
|
||||||
));
|
));
|
||||||
|
|
||||||
result->add( untyped_str(
|
result->add( untyped_str(
|
||||||
@ -253,32 +252,31 @@ Code make_ECode()
|
|||||||
{
|
{
|
||||||
Code ECode = make_global_body();
|
Code ECode = make_global_body();
|
||||||
{
|
{
|
||||||
ECode->add( parse_enum(
|
ECode->add( enum_code(
|
||||||
R"(enum genc_ECode
|
enum genc_ECode
|
||||||
{
|
{
|
||||||
Invalid,
|
Invalid,
|
||||||
Untyped,
|
Untyped,
|
||||||
Enum,
|
Enum,
|
||||||
Enum_Body,
|
Enum_Body,
|
||||||
Global_Body,
|
Global_Body,
|
||||||
Parameters,
|
Parameters,
|
||||||
Proc,
|
Proc,
|
||||||
Proc_Body,
|
Proc_Body,
|
||||||
Proc_Forward,
|
Proc_Forward,
|
||||||
Specifiers,
|
Specifiers,
|
||||||
Struct,
|
Struct,
|
||||||
Struct_Body,
|
Struct_Body,
|
||||||
Variable,
|
Variable,
|
||||||
Typedef,
|
Typedef,
|
||||||
Typename,
|
Typename,
|
||||||
|
|
||||||
Num_Types
|
Num_Types
|
||||||
};
|
};
|
||||||
typedef u32 genc_CodeT;)" + 1
|
typedef u32 genc_CodeT;
|
||||||
, 280
|
|
||||||
));
|
));
|
||||||
|
|
||||||
ECode->add( proc_code(
|
ECode->add( function_code(
|
||||||
inline
|
inline
|
||||||
char const* genc_ecode_to_str( Type type )
|
char const* genc_ecode_to_str( Type type )
|
||||||
{
|
{
|
||||||
@ -353,11 +351,11 @@ Code make_Code()
|
|||||||
typedef genc_AST* Code;
|
typedef genc_AST* Code;
|
||||||
));
|
));
|
||||||
|
|
||||||
code->add( proc_code(
|
code->add( function_code(
|
||||||
bool genc_ast_add( genc_Code other );
|
bool genc_ast_add( genc_Code other );
|
||||||
));
|
));
|
||||||
|
|
||||||
code->add( proc_code(
|
code->add( function_code(
|
||||||
genc_forceinline
|
genc_forceinline
|
||||||
void genc_ast_add_entry( genc_Code self, genc_Code other )
|
void genc_ast_add_entry( genc_Code self, genc_Code other )
|
||||||
{
|
{
|
||||||
@ -371,7 +369,7 @@ Code make_Code()
|
|||||||
R"(#define genc_code_body( AST_ ) AST->Entries[0])", 47
|
R"(#define genc_code_body( AST_ ) AST->Entries[0])", 47
|
||||||
));
|
));
|
||||||
|
|
||||||
code->add( proc_code(
|
code->add( function_code(
|
||||||
genc_forceinline
|
genc_forceinline
|
||||||
bool genc_code_has_entries( Code self ) const
|
bool genc_code_has_entries( Code self ) const
|
||||||
{
|
{
|
||||||
@ -406,7 +404,7 @@ Code make_static_Data()
|
|||||||
Code
|
Code
|
||||||
data = make_global_body();
|
data = make_global_body();
|
||||||
data->add( IfDef_GENC_IMPLEMENTATION );
|
data->add( IfDef_GENC_IMPLEMENTATION );
|
||||||
data->add( global_code(
|
data->add( global_body_code(
|
||||||
static genc_array(genc_AST) genc_CodePool = nullptr;
|
static genc_array(genc_AST) genc_CodePool = nullptr;
|
||||||
|
|
||||||
static genc_array(genc_arena) genc_StringArenas = nullptr;
|
static genc_array(genc_arena) genc_StringArenas = nullptr;
|
||||||
@ -425,7 +423,7 @@ Code make_static_Data()
|
|||||||
static allocator genc_Allocator_TypeTable = zpl_heap();
|
static allocator genc_Allocator_TypeTable = zpl_heap();
|
||||||
));
|
));
|
||||||
data->add( untyped_str( R"(#ifdef GENC_DEFINE_LIBRARY_CODE_CONSTANTS)"));
|
data->add( untyped_str( R"(#ifdef GENC_DEFINE_LIBRARY_CODE_CONSTANTS)"));
|
||||||
data->add( global_code(
|
data->add( global_body_code(
|
||||||
Code t_void;
|
Code t_void;
|
||||||
|
|
||||||
Code t_bool;
|
Code t_bool;
|
||||||
@ -449,7 +447,7 @@ Code make_static_Data()
|
|||||||
Code t_f64;
|
Code t_f64;
|
||||||
));
|
));
|
||||||
data->add( untyped_str( R"(#endif)"));
|
data->add( untyped_str( R"(#endif)"));
|
||||||
data->add( global_code(
|
data->add( global_body_code(
|
||||||
Code spec_inline;
|
Code spec_inline;
|
||||||
Code spec_const;
|
Code spec_const;
|
||||||
));
|
));
|
||||||
@ -509,11 +507,11 @@ int gen_main()
|
|||||||
Memory::setup();
|
Memory::setup();
|
||||||
gen::init();
|
gen::init();
|
||||||
|
|
||||||
IfDef_GENC_IMPLEMENTATION = untyped(
|
IfDef_GENC_IMPLEMENTATION = untyped_str(
|
||||||
R"(#ifdef GENC_IMPLEMENTATION)"
|
R"(#ifdef GENC_IMPLEMENTATION)"
|
||||||
);
|
);
|
||||||
|
|
||||||
EndIf_GENC_IMPLEMENTATION = untyped(
|
EndIf_GENC_IMPLEMENTATION = untyped_str(
|
||||||
R"(#endif // GENC_IMPLEMENTATION)"
|
R"(#endif // GENC_IMPLEMENTATION)"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
233
test/Array.hpp
233
test/Array.hpp
@ -13,7 +13,7 @@
|
|||||||
#ifdef gen_time
|
#ifdef gen_time
|
||||||
Code gen__array_base()
|
Code gen__array_base()
|
||||||
{
|
{
|
||||||
#ifndef GEN_DEFINE_DSL
|
# ifndef GEN_DEFINE_DSL
|
||||||
using namespace gen;
|
using namespace gen;
|
||||||
|
|
||||||
Code t_allocator = def_type( txt(allocator) );
|
Code t_allocator = def_type( txt(allocator) );
|
||||||
@ -34,39 +34,40 @@
|
|||||||
Code params = def_params(1, t_uw, "value" );
|
Code params = def_params(1, t_uw, "value" );
|
||||||
Code body = untyped_str( txt( return 2 * value * 8; ) );
|
Code body = untyped_str( txt( return 2 * value * 8; ) );
|
||||||
|
|
||||||
grow_formula = def_proc( "grow_formula", spec, params, t_sw, body );
|
grow_formula = def_function( "grow_formula", spec, params, t_sw, body );
|
||||||
}
|
}
|
||||||
|
|
||||||
Code body = def_struct_body(2, header, grow_formula);
|
Code body = def_struct_body(2, header, grow_formula);
|
||||||
Code ArrayBase = def_struct( "ArrayBase", body );
|
Code ArrayBase = def_struct( "ArrayBase", body );
|
||||||
|
|
||||||
#else
|
# else
|
||||||
typename( allocator, allocator );
|
Code t_allocator = type( allocator );
|
||||||
|
|
||||||
Code Header;
|
Code Header;
|
||||||
{
|
{
|
||||||
variable( uw, Num, );
|
Code Num = variable( uw, Num, );
|
||||||
variable( uw, Capacity );
|
Code Capacity = variable( uw, Capacity );
|
||||||
variable( allocator, Allocator );
|
Code Allocator = variable( allocator, Allocator );
|
||||||
|
Code body = struct_body( Num, Capacity, Allocator );
|
||||||
|
|
||||||
Code body = struct_body( Num, Capacity, Allocator );
|
Header = struct( Header, __, __, body );
|
||||||
|
|
||||||
struct( Header, __, __, body );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Code proc( grow_formula, spec_inline, t_uw, params( t_uw, "value" ),
|
Code test = params( uw, value );
|
||||||
untyped( return 2 * value * 8 )
|
|
||||||
|
Code grow_formula = function( grow_formula, params( uw, value ), uw, spec_inline,
|
||||||
|
code_str( return 2 * value * 8 )
|
||||||
);
|
);
|
||||||
|
|
||||||
Code struct( ArrayBase, __, __, struct_body( Header, grow_formula ) );
|
Code ArrayBase = struct( ArrayBase, __, __, struct_body( Header, grow_formula ) );
|
||||||
#endif
|
# endif
|
||||||
|
|
||||||
return ArrayBase;
|
return ArrayBase;
|
||||||
}
|
}
|
||||||
|
|
||||||
Code gen__array( char const* type_str, s32 type_size, Code parent )
|
Code gen__array( char const* type_str, s32 type_size, Code parent )
|
||||||
{
|
{
|
||||||
#ifndef GEN_DEFINE_DSL
|
# ifndef GEN_DEFINE_DSL
|
||||||
// Make these global consts to be accessed anywhere...
|
// Make these global consts to be accessed anywhere...
|
||||||
Code t_allocator = def_type( txt(allocator) );
|
Code t_allocator = def_type( txt(allocator) );
|
||||||
|
|
||||||
@ -96,7 +97,7 @@
|
|||||||
Code params = def_params( 1, t_allocator, "mem_handler" );
|
Code params = def_params( 1, t_allocator, "mem_handler" );
|
||||||
Code body = untyped_str( txt( return init_reserve( mem_handler, grow_formula(0) ); ) );
|
Code body = untyped_str( txt( return init_reserve( mem_handler, grow_formula(0) ); ) );
|
||||||
|
|
||||||
init = def_proc( "init", UnusedCode, params, t_bool, body );
|
init = def_function( "init", UnusedCode, params, t_bool, body );
|
||||||
}
|
}
|
||||||
|
|
||||||
Code init_reserve;
|
Code init_reserve;
|
||||||
@ -104,8 +105,8 @@
|
|||||||
Code params = def_params( 2, t_allocator, "mem_handler", t_sw, "capacity" );
|
Code params = def_params( 2, t_allocator, "mem_handler", t_sw, "capacity" );
|
||||||
Code body;
|
Code body;
|
||||||
{
|
{
|
||||||
Code header_value = untyped_str( txt(
|
Code header_value = untyped_str( txt(
|
||||||
rcast( Header*, alloc( mem_handler, sizeof( Header ) + sizeof(Type) + capacity ))
|
rcast( Header*, alloc( mem_handler, sizeof( Header ) + sizeof(Type) + capacity ))
|
||||||
));
|
));
|
||||||
|
|
||||||
Code header = def_variable( ptr_header, "header", header_value );
|
Code header = def_variable( ptr_header, "header", header_value );
|
||||||
@ -125,11 +126,11 @@
|
|||||||
"Data = rcast( %s, header + 1 );", ptr_type
|
"Data = rcast( %s, header + 1 );", ptr_type
|
||||||
);
|
);
|
||||||
|
|
||||||
Code ret_true = untyped_str( txt(
|
Code ret_true = untyped_str( txt(
|
||||||
return true
|
return true
|
||||||
));
|
));
|
||||||
|
|
||||||
body = def_proc_body( 5
|
body = def_function_body( 5
|
||||||
, header
|
, header
|
||||||
, null_check
|
, null_check
|
||||||
, header_init
|
, header_init
|
||||||
@ -138,7 +139,7 @@
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
init_reserve = def_proc( "init_reserve", UnusedCode, params, t_bool, body );
|
init_reserve = def_function( "init_reserve", UnusedCode, params, t_bool, body );
|
||||||
}
|
}
|
||||||
|
|
||||||
Code free;
|
Code free;
|
||||||
@ -148,17 +149,17 @@
|
|||||||
::free( header.Allocator, & get_header() );
|
::free( header.Allocator, & get_header() );
|
||||||
));
|
));
|
||||||
|
|
||||||
free = def_proc( "free", UnusedCode, UnusedCode, t_void, body );
|
free = def_function( "free", UnusedCode, UnusedCode, t_void, body );
|
||||||
}
|
}
|
||||||
|
|
||||||
Code append = make_proc( "append" );
|
Code append = make_function( "append" );
|
||||||
{
|
{
|
||||||
append->add( def_params( 1, type, "value") );
|
append->add( def_params( 1, type, "value") );
|
||||||
append->add( t_bool );
|
append->add( t_bool );
|
||||||
|
|
||||||
Code
|
Code
|
||||||
body = append.body();
|
body = append.body();
|
||||||
body->add(
|
body->add(
|
||||||
untyped_str( txt(
|
untyped_str( txt(
|
||||||
if ( header.Capacity < header.Num + 1 )
|
if ( header.Capacity < header.Num + 1 )
|
||||||
if ( ! grow(0) )
|
if ( ! grow(0) )
|
||||||
@ -169,7 +170,7 @@
|
|||||||
body->add( untyped_str( txt(
|
body->add( untyped_str( txt(
|
||||||
Data[ header.Num ] = value;
|
Data[ header.Num ] = value;
|
||||||
header.Num++;
|
header.Num++;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
)));
|
)));
|
||||||
|
|
||||||
@ -184,14 +185,14 @@
|
|||||||
return data[ header.Num - 1 ];
|
return data[ header.Num - 1 ];
|
||||||
));
|
));
|
||||||
|
|
||||||
back = def_proc( "back", UnusedCode, UnusedCode, type, body );
|
back = def_function( "back", UnusedCode, UnusedCode, type, body );
|
||||||
}
|
}
|
||||||
|
|
||||||
Code clear;
|
Code clear;
|
||||||
{
|
{
|
||||||
Code body = untyped_str( txt( get_header().Num = 0; ));
|
Code body = untyped_str( txt( get_header().Num = 0; ));
|
||||||
|
|
||||||
clear = def_proc( "clear", UnusedCode, UnusedCode, t_void, body );
|
clear = def_function( "clear", UnusedCode, UnusedCode, t_void, body );
|
||||||
}
|
}
|
||||||
|
|
||||||
Code fill;
|
Code fill;
|
||||||
@ -209,17 +210,17 @@
|
|||||||
Data[index] = vallue;
|
Data[index] = vallue;
|
||||||
));
|
));
|
||||||
|
|
||||||
body = def_proc_body( 3, header, check, iter );
|
body = def_function_body( 3, header, check, iter );
|
||||||
}
|
}
|
||||||
|
|
||||||
fill = def_proc( "fill", UnusedCode, params, t_void, body );
|
fill = def_function( "fill", UnusedCode, params, t_void, body );
|
||||||
}
|
}
|
||||||
|
|
||||||
Code get_header;
|
Code get_header;
|
||||||
{
|
{
|
||||||
Code body = untyped_str( txt( return pcast( Header, Data - 1 ); ));
|
Code body = untyped_str( txt( return pcast( Header, Data - 1 ); ));
|
||||||
|
|
||||||
get_header = def_proc( "get_header", spec_inline, UnusedCode, ref_header, body );
|
get_header = def_function( "get_header", spec_inline, UnusedCode, ref_header, body );
|
||||||
}
|
}
|
||||||
|
|
||||||
Code grow;
|
Code grow;
|
||||||
@ -236,10 +237,10 @@
|
|||||||
|
|
||||||
Code ret = untyped_str( "return set_capacity( new_capacity );" );
|
Code ret = untyped_str( "return set_capacity( new_capacity );" );
|
||||||
|
|
||||||
body = def_proc_body( 4, header, new_capacity, check_n_set, ret );
|
body = def_function_body( 4, header, new_capacity, check_n_set, ret );
|
||||||
}
|
}
|
||||||
|
|
||||||
grow = def_proc( "grow", UnusedCode, param, t_bool, body );
|
grow = def_function( "grow", UnusedCode, param, t_bool, body );
|
||||||
}
|
}
|
||||||
|
|
||||||
Code pop;
|
Code pop;
|
||||||
@ -249,10 +250,10 @@
|
|||||||
Code assertion = untyped_str( "assert( header.Num > 0 );" );
|
Code assertion = untyped_str( "assert( header.Num > 0 );" );
|
||||||
Code decrement = untyped_str( "header.Num--; " );
|
Code decrement = untyped_str( "header.Num--; " );
|
||||||
|
|
||||||
body = def_proc_body( 3, header, assertion, decrement );
|
body = def_function_body( 3, header, assertion, decrement );
|
||||||
}
|
}
|
||||||
|
|
||||||
pop = def_proc( "pop", UnusedCode, UnusedCode, t_void, body );
|
pop = def_function( "pop", UnusedCode, UnusedCode, t_void, body );
|
||||||
}
|
}
|
||||||
|
|
||||||
Code reserve;
|
Code reserve;
|
||||||
@ -267,10 +268,10 @@
|
|||||||
|
|
||||||
Code ret = untyped_str( "\t" "return true" );
|
Code ret = untyped_str( "\t" "return true" );
|
||||||
|
|
||||||
body = def_proc_body( 3, header, check_n_set, ret );
|
body = def_function_body( 3, header, check_n_set, ret );
|
||||||
}
|
}
|
||||||
|
|
||||||
reserve = def_proc( "reserve", UnusedCode, params, t_bool, body );
|
reserve = def_function( "reserve", UnusedCode, params, t_bool, body );
|
||||||
}
|
}
|
||||||
|
|
||||||
Code resize;
|
Code resize;
|
||||||
@ -290,10 +291,10 @@
|
|||||||
"\n""return true;"
|
"\n""return true;"
|
||||||
);
|
);
|
||||||
|
|
||||||
body = def_proc_body( 3, header, check_n_grow, set_n_ret );
|
body = def_function_body( 3, header, check_n_grow, set_n_ret );
|
||||||
}
|
}
|
||||||
|
|
||||||
resize = def_proc( "resize", UnusedCode, param, t_bool, body );
|
resize = def_function( "resize", UnusedCode, param, t_bool, body );
|
||||||
}
|
}
|
||||||
|
|
||||||
Code set_capacity = parse_proc( txt_with_length(
|
Code set_capacity = parse_proc( txt_with_length(
|
||||||
@ -350,191 +351,192 @@
|
|||||||
|
|
||||||
array_def = def_struct( name, body, parent );
|
array_def = def_struct( name, body, parent );
|
||||||
}
|
}
|
||||||
#else
|
# else
|
||||||
typename( allocator, allocator );
|
type( allocator );
|
||||||
|
|
||||||
untyped( v_nullptr, nullptr );
|
|
||||||
|
|
||||||
typename( elem_type, type_str );
|
Code v_nullptr = code_str( nullptr );
|
||||||
typename_fmt( ptr_type, "%s*", type_str );
|
|
||||||
typename_fmt( ref_type, "%&", type_str );
|
Code t_elem_type = def_type( type_str );
|
||||||
|
Code t_ptr_type = def_type( type_str, spec_ptr );
|
||||||
|
Code t_ref_type = type_fmt( type_str, spec_ref );
|
||||||
|
|
||||||
|
|
||||||
// From ArrayBase
|
// From ArrayBase
|
||||||
typename( header, Header );
|
Code t_Header = type( Header );
|
||||||
typename( ptr_header, Header* );
|
Code t_ref_Header = type( ref_Header, spec_ref );
|
||||||
typename( ref_header, Header& );
|
Code t_ptr_Header = type( ptr_Header, spec_ptr );
|
||||||
|
|
||||||
|
# pragma push_macro("rcast")
|
||||||
|
# undef rcast
|
||||||
Code array_def;
|
Code array_def;
|
||||||
{
|
{
|
||||||
using_type( Type, elem_type );
|
Code Type = using( Type, elem_type );
|
||||||
|
|
||||||
variable( ptr_type, Data );
|
Code Data = variable( ptr_type, Data );
|
||||||
variable( ref_header, header, untyped_str("get_header()") );
|
Code header = variable( ref_Header, header, code_str(get_header()) );
|
||||||
|
|
||||||
Code init;
|
Code init;
|
||||||
{
|
{
|
||||||
Code body = proc_body( untyped(
|
Code body = function_body( code_str(
|
||||||
return init_reserve( mem_handler, grow_formula(0) );
|
return init_reserve( mem_handler, grow_formula(0) );
|
||||||
));
|
));
|
||||||
|
|
||||||
proc( init, __, t_bool, params( t_allocator, "mem_handler" ), body );
|
init = function( init, params( allocator, mem_handler ), bool, __, body );
|
||||||
}
|
}
|
||||||
|
|
||||||
make( proc, init_reserve, __, params( t_ref_type, "mem_handler" ), t_bool);
|
make( function, init_reserve, params( ref_type, mem_handler ), bool, __);
|
||||||
{
|
{
|
||||||
Code
|
Code
|
||||||
body = init_reserve.body();
|
body = init_reserve.body();
|
||||||
body->add_var( ptr_header, header, untyped(
|
body->add( variable( ptr_Header, header,
|
||||||
value_str( rcast( Header*, alloc( mem_handler, sizeof(Header) + sizeof(Type) + capacity)) )
|
code_str( rcast( Header*, alloc( mem_handler, sizeof(Header) + sizeof(Type) + capacity)) )
|
||||||
) );
|
) );
|
||||||
|
|
||||||
body->add_untyped(
|
body->add( code_str(
|
||||||
if (header == nullptr)
|
if (header == nullptr)
|
||||||
return false;
|
return false;
|
||||||
);
|
));
|
||||||
|
|
||||||
body->add_untyped(
|
body->add( code_str(
|
||||||
header->Num = 0;
|
header->Num = 0;
|
||||||
header->Capacity = capacity;
|
header->Capacity = capacity;
|
||||||
header->Allocator = mem_handler;
|
header->Allocator = mem_handler;
|
||||||
);
|
));
|
||||||
|
|
||||||
body->add_untyped(
|
body->add( code_str(
|
||||||
Data = rcast( Type*, header + 1 );
|
Data = rcast( Type*, header + 1 );
|
||||||
return true;
|
return true;
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Code free;
|
|
||||||
{
|
|
||||||
proc( free, __, t_void, __, untyped(
|
|
||||||
Header& header = get_header();
|
|
||||||
|
|
||||||
free( header.Allocator, & get_header() );
|
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
make( proc, append )
|
Code free = function( free, __, void, __, code_str(
|
||||||
{
|
Header& header = get_header();
|
||||||
append->add_params( t_elem_value, "value" );
|
|
||||||
append->add_ret_type( void );
|
|
||||||
|
|
||||||
Code
|
free( header.Allocator, & get_header() );
|
||||||
|
));
|
||||||
|
|
||||||
|
make( function, append )
|
||||||
|
{
|
||||||
|
append->add( params( elem_type, value) );
|
||||||
|
append->add( type( void ) );
|
||||||
|
|
||||||
|
Code
|
||||||
body = append.body();
|
body = append.body();
|
||||||
body->add_untyped(
|
body->add( code_str(
|
||||||
if ( header.Capacity < header.Num + 1 )
|
if ( header.Capacity < header.Num + 1 )
|
||||||
if ( ! grow(0) )
|
if ( ! grow(0) )
|
||||||
return false;
|
return false;
|
||||||
);
|
));
|
||||||
|
|
||||||
body->add_untyped( assign,
|
body->add( code_str(
|
||||||
Data[ header.Num ] = value;
|
Data[ header.Num ] = value;
|
||||||
header.Num++;
|
header.Num++;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
);
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
Code back;
|
Code back;
|
||||||
{
|
{
|
||||||
Code body = untyped(
|
Code body = code_str(
|
||||||
Header& header = get_header();
|
Header& header = get_header();
|
||||||
|
|
||||||
return data[ header.Num - 1 ];
|
return data[ header.Num - 1 ];
|
||||||
);
|
);
|
||||||
|
|
||||||
proc( back, __, t_elem_type, __, body );
|
back = function( back, __, elem_type, __, body );
|
||||||
}
|
}
|
||||||
|
|
||||||
Code clear;
|
Code clear;
|
||||||
proc( clear, __, t_void, __, untyped_str("get_header().Num = 0;") );
|
function( clear, __, t_void, __, untyped_str("get_header().Num = 0;") );
|
||||||
|
|
||||||
Code fill;
|
Code fill;
|
||||||
{
|
{
|
||||||
Code check = untyped(
|
Code check = code_str(
|
||||||
if ( begin < 0 || end >= header.Num )
|
if ( begin < 0 || end >= header.Num )
|
||||||
fatal( "Range out of bounds" );
|
fatal( "Range out of bounds" );
|
||||||
);
|
);
|
||||||
|
|
||||||
Code iter = untyped(
|
Code iter = code_str(
|
||||||
for ( sw index = begin; index < end; index++ )
|
for ( sw index = begin; index < end; index++ )
|
||||||
Data[index] = vallue;
|
Data[index] = vallue;
|
||||||
);
|
);
|
||||||
|
|
||||||
Code body = proc_body( header, check, iter );
|
Code body = function_body( header, check, iter );
|
||||||
|
|
||||||
proc( fill, __, t_void, params( t_uw, "begin", t_uw, "end", t_elem_type, "value" ), body );
|
fill = function( fill, params( uw, begin, uw, end, elem_type, value ), void, __, body );
|
||||||
}
|
}
|
||||||
|
|
||||||
Code get_header;
|
Code get_header;
|
||||||
proc( get_header, spec_inline, t_ref_header, __, untyped_str("return pcast( Header, Data - 1);") );
|
function( get_header, __, ref_Header, spec_inline, code_str( return pcast( Header, Data - 1); ) );
|
||||||
|
|
||||||
|
Code test = function( test, __, void, __, __ );
|
||||||
|
|
||||||
Code grow;
|
Code grow;
|
||||||
{
|
{
|
||||||
Code body;
|
Code body;
|
||||||
{
|
{
|
||||||
variable( uw, new_capacity, untyped( grow_formula( header.Capacity) ));
|
variable( uw, new_capacity, code_str( grow_formula( header.Capacity) ));
|
||||||
|
|
||||||
Code check_n_set = untyped(
|
Code check_n_set = code_str(
|
||||||
if ( new_capacity < min_capacity )
|
if ( new_capacity < min_capacity )
|
||||||
new_capacity = min_capacity;
|
new_capacity = min_capacity;
|
||||||
);
|
);
|
||||||
|
|
||||||
Code ret = untyped( return set_capacity( new_capacity ); );
|
Code ret = code_str( return set_capacity( new_capacity ); );
|
||||||
|
|
||||||
body = proc_body( header, new_capacity, check_n_set, ret );
|
body = function_body( header, new_capacity, check_n_set, ret );
|
||||||
}
|
}
|
||||||
|
|
||||||
proc( grow, __, t_bool, params( t_uw, "min_capacity" ), body );
|
grow = function( grow, params( uw, min_capacity ), bool, body );
|
||||||
}
|
}
|
||||||
|
|
||||||
Code pop;
|
Code pop;
|
||||||
{
|
{
|
||||||
untyped_code( assertion, assert( header.Num > 0 ); );
|
Code assertion = code_str( assert( header.Num > 0 ); );
|
||||||
untyped_code( decrement, header.Num--; );
|
Code decrement = code_str( header.Num--; );
|
||||||
|
|
||||||
Code body = proc_body( header, assertion, decrement );
|
Code body = function_body( header, assertion, decrement );
|
||||||
|
|
||||||
proc( pop, __, t_void, __, body );
|
pop = function( pop, __, void, __, body );
|
||||||
}
|
}
|
||||||
|
|
||||||
Code reserve;
|
Code reserve;
|
||||||
{
|
{
|
||||||
untyped_code( check_n_set,
|
Code check_n_set = code_str(
|
||||||
if ( header.Capacity < new_capacity )
|
if ( header.Capacity < new_capacity )
|
||||||
return set_capacity( new_capacity );
|
return set_capacity( new_capacity );
|
||||||
);
|
);
|
||||||
|
|
||||||
Code ret = untyped_str("return true");
|
Code ret = code_str( return true );
|
||||||
|
|
||||||
Code body = proc_body( header, check_n_set, ret );
|
Code body = function_body( header, check_n_set, ret );
|
||||||
|
|
||||||
proc( reserve, __, t_bool, params( t_uw, "new_capacity" ), body );
|
reserve = function( reserve, params( uw, new_capacity ), bool, __, body );
|
||||||
}
|
}
|
||||||
|
|
||||||
Code resize;
|
Code resize;
|
||||||
{
|
{
|
||||||
Code body;
|
Code body;
|
||||||
{
|
{
|
||||||
untyped_code( check_n_grow,
|
Code check_n_grow = code_str(
|
||||||
if ( header.Capacity < new_num )
|
if ( header.Capacity < new_num )
|
||||||
if ( ! grow( new_num) )
|
if ( ! grow( new_num) )
|
||||||
return false;
|
return false;
|
||||||
);
|
);
|
||||||
|
|
||||||
untyped_code( set_n_ret,
|
Code set_n_ret = code_str(
|
||||||
header.Count = new_num;
|
header.Count = new_num;
|
||||||
return true;
|
return true;
|
||||||
);
|
);
|
||||||
|
|
||||||
body = proc_body( header, check_n_grow, set_n_ret );
|
body = function_body( header, check_n_grow, set_n_ret );
|
||||||
}
|
}
|
||||||
|
|
||||||
proc( resize, __, t_bool, params( t_uw, "new_num" ), body );
|
resize = function( resize, params( uw, new_num ), bool, __, body );
|
||||||
}
|
}
|
||||||
|
|
||||||
Code set_capacity = proc_code(
|
Code set_capacity = function_code(
|
||||||
bool set_capacity( new_capacity )
|
bool set_capacity( new_capacity )
|
||||||
{
|
{
|
||||||
Header& header = get_header();
|
Header& header = get_header();
|
||||||
@ -546,7 +548,7 @@
|
|||||||
header.Num = capacity;
|
header.Num = capacity;
|
||||||
|
|
||||||
uw size = sizeof(Header) + sizeof(Type) * capacity;
|
uw size = sizeof(Header) + sizeof(Type) * capacity;
|
||||||
Header* new_header = rcast( Header* alloc( header.Allocator, size ));
|
Header* new_header = rcast( Header*, alloc( header.Allocator, size ));
|
||||||
|
|
||||||
if ( new_header == nullptr )
|
if ( new_header == nullptr )
|
||||||
return false;
|
return false;
|
||||||
@ -568,7 +570,7 @@
|
|||||||
char const* name = bprintf( "Array_%s", type_str );
|
char const* name = bprintf( "Array_%s", type_str );
|
||||||
|
|
||||||
Code body = struct_body(
|
Code body = struct_body(
|
||||||
Type
|
Type
|
||||||
, Data
|
, Data
|
||||||
|
|
||||||
, init
|
, init
|
||||||
@ -586,9 +588,10 @@
|
|||||||
, set_capacity
|
, set_capacity
|
||||||
);
|
);
|
||||||
|
|
||||||
array_def = def_struct( name, body, parent );
|
array_def = struct( name, parent, body );
|
||||||
}
|
}
|
||||||
#endif
|
# pragma pop_macro("rcast")
|
||||||
|
# endif
|
||||||
|
|
||||||
return array_def;
|
return array_def;
|
||||||
}
|
}
|
||||||
|
@ -2,10 +2,10 @@ project( 'test', 'c', 'cpp', default_options : ['buildtype=debug'] )
|
|||||||
|
|
||||||
# add_global_arguments('-E', language : 'cpp')
|
# add_global_arguments('-E', language : 'cpp')
|
||||||
|
|
||||||
includes = include_directories(
|
includes = include_directories(
|
||||||
[
|
[
|
||||||
'../../project',
|
'../../project',
|
||||||
'../../thirdparty'
|
'../../thirdparty'
|
||||||
])
|
])
|
||||||
|
|
||||||
# get_sources = files('./get_sources.ps1')
|
# get_sources = files('./get_sources.ps1')
|
||||||
@ -16,8 +16,11 @@ sources = [ '../test.cpp' ]
|
|||||||
if get_option('buildtype').startswith('debug')
|
if get_option('buildtype').startswith('debug')
|
||||||
|
|
||||||
add_project_arguments('-DBuild_Debug', language : ['c', 'cpp'])
|
add_project_arguments('-DBuild_Debug', language : ['c', 'cpp'])
|
||||||
|
# add_project_arguments('-E', language : ['c', 'cpp'])
|
||||||
|
|
||||||
endif
|
endif
|
||||||
|
# add_project_arguments('-E', language : ['c', 'cpp'])
|
||||||
|
# add_global_arguments( '-E', language : ['cpp'])
|
||||||
|
|
||||||
add_project_arguments('-Dgen_time', language : ['c', 'cpp'])
|
add_project_arguments('-Dgen_time', language : ['c', 'cpp'])
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
What it should generate:
|
What it should generate:
|
||||||
|
|
||||||
inline
|
inline
|
||||||
type square( type value )
|
type square( type value )
|
||||||
{
|
{
|
||||||
@ -20,19 +20,19 @@
|
|||||||
#define gen_square( Type_ ) gen__square( #Type_ )
|
#define gen_square( Type_ ) gen__square( #Type_ )
|
||||||
Code gen__square( char const* type )
|
Code gen__square( char const* type )
|
||||||
{
|
{
|
||||||
Code integral_type = def_type( type );
|
Code t_integral_type = def_type( type );
|
||||||
|
|
||||||
#ifndef GEN_DEFINE_DSL
|
#ifndef GEN_DEFINE_DSL
|
||||||
string name = string_sprintf( g_allocator, (char*)sprintf_buf, ZPL_PRINTF_MAXLEN, "square", type );
|
string name = string_sprintf( g_allocator, (char*)sprintf_buf, ZPL_PRINTF_MAXLEN, "square", type );
|
||||||
|
|
||||||
#if 0
|
#if 1
|
||||||
Code square;
|
Code square;
|
||||||
{
|
{
|
||||||
Code params = def_params( 1, integral_type, "value" );
|
Code params = def_params( 1, integral_type, "value" );
|
||||||
Code specifiers = def_specifiers( 1, SpecifierT::Inline );
|
Code specifiers = def_specifiers( 1, SpecifierT::Inline );
|
||||||
Code ret_stmt = untyped_str( txt( return value * value; ));
|
Code ret_stmt = untyped_str( txt( return value * value; ));
|
||||||
|
|
||||||
square = def_proc( name, specifiers, params, integral_type, ret_stmt );
|
square = def_function( name, specifiers, params, integral_type, ret_stmt );
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
@ -45,16 +45,15 @@
|
|||||||
);
|
);
|
||||||
char const* gen_code = token_fmt( tmpl, 1, "type", type );
|
char const* gen_code = token_fmt( tmpl, 1, "type", type );
|
||||||
|
|
||||||
Code square = parse_proc(gen_code, strlen(gen_code));
|
Code square = parse_function(gen_code, strlen(gen_code));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
Code square = function( square, params( integral_type, value), integral_type, __,
|
||||||
Code proc( square, __, integral_type, params( integral_type, "value" ),
|
code_str(return value * value)
|
||||||
untyped(return value * value)
|
|
||||||
);
|
);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if ( ! square )
|
if ( ! square )
|
||||||
fatal( "Failed to generate square function for: %s", type );
|
fatal( "Failed to generate square function for: %s", type );
|
||||||
|
|
||||||
@ -68,7 +67,7 @@
|
|||||||
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 );
|
||||||
|
Loading…
Reference in New Issue
Block a user