summaryrefslogtreecommitdiff
path: root/val.c
diff options
context:
space:
mode:
authorubq323 <ubq323@ubq323.website>2024-08-17 21:29:40 +0100
committerubq323 <ubq323@ubq323.website>2024-08-17 21:29:52 +0100
commitfaba0abf74dcdab3a4957bd8f13afa3c4dd19950 (patch)
tree5dc4f0110ffe204e83fc9db94f52d0803416d25a /val.c
parentfc5fb73c08d563ae441f785276f1304da7538fea (diff)
add delete! and objarr_delete
Diffstat (limited to 'val.c')
-rw-r--r--val.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/val.c b/val.c
index ed375ac..3e8558f 100644
--- a/val.c
+++ b/val.c
@@ -98,6 +98,16 @@ void objarr_insert(State *S, ObjArr *arr, size_t ix, Val v) {
arr->d[ix] = v;
}
}
+void objarr_delete(State *S, ObjArr *arr, size_t ix) {
+ CHECK(ix < arr->len, "array index out of bounds");
+ if (ix < arr->len - 1) {
+ size_t nix = ix+1;
+ size_t n = arr->len - nix;
+ memmove(&arr->d[ix], &arr->d[ix+1], n*sizeof(Val));
+ }
+ arr->len --;
+}
+
static void print_val_h(Val v, int depth);
void print_val(Val v) {