mirror of
https://github.com/Ed94/gencpp.git
synced 2025-06-30 19:01:02 -07:00
borken : lots of stuff changed, explaining in later commit...v
This commit is contained in:
@ -5,7 +5,6 @@
|
||||
#endif
|
||||
|
||||
#pragma region Basic Types
|
||||
GEN_API_C_BEGIN
|
||||
|
||||
#define GEN_U8_MIN 0u
|
||||
#define GEN_U8_MAX 0xffu
|
||||
@ -127,14 +126,12 @@ typedef s32 b32;
|
||||
typedef void* mem_ptr;
|
||||
typedef void const* mem_ptr_const ;
|
||||
|
||||
#if ! GEN_COMPILER_C
|
||||
GEN_API_C_END
|
||||
#if GEN_COMPILER_CPP
|
||||
template<typename Type> uptr to_uptr( Type* ptr ) { return (uptr)ptr; }
|
||||
template<typename Type> sptr to_sptr( Type* ptr ) { return (sptr)ptr; }
|
||||
|
||||
template<typename Type> mem_ptr to_mem_ptr ( Type ptr ) { return (mem_ptr) ptr; }
|
||||
template<typename Type> mem_ptr_const to_mem_ptr_const( Type ptr ) { return (mem_ptr_const)ptr; }
|
||||
GEN_API_C_BEGIN
|
||||
#else
|
||||
#define to_uptr( ptr ) ((uptr)(ptr))
|
||||
#define to_sptr( ptr ) ((sptr)(ptr))
|
||||
@ -143,5 +140,4 @@ GEN_API_C_BEGIN
|
||||
#define to_mem_ptr_const( ptr) ((mem_ptr)ptr)
|
||||
#endif
|
||||
|
||||
GEN_API_C_END
|
||||
#pragma endregion Basic Types
|
||||
|
@ -26,12 +26,9 @@ template <class TType> using TRemovePtr = typename RemovePtr<TType>::Type;
|
||||
|
||||
struct ArrayHeader;
|
||||
|
||||
#if GEN_SUPPORT_CPP_MEMBER_FEATURES
|
||||
#if GEN_COMPILER_CPP
|
||||
template<class Type> struct Array;
|
||||
# define get_array_underlying_type(array) typename TRemovePtr<typeof(array)>:: DataType
|
||||
#else
|
||||
template<class Type> using Array = Type*;
|
||||
# define get_array_underlying_type(array) TRemovePtr<typeof(array)>
|
||||
#endif
|
||||
|
||||
usize array_grow_formula(ssize value);
|
||||
@ -62,7 +59,7 @@ struct ArrayHeader {
|
||||
usize Num;
|
||||
};
|
||||
|
||||
#if GEN_SUPPORT_CPP_MEMBER_FEATURES
|
||||
#if GEN_COMPILER_CPP
|
||||
template<class Type>
|
||||
struct Array
|
||||
{
|
||||
@ -104,7 +101,7 @@ struct Array
|
||||
};
|
||||
#endif
|
||||
|
||||
#if GEN_SUPPORT_CPP_REFERENCES
|
||||
#if GEN_COMPILER_CPP && 0
|
||||
template<class Type> bool append(Array<Type>& array, Array<Type> other) { return GEN_NS append( & array, other ); }
|
||||
template<class Type> bool append(Array<Type>& array, Type value) { return GEN_NS append( & array, value ); }
|
||||
template<class Type> bool append(Array<Type>& array, Type* items, usize item_num) { return GEN_NS append( & array, items, item_num ); }
|
||||
|
@ -6,7 +6,6 @@
|
||||
#endif
|
||||
|
||||
#pragma region Debug
|
||||
GEN_API_C_BEGIN
|
||||
|
||||
void assert_handler( char const* condition, char const* file, s32 line, char const* msg, ... )
|
||||
{
|
||||
@ -46,5 +45,4 @@ s32 assert_crash( char const* condition )
|
||||
}
|
||||
#endif
|
||||
|
||||
GEN_API_C_END
|
||||
#pragma endregion Debug
|
||||
|
@ -56,10 +56,8 @@
|
||||
while (0)
|
||||
#endif
|
||||
|
||||
GEN_API_C_BEGIN
|
||||
void assert_handler( char const* condition, char const* file, s32 line, char const* msg, ... );
|
||||
s32 assert_crash( char const* condition );
|
||||
void process_exit( u32 code );
|
||||
GEN_API_C_END
|
||||
|
||||
#pragma endregion Debug
|
||||
|
@ -4,7 +4,6 @@
|
||||
#endif
|
||||
|
||||
#pragma region File Handling
|
||||
GEN_API_C_BEGIN
|
||||
|
||||
#if defined( GEN_SYSTEM_WINDOWS ) || defined( GEN_SYSTEM_CYGWIN )
|
||||
|
||||
@ -656,5 +655,4 @@ GEN_FILE_CLOSE_PROC( _memory_file_close )
|
||||
|
||||
FileOperations const memory_file_operations = { _memory_file_read, _memory_file_write, _memory_file_seek, _memory_file_close };
|
||||
|
||||
GEN_API_C_END
|
||||
#pragma endregion File Handling
|
||||
|
@ -4,11 +4,10 @@
|
||||
#endif
|
||||
|
||||
#pragma region File Handling
|
||||
GEN_API_C_BEGIN
|
||||
|
||||
typedef u32 FileMode;
|
||||
|
||||
enum FileModeFlag_Def
|
||||
enum FileModeFlag
|
||||
{
|
||||
EFileMode_READ = bit( 0 ),
|
||||
EFileMode_WRITE = bit( 1 ),
|
||||
@ -16,18 +15,16 @@ enum FileModeFlag_Def
|
||||
EFileMode_RW = bit( 3 ),
|
||||
GEN_FILE_MODES = EFileMode_READ | EFileMode_WRITE | EFileMode_APPEND | EFileMode_RW,
|
||||
};
|
||||
typedef enum FileModeFlag_Def FileModeFlag;
|
||||
|
||||
// NOTE: Only used internally and for the file operations
|
||||
enum SeekWhenceType_Def
|
||||
enum SeekWhenceType
|
||||
{
|
||||
ESeekWhence_BEGIN = 0,
|
||||
ESeekWhence_CURRENT = 1,
|
||||
ESeekWhence_END = 2,
|
||||
};
|
||||
typedef enum SeekWhenceType_Def SeekWhenceType;
|
||||
|
||||
enum FileError_Def
|
||||
enum FileError
|
||||
{
|
||||
EFileError_NONE,
|
||||
EFileError_INVALID,
|
||||
@ -40,17 +37,15 @@ enum FileError_Def
|
||||
EFileError_NAME_TOO_LONG,
|
||||
EFileError_UNKNOWN,
|
||||
};
|
||||
typedef enum FileError_Def FileError;
|
||||
|
||||
union FileDescriptor_Def
|
||||
union FileDescriptor
|
||||
{
|
||||
void* p;
|
||||
sptr i;
|
||||
uptr u;
|
||||
};
|
||||
typedef union FileDescriptor_Def FileDescriptor;
|
||||
|
||||
typedef struct FileOperations_Def FileOperations;
|
||||
typedef struct FileOperations FileOperations;
|
||||
|
||||
#define GEN_FILE_OPEN_PROC( name ) FileError name( FileDescriptor* fd, FileOperations* ops, FileMode mode, char const* filename )
|
||||
#define GEN_FILE_READ_AT_PROC( name ) b32 name( FileDescriptor fd, void* buffer, ssize size, s64 offset, ssize* bytes_read, b32 stop_at_newline )
|
||||
@ -64,39 +59,35 @@ typedef GEN_FILE_WRITE_AT_PROC( FileWriteProc );
|
||||
typedef GEN_FILE_SEEK_PROC( FileSeekProc );
|
||||
typedef GEN_FILE_CLOSE_PROC( FileCloseProc );
|
||||
|
||||
struct FileOperations_Def
|
||||
struct FileOperations
|
||||
{
|
||||
FileReadProc* read_at;
|
||||
FileWriteProc* write_at;
|
||||
FileSeekProc* seek;
|
||||
FileCloseProc* close;
|
||||
};
|
||||
typedef struct FileOperations_Def FileOperations;
|
||||
|
||||
extern FileOperations const default_file_operations;
|
||||
|
||||
typedef u64 FileTime;
|
||||
|
||||
enum DirType_Def
|
||||
enum DirType
|
||||
{
|
||||
GEN_DIR_TYPE_FILE,
|
||||
GEN_DIR_TYPE_FOLDER,
|
||||
GEN_DIR_TYPE_UNKNOWN,
|
||||
};
|
||||
typedef enum DirType_Def DirType;
|
||||
|
||||
struct DirInfo_Def;
|
||||
typedef struct DirInfo_Def DirInfo;
|
||||
struct DirInfo;
|
||||
|
||||
struct DirEntry_Def
|
||||
struct DirEntry
|
||||
{
|
||||
char const* filename;
|
||||
DirInfo* dir_info;
|
||||
u8 type;
|
||||
};
|
||||
typedef struct DirEntry_Def DirEntry;
|
||||
|
||||
struct DirInfo_Def
|
||||
struct DirInfo
|
||||
{
|
||||
char const* fullpath;
|
||||
DirEntry* entries; // zpl_array
|
||||
@ -106,7 +97,7 @@ struct DirInfo_Def
|
||||
String buf;
|
||||
};
|
||||
|
||||
struct FileInfo_Def
|
||||
struct FileInfo
|
||||
{
|
||||
FileOperations ops;
|
||||
FileDescriptor fd;
|
||||
@ -116,9 +107,9 @@ struct FileInfo_Def
|
||||
FileTime last_write_time;
|
||||
DirEntry* dir;
|
||||
};
|
||||
typedef struct FileInfo_Def FileInfo;
|
||||
typedef struct FileInfo FileInfo;
|
||||
|
||||
enum FileStandardType_Def
|
||||
enum FileStandardType
|
||||
{
|
||||
EFileStandard_INPUT,
|
||||
EFileStandard_OUTPUT,
|
||||
@ -126,7 +117,7 @@ enum FileStandardType_Def
|
||||
|
||||
EFileStandard_COUNT,
|
||||
};
|
||||
typedef enum FileStandardType_Def FileStandardType;
|
||||
typedef enum FileStandardType FileStandardType;
|
||||
|
||||
/**
|
||||
* Get standard file I/O.
|
||||
@ -269,7 +260,7 @@ b32 file_write_at( FileInfo* file, void const* buffer, ssize size, s64 offset );
|
||||
*/
|
||||
b32 file_write_at_check( FileInfo* file, void const* buffer, ssize size, s64 offset, ssize* bytes_written );
|
||||
|
||||
enum FileStreamFlags_Def enum_underlying(u32)
|
||||
enum FileStreamFlags : u32
|
||||
{
|
||||
/* Allows us to write to the buffer directly. Beware: you can not append a new data! */
|
||||
EFileStream_WRITABLE = bit( 0 ),
|
||||
@ -280,7 +271,6 @@ enum FileStreamFlags_Def enum_underlying(u32)
|
||||
|
||||
EFileStream_UNDERLYING = GEN_U32_MAX,
|
||||
};
|
||||
typedef enum FileStreamFlags_Def FileStreamFlags;
|
||||
|
||||
/**
|
||||
* Opens a new memory stream
|
||||
@ -396,5 +386,4 @@ b32 file_write_at_check( FileInfo* f, void const* buffer, ssize size, s64 offset
|
||||
return f->ops.write_at( f->fd, buffer, size, offset, bytes_written );
|
||||
}
|
||||
|
||||
GEN_API_C_END
|
||||
#pragma endregion File Handling
|
||||
|
@ -4,7 +4,6 @@
|
||||
#endif
|
||||
|
||||
#pragma region Hashing
|
||||
GEN_API_C_BEGIN
|
||||
|
||||
global u32 const _crc32_table[ 256 ] = {
|
||||
0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd,
|
||||
@ -88,5 +87,4 @@ u64 crc64( void const* data, ssize len )
|
||||
return result;
|
||||
}
|
||||
|
||||
GEN_API_C_END
|
||||
#pragma endregion Hashing
|
||||
|
@ -4,10 +4,8 @@
|
||||
#endif
|
||||
|
||||
#pragma region Hashing
|
||||
GEN_API_C_BEGIN
|
||||
|
||||
u32 crc32( void const* data, ssize len );
|
||||
u64 crc64( void const* data, ssize len );
|
||||
|
||||
GEN_API_C_END
|
||||
#pragma endregion Hashing
|
||||
|
@ -19,10 +19,22 @@
|
||||
#define bitfield_is_equal( Type, Field, Mask ) ( (Type(Mask) & Type(Field)) == Type(Mask) )
|
||||
#endif
|
||||
|
||||
// Mainly intended for forcing the base library to utilize only C-valid constructs or type coercion
|
||||
#ifndef GEN_C_LIKE_CPP
|
||||
#define GEN_C_LIKE_CPP 0
|
||||
#endif
|
||||
|
||||
#if GEN_COMPILER_CPP
|
||||
# ifndef cast
|
||||
# define cast( type, value ) (tmpl_cast<type>( value ))
|
||||
# endif
|
||||
#else
|
||||
# ifndef cast
|
||||
# define cast( type, value ) ( (type)(value) )
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if GEN_COMPILER_CPP
|
||||
# ifndef ccast
|
||||
# define ccast( type, value ) ( const_cast< type >( (value) ) )
|
||||
# endif
|
||||
@ -36,9 +48,6 @@
|
||||
# define scast( type, value ) static_cast< type >( value )
|
||||
# endif
|
||||
#else
|
||||
# ifndef cast
|
||||
# define cast( type, value ) ( (type)(value) )
|
||||
# endif
|
||||
# ifndef ccast
|
||||
# define ccast( type, value ) ( (type)(value) )
|
||||
# endif
|
||||
@ -210,22 +219,6 @@
|
||||
# error "No thread local support"
|
||||
#endif
|
||||
|
||||
#if !defined(GEN_SUPPORT_CPP_REFERENCES)
|
||||
# define GEN_SUPPORT_CPP_REFERENCES 1
|
||||
#endif
|
||||
#if GEN_COMPILER_C && defined(GEN_SUPPORT_CPP_REFERENCES)
|
||||
# undef GEN_SUPPORT_CPP_REFERENCES
|
||||
# define GEN_SUPPORT_CPP_REFERENCES 0
|
||||
#endif
|
||||
|
||||
#if !defined(GEN_SUPPORT_CPP_MEMBER_FEATURES)
|
||||
# define GEN_SUPPORT_CPP_MEMBER_FEATURES 1
|
||||
#endif
|
||||
#if GEN_COMPILER_C && defined(GEN_SUPPORT_CPP_MEMBER_FEATURES)
|
||||
# undef GEN_SUPPORT_CPP_MEMBER_FEATURES
|
||||
# define GEN_SUPPORT_CPP_MEMBER_FEATURES 0
|
||||
#endif
|
||||
|
||||
#if ! defined(typeof) && (!GEN_COMPILER_C || __STDC_VERSION__ < 202311L)
|
||||
# if ! GEN_COMPILER_C
|
||||
# define typeof decltype
|
||||
@ -239,12 +232,12 @@
|
||||
#endif
|
||||
|
||||
#ifndef GEN_API_C_BEGIN
|
||||
# if GEN_COMPILER_C || (GEN_COMPILER_CPP && GEN_SUPPORT_CPP_REFERENCES)
|
||||
# if GEN_COMPILER_C
|
||||
# define GEN_API_C_BEGIN
|
||||
# define GEN_API_C_END
|
||||
# else
|
||||
# define GEN_API_C_BEGIN extern "C" {
|
||||
# define GEN_API_C_END }
|
||||
# define GEN_API_C_END }
|
||||
# endif
|
||||
#endif
|
||||
|
||||
@ -280,6 +273,16 @@
|
||||
#define struct_init(type, value) {value}
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
#ifndef GEN_OPTIMIZE_MAPPINGS_BEGIN
|
||||
# define GEN_OPTIMIZE_MAPPINGS_BEGIN _pragma(optimize("gt", on))
|
||||
# define GEN_OPITMIZE_MAPPINGS_END _pragma(optimize("", on))
|
||||
#endif
|
||||
#else
|
||||
# define GEN_OPTIMIZE_MAPPINGS_BEGIN
|
||||
# define GEN_OPITMIZE_MAPPINGS_END
|
||||
#endif
|
||||
|
||||
#if GEN_COMPILER_C
|
||||
// ------------------------ _Generic function overloading -----------------------------------------
|
||||
// This implemnents macros for utilizing "The Naive Extendible _Generic Macro" explained in:
|
||||
@ -295,12 +298,7 @@
|
||||
// Helper macros for argument selection
|
||||
#define GEN_SELECT_ARG_1( _1, ... ) _1 // <-- Of all th args passed pick _1.
|
||||
#define GEN_SELECT_ARG_2( _1, _2, ... ) _2 // <-- Of all the args passed pick _2.
|
||||
#define GEN_SELECT_ARG_3( _1, _2, _3, ... ) _3 // etc.. (by induction until _8, which we don't support any more beyond)
|
||||
// #define GEN_SELECT_ARG_4( _1, _2, _3, _4, ... ) _4
|
||||
// #define GEN_SELECT_ARG_5( _1, _2, _3, _4, _5, ... ) _5
|
||||
// #define GEN_SELECT_ARG_6( _1, _2, _3, _4, _5, _6, ... ) _6
|
||||
// #define GEN_SELECT_ARG_7( _1, _2, _3, _4, _5, _6, _7, ... ) _7
|
||||
// #define GEN_SELECT_ARG_8( _1, _2, _3, _4, _5, _6, _7, _8, ... ) _8
|
||||
#define GEN_SELECT_ARG_3( _1, _2, _3, ... ) _3 // etc..
|
||||
|
||||
#define GEN_GENERIC_SEL_ENTRY_TYPE GEN_SELECT_ARG_1 // Use the arg expansion macro to select arg 1 which should have the type.
|
||||
#define GEN_GENERIC_SEL_ENTRY_FUNCTION GEN_SELECT_ARG_2 // Use the arg expansion macro to select arg 2 which should have the function.
|
||||
@ -314,10 +312,10 @@
|
||||
// Expands to ',' if it can find (type): (function) <comma_operator: ',' >
|
||||
// Where GEN_GENERIC_SEL_ENTRY_COMMA_DELIMITER is specifically looking for that <comma> ,
|
||||
#define GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( slot_exp ) GEN_GENERIC_SEL_ENTRY_COMMA_DELIMITER( slot_exp, GEN_GENERIC_SEL_ENTRY_TYPE( slot_exp, ): GEN_GENERIC_SEL_ENTRY_FUNCTION( slot_exp, ) GEN_COMMA_OPERATOR, , )
|
||||
// ^ Selects the comma ^ is the type ^ is the function ^ Insert a comma
|
||||
// The slot won't exist if that comma is not found. |
|
||||
// |
|
||||
// This is the same as above but it does not insert a comma V no comma here.
|
||||
// ^ Selects the comma ^ is the type ^ is the function ^ Insert a comma
|
||||
// The slot won't exist if that comma is not found. |
|
||||
// |
|
||||
// This is the same as above but it does not insert a comma V no comma here.
|
||||
#define GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT_LAST( slot_exp ) GEN_GENERIC_SEL_ENTRY_COMMA_DELIMITER( slot_exp, GEN_GENERIC_SEL_ENTRY_TYPE( slot_exp, ): GEN_GENERIC_SEL_ENTRY_FUNCTION( slot_exp, ), , )
|
||||
// Needed for the last slot as they don't allow trailing commas.
|
||||
// ----------------------------------------------------------------------------------------------------------------------------------
|
||||
@ -392,6 +390,7 @@ size_t gen_example_hash__P_long_long( long long val ) { return val * 2654435761u
|
||||
|
||||
// typedef void* GEN_GenericExampleType;
|
||||
// GEN_FUNCTION_GENERIC_EXAMPLE_DIRECT_TYPE( GEN_GenericExampleType );
|
||||
|
||||
// END OF ------------------------ _Generic function overloading ----------------------------------------- END OF
|
||||
#endif
|
||||
|
||||
|
@ -4,13 +4,12 @@
|
||||
#endif
|
||||
|
||||
#pragma region Memory
|
||||
GEN_API_C_BEGIN
|
||||
|
||||
void* mem_copy( void* dest, void const* source, ssize n )
|
||||
{
|
||||
if ( dest == NULL )
|
||||
if ( dest == nullptr )
|
||||
{
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return memcpy( dest, source, n );
|
||||
@ -518,5 +517,4 @@ void pool_clear(Pool* pool)
|
||||
pool->FreeList = pool->PhysicalStart;
|
||||
}
|
||||
|
||||
GEN_API_C_END
|
||||
#pragma endregion Memory
|
||||
|
@ -22,8 +22,6 @@ void swap( Type& a, Type& b )
|
||||
b = tmp;
|
||||
}
|
||||
|
||||
GEN_API_C_BEGIN
|
||||
|
||||
//! Checks if value is power of 2.
|
||||
b32 is_power_of_two( ssize x );
|
||||
|
||||
@ -64,23 +62,21 @@ void zero_size( void* ptr, ssize size );
|
||||
//! Clears up an array.
|
||||
#define zero_array( a, count ) zero_size( ( a ), size_of( *( a ) ) * count )
|
||||
|
||||
enum AllocType_Def //enum_underlying(u8)
|
||||
enum AllocType : u8
|
||||
{
|
||||
EAllocation_ALLOC,
|
||||
EAllocation_FREE,
|
||||
EAllocation_FREE_ALL,
|
||||
EAllocation_RESIZE,
|
||||
};
|
||||
typedef enum AllocType_Def AllocType;
|
||||
|
||||
typedef void*(AllocatorProc)( void* allocator_data, AllocType type, ssize size, ssize alignment, void* old_memory, ssize old_size, u64 flags );
|
||||
|
||||
struct AllocatorInfo_Def
|
||||
struct AllocatorInfo
|
||||
{
|
||||
AllocatorProc* Proc;
|
||||
void* Data;
|
||||
};
|
||||
typedef struct AllocatorInfo_Def AllocatorInfo;
|
||||
|
||||
enum AllocFlag
|
||||
{
|
||||
@ -144,12 +140,11 @@ constexpr AllocatorInfo heap( void ) { AllocatorInfo allocator = { heap_allocato
|
||||
//! Helper to free memory allocated by heap allocator.
|
||||
#define mfree( ptr ) free( heap(), ptr )
|
||||
|
||||
struct VirtualMemory_Def
|
||||
struct VirtualMemory
|
||||
{
|
||||
void* data;
|
||||
ssize size;
|
||||
};
|
||||
typedef struct VirtualMemory_Def VirtualMemory;
|
||||
|
||||
//! Initialize virtual memory from existing data.
|
||||
VirtualMemory vm_from_memory( void* data, ssize size );
|
||||
@ -173,8 +168,7 @@ b32 vm_purge( VirtualMemory vm );
|
||||
ssize virtual_memory_page_size( ssize* alignment_out );
|
||||
|
||||
#pragma region Arena
|
||||
struct Arena_Def;
|
||||
typedef struct Arena_Def Arena;
|
||||
struct Arena;
|
||||
|
||||
AllocatorInfo arena_allocator_info( Arena* arena );
|
||||
|
||||
@ -191,7 +185,7 @@ void arena_check (Arena* arena);
|
||||
void arena_free (Arena* arena);
|
||||
ssize arena_size_remaining(Arena* arena, ssize alignment);
|
||||
|
||||
struct Arena_Def
|
||||
struct Arena
|
||||
{
|
||||
AllocatorInfo Backing;
|
||||
void* PhysicalStart;
|
||||
@ -199,7 +193,7 @@ struct Arena_Def
|
||||
ssize TotalUsed;
|
||||
ssize TempCount;
|
||||
|
||||
#if GEN_SUPPORT_CPP_MEMBER_FEATURES
|
||||
#if GEN_COMPILER_CPP
|
||||
#pragma region Member Mapping
|
||||
forceinline operator AllocatorInfo() { return GEN_NS arena_allocator_info(this); }
|
||||
|
||||
@ -221,8 +215,7 @@ struct Arena_Def
|
||||
#endif
|
||||
};
|
||||
|
||||
#if GEN_SUPPORT_CPP_REFERENCES
|
||||
GEN_API_C_END
|
||||
#if GEN_COMPILER_CPP
|
||||
forceinline AllocatorInfo allocator_info(Arena& arena ) { return arena_allocator_info(& arena); }
|
||||
forceinline Arena init_sub (Arena& parent, ssize size) { return arena_init_sub( & parent, size); }
|
||||
forceinline ssize alignment_of (Arena& arena, ssize alignment) { return arena_alignment_of( & arena, alignment); }
|
||||
@ -234,7 +227,6 @@ forceinline ssize size_remaining(Arena& arena, ssize alignment) { return
|
||||
#undef check
|
||||
forceinline void check(Arena& arena) { return arena_check(& arena); };
|
||||
#pragma pop_macro("check")
|
||||
GEN_API_C_BEGIN
|
||||
#endif
|
||||
|
||||
|
||||
@ -320,8 +312,6 @@ ssize arena_size_remaining(Arena* arena, ssize alignment)
|
||||
}
|
||||
#pragma endregion Arena
|
||||
|
||||
GEN_API_C_END
|
||||
|
||||
#pragma region FixedArena
|
||||
template<s32 Size>
|
||||
struct FixedArena;
|
||||
@ -330,7 +320,7 @@ template<s32 Size> FixedArena<Size> fixed_arena_init();
|
||||
template<s32 Size> AllocatorInfo fixed_arena_allocator_info(FixedArena<Size>* fixed_arena );
|
||||
template<s32 Size> ssize fixed_arena_size_remaining(FixedArena<Size>* fixed_arena, ssize alignment);
|
||||
|
||||
#if GEN_SUPPORT_CPP_REFERENCES
|
||||
#if 0
|
||||
template<s32 Size> AllocatorInfo allocator_info( FixedArena<Size>& fixed_arena ) { return allocator_info(& fixed_arena); }
|
||||
template<s32 Size> ssize size_remaining(FixedArena<Size>& fixed_arena, ssize alignment) { return size_remaining( & fixed_arena, alignment); }
|
||||
#endif
|
||||
@ -343,7 +333,7 @@ struct FixedArena
|
||||
char memory[Size];
|
||||
Arena arena;
|
||||
|
||||
#if GEN_SUPPORT_CPP_MEMBER_FEATURES
|
||||
#if 0
|
||||
#pragma region Member Mapping
|
||||
forceinline operator AllocatorInfo() { return GEN_NS allocator_info(this); }
|
||||
|
||||
@ -389,11 +379,8 @@ using Arena_2MB = FixedArena< megabytes( 2 ) >;
|
||||
using Arena_4MB = FixedArena< megabytes( 4 ) >;
|
||||
#pragma endregion FixedArena
|
||||
|
||||
GEN_API_C_BEGIN
|
||||
|
||||
#pragma region Pool
|
||||
struct Pool_Def;
|
||||
typedef struct Pool_Def Pool;
|
||||
struct Pool;
|
||||
|
||||
void* pool_allocator_proc(void* allocator_data, AllocType type, ssize size, ssize alignment, void* old_memory, ssize old_size, u64 flags);
|
||||
|
||||
@ -403,15 +390,13 @@ AllocatorInfo pool_allocator_info(Pool* pool);
|
||||
void pool_clear(Pool* pool);
|
||||
void pool_free(Pool* pool);
|
||||
|
||||
#if GEN_SUPPORT_CPP_REFERENCES
|
||||
GEN_API_C_END
|
||||
#if 0
|
||||
AllocatorInfo allocator_info(Pool& pool) { return pool_allocator_info(& pool); }
|
||||
void clear(Pool& pool) { return pool_clear(& pool); }
|
||||
void free(Pool& pool) { return pool_free(& pool); }
|
||||
GEN_API_C_BEGIN
|
||||
#endif
|
||||
|
||||
struct Pool_Def
|
||||
struct Pool
|
||||
{
|
||||
AllocatorInfo Backing;
|
||||
void* PhysicalStart;
|
||||
@ -421,7 +406,7 @@ struct Pool_Def
|
||||
ssize TotalSize;
|
||||
ssize NumBlocks;
|
||||
|
||||
#if GEN_SUPPORT_CPP_MEMBER_FEATURES
|
||||
#if ! GEN_C_LIKE_CPP
|
||||
#pragma region Member Mapping
|
||||
forceinline operator AllocatorInfo() { return GEN_NS pool_allocator_info(this); }
|
||||
|
||||
@ -684,6 +669,4 @@ void zero_size( void* ptr, ssize size ) {
|
||||
mem_set( ptr, 0, size );
|
||||
}
|
||||
|
||||
GEN_API_C_END
|
||||
|
||||
#pragma endregion Memory
|
||||
|
@ -4,7 +4,6 @@
|
||||
#endif
|
||||
|
||||
#pragma region ADT
|
||||
GEN_API_C_BEGIN
|
||||
|
||||
#define _adt_fprintf( s_, fmt_, ... ) \
|
||||
do \
|
||||
@ -1112,5 +1111,4 @@ String csv_write_string_delimiter( AllocatorInfo a, CSV_Object* obj, char delimi
|
||||
return output;
|
||||
}
|
||||
|
||||
GEN_API_C_END
|
||||
#pragma endregion CSV
|
||||
|
@ -3,7 +3,6 @@
|
||||
#endif
|
||||
|
||||
#pragma region ADT
|
||||
GEN_API_C_BEGIN
|
||||
|
||||
enum ADT_Type : u32
|
||||
{
|
||||
@ -430,5 +429,4 @@ String csv_write_string( AllocatorInfo a, CSV_Object* obj )
|
||||
return csv_write_string_delimiter( a, obj, ',' );
|
||||
}
|
||||
|
||||
GEN_API_C_END
|
||||
#pragma endregion CSV
|
||||
|
@ -76,17 +76,20 @@
|
||||
/* Platform compiler */
|
||||
|
||||
#if defined( _MSC_VER )
|
||||
# define GEN_COMPILER_CLANG 0
|
||||
# pragma message("Detected MSVC")
|
||||
// # define GEN_COMPILER_CLANG 0
|
||||
# define GEN_COMPILER_MSVC 1
|
||||
# define GEN_COMPILER_GCC 0
|
||||
// # define GEN_COMPILER_GCC 0
|
||||
#elif defined( __GNUC__ )
|
||||
# define GEN_COMPILER_CLANG 0
|
||||
# define GEN_COMPILER_MSVC 0
|
||||
# pragma message("Detected GCC")
|
||||
// # define GEN_COMPILER_CLANG 0
|
||||
// # define GEN_COMPILER_MSVC 0
|
||||
# define GEN_COMPILER_GCC 1
|
||||
#elif defined( __clang__ )
|
||||
# pragma message("Detected CLANG")
|
||||
# define GEN_COMPILER_CLANG 1
|
||||
# define GEN_COMPILER_MSVC 0
|
||||
# define GEN_COMPILER_GCC 1
|
||||
// # define GEN_COMPILER_MSVC 0
|
||||
// # define GEN_COMPILER_GCC 0
|
||||
#else
|
||||
# error Unknown compiler
|
||||
#endif
|
||||
|
@ -6,7 +6,6 @@
|
||||
#endif
|
||||
|
||||
#pragma region Printing
|
||||
GEN_API_C_BEGIN
|
||||
|
||||
enum
|
||||
{
|
||||
@ -598,5 +597,4 @@ ssize str_fmt_out_err( char const* fmt, ... )
|
||||
return res;
|
||||
}
|
||||
|
||||
GEN_API_C_END
|
||||
#pragma endregion Printing
|
||||
|
@ -5,9 +5,7 @@
|
||||
|
||||
#pragma region Printing
|
||||
|
||||
GEN_API_C_BEGIN
|
||||
|
||||
typedef struct FileInfo_Def FileInfo;
|
||||
typedef struct FileInfo FileInfo;
|
||||
|
||||
#ifndef GEN_PRINTF_MAXLEN
|
||||
# define GEN_PRINTF_MAXLEN kilobytes(128)
|
||||
@ -41,6 +39,4 @@ ssize log_fmt(char const* fmt, ...)
|
||||
return res;
|
||||
}
|
||||
|
||||
GEN_API_C_END
|
||||
|
||||
#pragma endregion Printing
|
||||
|
@ -5,7 +5,6 @@
|
||||
#endif
|
||||
|
||||
#pragma region String Ops
|
||||
GEN_API_C_BEGIN
|
||||
|
||||
internal
|
||||
ssize _scan_zpl_i64( const char* text, s32 base, s64* value )
|
||||
@ -213,5 +212,4 @@ f64 str_to_f64( const char* str, char** end_ptr )
|
||||
return result;
|
||||
}
|
||||
|
||||
GEN_API_C_END
|
||||
#pragma endregion String Ops
|
||||
|
@ -5,8 +5,6 @@
|
||||
|
||||
#pragma region String Ops
|
||||
|
||||
GEN_API_C_BEGIN
|
||||
|
||||
const char* char_first_occurence( const char* str, char c );
|
||||
|
||||
b32 char_is_alpha( char c );
|
||||
@ -286,6 +284,4 @@ void str_to_upper( char* str )
|
||||
}
|
||||
}
|
||||
|
||||
GEN_API_C_END
|
||||
|
||||
#pragma endregion String Ops
|
||||
|
@ -4,7 +4,6 @@
|
||||
#endif
|
||||
|
||||
#pragma region String
|
||||
GEN_API_C_BEGIN
|
||||
|
||||
String string_make_length( AllocatorInfo allocator, char const* str, ssize length )
|
||||
{
|
||||
@ -54,5 +53,4 @@ String string_make_reserve( AllocatorInfo allocator, ssize capacity )
|
||||
return result;
|
||||
}
|
||||
|
||||
GEN_API_C_END
|
||||
#pragma endregion String
|
||||
|
@ -5,8 +5,6 @@
|
||||
|
||||
#pragma region Strings
|
||||
|
||||
GEN_API_C_BEGIN
|
||||
|
||||
struct StrC_Def;
|
||||
typedef struct StrC_Def StrC;
|
||||
|
||||
@ -18,8 +16,6 @@ b32 strc_starts_with (StrC str, StrC substring);
|
||||
StrC strc_to_str (char const* bad_string);
|
||||
StrC strc_visualize_whitespace(StrC str, AllocatorInfo allocator);
|
||||
|
||||
GEN_API_C_END
|
||||
|
||||
// Constant string with length.
|
||||
struct StrC_Def
|
||||
{
|
||||
@ -30,7 +26,7 @@ struct StrC_Def
|
||||
forceinline operator char const* () const { return Ptr; }
|
||||
forceinline char const& operator[]( ssize index ) const { return Ptr[index]; }
|
||||
|
||||
#if GEN_SUPPORT_CPP_MEMBER_FEATURES
|
||||
#if ! GEN_C_LIKE_CPP
|
||||
forceinline bool is_equal (StrC rhs) const { return GEN_NS strc_are_equal(* this, rhs); }
|
||||
forceinline char const* back () const { return GEN_NS strc_back(* this); }
|
||||
forceinline bool contains (StrC substring) const { return GEN_NS strc_contains(* this, substring); }
|
||||
@ -63,8 +59,6 @@ forceinline char const* end (StrC str) { return str.Ptr + str
|
||||
forceinline char const* next (StrC str, char const* iter) { return iter + 1; }
|
||||
#endif
|
||||
|
||||
GEN_API_C_BEGIN
|
||||
|
||||
inline
|
||||
bool strc_are_equal(StrC lhs, StrC rhs)
|
||||
{
|
||||
@ -113,24 +107,21 @@ StrC to_strc_from_c_str( char const* bad_str ) {
|
||||
StrC result = { str_len( bad_str ), bad_str };
|
||||
return result;
|
||||
}
|
||||
GEN_API_C_END
|
||||
|
||||
// Dynamic String
|
||||
// This is directly based off the ZPL string api.
|
||||
// They used a header pattern
|
||||
// I kept it for simplicty of porting but its not necessary to keep it that way.
|
||||
#pragma region String
|
||||
struct StringHeader_Def;
|
||||
typedef struct StringHeader_Def StringHeader;
|
||||
struct StringHeader;
|
||||
typedef struct StringHeader StringHeader;
|
||||
|
||||
#if GEN_COMPILER_C || ! GEN_SUPPORT_CPP_MEMBER_FEATURES
|
||||
#if GEN_COMPILER_C
|
||||
typedef char* String;
|
||||
#else
|
||||
struct String;
|
||||
#endif
|
||||
|
||||
GEN_API_C_BEGIN
|
||||
|
||||
forceinline usize string_grow_formula(usize value);
|
||||
|
||||
String string_make_c_str (AllocatorInfo allocator, char const* str);
|
||||
@ -168,15 +159,13 @@ void string_trim (String str, char const* cut_set)
|
||||
void string_trim_space (String str);
|
||||
String string_visualize_whitespace(String const str);
|
||||
|
||||
GEN_API_C_END
|
||||
|
||||
struct StringHeader_Def {
|
||||
struct StringHeader {
|
||||
AllocatorInfo Allocator;
|
||||
ssize Capacity;
|
||||
ssize Length;
|
||||
};
|
||||
|
||||
#if GEN_COMPILER_CPP && GEN_SUPPORT_CPP_MEMBER_FEATURES
|
||||
#if GEN_COMPILER_CPP
|
||||
struct String
|
||||
{
|
||||
char* Data;
|
||||
@ -203,6 +192,7 @@ struct String
|
||||
friend forceinline bool operator==(std::nullptr_t, const String str) { return str.Data == nullptr; }
|
||||
friend forceinline bool operator!=(std::nullptr_t, const String str) { return str.Data != nullptr; }
|
||||
|
||||
#if ! GEN_C_LIKE_CPP
|
||||
forceinline char* begin() const { return Data; }
|
||||
forceinline char* end() const { return Data + string_length(* this); }
|
||||
|
||||
@ -273,6 +263,7 @@ struct String
|
||||
return string_append_c_str_len(this, buf, res);
|
||||
}
|
||||
#pragma endregion Member Mapping
|
||||
#endif
|
||||
};
|
||||
#endif
|
||||
|
||||
@ -282,13 +273,13 @@ forceinline char* string_end (String str) { return ((char*) s
|
||||
forceinline char* string_next (String str, char const* iter) { return ((char*) iter + 1); }
|
||||
GEN_API_C_END
|
||||
|
||||
#if GEN_COMPILER_CPP && 0
|
||||
#if GEN_COMPILER_CPP && ! GEN_C_LIKE_CPP
|
||||
forceinline char* begin(String str) { return ((char*) str); }
|
||||
forceinline char* end (String str) { return ((char*) str + string_length(str)); }
|
||||
forceinline char* next (String str, char* iter) { return ((char*) iter + 1); }
|
||||
#endif
|
||||
|
||||
#if GEN_SUPPORT_CPP_REFERENCES
|
||||
#if GEN_COMPILER_CPP && ! GEN_C_LIKE_CPP
|
||||
forceinline bool make_space_for(String& str, char const* to_append, ssize add_len);
|
||||
forceinline bool append(String& str, char c);
|
||||
forceinline bool append(String& str, char const* str_to_append);
|
||||
@ -301,8 +292,6 @@ forceinline void clear(String& str);
|
||||
forceinline void free(String& str);
|
||||
#endif
|
||||
|
||||
GEN_API_C_BEGIN
|
||||
|
||||
forceinline
|
||||
usize string_grow_formula(usize value) {
|
||||
// Using a very aggressive growth formula to reduce time mem_copying with recursive calls to append in this library.
|
||||
@ -755,8 +744,6 @@ StrC strc_visualize_whitespace(StrC str, AllocatorInfo allocator)
|
||||
// Should never be modified, if changed string is desired, cache_string( str ) another.
|
||||
typedef StrC StringCached;
|
||||
|
||||
GEN_API_C_END
|
||||
|
||||
// Implements basic string interning. Data structure is based off the ZPL Hashtable.
|
||||
typedef HashTable(StringCached) StringTable;
|
||||
#pragma endregion Strings
|
||||
|
@ -4,7 +4,6 @@
|
||||
#endif
|
||||
|
||||
#pragma region Timing
|
||||
GEN_API_C_BEGIN
|
||||
|
||||
#ifdef GEN_BENCHMARK
|
||||
#if defined( GEN_COMPILER_MSVC ) && ! defined( __clang__ )
|
||||
@ -165,5 +164,4 @@ GEN_API_C_BEGIN
|
||||
}
|
||||
#endif
|
||||
|
||||
GEN_API_C_END
|
||||
#pragma endregion Timing
|
||||
|
@ -5,8 +5,6 @@
|
||||
|
||||
#pragma region Timing
|
||||
|
||||
GEN_API_C_BEGIN
|
||||
|
||||
#ifdef GEN_BENCHMARK
|
||||
//! Return CPU timestamp.
|
||||
u64 read_cpu_time_stamp_counter( void );
|
||||
@ -18,6 +16,4 @@ f64 time_rel( void );
|
||||
u64 time_rel_ms( void );
|
||||
#endif
|
||||
|
||||
GEN_API_C_END
|
||||
|
||||
#pragma endregion Timing
|
||||
|
Reference in New Issue
Block a user