impl hash and copy methods for bools
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user