From 059ee9afcc575572f87f224c93288e2835cd1a52 Mon Sep 17 00:00:00 2001 From: kartofen Date: Thu, 24 Jul 2025 23:43:25 +0300 Subject: actually parsing grammar and generating a def.c file --- util/arena.h | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'util/arena.h') diff --git a/util/arena.h b/util/arena.h index 3d82b95..1142321 100644 --- a/util/arena.h +++ b/util/arena.h @@ -9,18 +9,26 @@ struct arena_ctx { size_t offset; }; + #define ARENA_CTX_INIT(buffer, sz) (struct arena_ctx){(buffer), (sz), 0} void *arena_allocate(struct arena_ctx *ctx, size_t sz); void arena_reset(struct arena_ctx *ctx); #ifdef ARENA_IMPLEMENTATION +#define ARENA_ALLIGNMENT 2 +// #include void *arena_allocate(struct arena_ctx *ctx, size_t sz) { + if(sz % ARENA_ALLIGNMENT != 0) + sz += ARENA_ALLIGNMENT - (sz % ARENA_ALLIGNMENT); + if(ctx->offset + sz > ctx->size) return NULL; - void *off = ctx->buffer + ctx->offset; + void *off = (void *)((intptr_t)ctx->buffer + ctx->offset); ctx->offset += sz; + + // assert(((intptr_t)off & 0x1) == 0); return off; } -- cgit v1.2.3