Implement OBLISTs
[muddle-interpreter.git] / src / atom.c
index 38cadc085ee5695738e775b6f8b00929e5cb448d..501545503bcd9c6951438a5f171efd1a8df629ba 100644 (file)
@@ -18,3 +18,40 @@ License along with this file. If not, see
 
 #include "alloc.h"
 #include "atom.h"
+
+#include <string.h>
+
+typedef struct atom_body
+{
+  evaltype type;               // UNBOUND/LOCI
+  // bindid
+  // value ptr
+  // oblist ptr
+  // type ptr
+  char pname[];
+} atom_body;
+
+atom_object
+atom_create (const char *name, uint32_t namelen)
+{
+  // C-compatible strings for simplicity
+  namelen += 1;
+  heap_ptr body = atom_body_alloc (namelen);
+  atom_body *content = (atom_body *) HEAP_OBJECT (body);
+  memcpy (&content->pname, name, namelen - 1);
+  content->pname[namelen - 1] = '\0';
+  atom_object new = new_atom (body, namelen);
+  return new;
+}
+
+heap_ptr
+atom_body_alloc (uint32_t namelen)
+{
+  return heap_alloc_uv ((sizeof (atom_body) + namelen + 63) / 64);
+}
+
+const char *
+atom_pname (atom_object o)
+{
+  return ATOM_BODY (o.val.body)->pname;
+}