summaryrefslogtreecommitdiff
path: root/prism/arena.h
diff options
context:
space:
mode:
Diffstat (limited to 'prism/arena.h')
-rw-r--r--prism/arena.h37
1 files changed, 37 insertions, 0 deletions
diff --git a/prism/arena.h b/prism/arena.h
new file mode 100644
index 0000000000..e1fa8fc6ad
--- /dev/null
+++ b/prism/arena.h
@@ -0,0 +1,37 @@
+/**
+ * @file arena.h
+ *
+ * A bump allocator for the prism parser.
+ */
+#ifndef PRISM_ARENA_H
+#define PRISM_ARENA_H
+
+#include "prism/compiler/exported.h"
+#include "prism/compiler/nodiscard.h"
+#include "prism/compiler/nonnull.h"
+
+#include <stddef.h>
+
+/**
+ * An opaque pointer to an arena that is used for allocations.
+ */
+typedef struct pm_arena_t pm_arena_t;
+
+/**
+ * Returns a newly allocated and initialized arena. If the arena cannot be
+ * allocated, this function aborts the process.
+ *
+ * @returns A pointer to the newly allocated arena. It is the responsibility of
+ * the caller to free the arena using pm_arena_free when it is no longer
+ * needed.
+ */
+PRISM_EXPORTED_FUNCTION PRISM_NODISCARD pm_arena_t * pm_arena_new(void);
+
+/**
+ * Frees both the held memory and the arena itself.
+ *
+ * @param arena The arena to free.
+ */
+PRISM_EXPORTED_FUNCTION void pm_arena_free(pm_arena_t *arena) PRISM_NONNULL(1);
+
+#endif