2021-07-08 11:24:24 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include "memory.h"
|
|
|
|
#include "value.h"
|
|
|
|
|
2021-08-25 10:08:14 +02:00
|
|
|
void initValueArray(ValueArray *array) {
|
2021-07-08 11:24:24 +02:00
|
|
|
array->values = NULL;
|
|
|
|
array->capacity = 0;
|
|
|
|
array->count = 0;
|
|
|
|
}
|
|
|
|
|
2021-08-25 10:08:14 +02:00
|
|
|
void writeValueArray(ValueArray *array, Value value) {
|
2021-07-08 11:24:24 +02:00
|
|
|
if (array->capacity < array->count + 1) {
|
|
|
|
int oldCapacity = array->capacity;
|
|
|
|
array->capacity = GROW_CAPACITY(oldCapacity);
|
2021-08-25 10:08:14 +02:00
|
|
|
array->values =
|
|
|
|
GROW_ARRAY(Value, array->values, oldCapacity, array->capacity);
|
2021-07-08 11:24:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
array->values[array->count] = value;
|
|
|
|
array->count++;
|
|
|
|
}
|
|
|
|
|
2021-08-25 10:08:14 +02:00
|
|
|
void freeValueArray(ValueArray *array) {
|
2021-07-08 11:24:24 +02:00
|
|
|
FREE_ARRAY(Value, array->values, array->capacity);
|
|
|
|
initValueArray(array);
|
|
|
|
}
|
|
|
|
|
2021-08-25 10:08:14 +02:00
|
|
|
void printValue(Value value) { printf("%g", AS_NUMBER(value)); }
|