Add intrinsics type_bit_set_elem_type & type_bit_set_underlying_type

This commit is contained in:
gingerBill
2024-05-09 15:47:09 +01:00
parent d85c8f0b2c
commit b0f0e4d02a
3 changed files with 69 additions and 8 deletions
+52
View File
@@ -5433,6 +5433,58 @@ gb_internal bool check_builtin_procedure(CheckerContext *c, Operand *operand, As
operand->value = exact_value_i64(u->Union.kind == UnionType_no_nil ? 0 : 1);
} break;
case BuiltinProc_type_bit_set_elem_type:
{
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 *bs = operand->type;
if (!is_type_bit_set(bs)) {
error(operand->expr, "Expected a bit_set type for '%.*s'", LIT(builtin_name));
operand->mode = Addressing_Invalid;
operand->type = t_invalid;
return false;
}
bs = base_type(bs);
GB_ASSERT(bs->kind == Type_BitSet);
operand->mode = Addressing_Type;
operand->type = bs->BitSet.elem;
} break;
case BuiltinProc_type_bit_set_underlying_type:
{
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 *bs = operand->type;
if (!is_type_bit_set(bs)) {
error(operand->expr, "Expected a bit_set type for '%.*s'", LIT(builtin_name));
operand->mode = Addressing_Invalid;
operand->type = t_invalid;
return false;
}
bs = base_type(bs);
GB_ASSERT(bs->kind == Type_BitSet);
operand->mode = Addressing_Type;
operand->type = bit_set_to_int(bs);
} break;
case BuiltinProc_type_union_variant_count:
{
if (operand->mode != Addressing_Type) {