implemented nullable type notation

This commit is contained in:
cozis
2022-12-04 18:39:42 +01:00
parent d610a973f4
commit 7a07a1eb3c
12 changed files with 156 additions and 9 deletions
+14
View File
@@ -33,14 +33,21 @@
#include "../common/defs.h"
static _Bool op_eql(Object *self, Object *other);
static bool istypeof(Object *self, Object *other);
TypeObject t_type = {
.base = (Object) { .type = &t_type, .flags = Object_STATIC },
.name = TYPENAME_TYPE,
.size = sizeof(TypeObject),
.istypeof = istypeof,
.op_eql = op_eql,
};
static bool istypeof(Object *self, Object *other)
{
return other->type == (TypeObject*) self;
}
TypeObject *Object_GetTypeType()
{
return &t_type;
@@ -71,6 +78,13 @@ const TypeObject *Object_GetType(const Object *obj)
return obj->type;
}
bool Object_IsTypeOf(Object *typ, Object *obj)
{
if (typ->type->istypeof == NULL)
return false;
return typ->type->istypeof(typ, obj);
}
int Object_Hash(Object *obj)
{
ASSERT(obj != NULL);