add type_is_enum

This commit is contained in:
Judah Caruso 2025-05-25 15:10:06 -06:00
parent 0632f97757
commit 7063c63c2d

View file

@ -38,27 +38,16 @@ type_is_struct :: ($$T: Type) -> bool, *Type_Info_Struct {
return ok, info.(*Type_Info_Struct);
}
enum_max :: (T: Type) -> int #expand {
#assert T.(*Type_Info).type == .ENUM;
return #run -> int {
info := T.(*Type_Info_Enum);
if info.values.count == 0 {
return 0;
}
max := 0;
for info.values if it > max {
max = it;
}
return max;
};
type_is_enum :: ($$T: Type) -> bool, *Type_Info_Enum {
ok, info := check_type_tag(T, .ENUM);
return ok, info.(*Type_Info_Enum);
}
enum_min :: (T: Type) -> int #expand {
#assert T.(*Type_Info).type == .ENUM;
return #run -> int {
info := T.(*Type_Info_Enum);
ok, info := type_is_enum(T);
assert(ok, "type given to enum_min must be an enum");
if info.values.count == 0 {
return 0;
}
@ -71,3 +60,21 @@ enum_min :: (T: Type) -> int #expand {
return min;
};
}
enum_max :: (T: Type) -> int #expand {
return #run -> int {
ok, info := type_is_enum(T);
assert(ok, "type given to enum_max must be an enum");
if info.values.count == 0 {
return 0;
}
max := 0;
for info.values if it > max {
max = it;
}
return max;
};
}