aboutsummaryrefslogtreecommitdiff
path: root/src/stdlib/lists.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/stdlib/lists.h')
-rw-r--r--src/stdlib/lists.h15
1 files changed, 9 insertions, 6 deletions
diff --git a/src/stdlib/lists.h b/src/stdlib/lists.h
index 457fed52..9ac8bf1b 100644
--- a/src/stdlib/lists.h
+++ b/src/stdlib/lists.h
@@ -20,8 +20,9 @@ extern char _EMPTY_LIST_SENTINEL;
int64_t index = index_expr; \
int64_t off = index + (index < 0) * (list.length + 1) - 1; \
if (unlikely(off < 0 || off >= list.length)) \
- fail_source(__SOURCE_FILE__, start, end, "Invalid list index: ", index, " (list has length ", \
- (int64_t)list.length, ")\n"); \
+ fail_source(__SOURCE_FILE__, start, end, \
+ Text$concat(Text("Invalid list index: "), convert_to_text(index), Text(" (list has length "), \
+ convert_to_text((int64_t)list.length), Text(")\n"))); \
*(item_type *)(list.data + list.stride * off); \
})
#define List_get(list_expr, index_expr, item_type, var, optional_expr, none_expr) \
@@ -40,8 +41,9 @@ extern char _EMPTY_LIST_SENTINEL;
int64_t index = index_expr; \
int64_t off = index + (index < 0) * (list->length + 1) - 1; \
if (unlikely(off < 0 || off >= list->length)) \
- fail_source(__SOURCE_FILE__, start, end, "Invalid list index: ", index, " (list has length ", \
- (int64_t)list->length, ")\n"); \
+ fail_source(__SOURCE_FILE__, start, end, \
+ Text$concat(Text("Invalid list index: "), convert_to_text(index), Text(" (list has length "), \
+ convert_to_text((int64_t)list->length), Text(")\n"))); \
if (list->data_refcount > 0) List$compact(list, sizeof(item_type)); \
(item_type *)(list->data + list->stride * off); \
})
@@ -61,7 +63,8 @@ extern char _EMPTY_LIST_SENTINEL;
t items[] = {__VA_ARGS__}; \
(List_t){.length = sizeof(items) / sizeof(items[0]), \
.stride = (int64_t)&items[1] - (int64_t)&items[0], \
- .data = memcpy(GC_MALLOC(sizeof(items)), items, sizeof(items)), \
+ .data = sizeof(items) == 0 ? &_EMPTY_LIST_SENTINEL \
+ : memcpy(GC_MALLOC(sizeof(items)), items, sizeof(items)), \
.atomic = 0, \
.data_refcount = 0}; \
})
@@ -70,7 +73,7 @@ extern char _EMPTY_LIST_SENTINEL;
t items[N] = {__VA_ARGS__}; \
(List_t){.length = N, \
.stride = (int64_t)&items[1] - (int64_t)&items[0], \
- .data = memcpy(GC_MALLOC(sizeof(items)), items, sizeof(items)), \
+ .data = N == 0 ? &_EMPTY_LIST_SENTINEL : memcpy(GC_MALLOC(sizeof(items)), items, sizeof(items)), \
.atomic = 0, \
.data_refcount = 0}; \
})