made an immutable map object specifically for builtins

This commit is contained in:
Francesco Cozzuto
2021-11-29 16:35:15 +01:00
parent ac4dfbc8d3
commit 0d805b84b0
9 changed files with 211 additions and 109 deletions
+20 -1
View File
@@ -14,19 +14,38 @@ static int hash(Object *self);
static int count(Object *self);
static Object *copy(Object *self, Heap *heap, Error *err);
static void print(Object *obj, FILE *fp);
static char *to_string(Object *self, int *size, Heap *heap, Error *err);
static _Bool op_eql(Object *self, Object *other);
static const Type t_string = {
.base = (Object) { .type = &t_type, .flags = Object_STATIC },
.name = "string",
.size = sizeof (StringObject),
.atomic = ATMTP_STRING,
.size = sizeof(StringObject),
.hash = hash,
.count = count,
.copy = copy,
.print = print,
.to_string = to_string,
.op_eql = op_eql,
};
static char *to_string(Object *self, int *size, Heap *heap, Error *err)
{
assert(self != NULL);
assert(self->type == &t_string);
(void) heap;
(void) err;
StringObject *s = (StringObject*) self;
if(size)
*size = s->size;
return s->body;
}
Object *Object_FromString(const char *str, int len, Heap *heap, Error *error)
{
assert(str != NULL);