renamed hcl to hak
This commit is contained in:
170
lib/cnode.c
170
lib/cnode.c
@ -22,13 +22,13 @@
|
||||
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "hcl-prv.h"
|
||||
#include "hak-prv.h"
|
||||
|
||||
hcl_cnode_t* hcl_makecnode (hcl_t* hcl, hcl_cnode_type_t type, int flags, const hcl_loc_t* loc, const hcl_oocs_t* tok)
|
||||
hak_cnode_t* hak_makecnode (hak_t* hak, hak_cnode_type_t type, int flags, const hak_loc_t* loc, const hak_oocs_t* tok)
|
||||
{
|
||||
hcl_cnode_t* cnode;
|
||||
hcl_oocs_t empty;
|
||||
hcl_ooch_t dummy;
|
||||
hak_cnode_t* cnode;
|
||||
hak_oocs_t empty;
|
||||
hak_ooch_t dummy;
|
||||
|
||||
if (!tok)
|
||||
{
|
||||
@ -36,196 +36,196 @@ hcl_cnode_t* hcl_makecnode (hcl_t* hcl, hcl_cnode_type_t type, int flags, const
|
||||
empty.len = 0;
|
||||
tok = ∅
|
||||
}
|
||||
cnode = (hcl_cnode_t*)hcl_callocmem(hcl, HCL_SIZEOF(*cnode) + HCL_SIZEOF(*tok->ptr) * (tok->len + 1));
|
||||
if (HCL_UNLIKELY(!cnode)) return HCL_NULL;
|
||||
cnode = (hak_cnode_t*)hak_callocmem(hak, HAK_SIZEOF(*cnode) + HAK_SIZEOF(*tok->ptr) * (tok->len + 1));
|
||||
if (HAK_UNLIKELY(!cnode)) return HAK_NULL;
|
||||
|
||||
cnode->cn_type = type;
|
||||
cnode->cn_flags = flags;
|
||||
cnode->cn_loc = *loc;
|
||||
|
||||
cnode->cn_tok.ptr = (hcl_ooch_t*)(cnode + 1);
|
||||
cnode->cn_tok.ptr = (hak_ooch_t*)(cnode + 1);
|
||||
cnode->cn_tok.len = tok->len;
|
||||
hcl_copy_oochars (cnode->cn_tok.ptr, tok->ptr, tok->len);
|
||||
hak_copy_oochars (cnode->cn_tok.ptr, tok->ptr, tok->len);
|
||||
cnode->cn_tok.ptr[tok->len] = '\0';
|
||||
|
||||
return cnode;
|
||||
}
|
||||
|
||||
hcl_cnode_t* hcl_makecnodenil (hcl_t* hcl, int flags, const hcl_loc_t* loc, const hcl_oocs_t* tok)
|
||||
hak_cnode_t* hak_makecnodenil (hak_t* hak, int flags, const hak_loc_t* loc, const hak_oocs_t* tok)
|
||||
{
|
||||
return hcl_makecnode(hcl, HCL_CNODE_NIL, flags, loc, tok);
|
||||
return hak_makecnode(hak, HAK_CNODE_NIL, flags, loc, tok);
|
||||
}
|
||||
|
||||
hcl_cnode_t* hcl_makecnodetrue (hcl_t* hcl, int flags, const hcl_loc_t* loc, const hcl_oocs_t* tok)
|
||||
hak_cnode_t* hak_makecnodetrue (hak_t* hak, int flags, const hak_loc_t* loc, const hak_oocs_t* tok)
|
||||
{
|
||||
return hcl_makecnode(hcl, HCL_CNODE_TRUE, flags, loc, tok);
|
||||
return hak_makecnode(hak, HAK_CNODE_TRUE, flags, loc, tok);
|
||||
}
|
||||
|
||||
hcl_cnode_t* hcl_makecnodefalse (hcl_t* hcl, int flags, const hcl_loc_t* loc, const hcl_oocs_t* tok)
|
||||
hak_cnode_t* hak_makecnodefalse (hak_t* hak, int flags, const hak_loc_t* loc, const hak_oocs_t* tok)
|
||||
{
|
||||
return hcl_makecnode(hcl, HCL_CNODE_FALSE, flags, loc, tok);
|
||||
return hak_makecnode(hak, HAK_CNODE_FALSE, flags, loc, tok);
|
||||
}
|
||||
|
||||
hcl_cnode_t* hcl_makecnodeself (hcl_t* hcl, int flags, const hcl_loc_t* loc, const hcl_oocs_t* tok)
|
||||
hak_cnode_t* hak_makecnodeself (hak_t* hak, int flags, const hak_loc_t* loc, const hak_oocs_t* tok)
|
||||
{
|
||||
return hcl_makecnode(hcl, HCL_CNODE_SELF, flags, loc, tok);
|
||||
return hak_makecnode(hak, HAK_CNODE_SELF, flags, loc, tok);
|
||||
}
|
||||
|
||||
hcl_cnode_t* hcl_makecnodesuper (hcl_t* hcl, int flags, const hcl_loc_t* loc, const hcl_oocs_t* tok)
|
||||
hak_cnode_t* hak_makecnodesuper (hak_t* hak, int flags, const hak_loc_t* loc, const hak_oocs_t* tok)
|
||||
{
|
||||
return hcl_makecnode(hcl, HCL_CNODE_SUPER, flags, loc, tok);
|
||||
return hak_makecnode(hak, HAK_CNODE_SUPER, flags, loc, tok);
|
||||
}
|
||||
|
||||
hcl_cnode_t* hcl_makecnodeellipsis (hcl_t* hcl, int flags, const hcl_loc_t* loc, const hcl_oocs_t* tok)
|
||||
hak_cnode_t* hak_makecnodeellipsis (hak_t* hak, int flags, const hak_loc_t* loc, const hak_oocs_t* tok)
|
||||
{
|
||||
return hcl_makecnode(hcl, HCL_CNODE_ELLIPSIS, flags, loc, tok);
|
||||
return hak_makecnode(hak, HAK_CNODE_ELLIPSIS, flags, loc, tok);
|
||||
}
|
||||
|
||||
hcl_cnode_t* hcl_makecnodetrpcolons (hcl_t* hcl, int flags, const hcl_loc_t* loc, const hcl_oocs_t* tok)
|
||||
hak_cnode_t* hak_makecnodetrpcolons (hak_t* hak, int flags, const hak_loc_t* loc, const hak_oocs_t* tok)
|
||||
{
|
||||
return hcl_makecnode(hcl, HCL_CNODE_TRPCOLONS, flags, loc, tok);
|
||||
return hak_makecnode(hak, HAK_CNODE_TRPCOLONS, flags, loc, tok);
|
||||
}
|
||||
|
||||
hcl_cnode_t* hcl_makecnodedblcolons (hcl_t* hcl, int flags, const hcl_loc_t* loc, const hcl_oocs_t* tok)
|
||||
hak_cnode_t* hak_makecnodedblcolons (hak_t* hak, int flags, const hak_loc_t* loc, const hak_oocs_t* tok)
|
||||
{
|
||||
return hcl_makecnode(hcl, HCL_CNODE_DBLCOLONS, flags, loc, tok);
|
||||
return hak_makecnode(hak, HAK_CNODE_DBLCOLONS, flags, loc, tok);
|
||||
}
|
||||
|
||||
hcl_cnode_t* hcl_makecnodecolon (hcl_t* hcl, int flags, const hcl_loc_t* loc, const hcl_oocs_t* tok)
|
||||
hak_cnode_t* hak_makecnodecolon (hak_t* hak, int flags, const hak_loc_t* loc, const hak_oocs_t* tok)
|
||||
{
|
||||
return hcl_makecnode(hcl, HCL_CNODE_COLON, flags, loc, tok);
|
||||
return hak_makecnode(hak, HAK_CNODE_COLON, flags, loc, tok);
|
||||
}
|
||||
|
||||
hcl_cnode_t* hcl_makecnodecolongt (hcl_t* hcl, int flags, const hcl_loc_t* loc, const hcl_oocs_t* tok)
|
||||
hak_cnode_t* hak_makecnodecolongt (hak_t* hak, int flags, const hak_loc_t* loc, const hak_oocs_t* tok)
|
||||
{
|
||||
return hcl_makecnode(hcl, HCL_CNODE_COLONGT, flags, loc, tok);
|
||||
return hak_makecnode(hak, HAK_CNODE_COLONGT, flags, loc, tok);
|
||||
}
|
||||
|
||||
hcl_cnode_t* hcl_makecnodecolonlt (hcl_t* hcl, int flags, const hcl_loc_t* loc, const hcl_oocs_t* tok)
|
||||
hak_cnode_t* hak_makecnodecolonlt (hak_t* hak, int flags, const hak_loc_t* loc, const hak_oocs_t* tok)
|
||||
{
|
||||
return hcl_makecnode(hcl, HCL_CNODE_COLONLT, flags, loc, tok);
|
||||
return hak_makecnode(hak, HAK_CNODE_COLONLT, flags, loc, tok);
|
||||
}
|
||||
|
||||
hcl_cnode_t* hcl_makecnodecharlit (hcl_t* hcl, int flags, const hcl_loc_t* loc, const hcl_oocs_t* tok, hcl_ooch_t v)
|
||||
hak_cnode_t* hak_makecnodecharlit (hak_t* hak, int flags, const hak_loc_t* loc, const hak_oocs_t* tok, hak_ooch_t v)
|
||||
{
|
||||
hcl_cnode_t* c = hcl_makecnode(hcl, HCL_CNODE_CHARLIT, flags, loc, tok);
|
||||
if (HCL_UNLIKELY(!c)) return HCL_NULL;
|
||||
hak_cnode_t* c = hak_makecnode(hak, HAK_CNODE_CHARLIT, flags, loc, tok);
|
||||
if (HAK_UNLIKELY(!c)) return HAK_NULL;
|
||||
c->u.charlit.v = v;
|
||||
return c;
|
||||
}
|
||||
|
||||
hcl_cnode_t* hcl_makecnodebchrlit (hcl_t* hcl, int flags, const hcl_loc_t* loc, const hcl_oocs_t* tok, hcl_oob_t v)
|
||||
hak_cnode_t* hak_makecnodebchrlit (hak_t* hak, int flags, const hak_loc_t* loc, const hak_oocs_t* tok, hak_oob_t v)
|
||||
{
|
||||
hcl_cnode_t* c = hcl_makecnode(hcl, HCL_CNODE_BCHRLIT, flags, loc, tok);
|
||||
if (HCL_UNLIKELY(!c)) return HCL_NULL;
|
||||
hak_cnode_t* c = hak_makecnode(hak, HAK_CNODE_BCHRLIT, flags, loc, tok);
|
||||
if (HAK_UNLIKELY(!c)) return HAK_NULL;
|
||||
c->u.bchrlit.v = v;
|
||||
return c;
|
||||
}
|
||||
|
||||
hcl_cnode_t* hcl_makecnodesymbol (hcl_t* hcl, int flags, const hcl_loc_t* loc, const hcl_oocs_t* tok)
|
||||
hak_cnode_t* hak_makecnodesymbol (hak_t* hak, int flags, const hak_loc_t* loc, const hak_oocs_t* tok)
|
||||
{
|
||||
return hcl_makecnode(hcl, HCL_CNODE_SYMBOL, flags, loc, tok);
|
||||
return hak_makecnode(hak, HAK_CNODE_SYMBOL, flags, loc, tok);
|
||||
}
|
||||
|
||||
hcl_cnode_t* hcl_makecnodedsymbol (hcl_t* hcl, int flags, const hcl_loc_t* loc, const hcl_oocs_t* tok, int is_cla)
|
||||
hak_cnode_t* hak_makecnodedsymbol (hak_t* hak, int flags, const hak_loc_t* loc, const hak_oocs_t* tok, int is_cla)
|
||||
{
|
||||
hcl_cnode_t* c = hcl_makecnode(hcl, HCL_CNODE_DSYMBOL, flags, loc, tok);
|
||||
if (HCL_UNLIKELY(!c)) return HCL_NULL;
|
||||
hak_cnode_t* c = hak_makecnode(hak, HAK_CNODE_DSYMBOL, flags, loc, tok);
|
||||
if (HAK_UNLIKELY(!c)) return HAK_NULL;
|
||||
c->u.dsymbol.is_cla = is_cla;
|
||||
return c;
|
||||
}
|
||||
|
||||
hcl_cnode_t* hcl_makecnodestrlit (hcl_t* hcl, int flags, const hcl_loc_t* loc, const hcl_oocs_t* tok)
|
||||
hak_cnode_t* hak_makecnodestrlit (hak_t* hak, int flags, const hak_loc_t* loc, const hak_oocs_t* tok)
|
||||
{
|
||||
return hcl_makecnode(hcl, HCL_CNODE_STRLIT, flags, loc, tok);
|
||||
return hak_makecnode(hak, HAK_CNODE_STRLIT, flags, loc, tok);
|
||||
}
|
||||
|
||||
hcl_cnode_t* hcl_makecnodebstrlit (hcl_t* hcl, int flags, const hcl_loc_t* loc, const hcl_oocs_t* tok)
|
||||
hak_cnode_t* hak_makecnodebstrlit (hak_t* hak, int flags, const hak_loc_t* loc, const hak_oocs_t* tok)
|
||||
{
|
||||
return hcl_makecnode(hcl, HCL_CNODE_BSTRLIT, flags, loc, tok);
|
||||
return hak_makecnode(hak, HAK_CNODE_BSTRLIT, flags, loc, tok);
|
||||
}
|
||||
|
||||
hcl_cnode_t* hcl_makecnodesymlit (hcl_t* hcl, int flags, const hcl_loc_t* loc, const hcl_oocs_t* tok)
|
||||
hak_cnode_t* hak_makecnodesymlit (hak_t* hak, int flags, const hak_loc_t* loc, const hak_oocs_t* tok)
|
||||
{
|
||||
return hcl_makecnode(hcl, HCL_CNODE_SYMLIT, flags, loc, tok);
|
||||
return hak_makecnode(hak, HAK_CNODE_SYMLIT, flags, loc, tok);
|
||||
}
|
||||
|
||||
hcl_cnode_t* hcl_makecnodenumlit (hcl_t* hcl, int flags, const hcl_loc_t* loc, const hcl_oocs_t* tok)
|
||||
hak_cnode_t* hak_makecnodenumlit (hak_t* hak, int flags, const hak_loc_t* loc, const hak_oocs_t* tok)
|
||||
{
|
||||
return hcl_makecnode(hcl, HCL_CNODE_NUMLIT, flags, loc, tok);
|
||||
return hak_makecnode(hak, HAK_CNODE_NUMLIT, flags, loc, tok);
|
||||
}
|
||||
|
||||
hcl_cnode_t* hcl_makecnoderadnumlit (hcl_t* hcl, int flags, const hcl_loc_t* loc, const hcl_oocs_t* tok)
|
||||
hak_cnode_t* hak_makecnoderadnumlit (hak_t* hak, int flags, const hak_loc_t* loc, const hak_oocs_t* tok)
|
||||
{
|
||||
return hcl_makecnode(hcl, HCL_CNODE_RADNUMLIT, flags, loc, tok);
|
||||
return hak_makecnode(hak, HAK_CNODE_RADNUMLIT, flags, loc, tok);
|
||||
}
|
||||
|
||||
hcl_cnode_t* hcl_makecnodefpdeclit (hcl_t* hcl, int flags, const hcl_loc_t* loc, const hcl_oocs_t* tok)
|
||||
hak_cnode_t* hak_makecnodefpdeclit (hak_t* hak, int flags, const hak_loc_t* loc, const hak_oocs_t* tok)
|
||||
{
|
||||
return hcl_makecnode(hcl, HCL_CNODE_FPDECLIT, flags, loc, tok);
|
||||
return hak_makecnode(hak, HAK_CNODE_FPDECLIT, flags, loc, tok);
|
||||
}
|
||||
|
||||
hcl_cnode_t* hcl_makecnodesmptrlit (hcl_t* hcl, int flags, const hcl_loc_t* loc, const hcl_oocs_t* tok, hcl_oow_t v)
|
||||
hak_cnode_t* hak_makecnodesmptrlit (hak_t* hak, int flags, const hak_loc_t* loc, const hak_oocs_t* tok, hak_oow_t v)
|
||||
{
|
||||
hcl_cnode_t* c = hcl_makecnode(hcl, HCL_CNODE_SMPTRLIT, flags, loc, tok);
|
||||
if (HCL_UNLIKELY(!c)) return HCL_NULL;
|
||||
hak_cnode_t* c = hak_makecnode(hak, HAK_CNODE_SMPTRLIT, flags, loc, tok);
|
||||
if (HAK_UNLIKELY(!c)) return HAK_NULL;
|
||||
c->u.smptrlit.v = v;
|
||||
return c;
|
||||
}
|
||||
|
||||
hcl_cnode_t* hcl_makecnodeerrlit (hcl_t* hcl, int flags, const hcl_loc_t* loc, const hcl_oocs_t* tok, hcl_ooi_t v)
|
||||
hak_cnode_t* hak_makecnodeerrlit (hak_t* hak, int flags, const hak_loc_t* loc, const hak_oocs_t* tok, hak_ooi_t v)
|
||||
{
|
||||
hcl_cnode_t* c = hcl_makecnode(hcl, HCL_CNODE_ERRLIT, flags, loc, tok);
|
||||
if (HCL_UNLIKELY(!c)) return HCL_NULL;
|
||||
hak_cnode_t* c = hak_makecnode(hak, HAK_CNODE_ERRLIT, flags, loc, tok);
|
||||
if (HAK_UNLIKELY(!c)) return HAK_NULL;
|
||||
c->u.errlit.v = v;
|
||||
return c;
|
||||
}
|
||||
|
||||
hcl_cnode_t* hcl_makecnodecons (hcl_t* hcl, int flags, const hcl_loc_t* loc, const hcl_oocs_t* tok, hcl_cnode_t* car, hcl_cnode_t* cdr)
|
||||
hak_cnode_t* hak_makecnodecons (hak_t* hak, int flags, const hak_loc_t* loc, const hak_oocs_t* tok, hak_cnode_t* car, hak_cnode_t* cdr)
|
||||
{
|
||||
hcl_cnode_t* c = hcl_makecnode(hcl, HCL_CNODE_CONS, flags, loc, tok);
|
||||
if (HCL_UNLIKELY(!c)) return HCL_NULL;
|
||||
hak_cnode_t* c = hak_makecnode(hak, HAK_CNODE_CONS, flags, loc, tok);
|
||||
if (HAK_UNLIKELY(!c)) return HAK_NULL;
|
||||
c->u.cons.car = car;
|
||||
c->u.cons.cdr = cdr;
|
||||
return c;
|
||||
}
|
||||
|
||||
hcl_cnode_t* hcl_makecnodeelist (hcl_t* hcl, int flags, const hcl_loc_t* loc, hcl_concode_t type)
|
||||
hak_cnode_t* hak_makecnodeelist (hak_t* hak, int flags, const hak_loc_t* loc, hak_concode_t type)
|
||||
{
|
||||
hcl_cnode_t* c = hcl_makecnode(hcl, HCL_CNODE_ELIST, flags, loc, HCL_NULL);
|
||||
if (HCL_UNLIKELY(!c)) return HCL_NULL;
|
||||
hak_cnode_t* c = hak_makecnode(hak, HAK_CNODE_ELIST, flags, loc, HAK_NULL);
|
||||
if (HAK_UNLIKELY(!c)) return HAK_NULL;
|
||||
c->u.elist.concode = type;
|
||||
return c;
|
||||
}
|
||||
|
||||
hcl_cnode_t* hcl_makecnodeshell (hcl_t* hcl, int flags, const hcl_loc_t* loc, hcl_cnode_t* obj)
|
||||
hak_cnode_t* hak_makecnodeshell (hak_t* hak, int flags, const hak_loc_t* loc, hak_cnode_t* obj)
|
||||
{
|
||||
hcl_cnode_t* c = hcl_makecnode(hcl, HCL_CNODE_SHELL, flags, loc, HCL_NULL);
|
||||
if (HCL_UNLIKELY(!c)) return HCL_NULL;
|
||||
hak_cnode_t* c = hak_makecnode(hak, HAK_CNODE_SHELL, flags, loc, HAK_NULL);
|
||||
if (HAK_UNLIKELY(!c)) return HAK_NULL;
|
||||
c->u.shell.obj = obj;
|
||||
return c;
|
||||
}
|
||||
|
||||
void hcl_freesinglecnode (hcl_t* hcl, hcl_cnode_t* c)
|
||||
void hak_freesinglecnode (hak_t* hak, hak_cnode_t* c)
|
||||
{
|
||||
hcl_freemem (hcl, c);
|
||||
hak_freemem (hak, c);
|
||||
}
|
||||
|
||||
void hcl_freecnode (hcl_t* hcl, hcl_cnode_t* c)
|
||||
void hak_freecnode (hak_t* hak, hak_cnode_t* c)
|
||||
{
|
||||
redo:
|
||||
switch (c->cn_type)
|
||||
{
|
||||
case HCL_CNODE_CONS:
|
||||
case HAK_CNODE_CONS:
|
||||
{
|
||||
hcl_cnode_t* tmp1, * tmp2;
|
||||
hak_cnode_t* tmp1, * tmp2;
|
||||
|
||||
tmp1 = c->u.cons.car;
|
||||
tmp2 = c->u.cons.cdr;
|
||||
|
||||
HCL_ASSERT (hcl, tmp1 != HCL_NULL);
|
||||
hcl_freemem (hcl, c);
|
||||
hcl_freecnode (hcl, tmp1); /* TODO: remove recursion? */
|
||||
HAK_ASSERT (hak, tmp1 != HAK_NULL);
|
||||
hak_freemem (hak, c);
|
||||
hak_freecnode (hak, tmp1); /* TODO: remove recursion? */
|
||||
if (tmp2)
|
||||
{
|
||||
c = tmp2;
|
||||
@ -235,12 +235,12 @@ redo:
|
||||
break;
|
||||
}
|
||||
|
||||
case HCL_CNODE_SHELL:
|
||||
case HAK_CNODE_SHELL:
|
||||
{
|
||||
hcl_cnode_t* tmp;
|
||||
hak_cnode_t* tmp;
|
||||
|
||||
tmp = c->u.shell.obj;
|
||||
hcl_freemem (hcl, c);
|
||||
hak_freemem (hak, c);
|
||||
if (tmp)
|
||||
{
|
||||
c = tmp;
|
||||
@ -251,20 +251,20 @@ redo:
|
||||
}
|
||||
|
||||
default:
|
||||
hcl_freemem (hcl, c);
|
||||
hak_freemem (hak, c);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
hcl_oow_t hcl_countcnodecons (hcl_t* hcl, hcl_cnode_t* cons)
|
||||
hak_oow_t hak_countcnodecons (hak_t* hak, hak_cnode_t* cons)
|
||||
{
|
||||
/* this function ignores the last cdr */
|
||||
hcl_oow_t count = 1;
|
||||
hak_oow_t count = 1;
|
||||
|
||||
HCL_ASSERT (hcl, HCL_CNODE_IS_CONS(cons));
|
||||
HAK_ASSERT (hak, HAK_CNODE_IS_CONS(cons));
|
||||
do
|
||||
{
|
||||
cons = HCL_CNODE_CONS_CDR(cons);
|
||||
cons = HAK_CNODE_CONS_CDR(cons);
|
||||
if (!cons) break;
|
||||
count++;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user