X-Git-Url: https://jxself.org/git/?a=blobdiff_plain;f=src%2Fobject.c;h=af50edaa191905c920704fc29af899f3117bbc08;hb=4b917a1f5fe2af0245454fe6be14710b2c24a475;hp=ff65f41651060c96e103a875cc06d96c1d6f53e3;hpb=58a5ffdfec139a0c9d399f603b77a764ae8607f7;p=muddle-interpreter.git diff --git a/src/object.c b/src/object.c index ff65f41..af50eda 100644 --- a/src/object.c +++ b/src/object.c @@ -1,5 +1,5 @@ /* -Copyright (C) 2017 Keziah Wesley +Copyright (C) 2017-2018 Keziah Wesley You can redistribute and/or modify this file under the terms of the GNU Affero General Public License as published by the Free Software @@ -18,6 +18,8 @@ License along with this file. If not, see #include "object.h" +#include + uint32_t list_length (const list_object * o) { @@ -64,3 +66,36 @@ static object rest(const object *lst) { return o; } */ + +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)); +}