diff options
| author | gingerBill <bill@gingerbill.org> | 2024-05-09 15:47:09 +0100 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2024-05-09 15:47:09 +0100 |
| commit | b0f0e4d02a88b27e04d9d7241959107ce08ff592 (patch) | |
| tree | 14cd9db7ef5927011184c43b5e851d8f2646a673 /src/check_builtin.cpp | |
| parent | d85c8f0b2c5989f7d14b02c9023060990d241111 (diff) | |
Add intrinsics `type_bit_set_elem_type` & `type_bit_set_underlying_type`
Diffstat (limited to 'src/check_builtin.cpp')
| -rw-r--r-- | src/check_builtin.cpp | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/src/check_builtin.cpp b/src/check_builtin.cpp index 3d31ec75d..c7d27cf38 100644 --- a/src/check_builtin.cpp +++ b/src/check_builtin.cpp @@ -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) { |