mirror of
https://github.com/Ed94/Odin.git
synced 2026-06-18 03:42:23 -07:00
Add intrinsics.type_is_specialization_of
This commit is contained in:
@@ -124,6 +124,8 @@ type_is_bit_field_value :: proc($T: typeid) -> bool ---
|
||||
type_is_bit_set :: proc($T: typeid) -> bool ---
|
||||
type_is_simd_vector :: proc($T: typeid) -> bool ---
|
||||
|
||||
type_is_specialization_of :: proc($T, $S: typeid) -> bool ---
|
||||
|
||||
type_has_nil :: proc($T: typeid) -> bool ---
|
||||
|
||||
type_proc_parameter_count :: proc($T: typeid) -> int where type_is_proc(T) ---
|
||||
|
||||
@@ -5499,6 +5499,36 @@ bool check_builtin_procedure(CheckerContext *c, Operand *operand, Ast *call, i32
|
||||
operand->type = t_untyped_bool;
|
||||
break;
|
||||
|
||||
case BuiltinProc_type_is_specialization_of:
|
||||
{
|
||||
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 *t = operand->type;
|
||||
Type *s = nullptr;
|
||||
|
||||
bool prev_ips = c->in_polymorphic_specialization;
|
||||
c->in_polymorphic_specialization = true;
|
||||
s = check_type(c, ce->args[1]);
|
||||
c->in_polymorphic_specialization = prev_ips;
|
||||
|
||||
if (s == t_invalid) {
|
||||
error(ce->args[1], "Invalid specialization type for '%.*s'", LIT(builtin_name));
|
||||
operand->mode = Addressing_Invalid;
|
||||
operand->type = t_invalid;
|
||||
return false;
|
||||
}
|
||||
|
||||
operand->mode = Addressing_Constant;
|
||||
operand->type = t_untyped_bool;
|
||||
operand->value = exact_value_bool(check_type_specialization_to(c, s, t, false, false));
|
||||
|
||||
}
|
||||
break;
|
||||
|
||||
case BuiltinProc_type_proc_parameter_count:
|
||||
operand->value = exact_value_i64(0);
|
||||
if (operand->mode != Addressing_Type) {
|
||||
|
||||
@@ -155,6 +155,8 @@ BuiltinProc__type_begin,
|
||||
BuiltinProc_type_is_bit_set,
|
||||
BuiltinProc_type_is_simd_vector,
|
||||
|
||||
BuiltinProc_type_is_specialization_of,
|
||||
|
||||
BuiltinProc_type_has_nil,
|
||||
|
||||
BuiltinProc_type_proc_parameter_count,
|
||||
@@ -319,6 +321,8 @@ gb_global BuiltinProc builtin_procs[BuiltinProc_COUNT] = {
|
||||
{STR_LIT("type_is_bit_set"), 1, false, Expr_Expr, BuiltinProcPkg_intrinsics},
|
||||
{STR_LIT("type_is_simd_vector"), 1, false, Expr_Expr, BuiltinProcPkg_intrinsics},
|
||||
|
||||
{STR_LIT("type_is_specialization_of"), 2, false, Expr_Expr, BuiltinProcPkg_intrinsics},
|
||||
|
||||
{STR_LIT("type_has_nil"), 1, false, Expr_Expr, BuiltinProcPkg_intrinsics},
|
||||
|
||||
{STR_LIT("type_proc_parameter_count"), 1, false, Expr_Expr, BuiltinProcPkg_intrinsics},
|
||||
|
||||
+1
-1
@@ -3172,7 +3172,7 @@ irValue *ir_emit_call(irProcedure *p, irValue *value, Array<irValue *> const &ar
|
||||
} else if (!is_type_pointer(arg_type)) {
|
||||
array_add(&processed_args, ir_copy_value_to_ptr(p, args[i], original_type, 16));
|
||||
}
|
||||
} else if (is_type_integer(new_type)) {
|
||||
} else if (is_type_integer(new_type) || is_type_float(new_type)) {
|
||||
array_add(&processed_args, ir_emit_transmute(p, args[i], new_type));
|
||||
} else if (new_type == t_llvm_bool) {
|
||||
array_add(&processed_args, ir_emit_conv(p, args[i], new_type));
|
||||
|
||||
Reference in New Issue
Block a user