mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-07 16:18:52 +00:00
Remove len,cap,min,max and implement type_union_base_tag_value, type_union_variant_count
This commit is contained in:
@@ -164,9 +164,11 @@ type_has_nil :: proc($T: typeid) -> bool ---
|
|||||||
type_is_specialization_of :: proc($T, $S: typeid) -> bool ---
|
type_is_specialization_of :: proc($T, $S: typeid) -> bool ---
|
||||||
|
|
||||||
type_is_variant_of :: proc($U, $V: typeid) -> bool where type_is_union(U) ---
|
type_is_variant_of :: proc($U, $V: typeid) -> bool where type_is_union(U) ---
|
||||||
type_union_tag_type :: proc($U: typeid) -> typeid where type_is_union(U) ---
|
type_union_tag_type :: proc($T: typeid) -> typeid where type_is_union(T) ---
|
||||||
type_union_tag_offset :: proc($U: typeid) -> int where type_is_union(U) ---
|
type_union_tag_offset :: proc($T: typeid) -> int where type_is_union(T) ---
|
||||||
type_variant_type_of :: proc($U: typeid, $index: int) -> typeid where type_is_union(U) ---
|
type_union_base_tag_value :: proc($T: typeid) -> int where type_is_union(U) ---
|
||||||
|
type_union_variant_count :: proc($T: typeid) -> int where type_is_union(T) ---
|
||||||
|
type_variant_type_of :: proc($T: typeid, $index: int) -> typeid where type_is_union(T) ---
|
||||||
type_variant_index_of :: proc($U, $V: typeid) -> int where type_is_union(U) ---
|
type_variant_index_of :: proc($U, $V: typeid) -> int where type_is_union(U) ---
|
||||||
|
|
||||||
type_has_field :: proc($T: typeid, $name: string) -> bool ---
|
type_has_field :: proc($T: typeid, $name: string) -> bool ---
|
||||||
|
|||||||
+54
-23
@@ -1780,11 +1780,6 @@ gb_internal bool check_builtin_procedure(CheckerContext *c, Operand *operand, As
|
|||||||
mode = Addressing_Constant;
|
mode = Addressing_Constant;
|
||||||
value = exact_value_i64(bt->SimdVector.count);
|
value = exact_value_i64(bt->SimdVector.count);
|
||||||
type = t_untyped_integer;
|
type = t_untyped_integer;
|
||||||
} else if (is_type_union(op_type)) {
|
|
||||||
Type *u = base_type(op_type);
|
|
||||||
mode = Addressing_Constant;
|
|
||||||
value = exact_value_i64(u->Union.variants.count);
|
|
||||||
type = t_untyped_integer;
|
|
||||||
}
|
}
|
||||||
if (operand->mode == Addressing_Type && mode != Addressing_Constant) {
|
if (operand->mode == Addressing_Type && mode != Addressing_Constant) {
|
||||||
mode = Addressing_Invalid;
|
mode = Addressing_Invalid;
|
||||||
@@ -2597,7 +2592,7 @@ gb_internal bool check_builtin_procedure(CheckerContext *c, Operand *operand, As
|
|||||||
|
|
||||||
Type *original_type = operand->type;
|
Type *original_type = operand->type;
|
||||||
Type *type = base_type(operand->type);
|
Type *type = base_type(operand->type);
|
||||||
if (operand->mode == Addressing_Type && (is_type_enumerated_array(type) || is_type_union(type))) {
|
if (operand->mode == Addressing_Type && is_type_enumerated_array(type)) {
|
||||||
// Okay
|
// Okay
|
||||||
} else if (!is_type_ordered(type) || !(is_type_numeric(type) || is_type_string(type))) {
|
} else if (!is_type_ordered(type) || !(is_type_numeric(type) || is_type_string(type))) {
|
||||||
gbString type_str = type_to_string(original_type);
|
gbString type_str = type_to_string(original_type);
|
||||||
@@ -2662,14 +2657,6 @@ gb_internal bool check_builtin_procedure(CheckerContext *c, Operand *operand, As
|
|||||||
operand->type = bt->EnumeratedArray.index;
|
operand->type = bt->EnumeratedArray.index;
|
||||||
operand->value = *bt->EnumeratedArray.min_value;
|
operand->value = *bt->EnumeratedArray.min_value;
|
||||||
return true;
|
return true;
|
||||||
} else if (is_type_union(type)) {
|
|
||||||
Type *bt = base_type(type);
|
|
||||||
GB_ASSERT(bt->kind == Type_Union);
|
|
||||||
operand->mode = Addressing_Constant;
|
|
||||||
operand->type = t_untyped_integer;
|
|
||||||
i64 min_tag = bt->Union.kind == UnionType_no_nil ? 0 : 1;
|
|
||||||
operand->value = exact_value_i64(min_tag);
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
gbString type_str = type_to_string(original_type);
|
gbString type_str = type_to_string(original_type);
|
||||||
error(call, "Invalid type for 'min', got %s", type_str);
|
error(call, "Invalid type for 'min', got %s", type_str);
|
||||||
@@ -2774,7 +2761,7 @@ gb_internal bool check_builtin_procedure(CheckerContext *c, Operand *operand, As
|
|||||||
Type *original_type = operand->type;
|
Type *original_type = operand->type;
|
||||||
Type *type = base_type(operand->type);
|
Type *type = base_type(operand->type);
|
||||||
|
|
||||||
if (operand->mode == Addressing_Type && (is_type_enumerated_array(type) || is_type_union(type))) {
|
if (operand->mode == Addressing_Type && is_type_enumerated_array(type)) {
|
||||||
// Okay
|
// Okay
|
||||||
} else if (!is_type_ordered(type) || !(is_type_numeric(type) || is_type_string(type))) {
|
} else if (!is_type_ordered(type) || !(is_type_numeric(type) || is_type_string(type))) {
|
||||||
gbString type_str = type_to_string(original_type);
|
gbString type_str = type_to_string(original_type);
|
||||||
@@ -2844,14 +2831,6 @@ gb_internal bool check_builtin_procedure(CheckerContext *c, Operand *operand, As
|
|||||||
operand->type = bt->EnumeratedArray.index;
|
operand->type = bt->EnumeratedArray.index;
|
||||||
operand->value = *bt->EnumeratedArray.max_value;
|
operand->value = *bt->EnumeratedArray.max_value;
|
||||||
return true;
|
return true;
|
||||||
} else if (is_type_union(type)) {
|
|
||||||
Type *bt = base_type(type);
|
|
||||||
GB_ASSERT(bt->kind == Type_Union);
|
|
||||||
operand->mode = Addressing_Constant;
|
|
||||||
operand->type = t_untyped_integer;
|
|
||||||
i64 max_tag = (bt->Union.kind == UnionType_no_nil ? 0 : 1) + bt->Union.variants.count - 1;
|
|
||||||
operand->value = exact_value_i64(max_tag);
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
gbString type_str = type_to_string(original_type);
|
gbString type_str = type_to_string(original_type);
|
||||||
error(call, "Invalid type for 'max', got %s", type_str);
|
error(call, "Invalid type for 'max', got %s", type_str);
|
||||||
@@ -5196,6 +5175,58 @@ gb_internal bool check_builtin_procedure(CheckerContext *c, Operand *operand, As
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case BuiltinProc_type_union_base_tag_value:
|
||||||
|
{
|
||||||
|
if (operand->mode != Addressing_Type) {
|
||||||
|
error(operand->expr, "Expected a type for '%.*s'", LIT(builtin_name));
|
||||||
|
operand->mode = Addressing_Invalid;
|
||||||
|
operand->type = t_invalid;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Type *u = operand->type;
|
||||||
|
|
||||||
|
if (!is_type_union(u)) {
|
||||||
|
error(operand->expr, "Expected a union type for '%.*s'", LIT(builtin_name));
|
||||||
|
operand->mode = Addressing_Invalid;
|
||||||
|
operand->type = t_invalid;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
u = base_type(u);
|
||||||
|
GB_ASSERT(u->kind == Type_Union);
|
||||||
|
|
||||||
|
operand->mode = Addressing_Constant;
|
||||||
|
operand->type = t_untyped_integer;
|
||||||
|
operand->value = exact_value_i64(u->Union.kind == UnionType_no_nil ? 0 : 1);
|
||||||
|
} break;
|
||||||
|
|
||||||
|
case BuiltinProc_type_union_variant_count:
|
||||||
|
{
|
||||||
|
if (operand->mode != Addressing_Type) {
|
||||||
|
error(operand->expr, "Expected a type for '%.*s'", LIT(builtin_name));
|
||||||
|
operand->mode = Addressing_Invalid;
|
||||||
|
operand->type = t_invalid;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Type *u = operand->type;
|
||||||
|
|
||||||
|
if (!is_type_union(u)) {
|
||||||
|
error(operand->expr, "Expected a union type for '%.*s'", LIT(builtin_name));
|
||||||
|
operand->mode = Addressing_Invalid;
|
||||||
|
operand->type = t_invalid;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
u = base_type(u);
|
||||||
|
GB_ASSERT(u->kind == Type_Union);
|
||||||
|
|
||||||
|
operand->mode = Addressing_Constant;
|
||||||
|
operand->type = t_untyped_integer;
|
||||||
|
operand->value = exact_value_i64(u->Union.variants.count);
|
||||||
|
} break;
|
||||||
|
|
||||||
case BuiltinProc_type_variant_type_of:
|
case BuiltinProc_type_variant_type_of:
|
||||||
{
|
{
|
||||||
if (operand->mode != Addressing_Type) {
|
if (operand->mode != Addressing_Type) {
|
||||||
|
|||||||
@@ -262,6 +262,8 @@ BuiltinProc__type_simple_boolean_end,
|
|||||||
BuiltinProc_type_is_variant_of,
|
BuiltinProc_type_is_variant_of,
|
||||||
BuiltinProc_type_union_tag_type,
|
BuiltinProc_type_union_tag_type,
|
||||||
BuiltinProc_type_union_tag_offset,
|
BuiltinProc_type_union_tag_offset,
|
||||||
|
BuiltinProc_type_union_base_tag_value,
|
||||||
|
BuiltinProc_type_union_variant_count,
|
||||||
BuiltinProc_type_variant_type_of,
|
BuiltinProc_type_variant_type_of,
|
||||||
BuiltinProc_type_variant_index_of,
|
BuiltinProc_type_variant_index_of,
|
||||||
|
|
||||||
@@ -561,11 +563,13 @@ gb_global BuiltinProc builtin_procs[BuiltinProc_COUNT] = {
|
|||||||
|
|
||||||
{STR_LIT("type_is_specialization_of"), 2, false, Expr_Expr, BuiltinProcPkg_intrinsics},
|
{STR_LIT("type_is_specialization_of"), 2, false, Expr_Expr, BuiltinProcPkg_intrinsics},
|
||||||
|
|
||||||
{STR_LIT("type_is_variant_of"), 2, false, Expr_Expr, BuiltinProcPkg_intrinsics},
|
{STR_LIT("type_is_variant_of"), 2, false, Expr_Expr, BuiltinProcPkg_intrinsics},
|
||||||
{STR_LIT("type_union_tag_type"), 1, false, Expr_Expr, BuiltinProcPkg_intrinsics},
|
{STR_LIT("type_union_tag_type"), 1, false, Expr_Expr, BuiltinProcPkg_intrinsics},
|
||||||
{STR_LIT("type_union_tag_offset"), 1, false, Expr_Expr, BuiltinProcPkg_intrinsics},
|
{STR_LIT("type_union_tag_offset"), 1, false, Expr_Expr, BuiltinProcPkg_intrinsics},
|
||||||
{STR_LIT("type_variant_type_of"), 2, false, Expr_Expr, BuiltinProcPkg_intrinsics},
|
{STR_LIT("type_union_base_tag_value"), 1, false, Expr_Expr, BuiltinProcPkg_intrinsics},
|
||||||
{STR_LIT("type_variant_index_of"), 2, false, Expr_Expr, BuiltinProcPkg_intrinsics},
|
{STR_LIT("type_union_variant_count"), 1, false, Expr_Expr, BuiltinProcPkg_intrinsics},
|
||||||
|
{STR_LIT("type_variant_type_of"), 2, false, Expr_Expr, BuiltinProcPkg_intrinsics},
|
||||||
|
{STR_LIT("type_variant_index_of"), 2, false, Expr_Expr, BuiltinProcPkg_intrinsics},
|
||||||
|
|
||||||
{STR_LIT("type_struct_field_count"), 1, false, Expr_Expr, BuiltinProcPkg_intrinsics},
|
{STR_LIT("type_struct_field_count"), 1, false, Expr_Expr, BuiltinProcPkg_intrinsics},
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user