From 001baf4419da9c43d4ef68d7ec1eac638d6fb742 Mon Sep 17 00:00:00 2001 From: Ginger Bill Date: Thu, 29 Jun 2017 15:13:41 +0100 Subject: Add `Type` -- Runtime type for comparing types (similar to TypeInfo but simpler) --- src/exact_value.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src/exact_value.cpp') 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"); -- cgit v1.2.3