diff options
author | dec05eba <dec05eba@protonmail.com> | 2019-08-17 02:57:08 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2020-07-25 14:36:46 +0200 |
commit | 81c5f8e750fcda6a2451fb54604130431434f88f (patch) | |
tree | 944fa06c781d57b1db90e9153080f411a1c34a55 /src/std | |
parent | 20662a1d203ffb9e05d6694347fd258115b41d0a (diff) |
Implement more instructions, implement function parameters and arguments
Diffstat (limited to 'src/std')
-rw-r--r-- | src/std/arena_allocator.c | 9 | ||||
-rw-r--r-- | src/std/buffer.c | 1 | ||||
-rw-r--r-- | src/std/buffer_view.c | 5 |
3 files changed, 10 insertions, 5 deletions
diff --git a/src/std/arena_allocator.c b/src/std/arena_allocator.c index 14787f1..73111dd 100644 --- a/src/std/arena_allocator.c +++ b/src/std/arena_allocator.c @@ -67,8 +67,7 @@ static CHECK_RESULT int arena_allocator_ensure_capacity_for(ArenaAllocator *self } static void* align_ptr_ceil(void *ptr, uintptr_t alignment) { - uintptr_t ptrval; - ptrval = (uintptr_t)ptr; + const uintptr_t ptrval = (uintptr_t)ptr; return (void*)((ptrval + alignment + 1) & ~(alignment - 1)); } @@ -76,7 +75,7 @@ static usize align_ptr_ceil_offset(void *ptr, uintptr_t alignment) { return (uintptr_t)align_ptr_ceil(ptr, alignment) - (uintptr_t)ptr; } -#define SCOPED_ALLOC_ALIGNMENT 8 +#define ALLOC_ALIGNMENT 8 int arena_allocator_alloc(ArenaAllocator *self, usize size, void **mem) { ArenaAllocatorNode *current; @@ -89,14 +88,14 @@ int arena_allocator_alloc(ArenaAllocator *self, usize size, void **mem) { return -1; } - alloc_size = size + align_ptr_ceil_offset(self->current->data + self->current->size, SCOPED_ALLOC_ALIGNMENT); + alloc_size = size + align_ptr_ceil_offset(self->current->data + self->current->size, ALLOC_ALIGNMENT); return_if_error(arena_allocator_ensure_capacity_for(self, alloc_size)); /* Reallocated (new node created) */ if(self->current != current) { *mem = self->current->data; self->current->size += size; } else { - *mem = align_ptr_ceil(self->current->data + self->current->size, SCOPED_ALLOC_ALIGNMENT); + *mem = align_ptr_ceil(self->current->data + self->current->size, ALLOC_ALIGNMENT); self->current->size += alloc_size; } return 0; diff --git a/src/std/buffer.c b/src/std/buffer.c index 0e4ca89..93e8558 100644 --- a/src/std/buffer.c +++ b/src/std/buffer.c @@ -48,6 +48,7 @@ static CHECK_RESULT int buffer_ensure_capacity(Buffer *self, usize new_capacity) self->data = new_mem; self->capacity = capacity; + /* Update list of buffers in the allocator with the new address of the buffer data */ if(self->allocator) am_memcpy(self->allocator->mems.data + sizeof(void*) * self->allocator_index, &self->data, sizeof(void*)); return BUFFER_OK; diff --git a/src/std/buffer_view.c b/src/std/buffer_view.c index 8ddfab9..f2d79c0 100644 --- a/src/std/buffer_view.c +++ b/src/std/buffer_view.c @@ -1,4 +1,5 @@ #include "../../include/std/buffer_view.h" +#include "../../include/std/mem.h" BufferView create_buffer_view_null() { BufferView buffer_view; @@ -13,3 +14,7 @@ BufferView create_buffer_view(const char *data, usize size) { buffer_view.size = size; return buffer_view; } + +bool buffer_view_equals(const BufferView *self, const BufferView *other) { + return self->size == other->size && am_memeql(self->data, other->data, self->size); +} |