diff options
Diffstat (limited to 'src/lib/memory.c')
| -rw-r--r-- | src/lib/memory.c | 71 |
1 files changed, 34 insertions, 37 deletions
diff --git a/src/lib/memory.c b/src/lib/memory.c index a348b93..24d3d68 100644 --- a/src/lib/memory.c +++ b/src/lib/memory.c @@ -1,24 +1,21 @@ #include "aplwc_internal.h" -struct memory -memory_init(uint8_t *data , size_t size) +void +memory_init(struct aplwc *aplwc, uint8_t *data , size_t size) { - struct memory mem; - - mem.data = data; - mem.size = size; - mem.offset = 0; - return mem; + aplwc->data = data; + aplwc->size = size; + aplwc->offset = 0; } static void * -alloc(struct memory *m, size_t size, size_t align) +alloc(struct aplwc *aplwc, size_t size, size_t align) { uintptr_t ptr; size_t alloc_size, adjust; void *p; - ptr = ((uintptr_t)m->data) + m->offset; + ptr = ((uintptr_t)aplwc->data) + aplwc->offset; alloc_size = size; if(NEVER(align == 0)) @@ -28,10 +25,10 @@ alloc(struct memory *m, size_t size, size_t align) if(adjust) alloc_size += align - adjust; - if((m->size - m->offset) >= alloc_size){ - p = m->data+m->offset+alloc_size-size; + if((aplwc->size - aplwc->offset) >= alloc_size){ + p = aplwc->data+aplwc->offset+alloc_size-size; assert((((uintptr_t)p) % align) == 0); - m->offset += alloc_size; + aplwc->offset += alloc_size; memset(p, 0, size); }else p = NULL; @@ -40,97 +37,97 @@ alloc(struct memory *m, size_t size, size_t align) } struct aplwc * -memory_alloc_aplwc(struct memory *m) +memory_alloc_aplwc(struct aplwc *aplwc) { struct aplwc *p; - p = alloc(m, sizeof(struct aplwc), alignof(struct aplwc)); + p = alloc(aplwc, sizeof(struct aplwc), alignof(struct aplwc)); return p; } void -memory_free_aplwc(struct memory *m, struct aplwc *p) +memory_free_aplwc(struct aplwc *aplwc, struct aplwc *p) { - UNUSED_PARAMETER(m); + UNUSED_PARAMETER(aplwc); UNUSED_PARAMETER(p); } struct aplwc_line * -memory_alloc_aplwc_line(struct memory *m) +memory_alloc_aplwc_line(struct aplwc *aplwc) { struct aplwc_line *p; - p = alloc(m, sizeof(struct aplwc_line), alignof(struct aplwc_line)); + p = alloc(aplwc, sizeof(struct aplwc_line), alignof(struct aplwc_line)); return p; } void -memory_free_aplwc_line(struct memory *m, struct aplwc_line *p) +memory_free_aplwc_line(struct aplwc *aplwc, struct aplwc_line *p) { - UNUSED_PARAMETER(m); + UNUSED_PARAMETER(aplwc); UNUSED_PARAMETER(p); } struct string * -memory_alloc_string(struct memory *m, size_t bytes) +memory_alloc_string(struct aplwc *aplwc, size_t bytes) { struct string *p; - p = alloc(m, sizeof(struct string) + bytes, alignof(struct string)); + p = alloc(aplwc, sizeof(struct string) + bytes, alignof(struct string)); return p; } void -memory_free_string(struct memory *m, struct string *p) +memory_free_string(struct aplwc *aplwc, struct string *p) { - UNUSED_PARAMETER(m); + UNUSED_PARAMETER(aplwc); UNUSED_PARAMETER(p); } struct token_list * -memory_alloc_token_list(struct memory *m, size_t tokens) +memory_alloc_token_list(struct aplwc *aplwc, size_t tokens) { struct token_list *p; - p = alloc(m, sizeof(struct token_list) + (tokens * sizeof(struct token)), alignof(struct token_list)); + p = alloc(aplwc, sizeof(struct token_list) + (tokens * sizeof(struct token)), alignof(struct token_list)); return p; } void -memory_free_token_list(struct memory *m, struct token_list *p) +memory_free_token_list(struct aplwc *aplwc, struct token_list *p) { - UNUSED_PARAMETER(m); + UNUSED_PARAMETER(aplwc); UNUSED_PARAMETER(p); } struct aplwc_value * -memory_alloc_aplwc_value(struct memory *m) +memory_alloc_aplwc_value(struct aplwc *aplwc) { struct aplwc_value *p; - p = alloc(m, sizeof(struct aplwc_value), alignof(struct aplwc_value)); + p = alloc(aplwc, sizeof(struct aplwc_value), alignof(struct aplwc_value)); return p; } void -memory_free_aplwc_value(struct memory *m, struct aplwc_value *p) +memory_free_aplwc_value(struct aplwc *aplwc, struct aplwc_value *p) { - UNUSED_PARAMETER(m); + UNUSED_PARAMETER(aplwc); UNUSED_PARAMETER(p); } struct aplwc_module * -memory_alloc_aplwc_module(struct memory *m) +memory_alloc_aplwc_module(struct aplwc *aplwc) { struct aplwc_module *p; - p = alloc(m, sizeof(struct aplwc_module), alignof(struct aplwc_module)); + p = alloc(aplwc, sizeof(struct aplwc_module), alignof(struct aplwc_module)); return p; } void -memory_free_aplwc_module(struct memory *m, struct aplwc_module *p) +memory_free_aplwc_module(struct aplwc *aplwc, struct aplwc_module *p) { - UNUSED_PARAMETER(m); + UNUSED_PARAMETER(aplwc); UNUSED_PARAMETER(p); } |