impl hash and copy methods for bools

This commit is contained in:
cozis
2022-03-09 12:45:20 +01:00
parent a481bafc94
commit 0e9075bdbc
+23
View File
@@ -5,12 +5,16 @@
static _Bool to_bool(Object *obj, Error *err); static _Bool to_bool(Object *obj, Error *err);
static void print(Object *obj, FILE *fp); static void print(Object *obj, FILE *fp);
static _Bool op_eql(Object *self, Object *other); static _Bool op_eql(Object *self, Object *other);
static int hash(Object *self);
static Object *copy(Object *self, Heap *heap, Error *err);
static TypeObject t_bool = { static TypeObject t_bool = {
.base = (Object) { .type = &t_type, .flags = Object_STATIC }, .base = (Object) { .type = &t_type, .flags = Object_STATIC },
.name = "bool", .name = "bool",
.size = sizeof (Object), .size = sizeof (Object),
.atomic = ATMTP_BOOL, .atomic = ATMTP_BOOL,
.hash = hash,
.copy = copy,
.to_bool = to_bool, .to_bool = to_bool,
.print = print, .print = print,
.op_eql = op_eql, .op_eql = op_eql,
@@ -26,6 +30,25 @@ static Object the_false_object = {
.flags = Object_STATIC, .flags = Object_STATIC,
}; };
static int hash(Object *self)
{
assert(self != NULL);
assert(self->type == &t_bool);
if(self == &the_true_object)
return 1;
assert(self == &the_false_object);
return 0;
}
static Object *copy(Object *self, Heap *heap, Error *err)
{
(void) heap;
(void) err;
return self;
}
static _Bool op_eql(Object *self, Object *other) static _Bool op_eql(Object *self, Object *other)
{ {
assert(self != NULL); assert(self != NULL);