From 000e8ca43f4968412ed5c8fc514bb6caa3e5c450 Mon Sep 17 00:00:00 2001 From: ubq323 Date: Sun, 4 Aug 2024 13:05:47 +0100 Subject: new reader --- val.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'val.c') 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) { -- cgit v1.2.3