X-Git-Url: https://jxself.org/git/?a=blobdiff_plain;f=src%2Fatom.c;h=501545503bcd9c6951438a5f171efd1a8df629ba;hb=e3dcc1d3966fb95a5a232daa193c6b5d89a06b7e;hp=38cadc085ee5695738e775b6f8b00929e5cb448d;hpb=58a5ffdfec139a0c9d399f603b77a764ae8607f7;p=muddle-interpreter.git diff --git a/src/atom.c b/src/atom.c index 38cadc0..5015455 100644 --- a/src/atom.c +++ b/src/atom.c @@ -18,3 +18,40 @@ License along with this file. If not, see #include "alloc.h" #include "atom.h" + +#include + +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; +}