M include/lang/object.h => include/lang/object.h +1 -0
@@ 193,6 193,7 @@ bool obj_array_index(struct workspace *wk, obj arr, int64_t i, obj *res);
void obj_array_extend(struct workspace *wk, obj arr, obj arr2);
bool obj_array_dup(struct workspace *wk, obj arr, obj *res);
bool obj_array_join(struct workspace *wk, obj arr, obj join, obj *res);
+void obj_array_set(struct workspace *wk, obj arr, int64_t i, obj v);
typedef enum iteration_result (*obj_dict_iterator)(struct workspace *wk, void *ctx, obj key, obj val);
bool obj_dict_foreach(struct workspace *wk, obj dict, void *ctx, obj_dict_iterator cb);
M src/lang/object.c => src/lang/object.c +22 -0
@@ 360,6 360,28 @@ obj_array_join(struct workspace *wk, obj arr, obj join, obj *res)
return obj_array_foreach(wk, arr, &ctx, obj_array_join_iter);
}
+void
+obj_array_set(struct workspace *wk, obj arr, int64_t i, obj v)
+{
+ assert(get_obj(wk, arr)->type == obj_array);
+ assert(i >= 0 && i < get_obj(wk, arr)->dat.arr.len);
+
+ uint32_t j = 0;
+
+ while (true) {
+ if (j == i) {
+ get_obj(wk, arr)->dat.arr.val = v;
+ return;
+ }
+
+ assert(get_obj(wk, arr)->dat.arr.have_next);
+ arr = get_obj(wk, arr)->dat.arr.next;
+ ++j;
+ }
+
+ assert(false && "unreachable");
+}
+
/*
* dictionaries
*/