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.
This commit is contained in:
2025-08-19 23:20:19 +01:00
parent 7ac2a80b11
commit 779c4b8305
2 changed files with 54 additions and 7 deletions

22
tag.c
View File

@@ -13,6 +13,7 @@
*/
#include <assert.h>
#include <stdlib.h>
#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;
}