more code to implement a new object reader

This commit is contained in:
hyung-hwan 2021-01-10 16:04:36 +00:00
parent 8936bb5bec
commit 963f162c4e
4 changed files with 37 additions and 18 deletions

View File

@ -7,10 +7,10 @@
modification, are permitted provided that the following conditions modification, are permitted provided that the following conditions
are met: are met:
1. Redistributions of source code must retain the above copyright 1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer. notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright 2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution. documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
@ -61,8 +61,6 @@ hcl_cnode_t* hcl_makecnodecharlit (hcl_t* hcl, const hcl_ioloc_t* loc, const hcl
return c; return c;
} }
hcl_cnode_t* hcl_makecnodenumlit (hcl_t* hcl, const hcl_ioloc_t* loc, const hcl_ooch_t* ptr, hcl_oow_t len) hcl_cnode_t* hcl_makecnodenumlit (hcl_t* hcl, const hcl_ioloc_t* loc, const hcl_ooch_t* ptr, hcl_oow_t len)
{ {
hcl_cnode_t* c = make_cnode(hcl, HCL_CNODE_NUMLIT, loc, HCL_SIZEOF(*ptr) * (len + 1)); hcl_cnode_t* c = make_cnode(hcl, HCL_CNODE_NUMLIT, loc, HCL_SIZEOF(*ptr) * (len + 1));
@ -91,7 +89,6 @@ hcl_cnode_t* hcl_makecnodefpdeclit (hcl_t* hcl, const hcl_ioloc_t* loc, const hc
{ {
hcl_cnode_t* c = make_cnode(hcl, HCL_CNODE_FPDECLIT, loc, HCL_SIZEOF(*ptr) * (len + 1)); hcl_cnode_t* c = make_cnode(hcl, HCL_CNODE_FPDECLIT, loc, HCL_SIZEOF(*ptr) * (len + 1));
if (HCL_UNLIKELY(!c)) return HCL_NULL; if (HCL_UNLIKELY(!c)) return HCL_NULL;
c->u.fpdeclit.ptr = (hcl_ooch_t*)(c + 1); c->u.fpdeclit.ptr = (hcl_ooch_t*)(c + 1);
c->u.fpdeclit.len = len; c->u.fpdeclit.len = len;
hcl_copy_oochars (c->u.fpdeclit.ptr, ptr, len); hcl_copy_oochars (c->u.fpdeclit.ptr, ptr, len);
@ -103,7 +100,6 @@ hcl_cnode_t* hcl_makecnodestrlit (hcl_t* hcl, const hcl_ioloc_t* loc, const hcl_
{ {
hcl_cnode_t* c = make_cnode(hcl, HCL_CNODE_STRLIT, loc, HCL_SIZEOF(*ptr) * (len + 1)); hcl_cnode_t* c = make_cnode(hcl, HCL_CNODE_STRLIT, loc, HCL_SIZEOF(*ptr) * (len + 1));
if (HCL_UNLIKELY(!c)) return HCL_NULL; if (HCL_UNLIKELY(!c)) return HCL_NULL;
c->u.strlit.ptr = (hcl_ooch_t*)(c + 1); c->u.strlit.ptr = (hcl_ooch_t*)(c + 1);
c->u.strlit.len = len; c->u.strlit.len = len;
hcl_copy_oochars (c->u.strlit.ptr, ptr, len); hcl_copy_oochars (c->u.strlit.ptr, ptr, len);
@ -111,12 +107,27 @@ hcl_cnode_t* hcl_makecnodestrlit (hcl_t* hcl, const hcl_ioloc_t* loc, const hcl_
return c; return c;
} }
hcl_cnode_t* hcl_makecnodesmptrlit (hcl_t* hcl, const hcl_ioloc_t* loc, hcl_oow_t v)
{
hcl_cnode_t* c = make_cnode(hcl, HCL_CNODE_ERRLIT, loc, 0);
if (HCL_UNLIKELY(!c)) return HCL_NULL;
c->u.smptrlit.v = v;
return c;
}
hcl_cnode_t* hcl_makecnodeerrlit (hcl_t* hcl, const hcl_ioloc_t* loc, hcl_ooi_t v) hcl_cnode_t* hcl_makecnodeerrlit (hcl_t* hcl, const hcl_ioloc_t* loc, hcl_ooi_t v)
{ {
hcl_cnode_t* c = make_cnode(hcl, HCL_CNODE_ERRLIT, loc, 0); hcl_cnode_t* c = make_cnode(hcl, HCL_CNODE_ERRLIT, loc, 0);
if (HCL_UNLIKELY(!c)) return HCL_NULL; if (HCL_UNLIKELY(!c)) return HCL_NULL;
c->u.errlit.v = v; c->u.errlit.v = v;
return c; return c;
} }
hcl_cnode_t* hcl_makecnodecons (hcl_t* hcl, const hcl_ioloc_t* loc, hcl_cnode_t* car, hcl_cnode_t* cdr)
{
hcl_cnode_t* c = make_cnode(hcl, HCL_CNODE_ERRLIT, loc, 0);
if (HCL_UNLIKELY(!c)) return HCL_NULL;
c->u.cons.car = car;
c->u.cons.cdr = cdr;
return c;
}

View File

@ -218,6 +218,7 @@ enum hcl_cnode_type_t
typedef enum hcl_cnode_type_t hcl_cnode_type_t; typedef enum hcl_cnode_type_t hcl_cnode_type_t;
/* NOTE: hcl_cnode_t used by the built-in compiler is not an OOP object */ /* NOTE: hcl_cnode_t used by the built-in compiler is not an OOP object */
typedef struct hcl_cnode_t hcl_cnode_t;
struct hcl_cnode_t struct hcl_cnode_t
{ {
hcl_cnode_type_t type; hcl_cnode_type_t type;
@ -250,12 +251,20 @@ struct hcl_cnode_t
hcl_oow_t len; hcl_oow_t len;
} fpdeclit; } fpdeclit;
struct struct
{
hcl_oow_t v;
} smptrlit;
struct
{ {
hcl_ooi_t v; hcl_ooi_t v;
} errlit; } errlit;
struct
{
hcl_cnode_t* car;
hcl_cnode_t* cdr;
} cons;
} u; } u;
}; };
typedef struct hcl_cnode_t hcl_cnode_t;
/* NOTE: hcl_cframe_t used by the built-in compiler is not an OOP object */ /* NOTE: hcl_cframe_t used by the built-in compiler is not an OOP object */
struct hcl_cframe_t struct hcl_cframe_t
@ -968,7 +977,7 @@ hcl_oop_t hcl_divints (
hcl_t* hcl, hcl_t* hcl,
hcl_oop_t x, hcl_oop_t x,
hcl_oop_t y, hcl_oop_t y,
int modulo, int modulo,
hcl_oop_t* rem hcl_oop_t* rem
); );
@ -1236,7 +1245,9 @@ hcl_cnode_t* hcl_makecnodestrlit (hcl_t* hcl, const hcl_ioloc_t* loc, const hcl_
hcl_cnode_t* hcl_makecnodenumlit (hcl_t* hcl, const hcl_ioloc_t* loc, const hcl_ooch_t* ptr, hcl_oow_t len); hcl_cnode_t* hcl_makecnodenumlit (hcl_t* hcl, const hcl_ioloc_t* loc, const hcl_ooch_t* ptr, hcl_oow_t len);
hcl_cnode_t* hcl_makecnoderadnumlit (hcl_t* hcl, const hcl_ioloc_t* loc, const hcl_ooch_t* ptr, hcl_oow_t len); hcl_cnode_t* hcl_makecnoderadnumlit (hcl_t* hcl, const hcl_ioloc_t* loc, const hcl_ooch_t* ptr, hcl_oow_t len);
hcl_cnode_t* hcl_makecnodefpdeclit (hcl_t* hcl, const hcl_ioloc_t* loc, const hcl_ooch_t* ptr, hcl_oow_t len); hcl_cnode_t* hcl_makecnodefpdeclit (hcl_t* hcl, const hcl_ioloc_t* loc, const hcl_ooch_t* ptr, hcl_oow_t len);
hcl_cnode_t* hcl_makecnodesmptrlit (hcl_t* hcl, const hcl_ioloc_t* loc, hcl_oow_t v);
hcl_cnode_t* hcl_makecnodeerrlit (hcl_t* hcl, const hcl_ioloc_t* loc, hcl_ooi_t v); hcl_cnode_t* hcl_makecnodeerrlit (hcl_t* hcl, const hcl_ioloc_t* loc, hcl_ooi_t v);
hcl_cnode_t* hcl_makecnodecons (hcl_t* hcl, const hcl_ioloc_t* loc, hcl_cnode_t* car, hcl_cnode_t* cdr);
#if defined(__cplusplus) #if defined(__cplusplus)
} }

View File

@ -1693,7 +1693,7 @@ static hcl_oop_t chain_to_list (hcl_t* hcl, hcl_oop_t obj)
hcl_pushvolat (hcl, (hcl_oop_t*)&rsa); hcl_pushvolat (hcl, (hcl_oop_t*)&rsa);
cons = hcl_makecons(hcl, obj, hcl->_nil); cons = hcl_makecons(hcl, obj, hcl->_nil);
hcl_popvolat (hcl); hcl_popvolat (hcl);
if (!cons) return HCL_NULL; if (HCL_UNLIKELY(!cons)) return HCL_NULL;
if (HCL_IS_NIL(hcl, rsa->slot[0])) if (HCL_IS_NIL(hcl, rsa->slot[0]))
{ {

View File

@ -1635,7 +1635,7 @@ static HCL_INLINE void clear_comma_colon_flag (hcl_t* hcl)
rsa->slot[2] = HCL_SMOOI_TO_OOP(flagv); rsa->slot[2] = HCL_SMOOI_TO_OOP(flagv);
} }
static hcl_oop_t chain_to_list (hcl_t* hcl, hcl_oop_t obj) static hcl_oop_t chain_to_list (hcl_t* hcl, hcl_cnode_t* obj)
{ {
hcl_oop_oop_t rsa; hcl_oop_oop_t rsa;
int flagv; int flagv;
@ -1690,9 +1690,9 @@ static hcl_oop_t chain_to_list (hcl_t* hcl, hcl_oop_t obj)
} }
hcl_pushvolat (hcl, (hcl_oop_t*)&rsa); hcl_pushvolat (hcl, (hcl_oop_t*)&rsa);
cons = hcl_makecons(hcl, obj, hcl->_nil); cons = hcl_makecnodecons(hcl, &obj->loc, obj, HCL_NULL);
hcl_popvolat (hcl); hcl_popvolat (hcl);
if (!cons) return HCL_NULL; if (HCL_UNLIKELY(!cons)) return HCL_NULL;
if (HCL_IS_NIL(hcl, rsa->slot[0])) if (HCL_IS_NIL(hcl, rsa->slot[0]))
{ {
@ -2027,7 +2027,7 @@ static int read_object (hcl_t* hcl)
return -1; return -1;
} }
obj = HCL_SMPTR_TO_OOP(v); cnode = hcl_makecnodesmptrlit(hcl, TOKEN_LOC(hcl), v);
break; break;
} }
@ -2058,17 +2058,14 @@ static int read_object (hcl_t* hcl)
break; break;
case HCL_IOTOK_NUMLIT: case HCL_IOTOK_NUMLIT:
//obj = string_to_num(hcl, TOKEN_NAME(hcl), TOKEN_TYPE(hcl) == HCL_IOTOK_RADNUMLIT);
cnode = hcl_makecnodenumlit(hcl, TOKEN_LOC(hcl), TOKEN_NAME_PTR(hcl), TOKEN_NAME_LEN(hcl)); cnode = hcl_makecnodenumlit(hcl, TOKEN_LOC(hcl), TOKEN_NAME_PTR(hcl), TOKEN_NAME_LEN(hcl));
break; break;
case HCL_IOTOK_RADNUMLIT: case HCL_IOTOK_RADNUMLIT:
//obj = string_to_num(hcl, TOKEN_NAME(hcl), TOKEN_TYPE(hcl) == HCL_IOTOK_RADNUMLIT);
cnode = hcl_makecnoderadnumlit(hcl, TOKEN_LOC(hcl), TOKEN_NAME_PTR(hcl), TOKEN_NAME_LEN(hcl)); cnode = hcl_makecnoderadnumlit(hcl, TOKEN_LOC(hcl), TOKEN_NAME_PTR(hcl), TOKEN_NAME_LEN(hcl));
break; break;
case HCL_IOTOK_FPDECLIT: case HCL_IOTOK_FPDECLIT:
//obj = string_to_fpdec(hcl, TOKEN_NAME(hcl), TOKEN_LOC(hcl));
cnode = hcl_makecnodefpdeclit(hcl, TOKEN_LOC(hcl), TOKEN_NAME_PTR(hcl), TOKEN_NAME_LEN(hcl)); cnode = hcl_makecnodefpdeclit(hcl, TOKEN_LOC(hcl), TOKEN_NAME_PTR(hcl), TOKEN_NAME_LEN(hcl));
break; break;