From a481bafc9477e22cf7d29bc11bde3c5c933b45cd Mon Sep 17 00:00:00 2001 From: cozis Date: Wed, 9 Mar 2022 12:42:29 +0100 Subject: [PATCH] impl hash and copy methods for floats --- src/objects/o_float.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/objects/o_float.c b/src/objects/o_float.c index 0a95e96..9982d0b 100644 --- a/src/objects/o_float.c +++ b/src/objects/o_float.c @@ -1,9 +1,12 @@ #include #include "objects.h" +#include "../utils/hash.h" static double to_float(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); typedef struct { Object base; @@ -15,11 +18,30 @@ static TypeObject t_float = { .name = "float", .size = sizeof (FloatObject), .atomic = ATMTP_FLOAT, + .hash = hash, + .copy = copy, .to_float = to_float, .print = print, .op_eql = op_eql }; +static int hash(Object *self) +{ + assert(self != NULL); + assert(self->type == &t_float); + + FloatObject *iobj = (FloatObject*) self; + + return hashbytes((unsigned char*) &iobj->val, sizeof(iobj->val)); +} + +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);