From 779c4b83055756a574f58e4097849a8acd6d5a32 Mon Sep 17 00:00:00 2001 From: Aryadev Chavali Date: Tue, 19 Aug 2025 23:20:19 +0100 Subject: Conses and Vectors for my tagging scheme Unfortunately, due to how vectors are implemented, pointers to them are unstable. We need to box them one more time (therefore adding a level of indirection) in order to stabilise them. This is annoying but currently necessary. Even if we implemented vectors as {u64, u64, ptr} instead of {u64, u64, bytes...}, we'd still have the same problem at access - two levels of indirection. I guess size and capacity checks would be one level of indirection which is nice at least, but we're already screwed at the point of doing lookup either way. --- tag.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'tag.c') diff --git a/tag.c b/tag.c index 7688d63..dbc47ba 100644 --- a/tag.c +++ b/tag.c @@ -13,6 +13,7 @@ */ #include +#include #include "./base.h" @@ -26,6 +27,11 @@ lisp_t *tag_sym(char *str) return TAG((u64)str, SYM); } +lisp_t *tag_cons(cons_t *cons) +{ + return TAG((u64)cons, CONS); +} + i64 as_int(lisp_t *obj) { assert(IS_TAG(obj, INT)); @@ -40,3 +46,19 @@ char *as_sym(lisp_t *obj) assert(IS_TAG(obj, SYM)); return (char *)UNTAG(obj, SYM); } + +cons_t *as_cons(lisp_t *obj) +{ + assert(IS_TAG(obj, CONS)); + return (cons_t *)UNTAG(obj, CONS); +} + +void *as_vec(lisp_t *obj) +{ + assert(IS_TAG(obj, VEC)); + lvec_t *vec = (lvec_t *)UNTAG(obj, VEC); + if (vec) + return vec->data; + else + return NULL; +} -- cgit v1.2.3-13-gbd6f