"FOREIGN BLOCK",
"ZERO VALUE",
-
+
"AST_NODE_KIND_COUNT",
};
"|>", "..", "->",
"[]", "[]=", "^[]",
-
+
"??"
};
return TYPE_MATCH_SUCCESS;
}
}
-
+
// String literals implicitly become c-strings for convience.
if (node->kind == Ast_Kind_StrLit
&& type->kind == Type_Kind_MultiPointer
return TYPE_MATCH_SUCCESS;
}
-
+
if (match == TYPE_MATCH_YIELD) return TYPE_MATCH_YIELD;
}
return get_expression_integer_value(((AstEnumValue *) node)->value, is_valid);
}
+ if (node->kind == Ast_Kind_Unary_Op && type_is_integer(node->type)) {
+ return get_expression_integer_value(((AstUnaryOp *) node)->expr, is_valid);
+ }
+
if (node_is_type((AstNode*) node)) {
Type* type = type_build_from_ast(context.ast_alloc, (AstType *) node);
if (type) return type->id;
*pnode = (AstTyped *) cmp;
return TYPE_MATCH_SUCCESS;
}
-
+
if (context.caches.implicit_cast_to_bool_cache.entries == NULL) {
bh_imap_init(&context.caches.implicit_cast_to_bool_cache, global_heap_allocator, 8);
}
if (!bh_imap_has(&context.caches.implicit_cast_to_bool_cache, (u64) node)) {
AstArgument *implicit_arg = make_argument(context.ast_alloc, node);
-
+
Arguments *args = bh_alloc_item(context.ast_alloc, Arguments);
bh_arr_new(context.ast_alloc, args->values, 1);
bh_arr_push(args->values, (AstTyped *) implicit_arg);
bh_imap_put(&context.caches.implicit_cast_to_bool_cache, (u64) node, (u64) args);
}
-
+
Arguments *args = (Arguments *) bh_imap_get(&context.caches.implicit_cast_to_bool_cache, (u64) node);
AstFunction *overload = (AstFunction *) find_matching_overload_by_arguments(builtin_implicit_bool_cast->overloads, args);
if (overload == NULL) return TYPE_MATCH_FAILED;
if (overload == (AstFunction *) &node_that_signals_a_yield) return TYPE_MATCH_YIELD;
-
+
AstCall *implicit_call = onyx_ast_node_new(context.ast_alloc, sizeof(AstCall), Ast_Kind_Call);
implicit_call->token = node->token;
implicit_call->callee = (AstTyped *) overload;
return NULL;
}
- count = get_expression_integer_value(a_node->count_expr, NULL);
+ b32 valid = 0;
+ count = get_expression_integer_value(a_node->count_expr, &valid);
+
+ if (!valid) {
+ onyx_report_error(a_node->token->pos, Error_Critical, "Array type size expression must be 'i32', got '%s'.",
+ type_get_name(a_node->count_expr->type));
+ return NULL;
+ }
+
+ if ((i32)count < 0) {
+ onyx_report_error(a_node->token->pos, Error_Critical, "Array type size must be a positive integer.");
+ return NULL;
+ }
}
Type* array_type = type_make_array(alloc, elem_type, count);
build_linear_types_with_offset(type->Compound.types[i], pdest, offset + elem_offset);
elem_offset += bh_max(type_size_of(type->Compound.types[i]), 4);
}
-
+
} else if (type->kind == Type_Kind_Slice || type->kind == Type_Kind_VarArgs || type->kind == Type_Kind_Function) {
u32 mem_count = type_structlike_mem_count(type);
StructMember smem = { 0 };
--- /dev/null
+#load "core/module"
+
+use core { * }
+
+An_Enum :: enum {
+ A;
+ B;
+ C;
+ D;
+
+ Count;
+}
+
+A_Struct :: struct {
+ a: i32;
+ b: i32;
+ c: i32;
+}
+
+main :: () {
+ arr1: [cast(i32)(3 * 4 - 5)]f32;
+ arr2: [cast(i32)An_Enum.Count]A_Struct;
+
+ assert(arr1.count == (3 * 4 - 5), "invalid count for arr1");
+ assert(sizeof(typeof(arr1)) == (3 * 4 - 5) * sizeof(f32), "invalid size for arr1");
+
+ assert(arr2.count == ~~An_Enum.Count, "invalid count for arr2");
+ assert(sizeof(typeof(arr2)) == ~~An_Enum.Count * sizeof(A_Struct), "invalid size for arr2");
+}