From: Brendan Hansen Date: Wed, 29 Sep 2021 17:52:14 +0000 (-0500) Subject: added ".count" to array-typed things X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=8f7049a3ff23b15fb2faab80b4f71e6111e67560;p=onyx.git added ".count" to array-typed things --- diff --git a/bin/onyx b/bin/onyx index 98028881..a2196a34 100755 Binary files a/bin/onyx and b/bin/onyx differ diff --git a/src/checker.c b/src/checker.c index 80c03d49..2681a434 100644 --- a/src/checker.c +++ b/src/checker.c @@ -1402,6 +1402,13 @@ CheckStatus check_field_access(AstFieldAccess** pfield) { } if (!type_lookup_member(field->expr->type, field->field, &smem)) { + if (field->expr->type->kind == Type_Kind_Array) { + if (!strcmp(field->field, "count")) { + *pfield = (AstFieldAccess *) make_int_literal(context.ast_alloc, field->expr->type->Array.count); + return Check_Success; + } + } + AstType* type_node = field->expr->type->ast_type; AstNode* n = try_symbol_raw_resolve_from_node((AstNode *) type_node, field->field); if (n) { diff --git a/src/types.c b/src/types.c index 785e3232..175e826a 100644 --- a/src/types.c +++ b/src/types.c @@ -1210,6 +1210,7 @@ b32 type_is_array_accessible(Type* type) { b32 type_is_structlike(Type* type) { if (type == NULL) return 0; + if (type->kind == Type_Kind_Array) return 1; if (type->kind == Type_Kind_Struct) return 1; if (type->kind == Type_Kind_Slice) return 1; if (type->kind == Type_Kind_DynArray) return 1;