mirror of
https://github.com/Ed94/gencpp.git
synced 2024-12-22 15:54:45 -08:00
Compare commits
2 Commits
a3e7ec4c72
...
47b9c37e94
Author | SHA1 | Date | |
---|---|---|---|
47b9c37e94 | |||
1c3134218e |
@ -102,6 +102,7 @@ int gen_main()
|
||||
|
||||
PreprocessorDefines.append(txt("GEN_API_C_BEGIN"));
|
||||
PreprocessorDefines.append(txt("GEN_API_C_END"));
|
||||
PreprocessorDefines.append(txt("HashTable("));
|
||||
|
||||
Code push_ignores = scan_file( project_dir "helpers/push_ignores.inline.hpp" );
|
||||
Code pop_ignores = scan_file( project_dir "helpers/pop_ignores.inline.hpp" );
|
||||
@ -198,7 +199,7 @@ int gen_main()
|
||||
(body_entry->Type) {
|
||||
case CT_Preprocess_If:
|
||||
{
|
||||
ignore_preprocess_cond_block(txt("GEN_SUPPORT_CPP_MEMBER_FEATURES"), body_entry, body );
|
||||
ignore_preprocess_cond_block(txt("GEN_SUPPORT_CPP_MEMBER_FEATURES"), body_entry, body, new_body );
|
||||
}
|
||||
break;
|
||||
|
||||
@ -213,10 +214,10 @@ int gen_main()
|
||||
break;
|
||||
case CT_Preprocess_If:
|
||||
{
|
||||
b32 found = ignore_preprocess_cond_block(txt("GEN_SUPPORT_CPP_MEMBER_FEATURES"), entry, parsed_memory );
|
||||
b32 found = ignore_preprocess_cond_block(txt("GEN_SUPPORT_CPP_MEMBER_FEATURES"), entry, parsed_memory, memory );
|
||||
if (found) break;
|
||||
|
||||
found = ignore_preprocess_cond_block(txt("GEN_SUPPORT_CPP_REFERENCES"), entry, parsed_memory );
|
||||
found = ignore_preprocess_cond_block(txt("GEN_SUPPORT_CPP_REFERENCES"), entry, parsed_memory, memory );
|
||||
if (found) break;
|
||||
|
||||
memory.append(entry);
|
||||
@ -224,7 +225,7 @@ int gen_main()
|
||||
break;
|
||||
case CT_Preprocess_IfDef:
|
||||
{
|
||||
b32 found = ignore_preprocess_cond_block(txt("GEN_INTELLISENSE_DIRECTIVES"), entry, parsed_memory );
|
||||
b32 found = ignore_preprocess_cond_block(txt("GEN_INTELLISENSE_DIRECTIVES"), entry, parsed_memory, memory );
|
||||
if (found) break;
|
||||
|
||||
memory.append(entry);
|
||||
@ -251,14 +252,10 @@ int gen_main()
|
||||
}
|
||||
}
|
||||
|
||||
// CodeBody selectors = generate_generic_selectors(needs_selectors);
|
||||
// memory.append_at(selectors, 0)
|
||||
// memory.append(fmt_newline);
|
||||
|
||||
header.print( dump_to_scratch_and_retireve(memory) );
|
||||
|
||||
Code string_ops = scan_file( project_dir "dependencies/string_ops.hpp" );
|
||||
// header.print( string_ops );
|
||||
header.print( string_ops );
|
||||
|
||||
CodeBody printing_parsed = parse_file( project_dir "dependencies/printing.hpp" );
|
||||
CodeBody printing = def_body(CT_Global_Body);
|
||||
@ -268,7 +265,7 @@ int gen_main()
|
||||
{
|
||||
case CT_Preprocess_IfDef:
|
||||
{
|
||||
b32 found = ignore_preprocess_cond_block(txt("GEN_INTELLISENSE_DIRECTIVES"), entry, printing_parsed );
|
||||
b32 found = ignore_preprocess_cond_block(txt("GEN_INTELLISENSE_DIRECTIVES"), entry, printing_parsed, printing );
|
||||
if (found) break;
|
||||
|
||||
printing.append(entry);
|
||||
@ -290,7 +287,7 @@ int gen_main()
|
||||
break;
|
||||
}
|
||||
}
|
||||
// header.print(dump_to_scratch_and_retireve(printing));
|
||||
header.print(dump_to_scratch_and_retireve(printing));
|
||||
|
||||
CodeBody containers = def_body(CT_Global_Body);
|
||||
{
|
||||
@ -299,13 +296,18 @@ int gen_main()
|
||||
containers.append( gen_array_base() );
|
||||
containers.append( gen_hashtable_base() );
|
||||
|
||||
containers.append(fmt_newline);
|
||||
|
||||
CodeBody array_ssize = gen_array(txt("ssize"), txt("Array_ssize"));
|
||||
containers.append(array_ssize);
|
||||
|
||||
containers.append( def_pragma(code(endregion Containers)));
|
||||
}
|
||||
// header.print(fmt_newline);
|
||||
// header.print(dump_to_scratch_and_retireve(containers));
|
||||
header.print(fmt_newline);
|
||||
header.print(dump_to_scratch_and_retireve(containers));
|
||||
|
||||
Code hashing = scan_file( project_dir "dependencies/hashing.hpp" );
|
||||
// header.print( hashing );
|
||||
header.print( hashing );
|
||||
|
||||
CodeBody parsed_strings = parse_file( project_dir "dependencies/strings.hpp" );
|
||||
CodeBody strings = def_body(CT_Global_Body);
|
||||
@ -318,8 +320,8 @@ int gen_main()
|
||||
CodePreprocessCond cond = cast(CodePreprocessCond, entry);
|
||||
if (cond->Content.starts_with(txt("GEN_COMPILER_C || ! GEN_SUPPORT_CPP_MEMBER_FEATURES")))
|
||||
{
|
||||
++ entry;
|
||||
strings.append(entry); // typedef
|
||||
for (; entry != end(parsed_strings) && entry->Type != CT_Typedef; ++ entry) {}
|
||||
strings.append(entry);
|
||||
strings.append(fmt_newline);
|
||||
|
||||
for (; entry != end(parsed_strings) && entry->Type != CT_Preprocess_EndIf; ++ entry) {}
|
||||
@ -327,16 +329,16 @@ int gen_main()
|
||||
break;
|
||||
}
|
||||
|
||||
bool found = ignore_preprocess_cond_block(txt("! GEN_COMPILER_C"), entry, parsed_strings);
|
||||
bool found = ignore_preprocess_cond_block(txt("GEN_COMPILER_CPP"), entry, parsed_strings, strings);
|
||||
if (found) break;
|
||||
|
||||
found = ignore_preprocess_cond_block(txt("GEN_SUPPORT_CPP_REFERENCES"), entry, parsed_strings);
|
||||
found = ignore_preprocess_cond_block(txt("GEN_SUPPORT_CPP_REFERENCES"), entry, parsed_strings, strings );
|
||||
}
|
||||
break;
|
||||
|
||||
case CT_Preprocess_IfDef:
|
||||
{
|
||||
ignore_preprocess_cond_block(txt("GEN_INTELLISENSE_DIRECTIVES"), entry, parsed_strings );
|
||||
ignore_preprocess_cond_block(txt("GEN_INTELLISENSE_DIRECTIVES"), entry, parsed_strings, strings );
|
||||
}
|
||||
break;
|
||||
|
||||
@ -362,7 +364,7 @@ int gen_main()
|
||||
(body_entry->Type) {
|
||||
case CT_Preprocess_If:
|
||||
{
|
||||
b32 found = ignore_preprocess_cond_block(txt("! GEN_COMPILER_C"), body_entry, body );
|
||||
b32 found = ignore_preprocess_cond_block(txt("GEN_COMPILER_CPP"), body_entry, body, new_body );
|
||||
if (found) break;
|
||||
|
||||
new_body.append(body_entry);
|
||||
@ -377,12 +379,28 @@ int gen_main()
|
||||
}
|
||||
break;
|
||||
|
||||
case CT_Typedef:
|
||||
{
|
||||
StrC name_string_table = txt("StringTable");
|
||||
|
||||
CodeTypedef td = cast(CodeTypedef, entry);
|
||||
if (td->Name.contains(name_string_table))
|
||||
{
|
||||
CodeBody ht = gen_hashtable(name_string_table, name_string_table);
|
||||
strings.append(ht);
|
||||
strings.append(td);
|
||||
break;
|
||||
}
|
||||
strings.append(td);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
strings.append(entry);
|
||||
break;
|
||||
}
|
||||
}
|
||||
// header.print(dump_to_scratch_and_retireve(strings));
|
||||
header.print(dump_to_scratch_and_retireve(strings));
|
||||
|
||||
Code filesystem = scan_file( project_dir "dependencies/filesystem.hpp" );
|
||||
Code timing = scan_file( project_dir "dependencies/timing.hpp" );
|
||||
|
@ -7,7 +7,7 @@ using namespace gen;
|
||||
|
||||
CodeBody gen_hashtable_base()
|
||||
{
|
||||
return parse_global_body( code(
|
||||
CodeBody struct_def = parse_global_body( code(
|
||||
typedef struct HT_FindResult HT_FindResult;
|
||||
struct HT_FindResult
|
||||
{
|
||||
@ -16,18 +16,21 @@ CodeBody gen_hashtable_base()
|
||||
ssize EntryIndex;
|
||||
};
|
||||
));
|
||||
|
||||
Code define_type = untyped_str(txt(
|
||||
R"(#define HashTable(_type) struct _type
|
||||
)"
|
||||
));
|
||||
|
||||
return def_global_body(args(struct_def, define_type));
|
||||
}
|
||||
|
||||
CodeBody gen_hashtable( StrC type, StrC hashtable_name )
|
||||
{
|
||||
String
|
||||
fn = String::make_reserve( GlobalAllocator, hashtable_name.Len + sizeof("gen") );
|
||||
fn.append_fmt( "%.*s", hashtable_name.Len, hashtable_name.Ptr );
|
||||
str_to_lower(fn.Data);
|
||||
|
||||
String
|
||||
tbl_type = String::make_reserve( GlobalAllocator, hashtable_name.Len + sizeof("gen") );
|
||||
tbl_type.append_fmt( "%.*s", hashtable_name.Len, hashtable_name.Ptr );
|
||||
String tbl_type = {(char*) hashtable_name.duplicate(GlobalAllocator).Ptr};
|
||||
String fn = tbl_type.duplicate(GlobalAllocator);
|
||||
str_to_lower(fn.Data);
|
||||
|
||||
String name_lower = String::make( GlobalAllocator, hashtable_name );
|
||||
str_to_lower( name_lower.Data );
|
||||
|
@ -5,7 +5,7 @@
|
||||
|
||||
|
||||
|
||||
b32 ignore_preprocess_cond_block( StrC cond_sig, Code& entry_iter, CodeBody& body )
|
||||
b32 ignore_preprocess_cond_block( StrC cond_sig, Code& entry_iter, CodeBody& parsed_body, CodeBody& body )
|
||||
{
|
||||
b32 found = false;
|
||||
CodePreprocessCond cond = cast(CodePreprocessCond, entry_iter);
|
||||
@ -16,7 +16,7 @@ b32 ignore_preprocess_cond_block( StrC cond_sig, Code& entry_iter, CodeBody& bod
|
||||
|
||||
s32 depth = 1;
|
||||
++ entry_iter;
|
||||
for(b32 continue_for = true; continue_for && entry_iter != body.end(); ) switch
|
||||
for(b32 continue_for = true; continue_for && entry_iter != parsed_body.end(); ) switch
|
||||
(entry_iter->Type) {
|
||||
case CT_Preprocess_If:
|
||||
case CT_Preprocess_IfDef:
|
||||
@ -27,7 +27,7 @@ b32 ignore_preprocess_cond_block( StrC cond_sig, Code& entry_iter, CodeBody& bod
|
||||
|
||||
case CT_Preprocess_Else:
|
||||
++ entry_iter;
|
||||
for(; continue_for && entry_iter != body.end(); ++ entry_iter)
|
||||
for(; continue_for && entry_iter != parsed_body.end(); ++ entry_iter)
|
||||
{
|
||||
if (entry_iter->Type == CT_Preprocess_EndIf)
|
||||
{
|
||||
|
@ -4957,6 +4957,13 @@ CodeTypedef parse_typedef()
|
||||
Context.Scope->Name = name;
|
||||
eat( Tok_Preprocess_Macro );
|
||||
// <ModuleFalgs> typedef <Preprocessed_Macro>
|
||||
|
||||
if ( currtok.Type == Tok_Identifier )
|
||||
{
|
||||
type = untyped_str({ name.Length, name.Text });
|
||||
name = currtok;
|
||||
eat(Tok_Identifier);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -5,6 +5,7 @@
|
||||
#endif
|
||||
|
||||
#pragma region Basic Types
|
||||
GEN_API_C_BEGIN
|
||||
|
||||
#define GEN_U8_MIN 0u
|
||||
#define GEN_U8_MAX 0xffu
|
||||
@ -127,11 +128,13 @@ typedef void* mem_ptr;
|
||||
typedef void const* mem_ptr_const ;
|
||||
|
||||
#if ! GEN_COMPILER_C
|
||||
GEN_API_C_END
|
||||
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))
|
||||
@ -140,4 +143,5 @@ template<typename Type> mem_ptr_const to_mem_ptr_const( Type ptr ) { return (mem
|
||||
#define to_mem_ptr_const( ptr) ((mem_ptr)ptr)
|
||||
#endif
|
||||
|
||||
GEN_API_C_END
|
||||
#pragma endregion Basic Types
|
||||
|
@ -423,6 +423,10 @@ bool array_set_capacity(Array<Type>* array, usize new_capacity)
|
||||
|
||||
template<class Type> struct HashTable;
|
||||
|
||||
#ifndef get_hashtable_underlying_type
|
||||
#define get_hashtable_underlying_type(table) typename TRemovePtr<typeof(table)>:: DataType
|
||||
#endif
|
||||
|
||||
struct HashTableFindResult {
|
||||
ssize HashIndex;
|
||||
ssize PrevIndex;
|
||||
@ -483,6 +487,8 @@ struct HashTable
|
||||
forceinline void map_mut(void (*proc)(u64, Type*)) { GEN_NS map_mut<Type>(*this, proc); }
|
||||
#pragma endregion Member Mapping
|
||||
#endif
|
||||
|
||||
using DataType = Type;
|
||||
};
|
||||
|
||||
#if GEN_SUPPORT_CPP_REFERENCES
|
||||
@ -710,21 +716,21 @@ bool hashtable_full(HashTable<Type> table) {
|
||||
|
||||
#define hashtable_init(type, allocator) hashtable_init <type >(allocator)
|
||||
#define hashtable_init_reserve(type, allocator, num) hashtable_init_reserve<type >(allocator, num)
|
||||
#define hashtable_clear(table) hashtable_clear < TStripPtr<table> >(table)
|
||||
#define hashtable_destroy(table) hashtable_destroy < TStripPtr<table> >(& table)
|
||||
#define hashtable_get(table, key) hashtable_get < TStripPtr<table> >(table, key)
|
||||
#define hashtable_grow(table) hashtable_grow < TStripPtr<table> >(& table)
|
||||
#define hashtable_rehash(table, new_num) hashtable_rehash < TStripPtr<table> >(& table, new_num)
|
||||
#define hashtable_rehash_fast(table) hashtable_rehash_fast < TStripPtr<table> >(table)
|
||||
#define hashtable_remove(table, key) hashtable_remove < TStripPtr<table> >(table, key)
|
||||
#define hashtable_remove_entry(table, idx) hashtable_remove_entry< TStripPtr<table> >(table, idx)
|
||||
#define hashtable_set(table, key, value) hashtable_set < TStripPtr<table> >(& table, key, value)
|
||||
#define hashtable_slot(table, key) hashtable_slot < TStripPtr<table> >(table, key)
|
||||
#define hashtable_add_entry(table, key) hashtable_add_entry < TStripPtr<table> >(& table, key)
|
||||
#define hashtable_find(table, key) hashtable_find < TStripPtr<table> >(table, key)
|
||||
#define hashtable_full(table) hashtable_full < TStripPtr<table> >(table)
|
||||
#define hashtable_map(table, map_proc) hashtable_map < TStripPtr<table> >(table, map_proc)
|
||||
#define hashtable_map_mut(table, map_proc) hashtable_map_mut < TStripPtr<table> >(table, map_proc)
|
||||
#define hashtable_clear(table) hashtable_clear < get_hashtable_underlying_type(table) >(table)
|
||||
#define hashtable_destroy(table) hashtable_destroy < get_hashtable_underlying_type(table) >(& table)
|
||||
#define hashtable_get(table, key) hashtable_get < get_hashtable_underlying_type(table) >(table, key)
|
||||
#define hashtable_grow(table) hashtable_grow < get_hashtable_underlying_type(table) >(& table)
|
||||
#define hashtable_rehash(table, new_num) hashtable_rehash < get_hashtable_underlying_type(table) >(& table, new_num)
|
||||
#define hashtable_rehash_fast(table) hashtable_rehash_fast < get_hashtable_underlying_type(table) >(table)
|
||||
#define hashtable_remove(table, key) hashtable_remove < get_hashtable_underlying_type(table) >(table, key)
|
||||
#define hashtable_remove_entry(table, idx) hashtable_remove_entry< get_hashtable_underlying_type(table) >(table, idx)
|
||||
#define hashtable_set(table, key, value) hashtable_set < get_hashtable_underlying_type(table) >(& table, key, value)
|
||||
#define hashtable_slot(table, key) hashtable_slot < get_hashtable_underlying_type(table) >(table, key)
|
||||
#define hashtable_add_entry(table, key) hashtable_add_entry < get_hashtable_underlying_type(table) >(& table, key)
|
||||
#define hashtable_find(table, key) hashtable_find < get_hashtable_underlying_type(table) >(table, key)
|
||||
#define hashtable_full(table) hashtable_full < get_hashtable_underlying_type(table) >(table)
|
||||
#define hashtable_map(table, map_proc) hashtable_map < get_hashtable_underlying_type(table) >(table, map_proc)
|
||||
#define hashtable_map_mut(table, map_proc) hashtable_map_mut < get_hashtable_underlying_type(table) >(table, map_proc)
|
||||
|
||||
#pragma endregion HashTable
|
||||
|
||||
|
@ -6,6 +6,7 @@
|
||||
#endif
|
||||
|
||||
#pragma region Debug
|
||||
GEN_API_C_BEGIN
|
||||
|
||||
void assert_handler( char const* condition, char const* file, s32 line, char const* msg, ... )
|
||||
{
|
||||
@ -45,4 +46,5 @@ s32 assert_crash( char const* condition )
|
||||
}
|
||||
#endif
|
||||
|
||||
GEN_API_C_END
|
||||
#pragma endregion Debug
|
||||
|
@ -4,6 +4,7 @@
|
||||
#endif
|
||||
|
||||
#pragma region File Handling
|
||||
GEN_API_C_BEGIN
|
||||
|
||||
#if defined( GEN_SYSTEM_WINDOWS ) || defined( GEN_SYSTEM_CYGWIN )
|
||||
|
||||
@ -655,4 +656,5 @@ 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,10 +4,11 @@
|
||||
#endif
|
||||
|
||||
#pragma region File Handling
|
||||
GEN_API_C_BEGIN
|
||||
|
||||
typedef u32 FileMode;
|
||||
|
||||
enum FileModeFlag
|
||||
enum FileModeFlag_Def
|
||||
{
|
||||
EFileMode_READ = bit( 0 ),
|
||||
EFileMode_WRITE = bit( 1 ),
|
||||
@ -15,16 +16,18 @@ enum FileModeFlag
|
||||
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
|
||||
enum SeekWhenceType_Def
|
||||
{
|
||||
ESeekWhence_BEGIN = 0,
|
||||
ESeekWhence_CURRENT = 1,
|
||||
ESeekWhence_END = 2,
|
||||
};
|
||||
typedef enum SeekWhenceType_Def SeekWhenceType;
|
||||
|
||||
enum FileError
|
||||
enum FileError_Def
|
||||
{
|
||||
EFileError_NONE,
|
||||
EFileError_INVALID,
|
||||
@ -37,15 +40,17 @@ enum FileError
|
||||
EFileError_NAME_TOO_LONG,
|
||||
EFileError_UNKNOWN,
|
||||
};
|
||||
typedef enum FileError_Def FileError;
|
||||
|
||||
union FileDescriptor
|
||||
union FileDescriptor_Def
|
||||
{
|
||||
void* p;
|
||||
sptr i;
|
||||
uptr u;
|
||||
};
|
||||
typedef union FileDescriptor_Def FileDescriptor;
|
||||
|
||||
typedef struct FileOperations FileOperations;
|
||||
typedef struct FileOperations_Def 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 )
|
||||
@ -59,35 +64,39 @@ typedef GEN_FILE_WRITE_AT_PROC( FileWriteProc );
|
||||
typedef GEN_FILE_SEEK_PROC( FileSeekProc );
|
||||
typedef GEN_FILE_CLOSE_PROC( FileCloseProc );
|
||||
|
||||
struct FileOperations
|
||||
struct FileOperations_Def
|
||||
{
|
||||
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
|
||||
enum DirType_Def
|
||||
{
|
||||
GEN_DIR_TYPE_FILE,
|
||||
GEN_DIR_TYPE_FOLDER,
|
||||
GEN_DIR_TYPE_UNKNOWN,
|
||||
};
|
||||
typedef enum DirType_Def DirType;
|
||||
|
||||
struct DirInfo;
|
||||
struct DirInfo_Def;
|
||||
typedef struct DirInfo_Def DirInfo;
|
||||
|
||||
struct DirEntry
|
||||
struct DirEntry_Def
|
||||
{
|
||||
char const* filename;
|
||||
struct DirInfo* dir_info;
|
||||
DirInfo* dir_info;
|
||||
u8 type;
|
||||
};
|
||||
typedef struct DirEntry_Def DirEntry;
|
||||
|
||||
struct DirInfo
|
||||
struct DirInfo_Def
|
||||
{
|
||||
char const* fullpath;
|
||||
DirEntry* entries; // zpl_array
|
||||
@ -97,7 +106,7 @@ struct DirInfo
|
||||
String buf;
|
||||
};
|
||||
|
||||
struct FileInfo
|
||||
struct FileInfo_Def
|
||||
{
|
||||
FileOperations ops;
|
||||
FileDescriptor fd;
|
||||
@ -107,8 +116,9 @@ struct FileInfo
|
||||
FileTime last_write_time;
|
||||
DirEntry* dir;
|
||||
};
|
||||
typedef struct FileInfo_Def FileInfo;
|
||||
|
||||
enum FileStandardType
|
||||
enum FileStandardType_Def
|
||||
{
|
||||
EFileStandard_INPUT,
|
||||
EFileStandard_OUTPUT,
|
||||
@ -116,6 +126,7 @@ enum FileStandardType
|
||||
|
||||
EFileStandard_COUNT,
|
||||
};
|
||||
typedef enum FileStandardType_Def FileStandardType;
|
||||
|
||||
/**
|
||||
* Get standard file I/O.
|
||||
@ -257,7 +268,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 : u32
|
||||
enum FileStreamFlags_Def enum_underlying(u32)
|
||||
{
|
||||
/* Allows us to write to the buffer directly. Beware: you can not append a new data! */
|
||||
EFileStream_WRITABLE = bit( 0 ),
|
||||
@ -265,7 +276,10 @@ enum FileStreamFlags : u32
|
||||
/* Clones the input buffer so you can write (zpl_file_write*) data into it. */
|
||||
/* Since we work with a clone, the buffer size can dynamically grow as well. */
|
||||
EFileStream_CLONE_WRITABLE = bit( 1 ),
|
||||
|
||||
EFileStream_UNDERLYING = GEN_U32_MAX,
|
||||
};
|
||||
typedef enum FileStreamFlags_Def FileStreamFlags;
|
||||
|
||||
/**
|
||||
* Opens a new memory stream
|
||||
@ -381,4 +395,5 @@ 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,6 +4,7 @@
|
||||
#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,
|
||||
@ -87,4 +88,5 @@ u64 crc64( void const* data, ssize len )
|
||||
return result;
|
||||
}
|
||||
|
||||
GEN_API_C_END
|
||||
#pragma endregion Hashing
|
||||
|
@ -4,12 +4,10 @@
|
||||
#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
|
||||
|
@ -183,6 +183,18 @@
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if GEN_COMPILER_CPP
|
||||
// Already Defined
|
||||
#elif GEN_COMPILER_C && __STDC_VERSION__ >= 201112L
|
||||
# define thread_local _Thread_local
|
||||
#elif GEN_COMPILER_MSVC
|
||||
# define thread_local __declspec(thread)
|
||||
#elif GEN_COMPILER_CLANG
|
||||
# define thread_local __thread
|
||||
#else
|
||||
# error "No thread local support"
|
||||
#endif
|
||||
|
||||
#if !defined(GEN_SUPPORT_CPP_REFERENCES)
|
||||
# define GEN_SUPPORT_CPP_REFERENCES 1
|
||||
#endif
|
||||
@ -203,7 +215,7 @@
|
||||
# if ! GEN_COMPILER_C
|
||||
# define typeof decltype
|
||||
# elif defined(_MSC_VER)
|
||||
# define typeof(x) __typeof(x)
|
||||
# define typeof(x) __typeof__(x)
|
||||
# elif defined(__GNUC__) || defined(__clang__)
|
||||
# define typeof(x) __typeof__(x)
|
||||
# else
|
||||
@ -247,4 +259,10 @@
|
||||
# define GEN_PARAM_DEFAULT
|
||||
#endif
|
||||
|
||||
#if GEN_COMPILER_CPP
|
||||
#define struct_init(type, value) {value}
|
||||
#else
|
||||
#define struct_init(type, value) {value}
|
||||
#endif
|
||||
|
||||
#pragma endregion Macros
|
||||
|
@ -4,7 +4,6 @@
|
||||
#endif
|
||||
|
||||
#pragma region Memory
|
||||
|
||||
GEN_API_C_BEGIN
|
||||
|
||||
void* mem_copy( void* dest, void const* source, ssize n )
|
||||
@ -520,5 +519,4 @@ void pool_clear(Pool* pool)
|
||||
}
|
||||
|
||||
GEN_API_C_END
|
||||
|
||||
#pragma endregion Memory
|
||||
|
@ -3,6 +3,7 @@
|
||||
#endif
|
||||
|
||||
#pragma region ADT
|
||||
GEN_API_C_BEGIN
|
||||
|
||||
#define _adt_fprintf( s_, fmt_, ... ) \
|
||||
do \
|
||||
@ -1110,5 +1111,5 @@ String csv_write_string_delimiter( AllocatorInfo a, CSV_Object* obj, char delimi
|
||||
return output;
|
||||
}
|
||||
|
||||
GEN_API_C_END
|
||||
#pragma endregion CSV
|
||||
|
||||
|
@ -3,6 +3,7 @@
|
||||
#endif
|
||||
|
||||
#pragma region ADT
|
||||
GEN_API_C_BEGIN
|
||||
|
||||
enum ADT_Type : u32
|
||||
{
|
||||
@ -429,4 +430,5 @@ String csv_write_string( AllocatorInfo a, CSV_Object* obj )
|
||||
return csv_write_string_delimiter( a, obj, ',' );
|
||||
}
|
||||
|
||||
GEN_API_C_END
|
||||
#pragma endregion CSV
|
||||
|
@ -6,6 +6,7 @@
|
||||
#endif
|
||||
|
||||
#pragma region Printing
|
||||
GEN_API_C_BEGIN
|
||||
|
||||
enum
|
||||
{
|
||||
@ -549,7 +550,7 @@ char* str_fmt_buf( char const* fmt, ... )
|
||||
return str;
|
||||
}
|
||||
|
||||
ssize str_fmt_file_va( struct FileInfo* f, char const* fmt, va_list va )
|
||||
ssize str_fmt_file_va( FileInfo* f, char const* fmt, va_list va )
|
||||
{
|
||||
local_persist thread_local char buf[ GEN_PRINTF_MAXLEN ];
|
||||
ssize len = str_fmt_va( buf, size_of( buf ), fmt, va );
|
||||
@ -557,7 +558,7 @@ ssize str_fmt_file_va( struct FileInfo* f, char const* fmt, va_list va )
|
||||
return res ? len : -1;
|
||||
}
|
||||
|
||||
ssize str_fmt_file( struct FileInfo* f, char const* fmt, ... )
|
||||
ssize str_fmt_file( FileInfo* f, char const* fmt, ... )
|
||||
{
|
||||
ssize res;
|
||||
va_list va;
|
||||
@ -597,4 +598,5 @@ ssize str_fmt_out_err( char const* fmt, ... )
|
||||
return res;
|
||||
}
|
||||
|
||||
GEN_API_C_END
|
||||
#pragma endregion Printing
|
||||
|
@ -7,11 +7,12 @@
|
||||
|
||||
GEN_API_C_BEGIN
|
||||
|
||||
struct FileInfo;
|
||||
typedef struct FileInfo_Def FileInfo;
|
||||
|
||||
#ifndef GEN_PRINTF_MAXLEN
|
||||
# define GEN_PRINTF_MAXLEN kilobytes(128)
|
||||
#endif
|
||||
typedef char PrintF_Buffer[GEN_PRINTF_MAXLEN];
|
||||
|
||||
// NOTE: A locally persisting buffer is used internally
|
||||
char* str_fmt_buf ( char const* fmt, ... );
|
||||
|
@ -5,6 +5,7 @@
|
||||
#endif
|
||||
|
||||
#pragma region String Ops
|
||||
GEN_API_C_BEGIN
|
||||
|
||||
internal
|
||||
ssize _scan_zpl_i64( const char* text, s32 base, s64* value )
|
||||
@ -212,4 +213,5 @@ f64 str_to_f64( const char* str, char** end_ptr )
|
||||
return result;
|
||||
}
|
||||
|
||||
GEN_API_C_END
|
||||
#pragma endregion String Ops
|
||||
|
@ -4,6 +4,8 @@
|
||||
#endif
|
||||
|
||||
#pragma region String
|
||||
GEN_API_C_BEGIN
|
||||
|
||||
String string_make_length( AllocatorInfo allocator, char const* str, ssize length )
|
||||
{
|
||||
constexpr ssize header_size = sizeof( StringHeader );
|
||||
@ -51,4 +53,6 @@ String string_make_reserve( AllocatorInfo allocator, ssize capacity )
|
||||
String result = { rcast(char*, allocation) + header_size };
|
||||
return result;
|
||||
}
|
||||
|
||||
GEN_API_C_END
|
||||
#pragma endregion String
|
||||
|
@ -7,7 +7,8 @@
|
||||
|
||||
GEN_API_C_BEGIN
|
||||
|
||||
struct StrC;
|
||||
struct StrC_Def;
|
||||
typedef struct StrC_Def StrC;
|
||||
|
||||
bool strc_are_equal (StrC lhs, StrC rhs);
|
||||
char const* strc_back (StrC str);
|
||||
@ -20,7 +21,7 @@ StrC strc_visualize_whitespace(StrC str, AllocatorInfo allocator);
|
||||
GEN_API_C_END
|
||||
|
||||
// Constant string with length.
|
||||
struct StrC
|
||||
struct StrC_Def
|
||||
{
|
||||
ssize Len;
|
||||
char const* Ptr;
|
||||
@ -41,7 +42,14 @@ struct StrC
|
||||
};
|
||||
|
||||
#define cast_to_strc( str ) * rcast( StrC*, (str) - sizeof(ssize) )
|
||||
|
||||
#ifndef txt
|
||||
# if GEN_COMPILER_CPP
|
||||
# define txt( text ) StrC { sizeof( text ) - 1, ( text ) }
|
||||
# else
|
||||
# define txt( text ) (StrC){ sizeof( text ) - 1, ( text ) }
|
||||
# endif
|
||||
#endif
|
||||
|
||||
GEN_API_C_BEGIN
|
||||
forceinline char const* strc_begin(StrC str) { return str.Ptr; }
|
||||
@ -64,7 +72,7 @@ bool strc_are_equal(StrC lhs, StrC rhs)
|
||||
return false;
|
||||
|
||||
for (ssize idx = 0; idx < lhs.Len; ++idx)
|
||||
if (lhs[idx] != rhs[idx])
|
||||
if (lhs.Ptr[idx] != rhs.Ptr[idx])
|
||||
return false;
|
||||
|
||||
return true;
|
||||
@ -102,7 +110,8 @@ b32 strc_starts_with(StrC str, StrC substring) {
|
||||
|
||||
inline
|
||||
StrC to_strc_from_c_str( char const* bad_str ) {
|
||||
return { str_len( bad_str ), bad_str };
|
||||
StrC result = { str_len( bad_str ), bad_str };
|
||||
return result;
|
||||
}
|
||||
GEN_API_C_END
|
||||
|
||||
@ -111,7 +120,8 @@ GEN_API_C_END
|
||||
// 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;
|
||||
struct StringHeader_Def;
|
||||
typedef struct StringHeader_Def StringHeader;
|
||||
|
||||
#if GEN_COMPILER_C || ! GEN_SUPPORT_CPP_MEMBER_FEATURES
|
||||
typedef char* String;
|
||||
@ -160,7 +170,7 @@ String string_visualize_whitespace(String const str);
|
||||
|
||||
GEN_API_C_END
|
||||
|
||||
struct StringHeader {
|
||||
struct StringHeader_Def {
|
||||
AllocatorInfo Allocator;
|
||||
ssize Capacity;
|
||||
ssize Length;
|
||||
@ -324,7 +334,7 @@ inline
|
||||
String string_fmt_buf(AllocatorInfo allocator, char const* fmt, ...)
|
||||
{
|
||||
local_persist thread_local
|
||||
char buf[GEN_PRINTF_MAXLEN] = { 0 };
|
||||
PrintF_Buffer buf = struct_init(PrintF_Buffer, {0});
|
||||
|
||||
va_list va;
|
||||
va_start(va, fmt);
|
||||
@ -366,7 +376,7 @@ inline
|
||||
bool string_append_c_str_len(String* str, char const* str_to_append, ssize append_length)
|
||||
{
|
||||
GEN_ASSERT(str != nullptr);
|
||||
if (sptr(str_to_append) > 0)
|
||||
if ( rcast(sptr, str_to_append) > 0)
|
||||
{
|
||||
ssize curr_len = string_length(* str);
|
||||
|
||||
@ -521,8 +531,8 @@ StringHeader* string_get_header(String str) {
|
||||
forceinline
|
||||
ssize string_length(String const str)
|
||||
{
|
||||
StringHeader const& header = *rcast(StringHeader const*, scast(char const*, str) - sizeof(StringHeader));
|
||||
return header.Length;
|
||||
StringHeader const* header = rcast(StringHeader const*, scast(char const*, str) - sizeof(StringHeader));
|
||||
return header->Length;
|
||||
}
|
||||
|
||||
inline
|
||||
@ -627,7 +637,8 @@ void strip_space(String str)
|
||||
|
||||
forceinline
|
||||
StrC string_to_strc(String str) {
|
||||
return { string_length(str), (char const*)str };
|
||||
StrC result = { string_length(str), (char const*)str };
|
||||
return result;
|
||||
}
|
||||
|
||||
inline
|
||||
@ -695,15 +706,17 @@ String visualize_whitespace(String const str)
|
||||
}
|
||||
#pragma endregion String
|
||||
|
||||
#if GEN_COMPILER_CPP
|
||||
struct String_POD {
|
||||
char* Data;
|
||||
};
|
||||
static_assert( sizeof( String_POD ) == sizeof( String ), "String is not a POD" );
|
||||
#endif
|
||||
|
||||
forceinline
|
||||
StrC strc_duplicate(StrC str, AllocatorInfo allocator) {
|
||||
String result = string_make_length(allocator, str.Ptr, str.Len);
|
||||
return { string_get_header(result)->Length, result };
|
||||
StrC result = string_to_strc( string_make_length(allocator, str.Ptr, str.Len));
|
||||
return result;
|
||||
}
|
||||
|
||||
inline
|
||||
@ -745,5 +758,5 @@ typedef StrC StringCached;
|
||||
GEN_API_C_END
|
||||
|
||||
// Implements basic string interning. Data structure is based off the ZPL Hashtable.
|
||||
typedef HashTable<StringCached> StringTable;
|
||||
typedef HashTable(StringCached) StringTable;
|
||||
#pragma endregion Strings
|
||||
|
@ -4,6 +4,7 @@
|
||||
#endif
|
||||
|
||||
#pragma region Timing
|
||||
GEN_API_C_BEGIN
|
||||
|
||||
#ifdef GEN_BENCHMARK
|
||||
#if defined( GEN_COMPILER_MSVC ) && ! defined( __clang__ )
|
||||
@ -164,4 +165,5 @@
|
||||
}
|
||||
#endif
|
||||
|
||||
GEN_API_C_END
|
||||
#pragma endregion Timing
|
||||
|
@ -5,6 +5,8 @@
|
||||
|
||||
#pragma region Timing
|
||||
|
||||
GEN_API_C_BEGIN
|
||||
|
||||
#ifdef GEN_BENCHMARK
|
||||
//! Return CPU timestamp.
|
||||
u64 read_cpu_time_stamp_counter( void );
|
||||
@ -16,4 +18,6 @@ f64 time_rel( void );
|
||||
u64 time_rel_ms( void );
|
||||
#endif
|
||||
|
||||
GEN_API_C_END
|
||||
|
||||
#pragma endregion Timing
|
||||
|
@ -35,21 +35,21 @@
|
||||
|
||||
#define hashtable_init(type, allocator) hashtable_init <type >(allocator)
|
||||
#define hashtable_init_reserve(type, allocator, num) hashtable_init_reserve<type >(allocator, num)
|
||||
#define hashtable_clear(table) hashtable_clear (table)
|
||||
#define hashtable_destroy(table) hashtable_destroy (& table)
|
||||
#define hashtable_get(table, key) hashtable_get (table, key)
|
||||
#define hashtable_grow(table) hashtable_grow (& table)
|
||||
#define hashtable_rehash(table, new_num) hashtable_rehash (& table, new_num)
|
||||
#define hashtable_rehash_fast(table) hashtable_rehash_fast (table)
|
||||
#define hashtable_remove(table, key) hashtable_remove (table, key)
|
||||
#define hashtable_remove_entry(table, idx) hashtable_remove_entry(table, idx)
|
||||
#define hashtable_set(table, key, value) hashtable_set (& table, key, value)
|
||||
#define hashtable_slot(table, key) hashtable_slot (table, key)
|
||||
#define hashtable_add_entry(table, key) hashtable_add_entry (& table, key)
|
||||
#define hashtable_find(table, key) hashtable_find (table, key)
|
||||
#define hashtable_full(table) hashtable_full (table)
|
||||
#define hashtable_map(table, map_proc) hashtable_map (table, map_proc)
|
||||
#define hashtable_map_mut(table, map_proc) hashtable_map_mut (table, map_proc)
|
||||
#define hashtable_clear(table) hashtable_clear < get_hashtable_underlying_type(table) >(table)
|
||||
#define hashtable_destroy(table) hashtable_destroy < get_hashtable_underlying_type(table) >(& table)
|
||||
#define hashtable_get(table, key) hashtable_get < get_hashtable_underlying_type(table) >(table, key)
|
||||
#define hashtable_grow(table) hashtable_grow < get_hashtable_underlying_type(table) >(& table)
|
||||
#define hashtable_rehash(table, new_num) hashtable_rehash < get_hashtable_underlying_type(table) >(& table, new_num)
|
||||
#define hashtable_rehash_fast(table) hashtable_rehash_fast < get_hashtable_underlying_type(table) >(table)
|
||||
#define hashtable_remove(table, key) hashtable_remove < get_hashtable_underlying_type(table) >(table, key)
|
||||
#define hashtable_remove_entry(table, idx) hashtable_remove_entry< get_hashtable_underlying_type(table) >(table, idx)
|
||||
#define hashtable_set(table, key, value) hashtable_set < get_hashtable_underlying_type(table) >(& table, key, value)
|
||||
#define hashtable_slot(table, key) hashtable_slot < get_hashtable_underlying_type(table) >(table, key)
|
||||
#define hashtable_add_entry(table, key) hashtable_add_entry < get_hashtable_underlying_type(table) >(& table, key)
|
||||
#define hashtable_find(table, key) hashtable_find < get_hashtable_underlying_type(table) >(table, key)
|
||||
#define hashtable_full(table) hashtable_full < get_hashtable_underlying_type(table) >(table)
|
||||
#define hashtable_map(table, map_proc) hashtable_map < get_hashtable_underlying_type(table) >(table, map_proc)
|
||||
#define hashtable_map_mut(table, map_proc) hashtable_map_mut < get_hashtable_underlying_type(table) >(table, map_proc)
|
||||
|
||||
//! If its desired to roll your own dependencies, define GEN_ROLL_OWN_DEPENDENCIES before including this file.
|
||||
//! Dependencies are derived from the c-zpl library: https://github.com/zpl-c/zpl
|
||||
|
@ -1,26 +1,19 @@
|
||||
#if GEN_SUPPORT_CPP_MEMBER_FEATURES
|
||||
// These are intended for use in the base library of gencpp and the C-variant of the library
|
||||
// It provides a interoperability between the C++ and C implementation of arrays. (not letting these do any crazy substiution though)
|
||||
// They are undefined in gen.hpp and gen.cpp at the end of the files.
|
||||
// We cpp library expects the user to use the regular calls as they can resolve the type fine.
|
||||
|
||||
#define array_init(type, allocator) array_init <typeof(array)>(type, allocator )
|
||||
#define array_init_reserve(type, allocator, cap) array_init_reserve<typeof(array)>(type, allocator, cap)
|
||||
#define array_append_array(type, array, other) array_append <typeof(array)>(type, & array, other )
|
||||
#define array_append_value(type, array, value) array_append <typeof(array)>(type, & array, value )
|
||||
#define array_append_items(type, array, items, item_num) array_append <typeof(array)>(type, & array, items, item_num )
|
||||
#define array_append_at(type, array, item, idx ) array_append_at <typeof(array)>(type, & array, item, idx )
|
||||
#define array_append_at(type, array, items, item_num, idx) array_append_at <typeof(array)>(type, & items, item_num, idx )
|
||||
#define array_back(type, array ) array_back <typeof(array)>(type, array )
|
||||
#define array_clear(type, array ) array_clear <typeof(array)>(type, array )
|
||||
#define array_fill(type, array, begin, end, value) array_fill <typeof(array)>(type, array, begin, end, value )
|
||||
#define array_free(type, array) array_free <typeof(array)>(type, & array )
|
||||
#define arary_grow(type, array, min_capacity) arary_grow <typeof(array)>(type, & array, min_capacity)
|
||||
#define array_num(type, array) array_num <typeof(array)>(type, array )
|
||||
#define arary_pop(type, array) arary_pop <typeof(array)>(type, array )
|
||||
#define arary_remove_at(type, array, idx) arary_remove_at <typeof(array)>(type, idx)
|
||||
#define arary_reserve(type, array, new_capacity) arary_reserve <typeof(array)>(type, & array, new_capacity )
|
||||
#define arary_resize(type, array, num) arary_resize <typeof(array)>(type, & array, num)
|
||||
#define arary_set_capacity(array, new_capacity) arary_set_capacity<typeof(array)>(type, & array, new_capacity )
|
||||
#define arary_get_header(array) arary_get_header <typeof(array)>(type, array )
|
||||
#endif
|
||||
#define array_init(type, allocator) array_init <type> (allocator )
|
||||
#define array_init_reserve(type, allocator, cap) array_init_reserve <type> (allocator, cap)
|
||||
#define array_append_array(array, other) array_append < get_array_underlying_type(array) > (& array, other )
|
||||
#define array_append_value(array, value) array_append < get_array_underlying_type(array) > (& array, value )
|
||||
#define array_append_items(array, items, item_num) array_append < get_array_underlying_type(array) > (& array, items, item_num )
|
||||
#define array_append_at(array, item, idx ) array_append_at < get_array_underlying_type(array) > (& array, item, idx )
|
||||
#define array_append_at_items(array, items, item_num, idx) array_append_at_items< get_array_underlying_type(array) > (& items, item_num, idx )
|
||||
#define array_back(array) array_back < get_array_underlying_type(array) > (array )
|
||||
#define array_clear(array) array_clear < get_array_underlying_type(array) > (array )
|
||||
#define array_fill(array, begin, end, value) array_fill < get_array_underlying_type(array) > (array, begin, end, value )
|
||||
#define array_free(array) array_free < get_array_underlying_type(array) > (& array )
|
||||
#define arary_grow(array, min_capacity) arary_grow < get_array_underlying_type(array) > (& array, min_capacity)
|
||||
#define array_num(array) array_num < get_array_underlying_type(array) > (array )
|
||||
#define arary_pop(array) arary_pop < get_array_underlying_type(array) > (array )
|
||||
#define arary_remove_at(array, idx) arary_remove_at < get_array_underlying_type(array) > (idx)
|
||||
#define arary_reserve(array, new_capacity) arary_reserve < get_array_underlying_type(array) > (& array, new_capacity )
|
||||
#define arary_resize(array, num) arary_resize < get_array_underlying_type(array) > (& array, num)
|
||||
#define arary_set_capacity(new_capacity) arary_set_capacity < get_array_underlying_type(array) > (& array, new_capacity )
|
||||
#define arary_get_header(array) arary_get_header < get_array_underlying_type(array) > (array )
|
||||
|
Loading…
Reference in New Issue
Block a user