beginnings of REPL
[muddle-interpreter.git] / src / object.c
diff --git a/src/object.c b/src/object.c
new file mode 100644 (file)
index 0000000..a2a81a6
--- /dev/null
@@ -0,0 +1,66 @@
+/*
+Copyright (C) 2017 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
+Foundation, either version 3 of the License, or (at your option) any
+later version.
+
+This file is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Affero General Public License for more details.
+
+You should have received a copy of the GNU Affero General Public
+License along with this file. If not, see
+<http://www.gnu.org/licenses/>.
+*/
+
+#include "object.h"
+
+uint32_t
+list_length (const list_object * o)
+{
+  const pool_object *p = POOL_OBJECT (o->head);
+  uint32_t n = 0;
+  while (p)
+    {
+      n++;
+      p = POOL_OBJECT (p->rest);
+    }
+  return n;
+}
+
+/*
+static object *cons_new(evaltype type, value v, object *cdr) {
+    object o;
+    o.type = type;
+    o.v = v;
+    return cons(&o, cdr);
+}
+*/
+
+/*
+object *cons(const object *car, const object *cdr) {
+    assert(car);
+    assert(cdr);
+    object *head = pool_alloc(1);
+    head->type = car->type;
+    head->rest = cdr->v.head;
+    head->v = car->v;
+    return head;
+}
+*/
+
+/*
+static object rest(const object *lst) {
+    assert(lst);
+    object *head = OBJECT_OF_POOL_PTR(lst->v.head);
+    assert(head);
+    object o;
+    o.type = EVALTYPE_LIST;
+    o.rest = 0;
+    o.v.head = ((object*)head)->rest;
+    return o;
+}
+*/