diff options
| author | Ginger Bill <bill@gingerbill.org> | 2017-06-29 15:13:41 +0100 |
|---|---|---|
| committer | Ginger Bill <bill@gingerbill.org> | 2017-06-29 15:13:41 +0100 |
| commit | 001baf4419da9c43d4ef68d7ec1eac638d6fb742 (patch) | |
| tree | 5d685a869cee84487a860e616034ed1e2428f50d /src/exact_value.cpp | |
| parent | d167290b280c2dfcb764ff1e8f48df975444962d (diff) | |
Add `Type` -- Runtime type for comparing types (similar to TypeInfo but simpler)
Diffstat (limited to 'src/exact_value.cpp')
| -rw-r--r-- | src/exact_value.cpp | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/exact_value.cpp b/src/exact_value.cpp index e84b5b794..3bee3cdb2 100644 --- a/src/exact_value.cpp +++ b/src/exact_value.cpp @@ -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"); |