diff options
Diffstat (limited to 'val.c')
-rw-r--r-- | val.c | 14 |
1 files changed, 14 insertions, 0 deletions
@@ -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) { |