From 8a0afd353df9f15384342f63c7836814e1b75591 Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Thu, 24 Sep 2015 21:59:29 -0400 Subject: [PATCH] added get and set functions for object --- source/gir.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/source/gir.c b/source/gir.c index 1c224c8..6961037 100644 --- a/source/gir.c +++ b/source/gir.c @@ -50,7 +50,7 @@ static int slot_cmp(void* a, void* b) { /* Base Object Definition *****************************************************************************/ -Obj* mkobject(uint32_t type, size_t datasz) { +Obj* obj_new(uint32_t type, size_t datasz) { Obj* obj = (Obj*)malloc(sizeof(struct Obj) + datasz); obj->type = type; obj->size = datasz; @@ -59,6 +59,19 @@ Obj* mkobject(uint32_t type, size_t datasz) { return obj; } +void obj_set(Obj* obj, uintptr_t sel, Obj* val) { + Slot* slot = (Slot*)malloc(sizeof(Slot)); + slot->sel = sel; + slot->val = val; + hamt_insert(&(obj->slots), slot); +} + +Obj* obj_get(Obj* obj, uintptr_t sel) { + Slot slot = { sel, NULL }; + Slot* entry = hamt_lookup(&(obj->slots), &slot); + return (entry != NULL) ? entry->val : NULL; +} + /* Main API *****************************************************************************/ GirCtx* gir_init(void) -- 2.54.0