X-Git-Url: https://jxself.org/git/?a=blobdiff_plain;f=src%2Fobject.c;h=5b115c0b89ffbcfc78c5b9e249f8488d573aa25d;hb=refs%2Fheads%2Fmaster;hp=f7b5526d42037f9f66a8feb69e7ef49877946065;hpb=9bdd7f99a7664d00bf9cda831cbbb31769a542cd;p=muddle-interpreter.git diff --git a/src/object.c b/src/object.c index f7b5526..5b115c0 100644 --- a/src/object.c +++ b/src/object.c @@ -18,6 +18,8 @@ License along with this file. If not, see #include "object.h" +#include + uint32_t list_length (const list_object * o) { @@ -65,9 +67,42 @@ static object rest(const object *lst) { } */ +dope_object * +vec_dope (const vector_object * o) +{ + return (dope_object *) & HEAP_OBJECT (o->val.body)[o->val.len]; +} + dope_object * uv_dope (const uvector_object * o) { return (dope_object *) & HEAP_OBJECT (o->val.body)[(o->val.len + 1) / 2 + 1]; } + +vector_object +vector_create (uint32_t capacity) +{ + heap_ptr body = heap_alloc (capacity); + memset (HEAP_OBJECT (body), '\0', capacity * sizeof (object)); + return new_vector (body + capacity, 0); +} + +object * +stack_push (vector_object * v) +{ + if (vec_dope (v)->len > v->val.len) + { + // TODO + assert (0 && "not implemented: GROW in stack_push"); + } + v->val.len++; + return HEAP_OBJECT (--(v->val.body)); +} + +object +uv_get (const uvector_object * o, uint32_t i) +{ + return (object) + {.type = utype (o),.uv_val = UV_VAL (o->val.body)[i]}; +}