experimenting with the new reader

This commit is contained in:
hyung-hwan 2021-01-15 09:12:28 +00:00
parent 554667b227
commit b327791484
9 changed files with 3136 additions and 73 deletions

View File

@ -810,7 +810,7 @@ static int handle_logopt (hcl_t* hcl, const hcl_bch_t* str)
#if defined(HCL_BUILD_DEBUG)
static int handle_dbgopt (hcl_t* hcl, const hcl_bch_t* str)
{
xtn_t* xtn = (xtn_t*)hcl_getxtn(hcl);
/*xtn_t* xtn = (xtn_t*)hcl_getxtn(hcl);*/
const hcl_bch_t* cm, * flt;
hcl_oow_t len;
hcl_bitmask_t trait, dbgopt = 0;
@ -1173,6 +1173,48 @@ hcl_logufmt (hcl, HCL_LOG_WARN, fmt, ustr, 0x6789);
}
#endif
#if 0
////////////////////////////
{
hcl_cnode_t* xx;
while (1)
{
xx = hcl_read2(hcl);
if (!xx)
{
if (hcl->errnum == HCL_EFINIS)
{
/* end of input */
break;
}
else if (hcl->errnum == HCL_ESYNERR)
{
print_synerr (hcl);
if (xtn->reader_istty && hcl_getsynerrnum(hcl) != HCL_SYNERR_EOF)
{
/* TODO: drain remaining data in the reader including the actual inputstream and buffered data in hcl */
}
continue;
}
else
{
hcl_logbfmt (hcl, HCL_LOG_STDERR, "ERROR: cannot read object - [%d] %js\n", hcl_geterrnum(hcl), hcl_geterrmsg(hcl));
}
goto oops;
}
else
{
hcl_logbfmt (hcl, HCL_LOG_STDERR, "OK: got cnode - %p\n", xx);
hcl_freecnode (hcl, xx);
}
}
}
////////////////////////////
#endif
while (1)
{
hcl_oop_t obj;

View File

@ -66,6 +66,7 @@ libhcl_la_SOURCES = \
bigint.c \
cnode.c \
comp.c \
comp2.c \
debug.c \
decode.c \
dic.c \
@ -83,6 +84,7 @@ libhcl_la_SOURCES = \
prim.c \
print.c \
rbt.c \
read.c \
read2.c \
sym.c \
utf8.c \

View File

@ -151,13 +151,14 @@ am__DEPENDENCIES_5 = $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_2) \
$(am__DEPENDENCIES_3) $(am__DEPENDENCIES_4)
libhcl_la_DEPENDENCIES = $(am__DEPENDENCIES_5) $(am__append_6)
am_libhcl_la_OBJECTS = libhcl_la-bigint.lo libhcl_la-cnode.lo \
libhcl_la-comp.lo libhcl_la-debug.lo libhcl_la-decode.lo \
libhcl_la-dic.lo libhcl_la-err.lo libhcl_la-exec.lo \
libhcl_la-fmt.lo libhcl_la-gc.lo libhcl_la-hcl.lo \
libhcl_la-heap.lo libhcl_la-number.lo libhcl_la-obj.lo \
libhcl_la-opt.lo libhcl_la-prim.lo libhcl_la-print.lo \
libhcl_la-rbt.lo libhcl_la-read2.lo libhcl_la-sym.lo \
libhcl_la-utf8.lo libhcl_la-utl.lo libhcl_la-xma.lo
libhcl_la-comp.lo libhcl_la-comp2.lo libhcl_la-debug.lo \
libhcl_la-decode.lo libhcl_la-dic.lo libhcl_la-err.lo \
libhcl_la-exec.lo libhcl_la-fmt.lo libhcl_la-gc.lo \
libhcl_la-hcl.lo libhcl_la-heap.lo libhcl_la-number.lo \
libhcl_la-obj.lo libhcl_la-opt.lo libhcl_la-prim.lo \
libhcl_la-print.lo libhcl_la-rbt.lo libhcl_la-read.lo \
libhcl_la-read2.lo libhcl_la-sym.lo libhcl_la-utf8.lo \
libhcl_la-utl.lo libhcl_la-xma.lo
libhcl_la_OBJECTS = $(am_libhcl_la_OBJECTS)
AM_V_lt = $(am__v_lt_@AM_V@)
am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@)
@ -197,6 +198,7 @@ depcomp = $(SHELL) $(top_srcdir)/ac/depcomp
am__maybe_remake_depfiles = depfiles
am__depfiles_remade = ./$(DEPDIR)/libhcl_la-bigint.Plo \
./$(DEPDIR)/libhcl_la-cnode.Plo ./$(DEPDIR)/libhcl_la-comp.Plo \
./$(DEPDIR)/libhcl_la-comp2.Plo \
./$(DEPDIR)/libhcl_la-debug.Plo \
./$(DEPDIR)/libhcl_la-decode.Plo ./$(DEPDIR)/libhcl_la-dic.Plo \
./$(DEPDIR)/libhcl_la-err.Plo ./$(DEPDIR)/libhcl_la-exec.Plo \
@ -205,9 +207,9 @@ am__depfiles_remade = ./$(DEPDIR)/libhcl_la-bigint.Plo \
./$(DEPDIR)/libhcl_la-number.Plo ./$(DEPDIR)/libhcl_la-obj.Plo \
./$(DEPDIR)/libhcl_la-opt.Plo ./$(DEPDIR)/libhcl_la-prim.Plo \
./$(DEPDIR)/libhcl_la-print.Plo ./$(DEPDIR)/libhcl_la-rbt.Plo \
./$(DEPDIR)/libhcl_la-read2.Plo ./$(DEPDIR)/libhcl_la-sym.Plo \
./$(DEPDIR)/libhcl_la-utf8.Plo ./$(DEPDIR)/libhcl_la-utl.Plo \
./$(DEPDIR)/libhcl_la-xma.Plo \
./$(DEPDIR)/libhcl_la-read.Plo ./$(DEPDIR)/libhcl_la-read2.Plo \
./$(DEPDIR)/libhcl_la-sym.Plo ./$(DEPDIR)/libhcl_la-utf8.Plo \
./$(DEPDIR)/libhcl_la-utl.Plo ./$(DEPDIR)/libhcl_la-xma.Plo \
./$(DEPDIR)/libhclx_la-cb-impl.Plo \
./$(DEPDIR)/libhclx_la-hcl-c.Plo \
./$(DEPDIR)/libhclx_la-hcl-s.Plo \
@ -438,6 +440,7 @@ libhcl_la_SOURCES = \
bigint.c \
cnode.c \
comp.c \
comp2.c \
debug.c \
decode.c \
dic.c \
@ -455,6 +458,7 @@ libhcl_la_SOURCES = \
prim.c \
print.c \
rbt.c \
read.c \
read2.c \
sym.c \
utf8.c \
@ -575,6 +579,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhcl_la-bigint.Plo@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhcl_la-cnode.Plo@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhcl_la-comp.Plo@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhcl_la-comp2.Plo@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhcl_la-debug.Plo@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhcl_la-decode.Plo@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhcl_la-dic.Plo@am__quote@ # am--include-marker
@ -590,6 +595,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhcl_la-prim.Plo@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhcl_la-print.Plo@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhcl_la-rbt.Plo@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhcl_la-read.Plo@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhcl_la-read2.Plo@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhcl_la-sym.Plo@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhcl_la-utf8.Plo@am__quote@ # am--include-marker
@ -653,6 +659,13 @@ libhcl_la-comp.lo: comp.c
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libhcl_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libhcl_la-comp.lo `test -f 'comp.c' || echo '$(srcdir)/'`comp.c
libhcl_la-comp2.lo: comp2.c
@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libhcl_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libhcl_la-comp2.lo -MD -MP -MF $(DEPDIR)/libhcl_la-comp2.Tpo -c -o libhcl_la-comp2.lo `test -f 'comp2.c' || echo '$(srcdir)/'`comp2.c
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libhcl_la-comp2.Tpo $(DEPDIR)/libhcl_la-comp2.Plo
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='comp2.c' object='libhcl_la-comp2.lo' libtool=yes @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libhcl_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libhcl_la-comp2.lo `test -f 'comp2.c' || echo '$(srcdir)/'`comp2.c
libhcl_la-debug.lo: debug.c
@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libhcl_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libhcl_la-debug.lo -MD -MP -MF $(DEPDIR)/libhcl_la-debug.Tpo -c -o libhcl_la-debug.lo `test -f 'debug.c' || echo '$(srcdir)/'`debug.c
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libhcl_la-debug.Tpo $(DEPDIR)/libhcl_la-debug.Plo
@ -758,6 +771,13 @@ libhcl_la-rbt.lo: rbt.c
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libhcl_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libhcl_la-rbt.lo `test -f 'rbt.c' || echo '$(srcdir)/'`rbt.c
libhcl_la-read.lo: read.c
@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libhcl_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libhcl_la-read.lo -MD -MP -MF $(DEPDIR)/libhcl_la-read.Tpo -c -o libhcl_la-read.lo `test -f 'read.c' || echo '$(srcdir)/'`read.c
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libhcl_la-read.Tpo $(DEPDIR)/libhcl_la-read.Plo
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='read.c' object='libhcl_la-read.lo' libtool=yes @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libhcl_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libhcl_la-read.lo `test -f 'read.c' || echo '$(srcdir)/'`read.c
libhcl_la-read2.lo: read2.c
@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libhcl_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libhcl_la-read2.lo -MD -MP -MF $(DEPDIR)/libhcl_la-read2.Tpo -c -o libhcl_la-read2.lo `test -f 'read2.c' || echo '$(srcdir)/'`read2.c
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libhcl_la-read2.Tpo $(DEPDIR)/libhcl_la-read2.Plo
@ -993,6 +1013,7 @@ distclean: distclean-am
-rm -f ./$(DEPDIR)/libhcl_la-bigint.Plo
-rm -f ./$(DEPDIR)/libhcl_la-cnode.Plo
-rm -f ./$(DEPDIR)/libhcl_la-comp.Plo
-rm -f ./$(DEPDIR)/libhcl_la-comp2.Plo
-rm -f ./$(DEPDIR)/libhcl_la-debug.Plo
-rm -f ./$(DEPDIR)/libhcl_la-decode.Plo
-rm -f ./$(DEPDIR)/libhcl_la-dic.Plo
@ -1008,6 +1029,7 @@ distclean: distclean-am
-rm -f ./$(DEPDIR)/libhcl_la-prim.Plo
-rm -f ./$(DEPDIR)/libhcl_la-print.Plo
-rm -f ./$(DEPDIR)/libhcl_la-rbt.Plo
-rm -f ./$(DEPDIR)/libhcl_la-read.Plo
-rm -f ./$(DEPDIR)/libhcl_la-read2.Plo
-rm -f ./$(DEPDIR)/libhcl_la-sym.Plo
-rm -f ./$(DEPDIR)/libhcl_la-utf8.Plo
@ -1068,6 +1090,7 @@ maintainer-clean: maintainer-clean-am
-rm -f ./$(DEPDIR)/libhcl_la-bigint.Plo
-rm -f ./$(DEPDIR)/libhcl_la-cnode.Plo
-rm -f ./$(DEPDIR)/libhcl_la-comp.Plo
-rm -f ./$(DEPDIR)/libhcl_la-comp2.Plo
-rm -f ./$(DEPDIR)/libhcl_la-debug.Plo
-rm -f ./$(DEPDIR)/libhcl_la-decode.Plo
-rm -f ./$(DEPDIR)/libhcl_la-dic.Plo
@ -1083,6 +1106,7 @@ maintainer-clean: maintainer-clean-am
-rm -f ./$(DEPDIR)/libhcl_la-prim.Plo
-rm -f ./$(DEPDIR)/libhcl_la-print.Plo
-rm -f ./$(DEPDIR)/libhcl_la-rbt.Plo
-rm -f ./$(DEPDIR)/libhcl_la-read.Plo
-rm -f ./$(DEPDIR)/libhcl_la-read2.Plo
-rm -f ./$(DEPDIR)/libhcl_la-sym.Plo
-rm -f ./$(DEPDIR)/libhcl_la-utf8.Plo

