c2acaa0b239f — Leonard Ritter 8 months ago
* `'kind` of `type` will now return values of `TypeKind` type
5 files changed, 16 insertions(+), 4 deletions(-)

M lib/scopes/core.sc
M src/globals.cpp
M src/type.cpp
M src/type.hpp
M testing/test_inspect.sc
M lib/scopes/core.sc +6 -2
@@ 1126,6 1126,9 @@ run-stage; # 3
     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 @@ let
     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 @@ let
     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 @@ fn cenum-gen-repr-funcs (this-type)
     '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)

          
M src/globals.cpp +6 -2
@@ 2655,7 2655,7 @@ void init_globals(int argc, char *argv[]
     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 @@ B_TYPES()
 #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
 

          
M src/type.cpp +2 -0
@@ 554,7 554,9 @@ void init_types() {
 
     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);
 

          
M src/type.hpp +1 -0
@@ 117,6 117,7 @@ typedef std::vector<const Type *> Types;
     T(TYPE_ValueRef, "Value") \
     \
     T(TYPE_ValueKind, "ValueKind") \
+    T(TYPE_TypeKind, "TypeKind") \
     \
     T(TYPE_Bool, "bool") \
     \

          
M testing/test_inspect.sc +1 -0
@@ 15,5 15,6 @@ somefunc := `[(static-typify somefunc bo
 
 assert ((tostring ('kind somefunc)) == "Function")
 
+assert ((tostring ('kind i32)) == "IntegerType")
 
 ;
  No newline at end of file