#include "aplwc_internal.h" struct memory memory_init(uint8_t *data , size_t size) { struct memory mem; mem.data = data; mem.size = size; mem.offset = 0; return mem; } static void * alloc(struct memory *m, size_t size, size_t align) { uintptr_t ptr; size_t alloc_size, adjust; void *p; ptr = ((uintptr_t)m->data) + m->offset; alloc_size = size; if(NEVER(align == 0)) return NULL; adjust = ptr % align; if(adjust) alloc_size += align - adjust; if((m->size - m->offset) >= alloc_size){ p = m->data+m->offset+alloc_size-size; assert((((uintptr_t)p) % align) == 0); m->offset += alloc_size; memset(p, 0, size); }else p = NULL; return p; } struct aplwc * memory_alloc_aplwc(struct memory *m) { struct aplwc *p; p = alloc(m, sizeof(struct aplwc), alignof(struct aplwc)); return p; } void memory_free_aplwc(struct memory *m, struct aplwc *p) { UNUSED_PARAMETER(m); UNUSED_PARAMETER(p); } struct aplwc_line * memory_alloc_aplwc_line(struct memory *m) { struct aplwc_line *p; p = alloc(m, sizeof(struct aplwc_line), alignof(struct aplwc_line)); return p; } void memory_free_aplwc_line(struct memory *m, struct aplwc_line *p) { UNUSED_PARAMETER(m); UNUSED_PARAMETER(p); } struct string * memory_alloc_string(struct memory *m, size_t bytes) { struct string *p; p = alloc(m, sizeof(struct string) + bytes, alignof(struct string)); return p; } void memory_free_string(struct memory *m, struct string *p) { UNUSED_PARAMETER(m); UNUSED_PARAMETER(p); } struct token_list * memory_alloc_token_list(struct memory *m, size_t tokens) { struct token_list *p; p = alloc(m, 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) { UNUSED_PARAMETER(m); UNUSED_PARAMETER(p); }