about summary refs log tree commit diff
path: root/std
diff options
context:
space:
mode:
authorBaitinq <[email protected]>2025-05-30 23:59:51 +0200
committerBaitinq <[email protected]>2025-05-30 23:59:51 +0200
commit415caeda7c3e27c300c88b413252fe766f020f95 (patch)
tree13454af4170dfbcc44031bb49b49ef9c7b1b5fbb /std
parentFeature: Support recursive structs (diff)
downloadinterpreter-415caeda7c3e27c300c88b413252fe766f020f95.tar.gz
interpreter-415caeda7c3e27c300c88b413252fe766f020f95.tar.bz2
interpreter-415caeda7c3e27c300c88b413252fe766f020f95.zip
std: Add arena impl
Diffstat (limited to 'std')
-rw-r--r--std/mem.src32
1 files changed, 32 insertions, 0 deletions
diff --git a/std/mem.src b/std/mem.src
new file mode 100644
index 0000000..02ca775
--- /dev/null
+++ b/std/mem.src
@@ -0,0 +1,32 @@
+extern malloc = (i64) => *void;
+extern realloc = (*void, i64) => *void;
+extern free = (*void) => void;
+
+import "!stdlib.src";
+
+let arena = struct {
+	buf: *void,
+	offset: i64,
+};
+
+let arena_init = (size: i64) => *arena {
+	let a = cast(*arena, malloc(sizeof(arena)));
+	(*a).buf = malloc(size);
+	(*a).offset = 0;
+	return a;
+};
+
+let arena_free = (a: *arena) => void {
+	free((*a).buf);
+	free(cast(*void, a));
+	return;
+};
+
+let arena_alloc = (a: *arena, size: i64) => *void {
+	if ((*a).offset + size > 10000000) {
+		println("LOOOOOOOOOOOOOOOOOOOL!");
+	};
+	let old_offset = (*a).offset;
+	(*a).offset = (*a).offset + size;
+	return cast(*void, cast(*i8, (*a).buf) + cast(*i8, old_offset));
+};