# HG changeset patch # User Leonard Ritter # Date 1679080511 -3600 # Fri Mar 17 20:15:11 2023 +0100 # Node ID c2acaa0b239fdcb40f188c639a75a5567c9f5c69 # Parent f6b72ee0dbb63c30d6b1297bf780c984174ca3fa * `'kind` of `type` will now return values of `TypeKind` type diff --git a/lib/scopes/core.sc b/lib/scopes/core.sc --- a/lib/scopes/core.sc +++ b/lib/scopes/core.sc @@ -1126,6 +1126,9 @@ unsized? = sc_type_is_unsized storageof = sc_type_storage kind = sc_type_kind + kind? = + inline (self kind) + icmp== (sc_type_kind self) kind sizeof = sc_type_sizeof alignof = sc_type_alignof offsetof = sc_type_offsetof @@ -3591,7 +3594,7 @@ mutable? = make-const-type-property-function fn (T) - if (== ('kind T) type-kind-pointer) + if ('kind? T type-kind-pointer) 'writable? T else hide-traceback; @@ -3599,7 +3602,7 @@ signed? = make-const-type-property-function fn (T) - if (== ('kind T) type-kind-integer) + if ('kind? T type-kind-integer) 'signed? T else hide-traceback; @@ -8590,6 +8593,7 @@ 'set-symbol this-type '__tostring (gen-repr-func this-type false) cenum-gen-repr-funcs ValueKind +cenum-gen-repr-funcs TypeKind do inline simple-unary-storage-op (f) diff --git a/src/globals.cpp b/src/globals.cpp --- a/src/globals.cpp +++ b/src/globals.cpp @@ -2655,7 +2655,7 @@ DEFINE_RAISING_EXTERN_C_FUNCTION(sc_type_offsetof, TYPE_USize, TYPE_Type, TYPE_I32); DEFINE_RAISING_EXTERN_C_FUNCTION(sc_type_countof, TYPE_I32, TYPE_Type); DEFINE_RAISING_EXTERN_C_FUNCTION(sc_type_is_unsized, TYPE_Bool, TYPE_Type); - DEFINE_EXTERN_C_FUNCTION(sc_type_kind, TYPE_I32, TYPE_Type); + DEFINE_EXTERN_C_FUNCTION(sc_type_kind, TYPE_TypeKind, TYPE_Type); DEFINE_EXTERN_C_FUNCTION(sc_type_debug_abi, _void, TYPE_Type); DEFINE_RAISING_EXTERN_C_FUNCTION(sc_type_storage, TYPE_Type, TYPE_Type); DEFINE_EXTERN_C_FUNCTION(sc_type_is_opaque, TYPE_Bool, TYPE_Type); @@ -2809,7 +2809,11 @@ #undef T #define T(NAME, BNAME, CLASS) \ - bind_new_value(Symbol(BNAME), ConstInt::from(TYPE_I32, (int32_t)NAME)); + { \ + ConstIntRef tk = ConstInt::from(TYPE_TypeKind, (int32_t)NAME); \ + bind_new_value(Symbol(BNAME), tk); \ + TYPE_TypeKind->bind(Symbol(#CLASS), tk); \ + } B_TYPE_KIND() #undef T diff --git a/src/type.cpp b/src/type.cpp --- a/src/type.cpp +++ b/src/type.cpp @@ -554,7 +554,9 @@ DEFINE_BASIC_TYPE("Symbol", Symbol, TYPE_Symbol, TYPE_Immutable, TYPE_U64); DEFINE_BASIC_TYPE("Builtin", Builtin, TYPE_Builtin, nullptr, TYPE_U64); + DEFINE_BASIC_TYPE("ValueKind", ValueKind, TYPE_ValueKind, TYPE_CEnum, TYPE_I32); + DEFINE_BASIC_TYPE("TypeKind", TypeKind, TYPE_TypeKind, TYPE_CEnum, TYPE_I32); DEFINE_OPAQUE_HANDLE_TYPE("_Value", Value, TYPE__Value, nullptr); diff --git a/src/type.hpp b/src/type.hpp --- a/src/type.hpp +++ b/src/type.hpp @@ -117,6 +117,7 @@ T(TYPE_ValueRef, "Value") \ \ T(TYPE_ValueKind, "ValueKind") \ + T(TYPE_TypeKind, "TypeKind") \ \ T(TYPE_Bool, "bool") \ \ diff --git a/testing/test_inspect.sc b/testing/test_inspect.sc --- a/testing/test_inspect.sc +++ b/testing/test_inspect.sc @@ -15,5 +15,6 @@ assert ((tostring ('kind somefunc)) == "Function") +assert ((tostring ('kind i32)) == "IntegerType") ; \ No newline at end of file