adjustments to parse_from_text_tokens

This commit is contained in:
2025-02-08 18:08:27 -05:00
parent 2ef486b7a0
commit 843cc7fa90
6 changed files with 124 additions and 90 deletions
+12 -1
View File
@@ -452,9 +452,11 @@ dll__insert_npz(
) \
) \
)
// ! MD_LINKED_LIST_PURE_MACRO
#endif
// dll_insert_npz
#endif
#endif
#ifndef dll_push_back_npz
// push-back next-previous with nil
#define dll_push_back_npz(nil, f, l, n, next, prev) dll_insert_npz(nil, f, l, l, n, next, prev)
@@ -517,7 +519,9 @@ dll__remove_npz(
: ((n)->next->prev = (n)->prev) \
) \
)
// ! MD_LINKED_LIST_PURE_MACRO
#endif
// dll_remove_npz
#endif
//- rjf: singly-linked, doubly-headed lists (queues)
@@ -558,7 +562,9 @@ sll__queue_push_nz(
set_nil(nil,(n)->next) \
) \
)
// ! MD_LINKED_LIST_PURE_MACRO
#endif
// sll_queue_push_nz
#endif
#ifndef sll_queue_push_front_nz
@@ -589,6 +595,8 @@ sll__queue_push_front_nz(void* nil, void** f, void** l, void* n, void** n_next)
(f) = (n) \
) \
)
// ! MD_LINKED_LIST_PURE_MACRO
#endif
#endif
#ifndef sll_queue_pop_nz
@@ -618,6 +626,9 @@ sll__queue_pop_nz(void* nil, void** f, void* f_next, void** l)
(f)=(f)->next \
) \
)
// ! MD_LINKED_LIST_PURE_MACRO
#endif
// sll_queue_pop_nz
#endif
//- rjf: singly-linked, singly-headed lists (stacks)
+18 -9
View File
@@ -17,25 +17,29 @@ struct _heap_stats
global _heap_stats _heap_stats_info;
void heap_stats_init( void )
void
heap_stats_init( void )
{
memory_zero_struct( &_heap_stats_info );
_heap_stats_info.magic = GEN_HEAP_STATS_MAGIC;
}
SSIZE heap_stats_used_memory( void )
SSIZE
heap_stats_used_memory( void )
{
assert_msg( _heap_stats_info.magic == GEN_HEAP_STATS_MAGIC, "heap_stats is not initialised yet, call heap_stats_init first!" );
return _heap_stats_info.used_memory;
}
SSIZE heap_stats_alloc_count( void )
SSIZE
heap_stats_alloc_count( void )
{
assert_msg( _heap_stats_info.magic == GEN_HEAP_STATS_MAGIC, "heap_stats is not initialised yet, call heap_stats_init first!" );
return _heap_stats_info.alloc_count;
}
void heap_stats_check( void )
void
heap_stats_check( void )
{
assert_msg( _heap_stats_info.magic == GEN_HEAP_STATS_MAGIC, "heap_stats is not initialised yet, call heap_stats_init first!" );
assert( _heap_stats_info.used_memory == 0 );
@@ -50,7 +54,8 @@ struct _heap_alloc_info
};
#endif
void* heap_allocator_proc( void* allocator_data, AllocatorMode mode, SSIZE size, SSIZE alignment, void* old_memory, SSIZE old_size, U64 flags )
void*
heap_allocator_proc( void* allocator_data, AllocatorMode mode, SSIZE size, SSIZE alignment, void* old_memory, SSIZE old_size, U64 flags )
{
void* ptr = nullptr;
// unused( allocator_data );
@@ -184,7 +189,8 @@ void* heap_allocator_proc( void* allocator_data, AllocatorMode mode, SSIZE size,
return ptr;
}
VArena varena__alloc(VArenaParams params)
VArena
varena__alloc(VArenaParams params)
{
if (params.reserve_size == 0) {
params.reserve_size = VARENA_DEFAULT_RESERVE;
@@ -238,13 +244,15 @@ VArena varena__alloc(VArenaParams params)
vm->flags = params.flags;
}
void varena_release(VArena* arena)
void
varena_release(VArena* arena)
{
os_release(arena, arena->reserve);
arena = nullptr;
}
void* varena_allocator_proc(void* allocator_data, AllocatorMode mode, SSIZE requested_size, SSIZE alignment, void* old_memory, SSIZE old_size, U64 flags)
void*
varena_allocator_proc(void* allocator_data, AllocatorMode mode, SSIZE requested_size, SSIZE alignment, void* old_memory, SSIZE old_size, U64 flags)
{
OS_SystemInfo const* info = os_get_system_info();
@@ -372,7 +380,8 @@ void* varena_allocator_proc(void* allocator_data, AllocatorMode mode, SSIZE requ
return allocated_mem;
}
void* farena_allocator_proc(void* allocator_data, AllocatorMode mode, SSIZE size, SSIZE alignment, void* old_memory, SSIZE old_size, U64 flags)
void*
farena_allocator_proc(void* allocator_data, AllocatorMode mode, SSIZE size, SSIZE alignment, void* old_memory, SSIZE old_size, U64 flags)
{
FArena* arena = rcast(FArena*, allocator_data);
+19 -18
View File
@@ -106,6 +106,7 @@ void* resize_align( AllocatorInfo a, void* ptr, SSIZE old_size, SSIZE new_size,
#ifndef alloc_array
// Allocate memory for an array of items.
#define alloc_array( allocator_, Type, count ) (Type*)memory_zero(alloc( allocator_, size_of(Type) * (count) ), size_of(Type) * (count))
// Allocate memory for an array of items. (Don't zero initialize)
#define alloc_array_no_zero( allocator_, Type, count ) (Type*) alloc( allocator_, size_of(Type) * (count) )
#endif
@@ -221,40 +222,40 @@ MD_API void* farena_allocator_proc(void* allocator_data, AllocatorMode mode, SSI
// Inlines
inline
AllocatorType allocator_type(AllocatorInfo a) {
inline AllocatorType
allocator_type(AllocatorInfo a) {
if (a.proc == nullptr) {
a = default_allocator();
}
return (AllocatorType) a.proc(a.data, AllocatorMode_QueryType, 0, 0, nullptr, 0, MD_DEFAULT_ALLOCATOR_FLAGS);
}
inline
AllocatorQueryFlags allocator_query_support(AllocatorInfo a) {
inline AllocatorQueryFlags
allocator_query_support(AllocatorInfo a) {
if (a.proc == nullptr) {
a = default_allocator();
}
return (AllocatorType) a.proc(a.data, AllocatorMode_QuerySupport, 0, 0, nullptr, 0, MD_DEFAULT_ALLOCATOR_FLAGS);
}
inline
void* alloc_align( AllocatorInfo a, SSIZE size, SSIZE alignment ) {
inline void*
alloc_align( AllocatorInfo a, SSIZE size, SSIZE alignment ) {
if (a.proc == nullptr) {
a = default_allocator();
}
return a.proc( a.data, AllocatorMode_Alloc, size, alignment, nullptr, 0, MD_DEFAULT_ALLOCATOR_FLAGS );
}
inline
void* alloc( AllocatorInfo a, SSIZE size ) {
inline void*
alloc( AllocatorInfo a, SSIZE size ) {
if (a.proc == nullptr) {
a = default_allocator();
}
return alloc_align( a, size, MD_DEFAULT_MEMORY_ALIGNMENT );
}
inline
void alloc_free( AllocatorInfo a, void* ptr ) {
inline void
alloc_free( AllocatorInfo a, void* ptr ) {
if (a.proc == nullptr) {
a = default_allocator();
}
@@ -263,32 +264,32 @@ void alloc_free( AllocatorInfo a, void* ptr ) {
}
}
inline
void free_all( AllocatorInfo a ) {
inline void
free_all( AllocatorInfo a ) {
if (a.proc == nullptr) {
a = default_allocator();
}
a.proc( a.data, AllocatorMode_FreeAll, 0, 0, nullptr, 0, MD_DEFAULT_ALLOCATOR_FLAGS );
}
inline
void* resize( AllocatorInfo a, void* ptr, SSIZE old_size, SSIZE new_size ) {
inline void*
resize( AllocatorInfo a, void* ptr, SSIZE old_size, SSIZE new_size ) {
if (a.proc == nullptr) {
a = default_allocator();
}
return resize_align( a, ptr, old_size, new_size, MD_DEFAULT_ALLOCATOR_FLAGS );
}
inline
void* resize_align( AllocatorInfo a, void* ptr, SSIZE old_size, SSIZE new_size, SSIZE alignment ) {
inline void*
resize_align( AllocatorInfo a, void* ptr, SSIZE old_size, SSIZE new_size, SSIZE alignment ) {
if (a.proc == nullptr) {
a = default_allocator();
}
return a.proc( a.data, AllocatorMode_Resize, new_size, alignment, ptr, old_size, MD_DEFAULT_ALLOCATOR_FLAGS );
}
inline
void* default_resize_align( AllocatorInfo a, void* old_memory, SSIZE old_size, SSIZE new_size, SSIZE alignment )
inline void*
default_resize_align( AllocatorInfo a, void* old_memory, SSIZE old_size, SSIZE new_size, SSIZE alignment )
{
if ( ! old_memory )
return alloc_align( a, new_size, alignment );