summaryrefslogtreecommitdiff
path: root/src/value.h
diff options
context:
space:
mode:
authorNathan Ringo <nathan@remexre.com>2024-11-27 20:28:40 -0600
committerNathan Ringo <nathan@remexre.com>2024-11-27 20:28:40 -0600
commitb252d0de46cf12b8e2521b3eb42da9acc41a4cc1 (patch)
tree456bfed5547745edacebe8c89194c26f03a25908 /src/value.h
parent62e41dcb40d0450d493a804e7f0ac3e32f35aabf (diff)
new simpler GC
Diffstat (limited to 'src/value.h')
-rw-r--r--src/value.h53
1 files changed, 50 insertions, 3 deletions
diff --git a/src/value.h b/src/value.h
index 3795486..1331d9d 100644
--- a/src/value.h
+++ b/src/value.h
@@ -1,9 +1,15 @@
#ifndef IMB3_VALUE_H
#define IMB3_VALUE_H
+#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
+/**
+ * Declared "for real" in gc.h.
+ */
+struct object;
+
struct value {
uintptr_t bits;
};
@@ -18,7 +24,7 @@ enum value_tag {
* Fixnums, i.e. integers that are stored directly in the value rather than
* being pointed to. This is a two-bit tag rather than a three-bit tag...
*/
- VALUE_FIXNUM = 0b01,
+ TAG_FIXNUM = 0b01,
/**
* A builtin-object.
@@ -34,13 +40,54 @@ enum value_tag {
* A standard-object, effectively a pair of a class and a slot array.
*/
TAG_STANDARD_OBJECT = 0b110,
+
+ /**
+ * An tag that is _invalid_ for values, but may be used by the internals of
+ * the garbage collector.
+ */
+ TAG_GC_INTERNAL = 0b111,
};
/**
+ * The nil constant.
+ */
+static const struct value NIL = {.bits = 0};
+
+/**
* Allocates a builtin-object with the given class and slot count.
*/
-struct value make_builtin_object(struct value class, size_t value_slot_count,
- size_t untraced_slot_count);
+struct value alloc_builtin_object(struct value class, size_t value_slot_count,
+ size_t untraced_slot_count);
+
+/**
+ * Stores an intptr_t as a fixnum or a bignum.
+ */
+struct value integer_of_int(intptr_t);
+
+/**
+ * Returns the tag of a value.
+ */
+enum value_tag get_tag(struct value);
+
+/**
+ * Returns whether a value is a pointer.
+ */
+bool is_ptr(struct value);
+
+/**
+ * Tags a pointer.
+ */
+struct value tag_ptr(struct object *, enum value_tag);
+
+/**
+ * Untags a fixnum.
+ */
+intptr_t untag_fixnum(struct value);
+
+/**
+ * Untags a pointer.
+ */
+struct object *untag_ptr(struct value);
/**
* Bootstraps the class heirarchy. This should only be called once.