mirror of
https://github.com/Ed94/Odin.git
synced 2026-06-18 11:52:22 -07:00
Add Type -- Runtime type for comparing types (similar to TypeInfo but simpler)
This commit is contained in:
@@ -5,6 +5,8 @@
|
||||
|
||||
struct AstNode;
|
||||
struct HashKey;
|
||||
struct Type;
|
||||
bool are_types_identical(Type *x, Type *y);
|
||||
|
||||
struct Complex128 {
|
||||
f64 real, imag;
|
||||
@@ -20,6 +22,7 @@ enum ExactValueKind {
|
||||
ExactValue_Complex,
|
||||
ExactValue_Pointer,
|
||||
ExactValue_Compound, // TODO(bill): Is this good enough?
|
||||
ExactValue_Type,
|
||||
|
||||
ExactValue_Count,
|
||||
};
|
||||
@@ -34,6 +37,7 @@ struct ExactValue {
|
||||
i64 value_pointer;
|
||||
Complex128 value_complex;
|
||||
AstNode * value_compound;
|
||||
Type * value_type;
|
||||
};
|
||||
};
|
||||
|
||||
@@ -99,6 +103,12 @@ ExactValue exact_value_pointer(i64 ptr) {
|
||||
return result;
|
||||
}
|
||||
|
||||
ExactValue exact_value_type(Type *type) {
|
||||
ExactValue result = {ExactValue_Type};
|
||||
result.value_type = type;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
ExactValue exact_value_integer_from_string(String string) {
|
||||
return exact_value_u128(u128_from_string(string));
|
||||
@@ -639,6 +649,13 @@ bool compare_exact_values(TokenKind op, ExactValue x, ExactValue y) {
|
||||
case Token_GtEq: return a >= b;
|
||||
}
|
||||
} break;
|
||||
|
||||
case ExactValue_Type:
|
||||
switch (op) {
|
||||
case Token_CmpEq: return are_types_identical(x.value_type, y.value_type);
|
||||
case Token_NotEq: return !are_types_identical(x.value_type, y.value_type);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
GB_PANIC("Invalid comparison");
|
||||
|
||||
Reference in New Issue
Block a user