Changed zpl implemenation based on latest refactor script I use, refactored code to changes.

This commit is contained in:
Edward R. Gonzalez 2023-04-09 13:59:39 -04:00
parent 642fb16d4f
commit 56d7aa1d72
5 changed files with 21561 additions and 18261 deletions

View File

@ -9,7 +9,9 @@ namespace Global
namespace Memory
{
arena Global_Arena {};
using namespace zpl;
Arena Global_Arena {};
void setup()
{
@ -68,10 +70,10 @@ sw token_fmt_va( char* buf, uw buf_size, char const* fmt, s32 num_tokens, va_lis
TokEntry entry
{
value,
zpl_strnlen(value, (sw)128)
strnlen(value, (sw)128)
};
u32 key = crc32( token, zpl_strnlen(token, 32) );
u32 key = crc32( token, strnlen(token, 32) );
tokmap_set( & tok_map, key, entry );
}

View File

@ -9,7 +9,7 @@
# define ZPL_IMPLEMENTATION
#endif
// TODO: This will be removed when making the library have zero dependencies.
#pragma region ZPL INCLUDE
#if __clang__
# pragma clang diagnostic push
@ -18,6 +18,7 @@
#endif
// # define ZPL_HEAP_ANALYSIS
# define ZPL_WRAP_IN_NAMESPACE
# define ZPL_NO_MATH_H
# define ZPL_CUSTOM_MODULES
# define ZPL_MODULE_ESSENTIALS
@ -35,6 +36,48 @@
// # define ZPL_MODULE_PARSER
#include "zpl.h"
using zpl::s8;
using zpl::s16;
using zpl::s32;
using zpl::s64;
using zpl::u8;
using zpl::u32;
using zpl::u64;
using zpl::uw;
using zpl::sw;
using zpl::Arena;
using zpl::AllocatorInfo;
using zpl::ArrayHeader;
using zpl::FileInfo;
using zpl::FileError;
using zpl::Pool;
using zpl::String;
// using zpl::StringHeader;
using zpl::EFileMode_WRITE;
using zpl::EFileError_NONE;
using zpl::arena_allocator;
using zpl::arena_init_from_memory;
using zpl::arena_free;
using zpl::char_is_alpha;
using zpl::char_is_space;
using zpl::crc32;
using zpl::memset;
using zpl::pool_free;
using zpl::printf_va;
using zpl::printf_err_va;
using zpl::snprintf_va;
using zpl::string_appendc;
using zpl::string_append_fmt;
using zpl::string_append_length;
using zpl::string_length;
using zpl::string_make;
using zpl::strnlen;
// using zpl::
#if __clang__
# pragma clang diagnostic pop
#endif
@ -135,7 +178,7 @@ namespace Memory
{
ct uw Initial_Reserve = megabytes(10);
extern arena Global_Arena;
extern Arena Global_Arena;
// #define g_allocator arena_allocator( & Memory::Global_Arena)
// Heap allocator is being used for now to isolate errors from being memory related (tech debt till ready to address)
@ -172,7 +215,7 @@ sw log_fmt(char const *fmt, ...)
va_list va;
va_start(va, fmt);
res = zpl_printf_va(fmt, va);
res = printf_va(fmt, va);
va_end(va);
return res;
@ -188,17 +231,17 @@ sw fatal(char const *fmt, ...)
#if Build_Debug
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);
assert_crash(buf);
return -1;
#else
va_start(va, fmt);
zpl_printf_err_va( fmt, va);
printf_err_va( fmt, va);
va_end(va);
zpl_exit(1);
exit(1);
return -1;
#endif
}

View File

@ -4,14 +4,14 @@
#ifdef gen_time
namespace gen
{
ZPL_TABLE_DEFINE( StringTable, str_tbl_, string );
ZPL_TABLE_DEFINE( StringTable, str_tbl_, String );
ZPL_TABLE_DEFINE( TypeTable, type_tbl_ , Code );
namespace StaticData
{
#ifndef GEN_CODE_USE_SOA
static array(pool) CodePools;
static array(pool) CodeEntriesPools;
static Array(Pool) CodePools;
static Array(Pool) CodeEntriesPools;
#else
using DataUnion = union
@ -67,7 +67,7 @@ namespace gen
}
#endif
static array(arena) StringArenas = nullptr;
static Array(Arena) StringArenas = nullptr;
static StringTable StringMap;
static TypeTable TypeMap;
@ -80,11 +80,11 @@ namespace gen
static sw SizePer_StringArena = megabytes(32);
static allocator Allocator_CodePool = heap();
static allocator Allocator_CodeEntriesPool = heap();
static allocator Allocator_StringArena = heap();
static allocator Allocator_StringTable = heap();
static allocator Allocator_TypeTable = heap();
static AllocatorInfo Allocator_CodePool = heap();
static AllocatorInfo Allocator_CodeEntriesPool = heap();
static AllocatorInfo Allocator_StringArena = heap();
static AllocatorInfo Allocator_StringTable = heap();
static AllocatorInfo Allocator_TypeTable = heap();
}
#pragma region CONSTANTS
@ -126,6 +126,21 @@ namespace gen
case Untyped:
break;
case Enum:
break;
case Enum_FwdDecl:
break;
case Enum_Body:
break;
case Enum_Class:
break;
case Enum_Class_FwdDecl:
break;
case Global_Body:
break;
@ -177,7 +192,58 @@ namespace gen
bool AST::check()
{
switch ( Type )
{
using namespace ECode;
case Untyped:
break;
case Global_Body:
break;
case Function:
break;
case Function_Body:
break;
case Function_FwdDecl:
break;
case Namespace:
break;
case Namespace_Body:
break;
case Parameters:
break;
case Specifiers:
break;
case Struct:
break;
case Struct_Body:
break;
case Variable:
break;
case Typedef:
break;
case Typename:
break;
case Using:
break;
}
return true;
}
AST* AST::duplicate()
@ -244,9 +310,9 @@ namespace gen
}
}
string AST::to_string() const
String AST::to_string() const
{
string result = string_make( g_allocator, "" );
String result = string_make( g_allocator, "" );
if ( Comment )
result = string_append_fmt( result, "// %s\n", Comment );
@ -256,44 +322,44 @@ namespace gen
using namespace ECode;
case Invalid:
fatal("Attempted to serialize invalid code! - %s", Name);
log_failure("Attempted to serialize invalid code! - %s", Name);
break;
case Untyped:
result = string_append_length( result, Content, string_length(Content) );
result = string_append_length( result, Content, string_length( ccast(String, Content)) );
break;
case Function_FwdDecl:
{
u32 index = 0;
u32 left = array_count( Entries );
case Access_Public:
case Access_Protected:
case Access_Private:
result = string_append_length( result, Name, string_length( ccast(String, Name)) ) ;
break;
if ( left <= 0 )
fatal( "Code::to_string - Name: %s Type: %s, expected definition", Name, Type );
case Class:
break;
if ( Entries[index]->Type == Specifiers )
{
result = string_append_fmt( result, "%s\n", Entries[index]->to_string() );
index++;
left--;
}
case Class_FwdDecl:
break;
if ( left <= 0 )
fatal( "Code::to_string - Name: %s Type: %s, expected return type", Name, Type );
case Class_Body:
break;
result = string_append_fmt( result, "\n%s %s(", Entries[index]->to_string(), Name );
index++;
left--;
case Enum:
break;
if ( left && Entries[index]->Type == Parameters )
{
result = string_append_fmt( result, "%s", Entries[index]->to_string() );
index++;
left--;
}
case Enum_FwdDecl:
break;
result = string_appendc( result, ");\n" );
}
case Enum_Body:
break;
case Enum_Class:
break;
case Enum_Class_FwdDecl:
break;
case Friend:
break;
case Function:
@ -302,7 +368,7 @@ namespace gen
u32 left = array_count( Entries );
if ( left <= 0 )
fatal( "Code::to_string - Name: %s Type: %s, expected definition", Name, Type );
log_failure( "Code::to_string - Name: %s Type: %s, expected definition", Name, Type );
if ( Entries[index]->Type == Specifiers )
{
@ -312,7 +378,7 @@ namespace gen
}
if ( left <= 0 )
fatal( "Code::to_string - Name: %s Type: %s, expected return type", Name, Type );
log_failure( "Code::to_string - Name: %s Type: %s, expected return type", Name, Type );
result = string_append_fmt( result, "\n%s %s(", Entries[index]->to_string(), Name );
index++;
@ -329,16 +395,58 @@ namespace gen
}
break;
case Function_FwdDecl:
{
u32 index = 0;
u32 left = array_count( Entries );
if ( left <= 0 )
log_failure( "Code::to_string - Name: %s Type: %s, expected definition", Name, Type );
if ( Entries[index]->Type == Specifiers )
{
result = string_append_fmt( result, "%s\n", Entries[index]->to_string() );
index++;
left--;
}
if ( left <= 0 )
log_failure( "Code::to_string - Name: %s Type: %s, expected return type", Name, Type );
result = string_append_fmt( result, "\n%s %s(", Entries[index]->to_string(), Name );
index++;
left--;
if ( left && Entries[index]->Type == Parameters )
{
result = string_append_fmt( result, "%s", Entries[index]->to_string() );
index++;
left--;
}
result = string_appendc( result, ");\n" );
}
break;
case Function_Body:
fatal("NOT SUPPORTED YET");
log_failure("NOT SUPPORTED YET");
break;
case Global_Body:
break;
case Namespace:
fatal("NOT SUPPORTED YET");
log_failure("NOT SUPPORTED YET");
break;
case Namespace_Body:
fatal("NOT SUPPORTED YET");
log_failure("NOT SUPPORTED YET");
break;
case Operator:
break;
case Operator_FwdDecl:
break;
case Parameters:
@ -361,19 +469,22 @@ namespace gen
break;
case Struct:
fatal("NOT SUPPORTED YET");
log_failure("NOT SUPPORTED YET");
break;
case Struct_FwdDecl:
break;
case Struct_Body:
fatal("NOT SUPPORTED YET");
log_failure("NOT SUPPORTED YET");
break;
case Variable:
fatal("NOT SUPPORTED YET");
log_failure("NOT SUPPORTED YET");
break;
case Typedef:
fatal("NOT SUPPORTED YET");
log_failure("NOT SUPPORTED YET");
break;
case Typename:
@ -381,7 +492,7 @@ namespace gen
break;
case Using:
fatal("NOT SUPPORTED YET");
log_failure("NOT SUPPORTED YET");
break;
}
@ -394,10 +505,10 @@ namespace gen
#pragma region Gen Interface
void init()
{
array_init( StaticData::CodePool, StaticData::Allocator_CodePool );
array_init( StaticData::CodePools, StaticData::Allocator_CodePool );
array_init( StaticData::StringArenas, heap() );
arena string_arena;
Arena string_arena;
arena_init_from_allocator( & string_arena, StaticData::Allocator_StringArena, StaticData::SizePer_StringArena );
str_tbl_init( & StaticData::StringMap, StaticData::Allocator_StringTable );
@ -443,8 +554,8 @@ namespace gen
spec_constexpr_write = ccast( Code, spec_constexpr );
spec_constexpr_write = def_specifiers( 1, ESpecifier::Constexpr );
# define def_constant_spec( Type_, ... ) \
Code& \
# define def_constant_spec( Type_, ... ) \
Code& \
spec_##Type_ = def_specifiers( macro_num_args(__VA_ARGS__), __VA_ARGS__); \
spec_##Type_.lock();
@ -461,7 +572,7 @@ namespace gen
s32 left = 0;
while (( left-- ))
{
pool* code_pool = & StaticData::CodePools[index];
Pool* code_pool = & StaticData::CodePools[index];
pool_free( code_pool );
}
@ -474,7 +585,7 @@ namespace gen
s32 left = 0;
while (( left-- ))
{
pool* code_entries_pool = & StaticData::CodeEntriesPools[index];
Pool* code_entries_pool = & StaticData::CodeEntriesPools[index];
pool_free( code_entries_pool );
}
@ -482,13 +593,13 @@ namespace gen
}
}
allocator get_string_allocator( s32 str_length )
AllocatorInfo get_string_allocator( s32 str_length )
{
using namespace StaticData;
if ( StringArenas->total_allocated + str_length > StringArenas->total_size )
{
arena new_arena;
Arena new_arena;
arena_init_from_allocator( & new_arena, Allocator_StringArena, SizePer_StringArena );
array_append( StringArenas, new_arena );
@ -506,7 +617,7 @@ namespace gen
u32 key = crc32( cstr, hash_length );
string* result = str_tbl_get( & StaticData::StringMap, key );
String* result = str_tbl_get( & StaticData::StringMap, key );
if ( result )
{
@ -532,11 +643,6 @@ namespace gen
array_append( CodePool, Invalid );
return pcast( Code, array_back( CodePool ));
# else
array_append( CodePool::Type, ECode::Invalid );
@ -551,7 +657,7 @@ namespace gen
# endif
}
array(AST*) make_code_entries()
Array(AST*) make_code_entries()
{
}
@ -561,16 +667,26 @@ namespace gen
}
void set_allocator_code_pool( AllocatorInfo pool_allocator )
{
StaticData::Allocator_CodePool = pool_allocator;
}
void set_allocator_string_arena( AllocatorInfo string_allocator )
{
StaticData::Allocator_StringArena = string_allocator;
}
void set_allocator_string_table( AllocatorInfo string_allocator )
{
StaticData::Allocator_StringArena = string_allocator;
}
void set_init_reserve_code_pool( sw size )
{
StaticData::InitSize_CodePool = size;
}
void set_init_reserve_string_arena( sw size )
{
StaticData::InitSize_StringArena = size;
}
void set_init_reserve_string_table( sw size )
{
StaticData::InitSize_StringTable = size;
@ -581,42 +697,44 @@ namespace gen
StaticData::InitSize_TypeTable = size;
}
void set_allocator_code_pool( allocator pool_allocator )
{
StaticData::Allocator_CodePool = pool_allocator;
}
void set_allocator_string_arena( allocator string_allocator )
{
StaticData::Allocator_StringArena = string_allocator;
}
void set_allocator_string_table( allocator string_allocator )
{
StaticData::Allocator_StringArena = string_allocator;
}
void set_allocator_type_table( allocator type_reg_allocator )
void set_allocator_type_table( AllocatorInfo type_reg_allocator )
{
StaticData::Allocator_TypeTable = type_reg_allocator;
}
void set_size_string_arena( sw size )
{
StaticData::SizePer_StringArena = size;
}
# pragma region Helper Functions
// This snippet is required in nearly all the functions.
# define name_check( Context_, Length_, Name_ ) \
do \
{ \
if ( Length_ <= 0 ) \
{ \
log_failure( "gen::%s: Invalid name length provided - %d", #Context_, length ); \
return Code::Invalid; \
} \
\
if ( Name_ == nullptr ) \
{ \
log_failure( "gen::%s: name is null", #Context_); \
return Code::Invalid; \
} \
} \
while (0)
# pragma endregion Helper Functions
# pragma region Upfront Constructors
Code def_class( s32 length, char const* name, Code parent, Code specifiers, Code body )
{
using namespace ECode;
if ( length <= 0 )
{
log_failure( "gen::def_class: Invalid name length provided - %d", length );
return Code::Invalid;
}
if ( name == nullptr )
{
log_failure( "gen::def_class: name is null");
return Code::Invalid;
}
name_check( def_class, length, name );
if ( parent && parent->Type != Class || parent->Type != Struct )
{
@ -634,8 +752,6 @@ namespace gen
result = make_code();
result->Name = cached_string( name, length );
array_init( result->Entries, StaticData::Allocator_CodePool );
if ( body )
{
switch ( body->Type )
@ -649,7 +765,8 @@ namespace gen
return Code::Invalid;
}
result->Type = Class;
result->Type = Class;
result->Entries = make_code_entries();
result->add_entry( body );
}
else
@ -671,17 +788,7 @@ namespace gen
{
using namespace ECode;
if ( length <= 0 )
{
log_failure( "gen::def_enum: Invalid name length provided - %d", length );
return Code::Invalid;
}
if ( name == nullptr )
{
log_failure( "gen::def_class: name is null" );
return Code::Invalid;
}
name_check( def_enum, length, name );
if ( type && type->Type != Typename )
{
@ -709,6 +816,7 @@ namespace gen
result->Type = specifier == EnumClass ?
Enum_Class : Enum;
result->Entries = make_code_entries();
result->add_entry( body );
}
else if ( specifier == EnumClass )
@ -726,6 +834,37 @@ namespace gen
return result;
}
Code def_friend( Code symbol )
{
using namespace ECode;
if ( ! symbol )
{
log_failure( "gen::def_friend: symbol provided is null!" );
}
if ( symbol == Code::Invalid )
{
log_failure("gen::def_friend: symbol provided is invalid!" );
return;
}
switch ( symbol->Type )
{
case Class_FwdDecl:
case Function_FwdDecl:
case Operator_FwdDecl:
case Struct_FwdDecl:
break;
default:
log_failure("gen::def_friend: symbol cannot be used with friend, must be a forward declare - %s", symbol->debug_str());
return;
}
}
Code def_function( s32 length, char const* name
, Code specifiers
, Code params
@ -735,17 +874,7 @@ namespace gen
{
using namespace ECode;
if ( length <= 0 )
{
log_failure( "gen::def_function: Invalid name length provided - %d", length );
return Code::Invalid;
}
if ( name == nullptr )
{
log_failure( "gen::def_function: name is null" );
return Code::Invalid;
}
name_check( def_function, length, name );
if ( specifiers && specifiers->Type != Specifiers )
{
@ -817,17 +946,7 @@ namespace gen
{
using namespace ECode;
if ( length <= 0 )
{
log_failure( "gen::def_namespace: Invalid name length provided - %d", length );
return Code::Invalid;
}
if ( name == nullptr )
{
log_failure( "gen::def_namespace: name is null" );
return Code::Invalid;
}
name_check( def_namespace, length, name );
Code
result = make_code();
@ -881,17 +1000,7 @@ namespace gen
{
using namespace ECode;
if ( length <= 0 )
{
log_failure( "gen::def_function: Invalid name length provided - %d", length );
return Code::Invalid;
}
if ( name == nullptr )
{
log_failure( "gen::def_function: name is null" );
return Code::Invalid;
}
name_check( def_struct, length, name );
if ( specifiers && specifiers->Type != Specifiers )
{
@ -912,11 +1021,10 @@ namespace gen
}
Code
result = make_code();
result->Type = Struct;
result->Name = cached_string( name, length );
array_init( result->Entries, g_allocator );
result = make_code();
result->Type = Struct;
result->Name = cached_string( name, length );
result->Entries = make_code_entries();
if ( body )
result->add_entry( body );
@ -932,17 +1040,7 @@ namespace gen
Code def_variable( Code type, u32 length, char const* name, Code value, Code specifiers )
{
if ( length <= 0 )
{
log_failure( "gen::def_function: Invalid name length provided - %d", length );
return Code::Invalid;
}
if ( name == nullptr )
{
log_failure( "gen::def_function: name is null" );
return Code::Invalid;
}
name_check( def_variable, length, name );
if ( specifiers && specifiers->Type != ECode::Specifiers )
{
@ -963,11 +1061,10 @@ namespace gen
}
Code
result = make_code();
result->Name = cached_string( name, length );
result->Type = ECode::Variable;
array_init( result->Entries, g_allocator );
result = make_code();
result->Name = cached_string( name, length );
result->Type = ECode::Variable;
result->Entries = make_code_entries();
if ( specifiers )
result->add_entry( specifiers );
@ -982,17 +1079,7 @@ namespace gen
Code def_type( u32 length, char const* name, Code specifiers )
{
if ( length <= 0 )
{
log_failure( "gen::def_function: Invalid name length provided - %d", length );
return Code::Invalid;
}
if ( name == nullptr )
{
log_failure( "gen::def_function: name is null" );
return Code::Invalid;
}
name_check( def_type, length, name );
Code
result = make_code();
@ -1004,17 +1091,7 @@ namespace gen
Code def_using( u32 length, char const* name, Code type, UsingT specifier )
{
if ( length <= 0 )
{
log_failure( "gen::def_function: Invalid name length provided - %d", length );
return Code::Invalid;
}
if ( name == nullptr )
{
log_failure( "gen::def_function: name is null" );
return Code::Invalid;
}
name_check( def_using, length, name );
Code
result = make_code();
@ -1259,7 +1336,7 @@ namespace gen
Code type = va_arg(va, Code);
char const* name = va_arg(va, char const*);
s32 name_length = zpl_strnlen(name, MaxNameLength);
s32 name_length = strnlen(name, MaxNameLength);
result->Name = cached_string( name, name_length );
@ -1278,7 +1355,7 @@ namespace gen
type = va_arg(va, Code);
name = va_arg(va, char const*);
name_length = zpl_strnlen(name, MaxNameLength);
name_length = strnlen(name, MaxNameLength);
Code
param = make_code();
@ -1312,12 +1389,12 @@ namespace gen
Code def_specifiers( s32 num, ... )
{
if ( num <= 0 )
fatal("gen::make_specifier: num cannot be zero or less");
log_failure("gen::make_specifier: num cannot be zero or less");
// This should be more than enough...
static u8 FixedSizedBuffer[kilobytes(1024)];
static arena str_arena;
static Arena str_arena;
do_once_start
arena_init_from_memory( & str_arena, FixedSizedBuffer, kilobytes(1024) );
do_once_end
@ -1326,7 +1403,7 @@ namespace gen
result = make_code();
result->Type = ECode::Specifiers;
string crafted = string_make( arena_allocator( & str_arena ), "" );
String crafted = string_make( arena_allocator( & str_arena ), "" );
va_list va;
va_start(va, num);
@ -1337,13 +1414,13 @@ namespace gen
switch ( type )
{
case ESpecifier::Alignas:
crafted = string_append_fmt( result->Content, "%s(%d)", ESpecifier::to_str(type), va_arg(va, u32) );
crafted = string_append_fmt( (String)result->Content, "%s(%d)", ESpecifier::to_str(type), va_arg(va, u32) );
break;
default:
const char* str = ESpecifier::to_str(type);
crafted = string_append_fmt( result->Content, "%s", str );
crafted = string_append_fmt( (String)result->Content, "%s", str );
break;
}
}
@ -1429,6 +1506,8 @@ namespace gen
{
using namespace ECode;
name_check( make_function, length, name );
if ( specifiers && specifiers->Type != Specifiers )
{
log_failure( "gen::def_function: specifiers was not a `Specifiers` type" );
@ -1472,14 +1551,15 @@ namespace gen
return result;
}
Code make_global_body( char const* name = "", s32 num = 0, ... )
Code make_global_body( s32 length, char const* name, s32 num, ... )
{
Code
result = make_code();
result->Type = ECode::Global_Body;
result->Name = string_make( g_allocator, "");
name_check( make_global_body, length, name );
array_init( result->Entries, g_allocator );
Code
result = make_code();
result->Type = ECode::Global_Body;
result->Name = cached_string( name, length );
result->Entries = make_code_entries();
// Making body at entry 0;
result->add_entry( make_code() );
@ -1507,10 +1587,12 @@ namespace gen
}
Code make_struct( char const* name, Code parent, Code specifiers )
Code make_struct( s32 length, char const* name, Code parent, Code specifiers )
{
using namespace ECode;
name_check( make_struct, length, name );
if ( specifiers && specifiers->Type != Specifiers )
{
log_failure( "gen::def_struct: specifiers was not a `Specifiers` type" );
@ -1527,7 +1609,7 @@ namespace gen
result = make_code();
result->Type = Struct;
result->Name = string_make( g_allocator, name );
result->Entires = make_code_entries();
result->Entries = make_code_entries();
Code
body = make_code();
@ -1575,7 +1657,7 @@ namespace gen
return Code::Invalid;
}
arena mem;
Arena mem;
do_once_start
{
arena_init_from_allocator( & mem, heap(), kilobytes( 10 ) );
@ -1600,7 +1682,7 @@ namespace gen
Param Params[ 64 ] { 0 };
// Zero out params before a run of this func.
zpl_memset( Params, 0, sizeof( Params ));
memset( Params, 0, sizeof( Params ));
char const* name;
s32 name_length = 0;
@ -1741,7 +1823,7 @@ namespace gen
Code parse_struct( s32 length, char const* def )
{
arena mem;
Arena mem;
do_once_start
arena_init_from_allocator( & mem, heap(), kilobytes( 10 ) );
do_once_end
@ -1848,7 +1930,7 @@ namespace gen
va_list va;
va_start(va, fmt);
zpl_snprintf_va(buf, ZPL_PRINTF_MAXLEN, fmt, va);
snprintf_va(buf, ZPL_PRINTF_MAXLEN, fmt, va);
va_end(va);
Code
@ -1892,11 +1974,11 @@ namespace gen
bool Builder::open( char const* path )
{
file_error error = file_open_mode( & File, ZPL_FILE_MODE_WRITE, path );
FileError error = file_open_mode( & File, EFileMode_WRITE, path );
if ( error != ZPL_FILE_ERROR_NONE )
if ( error != EFileError_NONE )
{
fatal( "gen::File::open - Could not open file: %s", path);
log_failure( "gen::File::open - Could not open file: %s", path);
return false;
}
@ -1910,7 +1992,7 @@ namespace gen
bool result = file_write( & File, Buffer, string_length(Buffer) );
if ( result == false )
fatal("gen::File::write - Failed to write to file: %s", file_name( & File ) );
log_failure("gen::File::write - Failed to write to file: %s", file_name( & File ) );
// file_seek( & File, 0 );
file_close( & File );

View File

@ -368,7 +368,7 @@ namespace gen
Entry( Namespace ) \
Entry( Namespace_Body ) \
Entry( Operator ) \
Entry( Operator_Fwd ) \
Entry( Operator_FwdDecl ) \
Entry( Parameters ) \
Entry( Specifiers ) \
Entry( Struct ) \
@ -580,7 +580,7 @@ namespace gen
{
char const* enum_str = to_str( (Type)index );
keymap[index] = crc32( enum_str, zpl_strnlen(enum_str, 42) );
keymap[index] = crc32( enum_str, strnlen(enum_str, 42) );
}
do_once_end
@ -684,7 +684,7 @@ namespace gen
// Thus if its desired to keep the debug str
// for multiple calls to bprintf,
// allocate this to proper string.
return bprintf( fmt
return zpl::bprintf( fmt
, type_str()
, Readonly ? "true" : "false"
, Parent ? Parent->Name : ""
@ -699,7 +699,7 @@ namespace gen
return ECode::str( Type );
}
string to_string() const;
String to_string() const;
# pragma endregion Member Functions
# define Using_Code_POD \
@ -707,7 +707,7 @@ namespace gen
string_const Name; \
string_const Comment; \
union { \
array(AST*) Entries; \
Array(AST*) Entries; \
string_const Content; \
}; \
CodeT Type; \
@ -851,7 +851,7 @@ namespace gen
/*
Implements basic string interning. Data structure is based off the ZPL Hashtable.
*/
ZPL_TABLE_DECLARE( ZPL_EXTERN, StringTable, str_tbl_, string );
ZPL_TABLE_DECLARE( ZPL_EXTERN, StringTable, str_tbl_, String );
// Represents strings cached with the string table.
// Should never be modified, if changed string is desired, cache_string( str ) another.
@ -895,20 +895,21 @@ namespace gen
This provides a fresh Code AST array for the entries field of the AST.
This is done separately from the regular CodePool allocator.
*/
array(AST*) make_code_entries();
Array(AST*) make_code_entries();
// Set these before calling gen's init() procedure.
void set_allocator_code_pool ( AllocatorInfo pool_allocator );
void set_allocator_string_arena( AllocatorInfo string_allocator );
void set_allocator_string_table( AllocatorInfo string_allocator );
void set_allocator_type_table ( AllocatorInfo type_reg_allocator );
void set_init_reserve_code_pool ( sw size );
void set_init_reserve_code_entries_pool( sw size );
void set_init_reserve_string_arena ( sw size );
void set_init_reserve_string_table ( sw size );
void set_init_reserve_type_table ( sw size );
void set_allocator_code_pool ( allocator pool_allocator );
void set_allocator_string_arena( allocator string_allocator );
void set_allocator_string_table( allocator string_allocator );
void set_allocator_type_table ( allocator type_reg_allocator );
void set_size_string_arena( sw size );
# pragma region Upfront
Code def_class ( char const* name, Code parent = NoCode, Code specifiers = NoCode, Code body = NoCode );
@ -945,7 +946,6 @@ namespace gen
Code def_function_body ( s32 num, Code* codes );
Code def_namespace_body ( s32 num, ... );
Code def_params ( s32 num, ... );
Code def_params_macro ( s32 num, ... );
Code def_params ( s32 num, Code* params );
Code def_specifiers ( s32 num , ... );
Code def_specifiers ( s32 num, SpecifierT* specs );
@ -954,21 +954,21 @@ namespace gen
# pragma endregion Upfront
# pragma region Incremental
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 ( char const* name, Code type = NoCode, EnumT specifier = EnumRegular );
Code make_enum ( s32 length, char const* name, Code type = NoCode, EnumT specifier = EnumRegular );
Code make_function ( char const* name, Code params = NoCode, Code ret_type = NoCode, Code specifiers = NoCode );
Code make_function ( s32 length, 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_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 ( char const* name, Code type = NoCode, EnumT specifier = EnumRegular );
Code make_enum ( s32 length, char const* name, Code type = NoCode, EnumT specifier = EnumRegular );
Code make_function ( char const* name, Code params = NoCode, Code ret_type = NoCode, Code specifiers = NoCode );
Code make_function ( s32 length, 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 = 1, 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_params ();
Code make_specifiers ();
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_struct ( char const* name, Code parent = NoCode, Code specifiers = NoCode );
Code make_struct ( s32 length, char const* name, Code parent = NoCode, Code specifiers = NoCode );
# pragma endregion Incremental
# pragma region Parsing
@ -1006,8 +1006,8 @@ namespace gen
struct Builder
{
zpl_file File;
string Buffer;
FileInfo File;
String Buffer;
void print( Code );
@ -1054,7 +1054,7 @@ namespace gen
{
union {
SymbolData Symbol;
string Specification;
String Specification;
};
RequestType Type;
};
@ -1067,13 +1067,13 @@ namespace gen
bool Result;
};
static allocator Allocator;
static AllocatorInfo Allocator;
static void set_allocator( allocator mem_allocator );
static void set_allocator( AllocatorInfo allocator );
array(zpl_file) Files;
string Buffer;
array(RequestEntry) Requests;
Array(FileInfo) Files;
String Buffer;
Array(RequestEntry) Requests;
void add_files( s32 num, char const** files );
@ -1085,7 +1085,7 @@ namespace gen
void refactor( char const* file_path, char const* specification_path );
# endif
bool process_requests( array(Receipt) out_receipts );
bool process_requests( Array(Receipt) out_receipts );
};
#endif
@ -1104,19 +1104,19 @@ namespace gen
bool Result;
};
allocator Allocator;
AllocatorInfo MemAlloc;
static void set_allocator( allocator mem_allocator );
static void set_allocator( AllocatorInfo allocator );
array(zpl_file) Files;
string Buffer;
array(RequestEntry) Requests;
Array(FileInfo) Files;
String Buffer;
Array(RequestEntry) Requests;
void add_files( s32 num, char const** files );
void add( SymbolInfo signature, Policy policy );
bool process_requests( array(Receipt) out_receipts );
bool process_requests( Array(Receipt) out_receipts );
};
#endif
#pragma endregion Gen Interface
@ -1175,8 +1175,8 @@ namespace gen
# define macrofn_chooser(_f0, _f1, _f2, _f3, _f4, _f5, _f6, _f7, _f8, _f9, _f10, _f11, _f12, _f13, _f14, _f15, _f16, ...) _f16
# define macrofn_recomposer(ArgsWithParentheses_) macrofn_chooser ArgsWithParentheses_
# 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 marcofn_no_arg_expander(Func) ,,,,,,,,,,,,,,,,Func_ ## _0
# define macrofn_finder(Func_, ...) macrofn_chose_from_arg_num(Func_, tbc_marcofn_no_arg_expander __VA_ARGS__ (Func_))
# define marcofn_no_arg_expander(Func_) ,,,,,,,,,,,,,,,,Func_ ## _0
# define macrofn_finder(Func_, ...) macrofn_chose_from_arg_num(Func_, marcofn_no_arg_expander __VA_ARGS__ (Func_))
# 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_ ), type_ns(RetType_), Specifiers_, Body_ )
@ -1306,91 +1306,91 @@ namespace gen
forceinline
Code def_class( char const* name, Code parent, Code specifiers, Code body )
{
return def_class( zpl_strnlen( name, MaxNameLength ), name, parent, specifiers, body );
return def_class( strnlen( name, MaxNameLength ), name, parent, specifiers, body );
}
forceinline
Code def_enum( char const* name, Code type, EnumT specifier, Code body )
{
return def_enum( zpl_strnlen( name, MaxNameLength ), name, type, specifier, body );
return def_enum( strnlen( name, MaxNameLength ), name, type, specifier, body );
}
forceinline
Code def_function( char const* name, Code params, Code ret_type, Code specifiers, Code body )
{
return def_function( zpl_strnlen( name, MaxNameLength), name, params, ret_type, specifiers, body );
return def_function( strnlen( name, MaxNameLength), name, params, ret_type, specifiers, body );
}
forceinline
Code def_namespace( char const* name, Code body )
{
return def_namespace( zpl_strnlen( name, MaxNameLength), name, body );
return def_namespace( strnlen( name, MaxNameLength), name, body );
}
forceinline
Code def_param( Code type, char const* name )
{
return def_param( type, zpl_strnlen( name, MaxNameLength ), name );
return def_param( type, strnlen( name, MaxNameLength ), name );
}
forceinline
Code def_struct( char const* name, Code parent, Code specifiers, Code body )
{
return def_struct( zpl_strnlen( name, MaxNameLength), name, parent, specifiers, body );
return def_struct( strnlen( name, MaxNameLength), name, parent, specifiers, body );
}
forceinline
Code def_type( char const* name, Code specifiers )
{
return def_type( zpl_strnlen( name, MaxNameLength ), name, specifiers );
return def_type( strnlen( name, MaxNameLength ), name, specifiers );
}
forceinline
Code def_using( char const* name, Code type, UsingT specifier )
{
return def_using( zpl_strnlen( name, MaxNameLength ), name, type, specifier );
return def_using( strnlen( name, MaxNameLength ), name, type, specifier );
}
forceinline
Code def_variable( Code type, char const* name, Code value, Code specifiers )
{
return def_variable( type, zpl_strnlen(name, MaxNameLength ), name, value, specifiers );
return def_variable( type, strnlen(name, MaxNameLength ), name, value, specifiers );
}
forceinline
Code make_class( char const* name, Code parent, Code specifiers )
{
return make_class( zpl_strnlen(name, MaxNameLength), name, parent, specifiers );
return make_class( strnlen(name, MaxNameLength), name, parent, specifiers );
}
forceinline
Code make_enum( char const* name, Code type, Code specifiers )
{
return make_struct( zpl_strnlen(name, MaxNameLength), name, type, specifiers );
return make_struct( strnlen(name, MaxNameLength), name, type, specifiers );
}
forceinline
Code make_function( char const* name, Code params, Code ret_type, Code specifiers )
{
return make_function( zpl_strnlen(name, MaxNameLength), name, params, ret_type, specifiers );
return make_function( strnlen(name, MaxNameLength), name, params, ret_type, specifiers );
}
forceinline
Code make_namespace( char const* name )
{
return make_namespace( zpl_strnlen( name, MaxNameLength ), name );
return make_namespace( strnlen( name, MaxNameLength ), name );
}
forceinline
Code make_struct( char const* name, Code parent, Code specifiers )
{
return make_struct( zpl_strnlen(name, MaxNameLength), name, parent, specifiers );
return make_struct( strnlen(name, MaxNameLength), name, parent, specifiers );
}
forceinline
Code untyped_str( char const* str )
{
return untyped_str( zpl_strnlen( str, MaxUntypedStrLength ), str );
return untyped_str( strnlen( str, MaxUntypedStrLength ), str );
}
}
#pragma endregion Gen Interface Inlines

39145
thirdparty/zpl.h vendored

File diff suppressed because it is too large Load Diff