summaryrefslogtreecommitdiff
path: root/val.c
diff options
context:
space:
mode:
authorubq323 <ubq323@ubq323.website>2024-08-04 13:05:47 +0100
committerubq323 <ubq323@ubq323.website>2024-08-04 13:05:47 +0100
commit000e8ca43f4968412ed5c8fc514bb6caa3e5c450 (patch)
treee82eddb3cb54f75f8468e9a80a17e8b14857aa45 /val.c
parent1f257ac91ef3813c563203eacb5320b210fc1aa7 (diff)
new reader
Diffstat (limited to 'val.c')
-rw-r--r--val.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/val.c b/val.c
index 685c504..43e47d3 100644
--- a/val.c
+++ b/val.c
@@ -84,6 +84,20 @@ void objarr_put(State *S, ObjArr *arr, size_t ix, Val v) {
arr->d[ix] = v;
}
}
+void objarr_insert(State *S, ObjArr *arr, size_t ix, Val v) {
+ CHECK(ix <= arr->len, "array index out of bounds");
+ if (ix == arr->len) {
+ objarr_append(S, arr, v);
+ } else {
+ if (arr->len == arr->cap) {
+ size_t newsz = (arr->cap == 0 ? 8 : arr->cap * 2);
+ arr->d = RENEW_ARR(S, arr->d, Val, arr->cap, newsz);
+ arr->cap = newsz;
+ }
+ memmove(&arr->d[ix+1], &arr->d[ix], (arr->len-ix)*sizeof(Val));
+ arr->d[ix] = v;
+ }
+}
static void print_val_h(Val v, int depth);
void print_val(Val v) {