diff --git a/alisp.h b/alisp.h index e552aff..78a0377 100644 --- a/alisp.h +++ b/alisp.h @@ -76,8 +76,8 @@ typedef struct Vector static_assert(sizeof(vec_t) == 64, "vec_t has to be 64 bytes as part of SBO"); -#define VEC_GET(V, T) ((T *)vec_data(V)) -#define VEC_SIZE(V, T) ((V)->size / (sizeof(T))) +#define VEC_GET(V, I, T) (((T *)vec_data(V))[I]) +#define VEC_SIZE(V, T) ((V)->size / (sizeof(T))) void vec_init(vec_t *, u64); void vec_free(vec_t *); diff --git a/runtime/symtable.c b/runtime/symtable.c index 60462d5..9331e6c 100644 --- a/runtime/symtable.c +++ b/runtime/symtable.c @@ -41,22 +41,22 @@ char *sym_table_find(sym_table_t *table, sv_t sv) // TODO: Deal with resizing this when table->count > table->size / 2 u64 index = djb2(sv) & (table->capacity - 1); - for (sv_t comp = VEC_GET(&table->entries, sv_t)[index]; comp.data; index += 1, + for (sv_t comp = VEC_GET(&table->entries, index, sv_t); comp.data; index += 1, index = index & (table->capacity - 1), - comp = VEC_GET(&table->entries, sv_t)[index]) + comp = VEC_GET(&table->entries, index, sv_t)) // Is it present in the table? if (sv.size == comp.size && strncmp(sv.data, comp.data, sv.size) == 0) break; // we couldn't find it in our linear search (worst case scenario) - if (!VEC_GET(&table->entries, sv_t)[index].data) + if (!VEC_GET(&table->entries, index, sv_t).data) { sv_t newsv = sv_copy(sv); - VEC_GET(&table->entries, sv_t)[index] = newsv; + VEC_GET(&table->entries, index, sv_t) = newsv; ++table->count; } - return VEC_GET(&table->entries, sv_t)[index].data; + return VEC_GET(&table->entries, index, sv_t).data; } void sym_table_cleanup(sym_table_t *table) @@ -65,7 +65,7 @@ void sym_table_cleanup(sym_table_t *table) sv_t current = {0}; for (u64 i = 0; i < table->capacity; ++i) { - current = VEC_GET(&table->entries, sv_t)[i]; + current = VEC_GET(&table->entries, i, sv_t); if (current.data) free(current.data); } diff --git a/runtime/sys.c b/runtime/sys.c index 689a28e..bd7148d 100644 --- a/runtime/sys.c +++ b/runtime/sys.c @@ -40,7 +40,7 @@ void sys_cleanup(sys_t *sys) // Iterate through each cons currently allocated and free them for (size_t i = 0; i < VEC_SIZE(&sys->conses, lisp_t **); ++i) { - lisp_t *allocated = VEC_GET(&sys->conses, lisp_t *)[i]; + lisp_t *allocated = VEC_GET(&sys->conses, i, lisp_t *); switch (get_tag(allocated)) { case TAG_CONS: