2 Copyright (C) 2017-2018 Keziah Wesley
4 You can redistribute and/or modify this file under the terms of the
5 GNU Affero General Public License as published by the Free Software
6 Foundation, either version 3 of the License, or (at your option) any
9 This file is distributed in the hope that it will be useful, but
10 WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Affero General Public License for more details.
14 You should have received a copy of the GNU Affero General Public
15 License along with this file. If not, see
16 <http://www.gnu.org/licenses/>.
24 list_length (const list_object * o)
26 const pool_object *p = POOL_OBJECT (o->val.head);
31 p = POOL_OBJECT (p->rest);
37 static object *cons_new(evaltype type, value v, object *cdr) {
46 object *cons(const object *car, const object *cdr) {
49 object *head = pool_alloc(1);
50 head->type = car->type;
51 head->rest = cdr->v.head;
58 static object rest(const object *lst) {
60 object *head = OBJECT_OF_POOL_PTR(lst->v.head);
63 o.type = EVALTYPE_LIST;
65 o.v.head = ((object*)head)->rest;
71 vec_dope (const vector_object * o)
73 return (dope_object *) & HEAP_OBJECT (o->val.body)[o->val.len];
77 uv_dope (const uvector_object * o)
79 return (dope_object *) & HEAP_OBJECT (o->val.body)[(o->val.len + 1) / 2 +
84 vector_create (uint32_t capacity)
86 heap_ptr body = heap_alloc (capacity);
87 memset (HEAP_OBJECT (body), '\0', capacity * sizeof (object));
88 return new_vector (body + capacity, 0);
92 stack_push (vector_object * v)
94 if (vec_dope (v)->len > v->val.len)
97 assert (0 && "not implemented: GROW in stack_push");
100 return HEAP_OBJECT (--(v->val.body));