diff options
author | dec05eba <dec05eba@protonmail.com> | 2019-04-22 02:34:30 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2020-07-25 14:36:46 +0200 |
commit | a76ba1b33e397638c4209dd77e6073e423ac07a8 (patch) | |
tree | 0ef62209546ba91d53a2fabb54f3b8ac9dcfafdf /src/std | |
parent | 6a9466da5377d0bc73c7e5aa48deca3740d3de6f (diff) |
Start on bytecode. Commit before os switch
Diffstat (limited to 'src/std')
-rw-r--r-- | src/std/buffer.c | 16 | ||||
-rw-r--r-- | src/std/hash_map.c | 4 | ||||
-rw-r--r-- | src/std/log.c | 2 | ||||
-rw-r--r-- | src/std/scoped_allocator.c | 4 |
4 files changed, 18 insertions, 8 deletions
diff --git a/src/std/buffer.c b/src/std/buffer.c index 8e23a30..5fb4b05 100644 --- a/src/std/buffer.c +++ b/src/std/buffer.c @@ -40,13 +40,23 @@ static CHECK_RESULT int buffer_ensure_capacity(Buffer *self, usize new_capacity) } int buffer_append(Buffer *self, const void *data, usize size) { + assert(data); return_if_error(buffer_ensure_capacity(self, self->size + size)); - if(data) - am_memcpy(self->data + self->size, data, size); + am_memcpy(self->data + self->size, data, size); self->size += size; return BUFFER_OK; } +int buffer_append_empty(Buffer *self, usize size) { + return_if_error(buffer_ensure_capacity(self, self->size + size)); + self->size += size; + return BUFFER_OK; +} + +int buffer_expand(Buffer *self, usize size) { + return buffer_ensure_capacity(self, self->size + size); +} + void* buffer_get(Buffer *self, usize index, usize type_size) { usize real_index; real_index = index * type_size; @@ -66,7 +76,7 @@ void buffer_clear(Buffer *self) { self->size = 0; } -void* buffer_start(Buffer *self) { +void* buffer_begin(Buffer *self) { return self->data; } diff --git a/src/std/hash_map.c b/src/std/hash_map.c index d9914e7..d13bf3d 100644 --- a/src/std/hash_map.c +++ b/src/std/hash_map.c @@ -84,7 +84,7 @@ int hash_map_init(HashMap *self, ScopedAllocator *allocator, usize value_type_si self->hash_func = hash_func; return_if_error(buffer_init(&self->buckets, self->allocator)); assert(self->buckets.size == 0); - return_if_error(buffer_append(&self->buckets, NULL, sizeof(HashMapBucket) * HASH_MAP_INITIAL_SIZE)); + return_if_error(buffer_append_empty(&self->buckets, sizeof(HashMapBucket) * HASH_MAP_INITIAL_SIZE)); am_memset(self->buckets.data, 0, self->buckets.size); return 0; } @@ -150,7 +150,7 @@ static CHECK_RESULT int hash_map_increase_buckets(HashMap *self) { usize bytes_to_append; prev_num_elements = buffer_get_size(&self->buckets, HashMapBucket); bytes_to_append = (usize)(prev_num_elements * 1.5) * sizeof(HashMapBucket); - return_if_error(buffer_append(&self->buckets, NULL, bytes_to_append)); + return_if_error(buffer_append_empty(&self->buckets, bytes_to_append)); am_memset(((HashMapBucket*)self->buckets.data) + prev_num_elements, 0, bytes_to_append); hash_map_reorder_nodes(self, prev_num_elements); return 0; diff --git a/src/std/log.c b/src/std/log.c index a03e62f..88ff0cf 100644 --- a/src/std/log.c +++ b/src/std/log.c @@ -72,4 +72,4 @@ void amal_log_warning(const char *fmt, ...) { va_end(args); fprintf(stderr, "\n"); ignore_result_int(amal_mutex_unlock(&mutex)); -}
\ No newline at end of file +} diff --git a/src/std/scoped_allocator.c b/src/std/scoped_allocator.c index 3104fd3..8b161a1 100644 --- a/src/std/scoped_allocator.c +++ b/src/std/scoped_allocator.c @@ -41,7 +41,7 @@ static void buffer_deinit(Buffer *self) { static void scoped_allocator_deinit_buffers(ScopedAllocator *self) { Buffer **buffer; Buffer **buffers_end; - buffer = buffer_start(&self->buffers); + buffer = buffer_begin(&self->buffers); buffers_end = buffer_end(&self->buffers); while(buffer != buffers_end) { buffer_deinit(*buffer); @@ -53,7 +53,7 @@ static void scoped_allocator_deinit_buffers(ScopedAllocator *self) { static void scoped_allocator_deinit_mutexes(ScopedAllocator *self) { amal_mutex **mutex; amal_mutex **mutexes_end; - mutex = buffer_start(&self->mutexes); + mutex = buffer_begin(&self->mutexes); mutexes_end = buffer_end(&self->mutexes); while(mutex != mutexes_end) { amal_mutex_deinit(*mutex); |