From ff4ea60daf8a97d07a5b0419c05441d7312a1901 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Sun, 4 Aug 2024 14:22:58 -0400 Subject: Tweaks to array implementation, including changing how the bits are allocated, making more explicit checks for refcounts and max values, optimizations for certain methods, and adding compile-time errors for arrays that hold items that are too large. --- compile.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'compile.c') diff --git a/compile.c b/compile.c index 3891f66e..1692d12b 100644 --- a/compile.c +++ b/compile.c @@ -1633,12 +1633,15 @@ CORD compile(env_t *env, ast_t *ast) "})"); } case Array: { + type_t *array_type = get_type(env, ast); + if (padded_type_size(Match(array_type, ArrayType)->item_type) > ARRAY_MAX_STRIDE) + code_err(ast, "This array holds items that take up %ld bytes, but the maximum supported size is %ld bytes. Consider using an array of pointers instead.", + padded_type_size(Match(array_type, ArrayType)->item_type), ARRAY_MAX_STRIDE); + auto array = Match(ast, Array); if (!array->items) return "(array_t){.length=0}"; - type_t *array_type = get_type(env, ast); - int64_t n = 0; for (ast_list_t *item = array->items; item; item = item->next) { ++n; -- cgit v1.2.3