progress on base

This commit is contained in:
2025-02-01 20:42:40 -05:00
parent 708fed034b
commit 73fe526501
14 changed files with 313 additions and 70 deletions
+1 -1
View File
@@ -12,4 +12,4 @@ MD_NS_BEGIN
#include "base/memory.h"
#include "base/zpl_memory.h"
MD_NS_END
MD_NS_END
+5 -6
View File
@@ -1,7 +1,6 @@
#ifdef MD_INTELLISENSE_DIRECTIVES
#pragma once
#include "base_types.h"
#include
#include "strings.h"
#endif
@@ -14,12 +13,12 @@
typedef struct CmdLineOpt CmdLineOpt;
struct CmdLineOpt
{
CmdLineOpt *next;
CmdLineOpt *hash_next;
U64 hash;
String8 string;
CmdLineOpt* next;
CmdLineOpt* hash_next;
U64 hash;
String8 string;
String8List value_strings;
String8 value_string;
String8 value_string;
};
typedef struct CmdLineOptList CmdLineOptList;
-22
View File
@@ -1,22 +0,0 @@
#if MD_INTELLISENSE_DIRECTIVES
#pragma once
#include "arch.h"
#include "os.h"
#include "compiler.h"
#endif
#pragma region Mandatory Includes
# include <stdarg.h>
# include <stddef.h>
# if defined( MD_SYSTEM_WINDOWS )
# include <intrin.h>
# endif
#if MD_COMPILER_C
#include <assert.h>
#include <stdbool.h>
#endif
#pragma endregion Mandatory Includes
+1 -19
View File
@@ -1,6 +1,6 @@
#if MD_INTELLISENSE_DIRECTIVES
#pragma once
#include "cstd.h"
#include "platform.h"
#endif
#ifndef MD_API
@@ -143,21 +143,3 @@
#endif
#endif
#endif
#if MD_DONT_USE_NAMESPACE || MD_COMPILER_C
# if MD_COMPILER_C
# define MD_NS
# define MD_NS_BEGIN
# define MD_NS_END
# else
# define MD_NS ::
# define MD_NS_BEGIN
# define MD_NS_END
# endif
#else
namespace MD {}
namespace md = MD;
# define MD_NS MD::
# define MD_NS_BEGIN namespace MD {
# define MD_NS_END }
#endif
+1 -1
View File
@@ -1,6 +1,6 @@
#if MD_INTELLISENSE_DIRECTIVES
#pragma once
#include "base/base_types.h"
#include "base_types.h"
#endif
typedef union Rng1U64 Rng1U64;
+209 -12
View File
@@ -1,5 +1,6 @@
#ifdef MD_INTELLISENSE_DIRECTIVES
#pragma once
#include "cracking_arch.h"
#include "macros.h"
#endif
@@ -64,20 +65,216 @@
#define memory_compare(a, b, size) memcmp((a), (b), (size))
#define memory_str_len(ptr) cstr_len(ptr)
#define memory_copy_struct(d,s) memory_copy((d),(s),sizeof(*(d)))
#define memory_copy_array(d,s) memory_copy((d),(s),sizeof(d))
#define memory_copy_type(d,s,c) memory_copy((d),(s),sizeof(*(d))*(c))
#define memory_copy_struct(d,s) memory_copy((d), (s), sizeof( *(d)))
#define memory_copy_array(d,s) memory_copy((d), (s), sizeof( d))
#define memory_copy_type(d,s,c) memory_copy((d), (s), sizeof( *(d)) * (c))
#define memory_zero(s,z) mem_set((s),0,(z))
#define memory_zero_struct(s) memory_zero((s),sizeof(*(s)))
#define memory_zero_array(a) memroy_zero((a),sizeof(a))
#define memory_zero_type(m,c) memroy_zero((m),sizeof(*(m))*(c))
#define memory_zero(s,z) mem_set((s), 0, (z))
#define memory_zero_struct(s) memory_zero((s), sizeof( *(s)))
#define memory_zero_array(a) memroy_zero((a), sizeof(a))
#define memory_zero_type(m,c) memroy_zero((m), sizeof( *(m)) * (c))
#define memory_match(a,b,z) (memory_compare((a),(b),(z)) == 0)
#define memory_match_struct(a,b) memory_match((a),(b),sizeof(*(a)))
#define memory_match_array(a,b) memory_match((a),(b),sizeof(a))
#define memory_match(a,b,z) (memory_compare((a), (b), (z)) == 0)
#define memory_match_struct(a,b) memory_match((a), (b), sizeof(*(a)))
#define memory_match_array(a,b) memory_match((a), (b), sizeof(a))
#define memory_read(T,p,e) ( ((p)+sizeof(T)<=(e))?(*(T*)(p)):(0) )
#define memory_consume(T,p,e) ( ((p)+sizeof(T)<=(e))?((p)+=sizeof(T),*(T*)((p)-sizeof(T))):((p)=(e),0) )
#define memory_read(T,p,e) ( ((p) + sizeof(T) <= (e)) ? ( *(T*)(p)) : (0) )
#define memory_consume(T,p,e) ( ((p) + sizeof(T) <= (e)) ? ((p) += sizeof(T), *(T*)((p) - sizeof(T))) : ((p) = (e),0) )
////////////////////////////////
//~ rjf: Asserts
#if MD_COMPILER_MSVC
# define trap() __debugbreak()
#elif MD_COMPILER_CLANG || COMPILER_GCC
# define trap() __builtin_trap()
#else
# error Unknown trap intrinsic for this compiler.
#endif
#define assert_always(x) do { if ( !(x) ) { trap(); } } while(0)
#if BUILD_DEBUG
# define assert(x) assert_always(x)
#else
# define assert(x) (void)(x)
#endif
#define InvalidPath assert( ! "Invalid Path!")
#define NotImplemented assert( ! "Not Implemented!")
#define no_op ((void)0)
#define md_static_assert(C, ID) global U8 glue(ID, __LINE__)[ (C) ? 1 : -1 ]
////////////////////////////////
//~ rjf: Atomic Operations
#if MD_OS_WINDOWS
// # include <windows.h>
// # include <tmmintrin.h>
// # include <wmmintrin.h>
// # include <intrin.h>
# if MD_ARCH_X64
# define ins_atomic_u64_eval(x) InterlockedAdd64((volatile __int64 *)(x), 0)
# define ins_atomic_u64_inc_eval(x) InterlockedIncrement64((volatile __int64 *)(x))
# define ins_atomic_u64_dec_eval(x) InterlockedDecrement64((volatile __int64 *)(x))
# define ins_atomic_u64_eval_assign(x,c) InterlockedExchange64((volatile __int64 *)(x), (c))
# define ins_atomic_u64_add_eval(x,c) InterlockedAdd64((volatile __int64 *)(x), c)
# define ins_atomic_u64_eval_cond_assign(x,k,c) InterlockedCompareExchange64((volatile __int64 *)(x), (k), (c))
# define ins_atomic_u32_eval(x,c) InterlockedAdd((volatile LONG *)(x), 0)
# define ins_atomic_u32_eval_assign(x,c) InterlockedExchange((volatile LONG *)(x), (c))
# define ins_atomic_u32_eval_cond_assign(x,k,c) InterlockedCompareExchange((volatile LONG *)(x), (k), (c))
# define ins_atomic_ptr_eval_assign(x,c) (void*) ins_atomic_u64_eval_assign((volatile __int64 *)(x), (__int64)(c))
# else
# error Atomic intrinsics not defined for this operating system / architecture combination.
# endif
#elif MD_OS_LINUX
# if MD_ARCH_X64
# define ins_atomic_u64_inc_eval(x) __sync_fetch_and_add((volatile U64 *)(x), 1)
# else
# error Atomic intrinsics not defined for this operating system / architecture combination.
# endif
#else
# error Atomic intrinsics not defined for this operating system.
#endif
////////////////////////////////
//~ rjf: Linked List Building Macros
//- rjf: linked list macro helpers
#define Check``Nil(nil,p) ((p) == 0 || (p) == nil)
#define SetNil(nil,p) ((p) = nil)
//- rjf: doubly-linked-lists
#define DLLInsert_NPZ(nil,f,l,p,n,next,prev) (CheckNil(nil,f) ? \
((f) = (l) = (n), SetNil(nil,(n)->next), SetNil(nil,(n)->prev)) :\
CheckNil(nil,p) ? \
((n)->next = (f), (f)->prev = (n), (f) = (n), SetNil(nil,(n)->prev)) :\
((p)==(l)) ? \
((l)->next = (n), (n)->prev = (l), (l) = (n), SetNil(nil, (n)->next)) :\
(((!CheckNil(nil,p) && CheckNil(nil,(p)->next)) ? (0) : ((p)->next->prev = (n))), ((n)->next = (p)->next), ((p)->next = (n)), ((n)->prev = (p))))
#define DLLPushBack_NPZ(nil,f,l,n,next,prev) DLLInsert_NPZ(nil,f,l,l,n,next,prev)
#define DLLPushFront_NPZ(nil,f,l,n,next,prev) DLLInsert_NPZ(nil,l,f,f,n,prev,next)
#define DLLRemove_NPZ(nil,f,l,n,next,prev) (((n) == (f) ? (f) = (n)->next : (0)),\
((n) == (l) ? (l) = (l)->prev : (0)),\
(CheckNil(nil,(n)->prev) ? (0) :\
((n)->prev->next = (n)->next)),\
(CheckNil(nil,(n)->next) ? (0) :\
((n)->next->prev = (n)->prev)))
//- rjf: singly-linked, doubly-headed lists (queues)
#define SLLQueuePush_NZ(nil,f,l,n,next) (CheckNil(nil,f)?\
((f)=(l)=(n),SetNil(nil,(n)->next)):\
((l)->next=(n),(l)=(n),SetNil(nil,(n)->next)))
#define SLLQueuePushFront_NZ(nil,f,l,n,next) (CheckNil(nil,f)?\
((f)=(l)=(n),SetNil(nil,(n)->next)):\
((n)->next=(f),(f)=(n)))
#define SLLQueuePop_NZ(nil,f,l,next) ((f)==(l)?\
(SetNil(nil,f),SetNil(nil,l)):\
((f)=(f)->next))
//- rjf: singly-linked, singly-headed lists (stacks)
#define sll_stack_push_n(f,n,next) ( (n)->next = (f), (f) = (n) )
#define sll_stack_pop_n(f,next) ( (f) = (f)->next )
//- rjf: doubly-linked-list helpers
#define dll_insert_np(f, l, p, n, next, prev) DLLInsert_NPZ (0, f, l, p, n, next, prev)
#define dll_push_back_np(f, l, n, next, prev) DLLPushBack_NPZ (0, f, l, n, next, prev)
#define dll_push_front_np(f, l, n, next, prev) DLLPushFront_NPZ(0, f, l, n, next, prev)
#define dll_remove_np(f, l, n, next, prev) DLLRemove_NPZ (0, f, l, n, next, prev)
#define dll_insert(f, l, p, n) DLLInsert_NPZ (0, f, l, p, n, next, prev)
#define dll_push_back(f, l, n) DLLPushBack_NPZ (0, f, l, n, next, prev)
#define dll_push_front(f, l, n) DLLPushFront_NPZ(0, f, l, n, next, prev)
#define dll_remove(f, l, n) DLLRemove_NPZ (0, f, l, n, next, prev)
//- rjf: singly-linked, doubly-headed list helpers
#define SLLQueuePush_N(f,l,n,next) SLLQueuePush_NZ(0,f,l,n,next)
#define SLLQueuePushFront_N(f,l,n,next) SLLQueuePushFront_NZ(0,f,l,n,next)
#define SLLQueuePop_N(f,l,next) SLLQueuePop_NZ(0,f,l,next)
#define SLLQueuePush(f,l,n) SLLQueuePush_NZ(0,f,l,n,next)
#define SLLQueuePushFront(f,l,n) SLLQueuePushFront_NZ(0,f,l,n,next)
#define SLLQueuePop(f,l) SLLQueuePop_NZ(0,f,l,next)
//- rjf: singly-linked, singly-headed list helpers
#define SLLStackPush(f,n) SLLStackPush_N(f,n,next)
#define SLLStackPop(f) SLLStackPop_N(f,next)
////////////////////////////////
//~ rjf: Address Sanitizer Markup
#if COMPILER_MSVC
# if defined(__SANITIZE_ADDRESS__)
# define ASAN_ENABLED 1
# define NO_ASAN __declspec(no_sanitize_address)
# else
# define NO_ASAN
# endif
#elif COMPILER_CLANG
# if defined(__has_feature)
# if __has_feature(address_sanitizer) || defined(__SANITIZE_ADDRESS__)
# define ASAN_ENABLED 1
# endif
# endif
# define NO_ASAN __attribute__((no_sanitize("address")))
#else
# define NO_ASAN
#endif
#if ASAN_ENABLED
#pragma comment(lib, "clang_rt.asan-x86_64.lib")
C_LINKAGE void __asan_poison_memory_region(void const volatile *addr, size_t size);
C_LINKAGE void __asan_unpoison_memory_region(void const volatile *addr, size_t size);
# define AsanPoisonMemoryRegion(addr, size) __asan_poison_memory_region((addr), (size))
# define AsanUnpoisonMemoryRegion(addr, size) __asan_unpoison_memory_region((addr), (size))
#else
# define AsanPoisonMemoryRegion(addr, size) ((void)(addr), (void)(size))
# define AsanUnpoisonMemoryRegion(addr, size) ((void)(addr), (void)(size))
#endif
////////////////////////////////
//~ rjf: Misc. Helper Macros
#define Stringify_(S) #S
#define Stringify(S) Stringify_(S)
#define Glue_(A,B) A##B
#define Glue(A,B) Glue_(A,B)
#define ArrayCount(a) (sizeof(a) / sizeof((a)[0]))
#define CeilIntegerDiv(a,b) (((a) + (b) - 1)/(b))
#define Swap(T,a,b) do{T t__ = a; a = b; b = t__;}while(0)
#if ARCH_64BIT
# define IntFromPtr(ptr) ((U64)(ptr))
#elif ARCH_32BIT
# define IntFromPtr(ptr) ((U32)(ptr))
#else
# error Missing pointer-to-integer cast for this architecture.
#endif
#define PtrFromInt(i) (void*)((U8*)0 + (i))
#define Compose64Bit(a,b) ((((U64)a) << 32) | ((U64)b));
#define AlignPow2(x,b) (((x) + (b) - 1)&(~((b) - 1)))
#define AlignDownPow2(x,b) ((x)&(~((b) - 1)))
#define AlignPadPow2(x,b) ((0-(x)) & ((b) - 1))
#define IsPow2(x) ((x)!=0 && ((x)&((x)-1))==0)
#define IsPow2OrZero(x) ((((x) - 1)&(x)) == 0)
#define ExtractBit(word, idx) (((word) >> (idx)) & 1)
#if LANG_CPP
# define zero_struct {}
#else
# define zero_struct {0}
#endif
#if COMPILER_MSVC && COMPILER_MSVC_YEAR < 2015
# define this_function_name "unknown"
#else
# define this_function_name __func__
#endif
+19
View File
@@ -0,0 +1,19 @@
// C++ namespace support
#if MD_DONT_USE_NAMESPACE || MD_COMPILER_C
# if MD_COMPILER_C
# define MD_NS
# define MD_NS_BEGIN
# define MD_NS_END
# else
# define MD_NS ::
# define MD_NS_BEGIN
# define MD_NS_END
# endif
#else
namespace MD {}
namespace md = MD;
# define MD_NS MD::
# define MD_NS_BEGIN namespace MD {
# define MD_NS_END }
#endif
+6
View File
@@ -0,0 +1,6 @@
#ifdef MD_INTELLISENSE_DIRECTIVES
#pragma once
#include "platform.h"
#endif
+22
View File
@@ -0,0 +1,22 @@
#if MD_INTELLISENSE_DIRECTIVES
#pragma once
#include "cracking_arch.h"
#include "cracking_os.h"
#include "cracking_compiler.h"
#endif
#pragma region Mandatory Includes
#include <stdarg.h>
#include <stddef.h>
#if defined( MD_SYSTEM_WINDOWS )
# include <intrin.h>
#endif
#if MD_COMPILER_C
# include <assert.h>
# include <stdbool.h>
#endif
#pragma endregion Mandatory Includes
+11 -9
View File
@@ -160,9 +160,9 @@ internal B32 char_is_lower(U8 c);
internal B32 char_is_alpha(U8 c);
internal B32 char_is_slash(U8 c);
internal B32 char_is_digit(U8 c, U32 base);
internal U8 char_to_lower(U8 c);
internal U8 char_to_upper(U8 c);
internal U8 char_to_correct_slash(U8 c);
internal U8 char_to_lower(U8 c);
internal U8 char_to_upper(U8 c);
internal U8 char_to_correct_slash(U8 c);
////////////////////////////////
//~ rjf: C-String Measurement
@@ -174,9 +174,9 @@ internal U64 cstring32_length(U32 *c);
////////////////////////////////
//~ rjf: String Constructors
#define str8_lit(S) str8((U8*)(S), sizeof(S) - 1)
#define str8_lit_comp(S) {(U8*)(S), sizeof(S) - 1,}
#define str8_varg(S) (int)((S).size), ((S).str)
#define str8_lit(S) str8((U8*)(S), sizeof(S) - 1)
#define str8_lit_comp(S) { (U8*)(S), sizeof(S) - 1, }
#define str8_varg(S) (int)((S).size), ((S).str)
#define str8_array(S,C) str8((U8*)(S), sizeof(*(S))*(C))
#define str8_array_fixed(S) str8((U8*)(S), sizeof(S))
@@ -367,8 +367,9 @@ internal void str8_serial_push_u16(Arena *arena, String8List *srl, U16 x);
internal void str8_serial_push_u8(Arena *arena, String8List *srl, U8 x);
internal void str8_serial_push_cstr(Arena *arena, String8List *srl, String8 str);
internal void str8_serial_push_string(Arena *arena, String8List *srl, String8 str);
#define str8_serial_push_array(arena, srl, ptr, count) str8_serial_push_data(arena, srl, ptr, sizeof(*(ptr)) * (count))
#define str8_serial_push_struct(arena, srl, ptr) str8_serial_push_array(arena, srl, ptr, 1)
#define str8_serial_push_struct(arena, srl, ptr) str8_serial_push_array(arena, srl, ptr, 1)
////////////////////////////////
//~ rjf: Deserialization Helpers
@@ -378,7 +379,8 @@ internal U64 str8_deserial_find_first_match(String8 string, U64 off, U16 scan
internal void * str8_deserial_get_raw_ptr(String8 string, U64 off, U64 size);internal U64 str8_deserial_read_cstr(String8 string, U64 off, String8 *cstr_out);
internal U64 str8_deserial_read_windows_utf16_string16(String8 string, U64 off, String16 *str_out);
internal U64 str8_deserial_read_block(String8 string, U64 off, U64 size, String8 *block_out);
#define str8_deserial_read_array(string, off, ptr, count) str8_deserial_read((string), (off), (ptr), sizeof(*(ptr))*(count), sizeof(*(ptr)))
#define str8_deserial_read_struct(string, off, ptr) str8_deserial_read((string), (off), (ptr), sizeof(*(ptr)), sizeof(*(ptr)))
#define str8_deserial_read_array(string, off, ptr, count) str8_deserial_read((string), (off), (ptr), sizeof(*(ptr)) * (count), sizeof( *(ptr)))
#define str8_deserial_read_struct(string, off, ptr) str8_deserial_read((string), (off), (ptr), sizeof(*(ptr)), sizeof( *(ptr)))
#endif // BASE_STRINGS_H
+38
View File
@@ -0,0 +1,38 @@
#ifdef MD_INTELLISENSE_DIRECTIVES
#pragma once
#endif
////////////////////////////////
//~ rjf: Toolchain/Environment Enums
typedef enum OperatingSystem
{
OperatingSystem_Null,
OperatingSystem_Windows,
OperatingSystem_Linux,
OperatingSystem_Mac,
OperatingSystem_COUNT,
}
OperatingSystem;
typedef enum Architecture
{
Architecture_Null,
Architecture_x64,
Architecture_x86,
Architecture_arm64,
Architecture_arm32,
Architecture_COUNT,
}
Architecture;
typedef enum Compiler
{
Compiler_Null,
Compiler_msvc,
Compiler_gcc,
Compiler_clang,
Compiler_COUNT,
}
Compiler;