Fix array_lvalue
This commit is contained in:
parent
f5dc37c86c
commit
ed935eb882
@ -17,14 +17,14 @@
|
||||
if (__builtin_expect(off < 0 || off >= arr.length, 0)) \
|
||||
fail_source(filename, start, end, "Invalid array index: %r (array has length %ld)\n", Int$as_text(&index, USE_COLOR, NULL), arr.length); \
|
||||
(item_type*)(arr.data + arr.stride * off);})
|
||||
#define Array_lvalue(item_type, arr_expr, index_expr, typeinfo, filename, start, end) { \
|
||||
#define Array_lvalue(item_type, arr_expr, index_expr, typeinfo, filename, start, end) *({ \
|
||||
array_t *arr = arr_expr; int64_t index = (int64_t)(index_expr); \
|
||||
int64_t off = index + (index < 0) * (arr->length + 1) - 1; \
|
||||
if (__builtin_expect(off < 0 || off >= arr->length, 0)) \
|
||||
fail_source(filename, start, end, "Invalid array index: %r (array has length %ld)\n", Int$as_text(&index, USE_COLOR, NULL), arr->length); \
|
||||
if (arr->data_refcount > 0) \
|
||||
Array$compact(arr, typeinfo); \
|
||||
*(item_type*)(arr->data + arr->stride * off); }
|
||||
(item_type*)(arr->data + arr->stride * off); })
|
||||
#define Array_set(item_type, arr, index, value, typeinfo, filename, start, end) \
|
||||
Array_lvalue(item_type, arr_expr, index, typeinfo, filename, start, end) = value
|
||||
#define Array_get_unchecked(type, x, i) *({ const array_t arr = x; int64_t index = (int64_t)(i); \
|
||||
|
@ -71,6 +71,7 @@ func main():
|
||||
= [10, 20]
|
||||
|
||||
>> arr[1] = 999
|
||||
>> arr
|
||||
= @[999, 20, 30]
|
||||
|
||||
do:
|
||||
|
Loading…
Reference in New Issue
Block a user