From 4a57ec6b1e35cf3223a78bf9aed15009464b09c7 Mon Sep 17 00:00:00 2001 From: Doyle Date: Tue, 24 Sep 2019 14:13:29 +1000 Subject: [PATCH] Forward declare stuff for linux --- Code/Build.sh | 6 ----- Code/Dqn.h | 75 +++++++++++++++++++++++++-------------------------- Code/build.sh | 4 +++ 3 files changed, 41 insertions(+), 44 deletions(-) delete mode 100755 Code/Build.sh create mode 100755 Code/build.sh diff --git a/Code/Build.sh b/Code/Build.sh deleted file mode 100755 index 28d3661..0000000 --- a/Code/Build.sh +++ /dev/null @@ -1,6 +0,0 @@ -if [ ! -d "../Bin/" ]; then - mkdir ../Bin/ -fi -pushd ../Bin/ - -g++ ../Code/Dqn_UnitTests.cpp -std=c++17 -o Dqn_UnitTests diff --git a/Code/Dqn.h b/Code/Dqn.h index 4c61ffa..e6cc759 100644 --- a/Code/Dqn.h +++ b/Code/Dqn.h @@ -654,6 +654,40 @@ struct Dqn_MemArenaScopedRegion #define DQN_MEM_ARENA_FREE(arena) Dqn_MemArena_Free(arena) DQN_HEADER_COPY_END +// @ ------------------------------------------------------------------------------------------------- +// @ +// @ NOTE: Dqn_Allocator +// @ +// @ ------------------------------------------------------------------------------------------------- +DQN_HEADER_COPY_PROTOTYPE(Dqn_Allocator, inline Dqn_Allocator_NullAllocator()) +{ + Dqn_Allocator result = {}; + result.type = Dqn_Allocator_Type::NullAllocator; + return result; +} + +DQN_HEADER_COPY_PROTOTYPE(Dqn_Allocator, inline Dqn_Allocator_HeapAllocator()) +{ + Dqn_Allocator result = {}; + result.type = Dqn_Allocator_Type::Heap; + return result; +} + +DQN_HEADER_COPY_PROTOTYPE(Dqn_Allocator, inline Dqn_Allocator_XHeapAllocator()) +{ + Dqn_Allocator result = {}; + result.type = Dqn_Allocator_Type::XHeap; + return result; +} + +DQN_HEADER_COPY_PROTOTYPE(Dqn_Allocator, inline Dqn_Allocator_ArenaAllocator(Dqn_MemArena *arena)) +{ + Dqn_Allocator result = {}; + result.type = Dqn_Allocator_Type::Arena; + result.data = arena; + return result; +} + // @ ------------------------------------------------------------------------------------------------- // @ // @ NOTE: String Builder @@ -786,6 +820,7 @@ DQN_HEADER_COPY_PROTOTYPE(template char *, Dqn_StringBuilder_Build return result; } +void *Dqn_MemArena_Alloc(Dqn_MemArena *arena, Dqn_usize size DQN_DEBUG_ARGS); DQN_HEADER_COPY_PROTOTYPE(template char *, Dqn_StringBuilder_BuildFromArena(Dqn_StringBuilder *builder, Dqn_MemArena *arena, Dqn_isize *len = nullptr)) { Dqn_isize len_w_null_terminator = Dqn_StringBuilder_BuildLen(builder); @@ -917,6 +952,7 @@ DQN_HEADER_COPY_PROTOTYPE(template inline bool, Dqn_Slice_Equals(Dq // @ NOTE: Dqn_Asprintf (Allocate Sprintf) // @ // @ ------------------------------------------------------------------------------------------------- +int Dqn_Safe_TruncateISizeToInt(Dqn_isize val); DQN_HEADER_COPY_PROTOTYPE(template Dqn_Slice, Dqn_AsprintfSlice(T *arena, char const *fmt, va_list va)) { Dqn_Slice result = {}; @@ -1160,7 +1196,6 @@ DQN_HEADER_COPY_PROTOTYPE(template void, Dqn_Array_Free(Dqn_Arrayallocator, a->data); } - template bool Dqn_Array__GrowIfNeeded(Dqn_Array *a, Dqn_isize num_to_add) { Dqn_isize new_len = a->len + num_to_add; @@ -1382,42 +1417,6 @@ DQN_HEADER_COPY_PROTOTYPE(Dqn_b32, Dqn_Log(Dqn_LogType type, char const *file, D return true; } -void *Dqn_MemArena_Alloc(Dqn_MemArena *arena, Dqn_usize size DQN_DEBUG_ARGS); -Dqn_b32 Dqn_MemArena_Reserve(Dqn_MemArena *arena, Dqn_usize size DQN_DEBUG_ARGS); -// @ ------------------------------------------------------------------------------------------------- -// @ -// @ NOTE: Dqn_Allocator -// @ -// @ ------------------------------------------------------------------------------------------------- -DQN_HEADER_COPY_PROTOTYPE(Dqn_Allocator, Dqn_Allocator_NullAllocator()) -{ - Dqn_Allocator result = {}; - result.type = Dqn_Allocator_Type::NullAllocator; - return result; -} - -DQN_HEADER_COPY_PROTOTYPE(Dqn_Allocator, Dqn_Allocator_HeapAllocator()) -{ - Dqn_Allocator result = {}; - result.type = Dqn_Allocator_Type::Heap; - return result; -} - -DQN_HEADER_COPY_PROTOTYPE(Dqn_Allocator, Dqn_Allocator_XHeapAllocator()) -{ - Dqn_Allocator result = {}; - result.type = Dqn_Allocator_Type::XHeap; - return result; -} - -DQN_HEADER_COPY_PROTOTYPE(Dqn_Allocator, Dqn_Allocator_ArenaAllocator(Dqn_MemArena *arena)) -{ - Dqn_Allocator result = {}; - result.type = Dqn_Allocator_Type::Arena; - result.data = arena; - return result; -} - DQN_HEADER_COPY_PROTOTYPE(void *, Dqn_Allocator_Allocate(Dqn_Allocator *allocator, Dqn_usize size)) { void *result = nullptr; @@ -1446,6 +1445,7 @@ DQN_HEADER_COPY_PROTOTYPE(void *, Dqn_Allocator_Allocate(Dqn_Allocator *allocato return result; } +Dqn_b32 Dqn_MemArena_Reserve(Dqn_MemArena *arena, Dqn_usize size DQN_DEBUG_ARGS); DQN_HEADER_COPY_PROTOTYPE(void *, Dqn_Allocator_Realloc(Dqn_Allocator *allocator, void *old_ptr, Dqn_isize old_size, Dqn_isize new_size)) { void *result = nullptr; @@ -1922,7 +1922,6 @@ DQN_HEADER_COPY_PROTOTYPE(Dqn_b32, Dqn_Bit_IsNotSet(Dqn_u32 flags, Dqn_u32 bitfi return result; } - // @ ------------------------------------------------------------------------------------------------- // @ // @ NOTE: Safe Arithmetic diff --git a/Code/build.sh b/Code/build.sh new file mode 100755 index 0000000..1023be7 --- /dev/null +++ b/Code/build.sh @@ -0,0 +1,4 @@ +mkdir -p ../Bin/ +pushd ../Bin/ +g++ ../Code/Dqn_UnitTests.cpp -std=c++17 -o Dqn_UnitTests +g++ ../Code/DqnHeader.h -D DQN_HEADER_IMPLEMENTATION -std=c++17 -o DqnHeader