mirror of
https://github.com/odin-lang/Odin.git
synced 2026-04-19 13:00:28 +00:00
Add intrinsics type_fixed_capacity_dynamic_array_len_offset and type_is_fixed_capacity_dynamic_array
This commit is contained in:
@@ -180,6 +180,7 @@ type_is_bit_set :: proc($T: typeid) -> bool ---
|
||||
type_is_bit_field :: proc($T: typeid) -> bool ---
|
||||
type_is_simd_vector :: proc($T: typeid) -> bool ---
|
||||
type_is_matrix :: proc($T: typeid) -> bool ---
|
||||
type_is_fixed_capacity_dynamic_array :: proc($T: typeid) -> bool ---
|
||||
|
||||
type_has_nil :: proc($T: typeid) -> bool ---
|
||||
|
||||
@@ -222,6 +223,8 @@ type_is_superset_of :: proc($Super, $Sub: typeid) -> bool ---
|
||||
|
||||
type_field_index_of :: proc($T: typeid, $name: string) -> uintptr ---
|
||||
|
||||
type_fixed_capacity_dynamic_array_len_offset :: proc($T: typeid/[dynamic; $N]$E) -> uintptr ---
|
||||
|
||||
// "Contiguous" means that the set of enum constants, when sorted, have a difference of either 0 or 1 between consecutive values.
|
||||
// This is the exact opposite of "sparse".
|
||||
type_enum_is_contiguous :: proc($T: typeid) -> bool where type_is_enum(T) ---
|
||||
|
||||
@@ -58,6 +58,7 @@ gb_global BuiltinTypeIsProc *builtin_type_is_procs[BuiltinProc__type_simple_bool
|
||||
is_type_simd_vector,
|
||||
is_type_matrix,
|
||||
is_type_raw_union,
|
||||
is_type_fixed_capacity_dynamic_array,
|
||||
|
||||
is_type_polymorphic_record_specialized,
|
||||
is_type_polymorphic_record_unspecialized,
|
||||
@@ -7628,6 +7629,31 @@ gb_internal bool check_builtin_procedure(CheckerContext *c, Operand *operand, As
|
||||
}
|
||||
break;
|
||||
|
||||
case BuiltinProc_type_fixed_capacity_dynamic_array_len_offset:
|
||||
{
|
||||
Operand op = {};
|
||||
Type *bt = check_type(c, ce->args[0]);
|
||||
Type *type = base_type(bt);
|
||||
if (type == nullptr || type == t_invalid) {
|
||||
error(ce->args[0], "Expected a fixed capacity dynamic array type for '%.*s'", LIT(builtin_name));
|
||||
return false;
|
||||
}
|
||||
if (!is_type_fixed_capacity_dynamic_array(type)) {
|
||||
error(ce->args[0], "Expected a fixed capacity dynamic array type for '%.*s'", LIT(builtin_name));
|
||||
return false;
|
||||
}
|
||||
|
||||
i64 sz = type_size_of(type);
|
||||
gb_unused(sz);
|
||||
i64 offset = type_offset_of(type, 1);
|
||||
|
||||
operand->mode = Addressing_Constant;
|
||||
operand->value = exact_value_u64(cast(u64)offset);
|
||||
operand->type = t_uintptr;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case BuiltinProc_type_bit_set_backing_type:
|
||||
{
|
||||
Operand op = {};
|
||||
|
||||
@@ -297,6 +297,7 @@ BuiltinProc__type_simple_boolean_begin,
|
||||
BuiltinProc_type_is_simd_vector,
|
||||
BuiltinProc_type_is_matrix,
|
||||
BuiltinProc_type_is_raw_union,
|
||||
BuiltinProc_type_is_fixed_capacity_dynamic_array,
|
||||
|
||||
|
||||
BuiltinProc_type_is_specialized_polymorphic_record,
|
||||
@@ -342,6 +343,8 @@ BuiltinProc__type_simple_boolean_end,
|
||||
|
||||
BuiltinProc_type_field_index_of,
|
||||
|
||||
BuiltinProc_type_fixed_capacity_dynamic_array_len_offset,
|
||||
|
||||
BuiltinProc_type_bit_set_backing_type,
|
||||
|
||||
BuiltinProc_type_enum_is_contiguous,
|
||||
@@ -674,6 +677,7 @@ gb_global BuiltinProc builtin_procs[BuiltinProc_COUNT] = {
|
||||
{STR_LIT("type_is_simd_vector"), 1, false, Expr_Expr, BuiltinProcPkg_intrinsics},
|
||||
{STR_LIT("type_is_matrix"), 1, false, Expr_Expr, BuiltinProcPkg_intrinsics},
|
||||
{STR_LIT("type_is_raw_union"), 1, false, Expr_Expr, BuiltinProcPkg_intrinsics},
|
||||
{STR_LIT("type_is_fixed_capacity_dynamic_array"), 1, false, Expr_Expr, BuiltinProcPkg_intrinsics},
|
||||
|
||||
{STR_LIT("type_is_specialized_polymorphic_record"), 1, false, Expr_Expr, BuiltinProcPkg_intrinsics},
|
||||
{STR_LIT("type_is_unspecialized_polymorphic_record"), 1, false, Expr_Expr, BuiltinProcPkg_intrinsics},
|
||||
@@ -717,6 +721,8 @@ gb_global BuiltinProc builtin_procs[BuiltinProc_COUNT] = {
|
||||
|
||||
{STR_LIT("type_field_index_of"), 2, false, Expr_Expr, BuiltinProcPkg_intrinsics},
|
||||
|
||||
{STR_LIT("type_fixed_capacity_dynamic_array_len_offset"), 1, false, Expr_Expr, BuiltinProcPkg_intrinsics},
|
||||
|
||||
{STR_LIT("type_bit_set_backing_type"), 1, false, Expr_Expr, BuiltinProcPkg_intrinsics},
|
||||
|
||||
{STR_LIT("type_enum_is_contiguous"), 1, false, Expr_Expr, BuiltinProcPkg_intrinsics },
|
||||
|
||||
@@ -4755,8 +4755,9 @@ gb_internal i64 type_offset_of(Type *t, i64 index, Type **field_type_) {
|
||||
case 1: // len
|
||||
if (field_type_) *field_type_ = t_int;
|
||||
{
|
||||
i64 elem_size = type_size_of(t->FixedCapacityDynamicArray.elem);
|
||||
i64 offset = 0;
|
||||
offset = type_size_of(alloc_type_array(t->FixedCapacityDynamicArray.elem, t->FixedCapacityDynamicArray.capacity));
|
||||
offset = elem_size * t->FixedCapacityDynamicArray.capacity;
|
||||
offset = align_formula(offset, build_context.int_size);
|
||||
return offset;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user