diff options
author | dec05eba <dec05eba@protonmail.com> | 2019-02-24 20:01:58 +0100 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2020-07-25 14:36:46 +0200 |
commit | e0544300fb7da9a660a55eaf25f1996af573cd43 (patch) | |
tree | d6e375f78f10a0c9ad16d984aa218234a5d078e1 /include | |
parent | 204a1cc2b01ed3f18cb3e33bd6aa756d1f99dda8 (diff) |
Separate buffers from general allocation, but still have them in scoped allocator
Diffstat (limited to 'include')
-rw-r--r-- | include/ast.h | 1 | ||||
-rw-r--r-- | include/buffer.h | 8 | ||||
-rw-r--r-- | include/scoped_allocator.h | 8 |
3 files changed, 12 insertions, 5 deletions
diff --git a/include/ast.h b/include/ast.h index ef06257..f3580c0 100644 --- a/include/ast.h +++ b/include/ast.h @@ -4,6 +4,7 @@ #include "buffer_view.h" #include "buffer.h" #include "misc.h" +#include "scoped_allocator.h" typedef struct FunctionDecl FunctionDecl; typedef struct FunctionCall FunctionCall; diff --git a/include/buffer.h b/include/buffer.h index 700ae7b..e0c4046 100644 --- a/include/buffer.h +++ b/include/buffer.h @@ -1,19 +1,21 @@ #ifndef AMALGAM_BUFFER_H #define AMALGAM_BUFFER_H -#include "scoped_allocator.h" +#include "types.h" +#include "misc.h" #define BUFFER_OK 0 #define BUFFER_ALLOC_FAIL -1 typedef struct { - ScopedAllocator *allocator; + struct ScopedAllocator *allocator; char* data; usize size; usize capacity; } Buffer; -CHECK_RESULT int buffer_init(Buffer *self, ScopedAllocator *allocator, usize initial_capacity); +CHECK_RESULT int buffer_init(Buffer *self, struct ScopedAllocator *allocator); +void buffer_deinit(Buffer *self); CHECK_RESULT int buffer_append(Buffer *self, void *data, usize size); void* buffer_get(Buffer *self, usize index, usize type_size); diff --git a/include/scoped_allocator.h b/include/scoped_allocator.h index 1193439..fdaee2a 100644 --- a/include/scoped_allocator.h +++ b/include/scoped_allocator.h @@ -3,8 +3,10 @@ #include "misc.h" #include "types.h" +#include "buffer.h" typedef struct ScopedAllocatorNode ScopedAllocatorNode; +typedef struct ScopedAllocator ScopedAllocator; struct ScopedAllocatorNode { char *data; @@ -12,10 +14,11 @@ struct ScopedAllocatorNode { ScopedAllocatorNode *next; }; -typedef struct { +struct ScopedAllocator { ScopedAllocatorNode head; ScopedAllocatorNode *current; -} ScopedAllocator; + Buffer buffers; +}; CHECK_RESULT int scoped_allocator_node_init(ScopedAllocatorNode *self); void scoped_allocator_node_deinit(ScopedAllocatorNode *self); @@ -23,5 +26,6 @@ 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_buffer(ScopedAllocator *self, Buffer *buffer); #endif
\ No newline at end of file |