From 1f28c3c733ea3ae4234bff91e1c55e61b1ee3e96 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Wed, 31 Jul 2019 01:25:05 +0200 Subject: Starting on asm, implementing extern function call so progress is visible --- include/std/arena_allocator.h | 29 +++++++++++++++++++++++++++++ include/std/buffer.h | 4 ++-- include/std/defs.h | 4 ++-- include/std/hash_map.h | 4 ++-- include/std/mem.h | 2 ++ include/std/misc.h | 2 +- include/std/scoped_allocator.h | 29 ----------------------------- 7 files changed, 38 insertions(+), 36 deletions(-) create mode 100644 include/std/arena_allocator.h delete mode 100644 include/std/scoped_allocator.h (limited to 'include/std') diff --git a/include/std/arena_allocator.h b/include/std/arena_allocator.h new file mode 100644 index 0000000..30147c8 --- /dev/null +++ b/include/std/arena_allocator.h @@ -0,0 +1,29 @@ +#ifndef AMALGAM_ARENA_ALLOCATOR_H +#define AMALGAM_ARENA_ALLOCATOR_H + +#include "defs.h" +#include "misc.h" +#include "types.h" +#include "buffer.h" + +struct ArenaAllocatorNode { + char *data; + usize size; + ArenaAllocatorNode *next; +}; + +struct ArenaAllocator { + ArenaAllocatorNode head; + ArenaAllocatorNode *current; + Buffer/**/ mems; +}; + +CHECK_RESULT int arena_allocator_node_init(ArenaAllocatorNode *self); +void arena_allocator_node_deinit(ArenaAllocatorNode *self); + +CHECK_RESULT int arena_allocator_init(ArenaAllocator *self); +void arena_allocator_deinit(ArenaAllocator *self); +CHECK_RESULT int arena_allocator_alloc(ArenaAllocator *self, usize size, void **mem); +CHECK_RESULT int arena_allocator_add_mem(ArenaAllocator *self, usize *result_index); + +#endif diff --git a/include/std/buffer.h b/include/std/buffer.h index 7a74d33..ac722b1 100644 --- a/include/std/buffer.h +++ b/include/std/buffer.h @@ -13,11 +13,11 @@ typedef struct { usize size; usize capacity; - ScopedAllocator *allocator; + ArenaAllocator *allocator; usize allocator_index; } Buffer; -CHECK_RESULT int buffer_init(Buffer *self, struct ScopedAllocator *allocator); +CHECK_RESULT int buffer_init(Buffer *self, struct ArenaAllocator *allocator); void buffer_deinit(Buffer *self); /* diff --git a/include/std/defs.h b/include/std/defs.h index ee049d4..8a63a69 100644 --- a/include/std/defs.h +++ b/include/std/defs.h @@ -4,7 +4,7 @@ typedef struct amal_thread amal_thread; typedef struct amal_mutex amal_mutex; -typedef struct ScopedAllocatorNode ScopedAllocatorNode; -typedef struct ScopedAllocator ScopedAllocator; +typedef struct ArenaAllocatorNode ArenaAllocatorNode; +typedef struct ArenaAllocator ArenaAllocator; #endif diff --git a/include/std/hash_map.h b/include/std/hash_map.h index 9b31213..b9b90c6 100644 --- a/include/std/hash_map.h +++ b/include/std/hash_map.h @@ -13,7 +13,7 @@ typedef int(*HashMapCompare)(const void *a, const void *b); typedef usize(*HashMapHash)(const u8 *data, usize size); struct HashMap { - ScopedAllocator *allocator; /* borrowed */ + ArenaAllocator *allocator; /* borrowed */ Buffer/*HashMapBucket*/ buckets; usize value_type_size; usize num_elements; @@ -21,7 +21,7 @@ struct HashMap { HashMapHash hash_func; }; -CHECK_RESULT int hash_map_init(HashMap *self, ScopedAllocator *allocator, usize value_type_size, HashMapCompare compare_func, HashMapHash hash_func); +CHECK_RESULT int hash_map_init(HashMap *self, ArenaAllocator *allocator, usize value_type_size, HashMapCompare compare_func, HashMapHash hash_func); /* Not thread-safe. Expected @value size to be @self->value_type_size. diff --git a/include/std/mem.h b/include/std/mem.h index ddd2b31..2afce0d 100644 --- a/include/std/mem.h +++ b/include/std/mem.h @@ -9,4 +9,6 @@ int am_memcmp(const void *lhs, const void *rhs, usize size); bool am_memeql(const void *lhs, const void *rhs, usize size); void am_memset(void *dest, int value, usize size); +long am_pagesize(); + #endif diff --git a/include/std/misc.h b/include/std/misc.h index b1932d5..2fbe92c 100644 --- a/include/std/misc.h +++ b/include/std/misc.h @@ -23,7 +23,7 @@ do { \ int return_if_result; \ return_if_result = (result); \ - if((return_if_result) != 0) { \ + if(return_if_result != 0) { \ return_if_debug_msg; \ return return_if_result; \ } \ diff --git a/include/std/scoped_allocator.h b/include/std/scoped_allocator.h deleted file mode 100644 index f037ea5..0000000 --- a/include/std/scoped_allocator.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef AMALGAM_SCOPED_ALLOCATOR_H -#define AMALGAM_SCOPED_ALLOCATOR_H - -#include "defs.h" -#include "misc.h" -#include "types.h" -#include "buffer.h" - -struct ScopedAllocatorNode { - char *data; - usize size; - ScopedAllocatorNode *next; -}; - -struct ScopedAllocator { - ScopedAllocatorNode head; - ScopedAllocatorNode *current; - Buffer/**/ mems; -}; - -CHECK_RESULT int scoped_allocator_node_init(ScopedAllocatorNode *self); -void scoped_allocator_node_deinit(ScopedAllocatorNode *self); - -CHECK_RESULT int scoped_allocator_init(ScopedAllocator *self); -void scoped_allocator_deinit(ScopedAllocator *self); -CHECK_RESULT int scoped_allocator_alloc(ScopedAllocator *self, usize size, void **mem); -CHECK_RESULT int scoped_allocator_add_mem(ScopedAllocator *self, usize *result_index); - -#endif -- cgit v1.2.3