From 0e9075bdbcb19d1d5eff29748e6dabfde3687573 Mon Sep 17 00:00:00 2001 From: cozis Date: Wed, 9 Mar 2022 12:45:20 +0100 Subject: [PATCH] impl hash and copy methods for bools --- src/objects/o_bool.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/objects/o_bool.c b/src/objects/o_bool.c index ccf5152..c789b22 100644 --- a/src/objects/o_bool.c +++ b/src/objects/o_bool.c @@ -5,12 +5,16 @@ static _Bool to_bool(Object *obj, Error *err); static void print(Object *obj, FILE *fp); 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 = { .base = (Object) { .type = &t_type, .flags = Object_STATIC }, .name = "bool", .size = sizeof (Object), .atomic = ATMTP_BOOL, + .hash = hash, + .copy = copy, .to_bool = to_bool, .print = print, .op_eql = op_eql, @@ -26,6 +30,25 @@ static Object the_false_object = { .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) { assert(self != NULL);