From b7f056a73ad4053eb2284c54873dfb3888dcb430 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Wed, 22 Jan 2020 19:14:06 +0100 Subject: Correctly parse and produce bytecode for example --- src/std/buffer.c | 6 ++++++ src/std/hash_map.c | 9 +++++---- 2 files changed, 11 insertions(+), 4 deletions(-) (limited to 'src/std') diff --git a/src/std/buffer.c b/src/std/buffer.c index e311c8f..dd7d0f6 100644 --- a/src/std/buffer.c +++ b/src/std/buffer.c @@ -2,6 +2,7 @@ #include #include #include +#include void tsl_buffer_init(TslBuffer *self) { self->data = NULL; @@ -44,6 +45,11 @@ int tsl_buffer_append(TslBuffer *self, const void *data, size_t size) { return 1; } +void tsl_buffer_pop(TslBuffer *self, size_t size) { + assert(self->size >= size); + self->size -= size; +} + void* tsl_buffer_begin(TslBuffer *self) { return self->data; } diff --git a/src/std/hash_map.c b/src/std/hash_map.c index 968a5ea..7ba1daf 100644 --- a/src/std/hash_map.c +++ b/src/std/hash_map.c @@ -43,10 +43,6 @@ void tsl_hash_map_deinit(TslHashMap *self) { /* TODO: Remove if (data) and if (output) */ static int tsl_hash_map_append_bucket(TslHashMapNode **head_node, uint64_t hash, const TslStringView *key, size_t size, const void *data, void **output) { TslHashMapNode *next_node; - /* - TODO: Instead of allocating space for the data, allow the user to pass a pointer in the insert - method and use that directly. - */ uint8_t *node_data = malloc(sizeof(hash) + sizeof(key->size) + key->size + sizeof(size) + size); if(output) *output = node_data; @@ -65,8 +61,13 @@ static int tsl_hash_map_append_bucket(TslHashMapNode **head_node, uint64_t hash, } memcpy(node_data, &hash, sizeof(hash)); + /* TODO: Instead of allocating space for the key, use the key data pointer and size directly. */ memcpy(node_data + sizeof(hash), &key->size, sizeof(key->size)); memcpy(node_data + sizeof(hash) + sizeof(key->size), key->data, key->size); + /* + TODO: Instead of allocating space for the data, allow the user to pass a pointer in the insert + method and use that directly. + */ memcpy(node_data + sizeof(hash) + sizeof(key->size) + key->size, &size, sizeof(size)); if(data) memcpy(node_data + sizeof(hash) + sizeof(key->size) + key->size + sizeof(size), data, size); -- cgit v1.2.3