Skip to content

Commit

Permalink
vector: rewrite to use new lone value functions
Browse files Browse the repository at this point in the history
This will make the code automatically adapt
to any changes in the lone value representation.
  • Loading branch information
matheusmoreira committed Dec 24, 2024
1 parent 751f711 commit 8cfad17
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions source/lone/lisp/value/vector.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ struct lone_lisp_value lone_lisp_vector_create(struct lone_lisp *lone, size_t ca

size_t lone_lisp_vector_count(struct lone_lisp_value vector)
{
return vector.as.heap_value->as.vector.count;
return lone_lisp_value_to_heap_value(vector)->as.vector.count;
}

void lone_lisp_vector_resize(struct lone_lisp *lone, struct lone_lisp_value vector, size_t new_capacity)
{
struct lone_lisp_vector *actual = &vector.as.heap_value->as.vector;
struct lone_lisp_vector *actual = &lone_lisp_value_to_heap_value(vector)->as.vector;

actual->capacity = new_capacity;
actual->values = lone_memory_array(lone->system, actual->values, actual->capacity, sizeof(*actual->values));
Expand All @@ -44,7 +44,7 @@ struct lone_lisp_value lone_lisp_vector_get_value_at(struct lone_lisp_value vect
{
struct lone_lisp_vector *actual;

actual = &vector.as.heap_value->as.vector;
actual = &lone_lisp_value_to_heap_value(vector)->as.vector;

if (lone_memory_array_is_bounded(i, actual->capacity, sizeof(*actual->values))) {
return actual->values[i];
Expand All @@ -65,7 +65,7 @@ void lone_lisp_vector_set_value_at(struct lone_lisp *lone, struct lone_lisp_valu
{
struct lone_lisp_vector *actual;

actual = &vector.as.heap_value->as.vector;
actual = &lone_lisp_value_to_heap_value(vector)->as.vector;

if (!lone_memory_array_is_bounded(i, actual->capacity, sizeof(*actual->values))) {
lone_lisp_vector_resize(lone, vector, 2 * (i + 1));
Expand Down

0 comments on commit 8cfad17

Please sign in to comment.