Use sv_t instead of raw char*

We're storing them as sv_t's anyway, we're fucked with regards to
indirection.  Thus, let's be nice to ourselves, and deal with the
structures.  We get the size of the structure for free anyway!
This commit is contained in:
2025-08-20 21:50:58 +01:00
parent 643896e2c8
commit df558da7e1
4 changed files with 11 additions and 11 deletions

View File

@@ -78,7 +78,7 @@ typedef struct
u64 djb2(sv_t string);
void sym_table_init(sym_table_t *table);
char *sym_table_find(sym_table_t *table, sv_t sv);
sv_t *sym_table_find(sym_table_t *table, sv_t sv);
void sym_table_cleanup(sym_table_t *table);
/// Basic defintions for a Lisp
@@ -115,7 +115,7 @@ lisp_t *intern(sys_t *sys, sv_t sv);
lisp_t *cons(sys_t *sys, lisp_t *car, lisp_t *cdr);
i64 as_int(lisp_t *);
char *as_sym(lisp_t *);
sv_t *as_sym(lisp_t *);
cons_t *as_cons(lisp_t *);
void *as_vec(lisp_t *);
@@ -160,7 +160,7 @@ enum Mask
tag_t get_tag(lisp_t *lisp);
lisp_t *tag_int(i64 i);
lisp_t *tag_sym(char *str);
lisp_t *tag_sym(sv_t *sv);
lisp_t *tag_cons(cons_t *cons);
lisp_t *tag_vec(lvec_t *lvec);

View File

@@ -43,6 +43,6 @@ lisp_t *make_vec(sys_t *sys, u64 capacity)
lisp_t *intern(sys_t *sys, sv_t sv)
{
char *s = sym_table_find(&sys->symtable, sv);
return tag_sym(s);
sv_t *str = sym_table_find(&sys->symtable, sv);
return tag_sym(str);
}

View File

@@ -32,9 +32,9 @@ void sym_table_init(sym_table_t *table)
vec_make((void **)&table->entries, table->capacity * sizeof(*table->entries));
}
char *sym_table_find(sym_table_t *table, sv_t sv)
sv_t *sym_table_find(sym_table_t *table, sv_t sv)
{
// TODO: Deal with resizing this when table->count > table->size / 2
// WIP: Deal with resizing this when table->count > table->size / 2
u64 index = djb2(sv) & (table->capacity - 1);
for (sv_t comp = table->entries[index]; comp.data; index += 1,
@@ -51,7 +51,7 @@ char *sym_table_find(sym_table_t *table, sv_t sv)
++table->count;
}
return table->entries[index].data;
return table->entries + index;
}
void sym_table_cleanup(sym_table_t *table)

6
tag.c
View File

@@ -22,7 +22,7 @@ lisp_t *tag_int(i64 i)
return TAG((u64)i, INT);
}
lisp_t *tag_sym(char *str)
lisp_t *tag_sym(sv_t *str)
{
return TAG((u64)str, SYM);
}
@@ -57,10 +57,10 @@ i64 as_int(lisp_t *obj)
;
}
char *as_sym(lisp_t *obj)
sv_t *as_sym(lisp_t *obj)
{
assert(IS_TAG(obj, SYM));
return (char *)UNTAG(obj, SYM);
return (sv_t *)UNTAG(obj, SYM);
}
cons_t *as_cons(lisp_t *obj)