39 lines
1 KiB
Text
39 lines
1 KiB
Text
// These return the bool first so you can check in a conditional,
|
|
// rather than having to do '_, ok := ...'
|
|
|
|
check_type_tag :: ($$T: Type, tag: Type_Info_Tag) -> bool, *Type_Info {
|
|
#if is_constant(T) {
|
|
info :: type_info(T);
|
|
if info.type == tag return true, info;
|
|
}
|
|
else {
|
|
info := T.(*Type_Info);
|
|
if info.type == tag return true, info;
|
|
}
|
|
|
|
return false, null;
|
|
}
|
|
|
|
type_is_integer :: ($$T: Type) -> bool, *Type_Info_Integer {
|
|
ok, info := check_type_tag(T, .INTEGER);
|
|
return ok, info.(*Type_Info_Integer);
|
|
}
|
|
|
|
type_is_float :: ($$T: Type) -> bool, *Type_Info_Float {
|
|
ok, info := check_type_tag(T, .FLOAT);
|
|
return ok, info.(*Type_Info_Float);
|
|
}
|
|
|
|
type_is_scalar :: (t: Type) -> bool {
|
|
return type_is_integer(t) || type_is_float(t);
|
|
}
|
|
|
|
type_is_array :: ($$T: Type) -> bool, *Type_Info_Array {
|
|
ok, info := check_type_tag(T, .ARRAY);
|
|
return ok, info.(*Type_Info_Array);
|
|
}
|
|
|
|
type_is_struct :: ($$T: Type) -> bool, *Type_Info_Struct {
|
|
ok, info := check_type_tag(T, .STRUCT);
|
|
return ok, info.(*Type_Info_Struct);
|
|
}
|