impl hash and copy methods for floats

This commit is contained in:
cozis
2022-03-09 12:42:29 +01:00
parent a74cbf2a18
commit a481bafc94
+22
View File
@@ -1,9 +1,12 @@
#include <assert.h> #include <assert.h>
#include "objects.h" #include "objects.h"
#include "../utils/hash.h"
static double to_float(Object *obj, Error *err); static double to_float(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);
typedef struct { typedef struct {
Object base; Object base;
@@ -15,11 +18,30 @@ static TypeObject t_float = {
.name = "float", .name = "float",
.size = sizeof (FloatObject), .size = sizeof (FloatObject),
.atomic = ATMTP_FLOAT, .atomic = ATMTP_FLOAT,
.hash = hash,
.copy = copy,
.to_float = to_float, .to_float = to_float,
.print = print, .print = print,
.op_eql = op_eql .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) static _Bool op_eql(Object *self, Object *other)
{ {
assert(self != NULL); assert(self != NULL);