From 34357640c0676f33ad13aac1fe28effc6f6e47c7 Mon Sep 17 00:00:00 2001 From: kartofen Date: Sun, 20 Jul 2025 01:32:24 +0300 Subject: start of grammar parsing --- util/arena.h | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 util/arena.h (limited to 'util') diff --git a/util/arena.h b/util/arena.h new file mode 100644 index 0000000..3d82b95 --- /dev/null +++ b/util/arena.h @@ -0,0 +1,30 @@ +#ifndef ARENA_H +#define ARENA_H + +#include // size_t + +struct arena_ctx { + void *buffer; + size_t size; + 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 + +void *arena_allocate(struct arena_ctx *ctx, size_t sz) +{ + if(ctx->offset + sz > ctx->size) return NULL; + + void *off = ctx->buffer + ctx->offset; + ctx->offset += sz; + return off; +} + +void arena_reset(struct arena_ctx *ctx) { ctx->offset = 0; } + +#endif +#endif -- cgit v1.2.3