View File

@ -167,8 +167,9 @@ redo:
hcl_cnode_t* tmp;
tmp = c->u.list.head;
hcl_freemem (hcl, c);
if (tmp)
if (tmp) /* it's not set for an empty list */
{
c = tmp;
goto redo;
}
@ -182,7 +183,10 @@ redo:
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? */
if (tmp2)
@ -190,9 +194,12 @@ redo:
c = tmp2;
goto redo;
}
break;
}
default:
hcl_freemem (hcl, c);
break;
}
}

View File

@ -2770,7 +2770,7 @@ static HCL_INLINE int emit_set (hcl_t* hcl)
/* ========================================================================= */
int hcl_compile (hcl_t* hcl, hcl_oop_t obj)
int hcl_compile2 (hcl_t* hcl, hcl_oop_t obj)
{
hcl_oow_t saved_bc_len, saved_lit_len;
hcl_bitmask_t log_default_type_mask;

2993
lib/comp2.c Normal file

File diff suppressed because it is too large Load Diff

View File

@ -216,7 +216,6 @@ enum 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 */
typedef struct hcl_cnode_t hcl_cnode_t;
struct hcl_cnode_t
{
hcl_cnode_type_t type;
@ -376,9 +375,7 @@ struct hcl_compiler_t
{
hcl_oop_t s; /* stack for reading */
hcl_oop_t e; /* last object read */
hcl_rstl_t* st;
hcl_cnode_t* ecn; /* last object cnode read */
struct
{

View File

@ -1368,6 +1368,7 @@ struct hcl_synerr_t
#if defined(HCL_INCLUDE_COMPILER)
typedef struct hcl_compiler_t hcl_compiler_t;
typedef struct hcl_cnode_t hcl_cnode_t;
#endif
#define HCL_ERRMSG_CAPA (2048)
@ -1977,6 +1978,10 @@ HCL_EXPORT hcl_oop_t hcl_read (
hcl_t* hcl
);
HCL_EXPORT hcl_cnode_t* hcl_read2 (
hcl_t* hcl
);
HCL_EXPORT int hcl_print (
hcl_t* hcl,

View File

@ -414,7 +414,7 @@ static HCL_INLINE int add_token_char (hcl_t* hcl, hcl_ooch_t c)
tmp.ptr = &c;
tmp.len = 1;
return copy_string_to (hcl, &tmp, TOKEN_NAME(hcl), &TOKEN_NAME_CAPA(hcl), 1, '\0');
return copy_string_to(hcl, &tmp, TOKEN_NAME(hcl), &TOKEN_NAME_CAPA(hcl), 1, '\0');
}
static HCL_INLINE void unget_char (hcl_t* hcl, const hcl_iolxc_t* c)
@ -1438,6 +1438,7 @@ static HCL_INLINE hcl_cnode_t* leave_list (hcl_t* hcl, int* flagv, int* oldflagv
if (fv & (COMMAED | COLONED))
{
hcl_setsynerr (hcl, ((fv & COMMAED)? HCL_SYNERR_COMMANOVALUE: HCL_SYNERR_COLONNOVALUE), TOKEN_LOC(hcl), HCL_NULL);
if (head) hcl_freecnode (hcl, head);
return HCL_NULL;
}
@ -1455,12 +1456,12 @@ static HCL_INLINE hcl_cnode_t* leave_list (hcl_t* hcl, int* flagv, int* oldflagv
*flagv = hcl->c->r.st->flagv;
}
/* return the head of the list being left */
/* NOTE: empty xlist will get translated to #nil.
* this is useful when used in the lambda expression to express an empty argument. also in defun.
* (lambda () ...) is equivalent to (lambda #nil ...)
* (defun x() ...) */
/* [NOTE] the head is NULL if the list is empty */
list = hcl_makecnodelist(hcl, &loc, concode, head);
if (HCL_UNLIKELY(!list)) hcl_freecnode (hcl, head);
return list;
@ -1537,7 +1538,7 @@ static HCL_INLINE void clear_comma_colon_flag (hcl_t* hcl)
rstl->flagv &= ~(COMMAED | COLONED);
}
static hcl_cnode_t* chain_to_list (hcl_t* hcl, hcl_cnode_t* obj)
static int chain_to_list (hcl_t* hcl, hcl_cnode_t* obj)
{
hcl_rstl_t* rstl;
int flagv;
@ -1555,7 +1556,7 @@ static hcl_cnode_t* chain_to_list (hcl_t* hcl, hcl_cnode_t* obj)
* allowed. so i can safely hard-code the error code to
* HCL_SYNERR_RBRACK. */
hcl_setsynerr (hcl, HCL_SYNERR_RBRACK, TOKEN_LOC(hcl), TOKEN_NAME(hcl));
return HCL_NULL;
return -1;
}
else if (flagv & DOTTED)
{
@ -1587,11 +1588,11 @@ static hcl_cnode_t* chain_to_list (hcl_t* hcl, hcl_cnode_t* obj)
/* there is no separator between array/dictionary elements
* for instance, [1 2] { 10 20 } */
hcl_setsynerr (hcl, HCL_SYNERR_NOSEP, TOKEN_LOC(hcl), HCL_NULL);
return HCL_NULL;
return -1;
}
cons = hcl_makecnodecons(hcl, &obj->loc, obj, HCL_NULL);
if (HCL_UNLIKELY(!cons)) return HCL_NULL;
if (HCL_UNLIKELY(!cons)) return -1;
if (rstl->count <= 0)
{
@ -1610,7 +1611,7 @@ static hcl_cnode_t* chain_to_list (hcl_t* hcl, hcl_cnode_t* obj)
* append it to the list */
tail = rstl->tail;
HCL_ASSERT (hcl, tail->type == HCL_CNODE_CONS);
tail->u.cons.cdr = obj;
tail->u.cons.cdr = cons;
rstl->tail = cons;
}
@ -1618,7 +1619,7 @@ static hcl_cnode_t* chain_to_list (hcl_t* hcl, hcl_cnode_t* obj)
rstl->count++;
}
return obj;
return 0;
}
static hcl_cnode_t* read_vlist (hcl_t* hcl)
@ -1686,13 +1687,13 @@ oops:
return HCL_NULL;
}
static int read_object (hcl_t* hcl)
static hcl_cnode_t* read_object (hcl_t* hcl)
{
/* this function read an s-expression non-recursively
* by manipulating its own stack. */
int level = 0, array_level = 0, flagv = 0;
hcl_cnode_t* obj;
hcl_cnode_t* obj = HCL_NULL;
while (1)
{
@ -1701,11 +1702,11 @@ static int read_object (hcl_t* hcl)
{
default:
hcl_setsynerr (hcl, HCL_SYNERR_ILTOK, TOKEN_LOC(hcl), TOKEN_NAME(hcl));
return -1;
goto oops;
case HCL_IOTOK_EOF:
hcl_setsynerr (hcl, HCL_SYNERR_EOF, TOKEN_LOC(hcl), TOKEN_NAME(hcl));
return -1;
goto oops;
case HCL_IOTOK_INCLUDE:
/* TODO: should i limit where #include can be specified?
@ -1714,9 +1715,9 @@ static int read_object (hcl_t* hcl)
if (TOKEN_TYPE(hcl) != HCL_IOTOK_STRLIT)
{
hcl_setsynerr (hcl, HCL_SYNERR_STRING, TOKEN_LOC(hcl), TOKEN_NAME(hcl));
return -1;
goto oops;
}
if (begin_include(hcl) <= -1) return -1;
if (begin_include(hcl) <= -1) goto oops;
goto redo;
case HCL_IOTOK_LBRACK: /* [] */
@ -1737,7 +1738,7 @@ static int read_object (hcl_t* hcl)
case HCL_IOTOK_QLPAREN: /* #() */
#if 1
hcl_setsynerr (hcl, HCL_SYNERR_ILTOK, TOKEN_LOC(hcl), TOKEN_NAME(hcl));
return -1;
goto oops;
#else
flagv = 0;
LIST_FLAG_SET_CONCODE (flagv, HCL_CONCODE_QLIST);
@ -1752,17 +1753,17 @@ static int read_object (hcl_t* hcl)
{
/* the nesting level has become too deep */
hcl_setsynerr (hcl, HCL_SYNERR_NESTING, TOKEN_LOC(hcl), TOKEN_NAME(hcl));
return -1;
goto oops;
}
/* push some data to simulate recursion into
* a list literal or an array literal */
if (enter_list(hcl, TOKEN_LOC(hcl), flagv) <= -1) return -1;
if (enter_list(hcl, TOKEN_LOC(hcl), flagv) <= -1) goto oops;
level++;
if (LIST_FLAG_GET_CONCODE(flagv) == HCL_CONCODE_ARRAY) array_level++;
/* read the next token */
GET_TOKEN (hcl);
GET_TOKEN_WITH_GOTO (hcl, oops);
goto redo;
case HCL_IOTOK_DOT:
@ -1773,30 +1774,30 @@ static int read_object (hcl_t* hcl)
* 2. at the beginning of a list
* 3. inside an #(), #[], #{}, () */
hcl_setsynerr (hcl, HCL_SYNERR_DOTBANNED, TOKEN_LOC(hcl), HCL_NULL);
return -1;
goto oops;
}
GET_TOKEN (hcl);
GET_TOKEN_WITH_GOTO (hcl, oops);
goto redo;
case HCL_IOTOK_COLON:
if (level <= 0 || !can_colon_list(hcl))
{
hcl_setsynerr (hcl, HCL_SYNERR_COLONBANNED, TOKEN_LOC(hcl), HCL_NULL);
return -1;
goto oops;
}
GET_TOKEN (hcl);
GET_TOKEN_WITH_GOTO (hcl, oops);
goto redo;
case HCL_IOTOK_COMMA:
if (level <= 0 || !can_comma_list(hcl))
{
hcl_setsynerr (hcl, HCL_SYNERR_COMMABANNED, TOKEN_LOC(hcl), HCL_NULL);
return -1;
goto oops;
}
GET_TOKEN (hcl);
GET_TOKEN_WITH_GOTO (hcl, oops);
goto redo;
case HCL_IOTOK_RPAREN: /* xlist (), qlist #() */
@ -1822,7 +1823,7 @@ static int read_object (hcl_t* hcl)
if (level <= 0)
{
hcl_setsynerr (hcl, HCL_SYNERR_UNBALPBB, TOKEN_LOC(hcl), HCL_NULL);
return -1;
goto oops;
}
concode = LIST_FLAG_GET_CONCODE(flagv);
@ -1830,7 +1831,7 @@ static int read_object (hcl_t* hcl)
if (req[concode].closer != TOKEN_TYPE(hcl))
{
hcl_setsynerr (hcl, req[concode].synerr, TOKEN_LOC(hcl), TOKEN_NAME(hcl));
return -1;
goto oops;
}
#if 0
@ -1854,7 +1855,7 @@ static int read_object (hcl_t* hcl)
* indicated by level<=0.
*/
hcl_setsynerr (hcl, HCL_SYNERR_LPAREN, TOKEN_LOC(hcl), TOKEN_NAME(hcl));
return -1;
goto oops;
}
#endif
obj = leave_list(hcl, &flagv, &oldflagv);
@ -1870,7 +1871,7 @@ static int read_object (hcl_t* hcl)
if (array_level > 0) /* TODO: this check is wrong... i think .. */
{
hcl_setsynerr (hcl, HCL_SYNERR_VBARBANNED, TOKEN_LOC(hcl), TOKEN_NAME(hcl));
return -1;
goto oops;
}
obj = read_vlist(hcl);
break;
@ -1902,7 +1903,7 @@ static int read_object (hcl_t* hcl)
if (!HCL_IN_SMPTR_RANGE(v))
{
hcl_setsynerr (hcl, HCL_SYNERR_SMPTRLIT, TOKEN_LOC(hcl), TOKEN_NAME(hcl));
return -1;
goto oops;
}
obj = hcl_makecnodesmptrlit(hcl, TOKEN_LOC(hcl), v);
@ -1923,7 +1924,7 @@ static int read_object (hcl_t* hcl)
if (v > HCL_ERROR_MAX)
{
hcl_setsynerr (hcl, HCL_SYNERR_ERRLIT, TOKEN_LOC(hcl), TOKEN_NAME(hcl));
return -1;
goto oops;
}
}
@ -1979,7 +1980,7 @@ static int read_object (hcl_t* hcl)
if (!pfbase)
{
/* TODO switch to syntax error */
return -1;
goto oops;
}
hcl_pushvolat (hcl, &obj);
@ -2005,13 +2006,13 @@ static int read_object (hcl_t* hcl)
default:
hcl_popvolat (hcl);
hcl_seterrbfmt (hcl, HCL_EINVAL, "invalid pfbase type - %d\n", pfbase->type);
return -1;
goto oops;
}
if (!val || !hcl_putatsysdic(hcl, obj, val))
{
hcl_popvolat (hcl);
return -1;
goto oops;
}
hcl_popvolat (hcl);
@ -2023,7 +2024,7 @@ static int read_object (hcl_t* hcl)
break;
}
if (!obj) return -1;
if (!obj) goto oops;
#if 0
/* check if the element is read for a quoted list */
@ -2034,11 +2035,7 @@ static int read_object (hcl_t* hcl)
HCL_ASSERT (hcl, level > 0);
/* if so, append the element read into the quote list */
if (chain_to_list(hcl, obj) == HCL_NULL)
{
hcl_freecnode (hcl, obj);
return -1;
}
if (chain_to_list(hcl, obj) <= -1) goto oops;
/* exit out of the quoted list. the quoted list can have
* one element only. */
@ -2056,43 +2053,38 @@ static int read_object (hcl_t* hcl)
/* if not, append the element read into the current list.
* if we are not at the top level, we must be in a list */
if (chain_to_list(hcl, obj) == HCL_NULL)
{
hcl_freecnode (hcl, obj);
return -1;
}
if (chain_to_list(hcl, obj) <= -1) goto oops;
clear_comma_colon_flag (hcl);
/* read the next token */
GET_TOKEN (hcl);
GET_TOKEN_WITH_GOTO (hcl, oops);
}
/* upon exit, we must be at the top level */
HCL_ASSERT (hcl, level == 0);
HCL_ASSERT (hcl, array_level == 0);
hcl->c->r.ecn = obj;
return 0;
return obj;
oops:
if (obj) hcl_freecnode (hcl, obj);
return HCL_NULL;
}
static HCL_INLINE int __read (hcl_t* hcl)
hcl_cnode_t* hcl_read2 (hcl_t* hcl)
{
if (get_token(hcl) <= -1) return -1;
HCL_ASSERT (hcl, hcl->c && hcl->c->reader);
if (get_token(hcl) <= -1) return HCL_NULL;
if (TOKEN_TYPE(hcl) == HCL_IOTOK_EOF)
{
hcl_seterrnum (hcl, HCL_EFINIS);
return -1;
return HCL_NULL;
}
return read_object(hcl);
}
hcl_oop_t hcl_read (hcl_t* hcl)
{
HCL_ASSERT (hcl, hcl->c && hcl->c->reader);
if (__read(hcl) <= -1) return HCL_NULL;
return hcl->c->r.e;
}
#if 0
/* ========================================================================= */
/* TODO: rename compiler to something else that can include reader, printer, and compiler
@ -2329,3 +2321,4 @@ int hcl_unreadchar (hcl_t* hcl, const hcl_iolxc_t* c)
unget_char (hcl, c);
return 0;
}
#endif