enhanced the compiler to prohibit variable declaration after 'do' if it's the head of block expression
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
hyung-hwan 2023-11-28 01:44:13 +09:00
parent f3c0c1b8c1
commit 9f4bf7485d
8 changed files with 140 additions and 106 deletions

View File

@ -24,7 +24,7 @@
#include "hcl-prv.h" #include "hcl-prv.h"
static hcl_cnode_t* make_cnode (hcl_t* hcl, hcl_cnode_type_t type, const hcl_loc_t* loc, const hcl_oocs_t* tok) static hcl_cnode_t* make_cnode (hcl_t* hcl, hcl_cnode_type_t type, int flags, const hcl_loc_t* loc, const hcl_oocs_t* tok)
{ {
hcl_cnode_t* cnode; hcl_cnode_t* cnode;
hcl_oocs_t empty; hcl_oocs_t empty;
@ -36,10 +36,11 @@ static hcl_cnode_t* make_cnode (hcl_t* hcl, hcl_cnode_type_t type, const hcl_loc
empty.len = 0; empty.len = 0;
tok = ∅ tok = ∅
} }
cnode = hcl_callocmem(hcl, HCL_SIZEOF(*cnode) + HCL_SIZEOF(*tok->ptr) * (tok->len + 1)); cnode = (hcl_cnode_t*)hcl_callocmem(hcl, HCL_SIZEOF(*cnode) + HCL_SIZEOF(*tok->ptr) * (tok->len + 1));
if (HCL_UNLIKELY(!cnode)) return HCL_NULL; if (HCL_UNLIKELY(!cnode)) return HCL_NULL;
cnode->cn_type = type; cnode->cn_type = type;
cnode->cn_flags = flags;
cnode->cn_loc = *loc; cnode->cn_loc = *loc;
cnode->cn_tok.ptr = (hcl_ooch_t*)(cnode + 1); cnode->cn_tok.ptr = (hcl_ooch_t*)(cnode + 1);
@ -50,123 +51,123 @@ static hcl_cnode_t* make_cnode (hcl_t* hcl, hcl_cnode_type_t type, const hcl_loc
return cnode; return cnode;
} }
hcl_cnode_t* hcl_makecnodenil (hcl_t* hcl, const hcl_loc_t* loc, const hcl_oocs_t* tok) hcl_cnode_t* hcl_makecnodenil (hcl_t* hcl, int flags, const hcl_loc_t* loc, const hcl_oocs_t* tok)
{ {
return make_cnode(hcl, HCL_CNODE_NIL, loc, tok); return make_cnode(hcl, HCL_CNODE_NIL, flags, loc, tok);
} }
hcl_cnode_t* hcl_makecnodetrue (hcl_t* hcl, const hcl_loc_t* loc, const hcl_oocs_t* tok) hcl_cnode_t* hcl_makecnodetrue (hcl_t* hcl, int flags, const hcl_loc_t* loc, const hcl_oocs_t* tok)
{ {
return make_cnode(hcl, HCL_CNODE_TRUE, loc, tok); return make_cnode(hcl, HCL_CNODE_TRUE, flags, loc, tok);
} }
hcl_cnode_t* hcl_makecnodefalse (hcl_t* hcl, const hcl_loc_t* loc, const hcl_oocs_t* tok) hcl_cnode_t* hcl_makecnodefalse (hcl_t* hcl, int flags, const hcl_loc_t* loc, const hcl_oocs_t* tok)
{ {
return make_cnode(hcl, HCL_CNODE_FALSE, loc, tok); return make_cnode(hcl, HCL_CNODE_FALSE, flags, loc, tok);
} }
hcl_cnode_t* hcl_makecnodeself (hcl_t* hcl, const hcl_loc_t* loc, const hcl_oocs_t* tok) hcl_cnode_t* hcl_makecnodeself (hcl_t* hcl, int flags, const hcl_loc_t* loc, const hcl_oocs_t* tok)
{ {
return make_cnode(hcl, HCL_CNODE_SELF, loc, tok); return make_cnode(hcl, HCL_CNODE_SELF, flags, loc, tok);
} }
hcl_cnode_t* hcl_makecnodesuper (hcl_t* hcl, const hcl_loc_t* loc, const hcl_oocs_t* tok) hcl_cnode_t* hcl_makecnodesuper (hcl_t* hcl, int flags, const hcl_loc_t* loc, const hcl_oocs_t* tok)
{ {
return make_cnode(hcl, HCL_CNODE_SUPER, loc, tok); return make_cnode(hcl, HCL_CNODE_SUPER, flags, loc, tok);
} }
hcl_cnode_t* hcl_makecnodeellipsis (hcl_t* hcl, const hcl_loc_t* loc, const hcl_oocs_t* tok) hcl_cnode_t* hcl_makecnodeellipsis (hcl_t* hcl, int flags, const hcl_loc_t* loc, const hcl_oocs_t* tok)
{ {
return make_cnode(hcl, HCL_CNODE_ELLIPSIS, loc, tok); return make_cnode(hcl, HCL_CNODE_ELLIPSIS, flags, loc, tok);
} }
hcl_cnode_t* hcl_makecnodetrpcolons (hcl_t* hcl, const hcl_loc_t* loc, const hcl_oocs_t* tok) hcl_cnode_t* hcl_makecnodetrpcolons (hcl_t* hcl, int flags, const hcl_loc_t* loc, const hcl_oocs_t* tok)
{ {
return make_cnode(hcl, HCL_CNODE_TRPCOLONS, loc, tok); return make_cnode(hcl, HCL_CNODE_TRPCOLONS, flags, loc, tok);
} }
hcl_cnode_t* hcl_makecnodedcstar (hcl_t* hcl, const hcl_loc_t* loc, const hcl_oocs_t* tok) hcl_cnode_t* hcl_makecnodedcstar (hcl_t* hcl, int flags, const hcl_loc_t* loc, const hcl_oocs_t* tok)
{ {
return make_cnode(hcl, HCL_CNODE_DCSTAR, loc, tok); return make_cnode(hcl, HCL_CNODE_DCSTAR, flags, loc, tok);
} }
hcl_cnode_t* hcl_makecnodecharlit (hcl_t* hcl, const hcl_loc_t* loc, const hcl_oocs_t* tok, const hcl_ooch_t v) hcl_cnode_t* hcl_makecnodecharlit (hcl_t* hcl, int flags, const hcl_loc_t* loc, const hcl_oocs_t* tok, const hcl_ooch_t v)
{ {
hcl_cnode_t* c = make_cnode(hcl, HCL_CNODE_CHARLIT, loc, tok); hcl_cnode_t* c = make_cnode(hcl, HCL_CNODE_CHARLIT, flags, loc, tok);
if (HCL_UNLIKELY(!c)) return HCL_NULL; if (HCL_UNLIKELY(!c)) return HCL_NULL;
c->u.charlit.v = v; c->u.charlit.v = v;
return c; return c;
} }
hcl_cnode_t* hcl_makecnodesymbol (hcl_t* hcl, const hcl_loc_t* loc, const hcl_oocs_t* tok) hcl_cnode_t* hcl_makecnodesymbol (hcl_t* hcl, int flags, const hcl_loc_t* loc, const hcl_oocs_t* tok)
{ {
hcl_cnode_t* c = make_cnode(hcl, HCL_CNODE_SYMBOL, loc, tok); hcl_cnode_t* c = make_cnode(hcl, HCL_CNODE_SYMBOL, flags, loc, tok);
if (HCL_UNLIKELY(!c)) return HCL_NULL; if (HCL_UNLIKELY(!c)) return HCL_NULL;
c->u.symbol.syncode = hcl_getsyncodebyoocs_noseterr(hcl, tok); c->u.symbol.syncode = hcl_getsyncodebyoocs_noseterr(hcl, tok);
return c; return c;
} }
hcl_cnode_t* hcl_makecnodedsymbol (hcl_t* hcl, const hcl_loc_t* loc, const hcl_oocs_t* tok) hcl_cnode_t* hcl_makecnodedsymbol (hcl_t* hcl, int flags, const hcl_loc_t* loc, const hcl_oocs_t* tok)
{ {
return make_cnode(hcl, HCL_CNODE_DSYMBOL, loc, tok); return make_cnode(hcl, HCL_CNODE_DSYMBOL, flags, loc, tok);
} }
hcl_cnode_t* hcl_makecnodestrlit (hcl_t* hcl, const hcl_loc_t* loc, const hcl_oocs_t* tok) hcl_cnode_t* hcl_makecnodestrlit (hcl_t* hcl, int flags, const hcl_loc_t* loc, const hcl_oocs_t* tok)
{ {
return make_cnode(hcl, HCL_CNODE_STRLIT, loc, tok); return make_cnode(hcl, HCL_CNODE_STRLIT, flags, loc, tok);
} }
hcl_cnode_t* hcl_makecnodenumlit (hcl_t* hcl, const hcl_loc_t* loc, const hcl_oocs_t* tok) hcl_cnode_t* hcl_makecnodenumlit (hcl_t* hcl, int flags, const hcl_loc_t* loc, const hcl_oocs_t* tok)
{ {
return make_cnode(hcl, HCL_CNODE_NUMLIT, loc, tok); return make_cnode(hcl, HCL_CNODE_NUMLIT, flags, loc, tok);
} }
hcl_cnode_t* hcl_makecnoderadnumlit (hcl_t* hcl, const hcl_loc_t* loc, const hcl_oocs_t* tok) hcl_cnode_t* hcl_makecnoderadnumlit (hcl_t* hcl, int flags, const hcl_loc_t* loc, const hcl_oocs_t* tok)
{ {
return make_cnode(hcl, HCL_CNODE_RADNUMLIT, loc, tok); return make_cnode(hcl, HCL_CNODE_RADNUMLIT, flags, loc, tok);
} }
hcl_cnode_t* hcl_makecnodefpdeclit (hcl_t* hcl, const hcl_loc_t* loc, const hcl_oocs_t* tok) hcl_cnode_t* hcl_makecnodefpdeclit (hcl_t* hcl, int flags, const hcl_loc_t* loc, const hcl_oocs_t* tok)
{ {
return make_cnode(hcl, HCL_CNODE_FPDECLIT, loc, tok); return make_cnode(hcl, HCL_CNODE_FPDECLIT, flags, loc, tok);
} }
hcl_cnode_t* hcl_makecnodesmptrlit (hcl_t* hcl, const hcl_loc_t* loc, const hcl_oocs_t* tok, hcl_oow_t v) hcl_cnode_t* hcl_makecnodesmptrlit (hcl_t* hcl, int flags, const hcl_loc_t* loc, const hcl_oocs_t* tok, hcl_oow_t v)
{ {
hcl_cnode_t* c = make_cnode(hcl, HCL_CNODE_SMPTRLIT, loc, tok); hcl_cnode_t* c = make_cnode(hcl, HCL_CNODE_SMPTRLIT, flags, loc, tok);
if (HCL_UNLIKELY(!c)) return HCL_NULL; if (HCL_UNLIKELY(!c)) return HCL_NULL;
c->u.smptrlit.v = v; c->u.smptrlit.v = v;
return c; return c;
} }
hcl_cnode_t* hcl_makecnodeerrlit (hcl_t* hcl, const hcl_loc_t* loc, const hcl_oocs_t* tok, hcl_ooi_t v) hcl_cnode_t* hcl_makecnodeerrlit (hcl_t* hcl, int flags, const hcl_loc_t* loc, const hcl_oocs_t* tok, hcl_ooi_t v)
{ {
hcl_cnode_t* c = make_cnode(hcl, HCL_CNODE_ERRLIT, loc, tok); hcl_cnode_t* c = make_cnode(hcl, HCL_CNODE_ERRLIT, flags, loc, tok);
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_loc_t* loc, const hcl_oocs_t* tok, hcl_cnode_t* car, hcl_cnode_t* cdr) 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)
{ {
hcl_cnode_t* c = make_cnode(hcl, HCL_CNODE_CONS, loc, tok); hcl_cnode_t* c = make_cnode(hcl, HCL_CNODE_CONS, flags, loc, tok);
if (HCL_UNLIKELY(!c)) return HCL_NULL; if (HCL_UNLIKELY(!c)) return HCL_NULL;
c->u.cons.car = car; c->u.cons.car = car;
c->u.cons.cdr = cdr; c->u.cons.cdr = cdr;
return c; return c;
} }
hcl_cnode_t* hcl_makecnodeelist (hcl_t* hcl, const hcl_loc_t* loc, hcl_concode_t type) hcl_cnode_t* hcl_makecnodeelist (hcl_t* hcl, int flags, const hcl_loc_t* loc, hcl_concode_t type)
{ {
hcl_cnode_t* c = make_cnode(hcl, HCL_CNODE_ELIST, loc, HCL_NULL); hcl_cnode_t* c = make_cnode(hcl, HCL_CNODE_ELIST, flags, loc, HCL_NULL);
if (HCL_UNLIKELY(!c)) return HCL_NULL; if (HCL_UNLIKELY(!c)) return HCL_NULL;
c->u.elist.concode = type; c->u.elist.concode = type;
return c; return c;
} }
hcl_cnode_t* hcl_makecnodeshell (hcl_t* hcl, const hcl_loc_t* loc, hcl_cnode_t* obj) hcl_cnode_t* hcl_makecnodeshell (hcl_t* hcl, int flags, const hcl_loc_t* loc, hcl_cnode_t* obj)
{ {
hcl_cnode_t* c = make_cnode(hcl, HCL_CNODE_SHELL, loc, HCL_NULL); hcl_cnode_t* c = make_cnode(hcl, HCL_CNODE_SHELL, flags, loc, HCL_NULL);
if (HCL_UNLIKELY(!c)) return HCL_NULL; if (HCL_UNLIKELY(!c)) return HCL_NULL;
c->u.shell.obj = obj; c->u.shell.obj = obj;
return c; return c;

View File

@ -1962,14 +1962,17 @@ inside_loop:
/* ========================================================================= */ /* ========================================================================= */
static int compile_expression_block (hcl_t* hcl, hcl_cnode_t* src, const hcl_bch_t* ctxname, int is_block) #define CEB_IS_BLOCK (1 << 0)
#define CEB_AUTO_FORGED (1 << 1)
static int compile_expression_block (hcl_t* hcl, hcl_cnode_t* src, const hcl_bch_t* ctxname, int flags)
{ {
hcl_cnode_t* cmd, * obj, * tmp; hcl_cnode_t* cmd, * obj, * tmp;
hcl_oow_t nlvars, tvslen; hcl_oow_t nlvars, tvslen;
hcl_fnblk_info_t* fbi; hcl_fnblk_info_t* fbi;
hcl_cframe_t* cf; hcl_cframe_t* cf;
if (is_block) if (flags & CEB_IS_BLOCK)
{ {
HCL_ASSERT (hcl, HCL_CNODE_IS_CONS_CONCODED(src, HCL_CONCODE_BLOCK) || HCL_CNODE_IS_ELIST_CONCODED(src, HCL_CONCODE_BLOCK)); HCL_ASSERT (hcl, HCL_CNODE_IS_CONS_CONCODED(src, HCL_CONCODE_BLOCK) || HCL_CNODE_IS_ELIST_CONCODED(src, HCL_CONCODE_BLOCK));
cmd = src; /* it's the cons cell itself */ cmd = src; /* it's the cons cell itself */
@ -1991,12 +1994,28 @@ static int compile_expression_block (hcl_t* hcl, hcl_cnode_t* src, const hcl_bch
} }
} }
if (is_in_class_init_scope(hcl) && is_followed_by_vlist(hcl, obj)) if (is_followed_by_vlist(hcl, obj))
{ {
hcl_setsynerrbfmt ( if (is_in_class_init_scope(hcl))
hcl, HCL_SYNERR_VARDCLBANNED, HCL_CNODE_GET_LOC(obj), HCL_NULL, {
"variable declaration disallowed in class init scope"); hcl_setsynerrbfmt (
return -1; hcl, HCL_SYNERR_VARDCLBANNED, HCL_CNODE_GET_LOC(obj), HCL_NULL,
"variable declaration disallowed in class init scope");
return -1;
}
if (!(flags & CEB_IS_BLOCK) && (flags & CEB_AUTO_FORGED))
{
/* `do` not explicitly enclosed in ().
* e.g. do | x | { set x 20; };
* ^
* +-- this is not allowed
*/
hcl_setsynerrbfmt (
hcl, HCL_SYNERR_VARDCLBANNED, HCL_CNODE_GET_LOC(obj), HCL_NULL,
"variable declaration disallowed in %hs context", ctxname);
return -1;
}
} }
tvslen = hcl->c->tv.s.len; tvslen = hcl->c->tv.s.len;
@ -2033,12 +2052,13 @@ static int compile_expression_block (hcl_t* hcl, hcl_cnode_t* src, const hcl_bch
return 0; return 0;
} }
static int compile_do (hcl_t* hcl, hcl_cnode_t* src) static int compile_do (hcl_t* hcl, hcl_cnode_t* xlist)
{ {
hcl_cnode_t* cmd, * obj, * tmp; hcl_cnode_t* cmd, * obj, * tmp;
hcl_oow_t nlvars, tvslen; hcl_oow_t nlvars, tvslen;
hcl_fnblk_info_t* fbi; hcl_fnblk_info_t* fbi;
hcl_cframe_t* cf; hcl_cframe_t* cf;
int flags = 0;
/* (do /* (do
* (+ 10 20) * (+ 10 20)
@ -2048,13 +2068,14 @@ static int compile_do (hcl_t* hcl, hcl_cnode_t* src)
* you can use this to combine multiple expressions to a single expression * you can use this to combine multiple expressions to a single expression
*/ */
HCL_ASSERT (hcl, HCL_CNODE_IS_CONS(src)); HCL_ASSERT (hcl, HCL_CNODE_IS_CONS(xlist));
HCL_ASSERT (hcl, HCL_CNODE_IS_SYMBOL_SYNCODED(HCL_CNODE_CONS_CAR(src), HCL_SYNCODE_DO)); HCL_ASSERT (hcl, HCL_CNODE_IS_SYMBOL_SYNCODED(HCL_CNODE_CONS_CAR(xlist), HCL_SYNCODE_DO));
cmd = HCL_CNODE_CONS_CAR(src); /* do itself */ cmd = HCL_CNODE_CONS_CAR(xlist); /* do itself */
obj = HCL_CNODE_CONS_CDR(src); /* expression list after it */ obj = HCL_CNODE_CONS_CDR(xlist); /* expression list after it */
return compile_expression_block(hcl, src, "do", 0); if (HCL_CNODE_GET_FLAGS(xlist) & HCL_CNODE_AUTO_FORGED) flags |= CEB_AUTO_FORGED;
return compile_expression_block(hcl, xlist, "do", flags);
} }
static int compile_do_p1 (hcl_t* hcl) static int compile_do_p1 (hcl_t* hcl)
@ -3927,7 +3948,7 @@ static int compile_cons_mlist_expression (hcl_t* hcl, hcl_cnode_t* obj, int nret
static int compile_cons_block_expression (hcl_t* hcl, hcl_cnode_t* obj) static int compile_cons_block_expression (hcl_t* hcl, hcl_cnode_t* obj)
{ {
return compile_expression_block(hcl, obj, "block", 1); return compile_expression_block(hcl, obj, "block", CEB_IS_BLOCK);
} }
static HCL_INLINE int compile_symbol (hcl_t* hcl, hcl_cnode_t* obj) static HCL_INLINE int compile_symbol (hcl_t* hcl, hcl_cnode_t* obj)

View File

@ -243,7 +243,14 @@ 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;
enum hcl_cnode_flag_t
{
HCL_CNODE_AUTO_FORGED = (1 << 0)
};
typedef enum hcl_cnode_flagt hcl_cnode_flag_t;
#define HCL_CNODE_GET_TYPE(x) ((x)->cn_type) #define HCL_CNODE_GET_TYPE(x) ((x)->cn_type)
#define HCL_CNODE_GET_FLAGS(x) ((x)->cn_flags)
#define HCL_CNODE_GET_LOC(x) (&(x)->cn_loc) #define HCL_CNODE_GET_LOC(x) (&(x)->cn_loc)
#define HCL_CNODE_GET_TOK(x) (&(x)->cn_tok) #define HCL_CNODE_GET_TOK(x) (&(x)->cn_tok)
#define HCL_CNODE_GET_TOKPTR(x) ((x)->cn_tok.ptr) #define HCL_CNODE_GET_TOKPTR(x) ((x)->cn_tok.ptr)
@ -274,6 +281,7 @@ typedef enum hcl_cnode_type_t hcl_cnode_type_t;
struct hcl_cnode_t struct hcl_cnode_t
{ {
hcl_cnode_type_t cn_type; hcl_cnode_type_t cn_type;
int cn_flags;
hcl_loc_t cn_loc; hcl_loc_t cn_loc;
hcl_oocs_t cn_tok; hcl_oocs_t cn_tok;
@ -283,12 +291,10 @@ struct hcl_cnode_t
{ {
hcl_ooch_t v; hcl_ooch_t v;
} charlit; } charlit;
struct struct
{ {
hcl_syncode_t syncode; /* special if non-zero */ hcl_syncode_t syncode; /* special if non-zero */
} symbol; } symbol;
struct struct
{ {
hcl_oow_t v; hcl_oow_t v;
@ -1707,26 +1713,26 @@ int hcl_emitbyteinstruction (
/* ========================================================================= */ /* ========================================================================= */
/* cnode.c */ /* cnode.c */
/* ========================================================================= */ /* ========================================================================= */
hcl_cnode_t* hcl_makecnodenil (hcl_t* hcl, const hcl_loc_t* loc, const hcl_oocs_t* tok); hcl_cnode_t* hcl_makecnodenil (hcl_t* hcl, int flags, const hcl_loc_t* loc, const hcl_oocs_t* tok);
hcl_cnode_t* hcl_makecnodetrue (hcl_t* hcl, const hcl_loc_t* loc, const hcl_oocs_t* tok); hcl_cnode_t* hcl_makecnodetrue (hcl_t* hcl, int flags, const hcl_loc_t* loc, const hcl_oocs_t* tok);
hcl_cnode_t* hcl_makecnodefalse (hcl_t* hcl, const hcl_loc_t* loc, const hcl_oocs_t* tok); hcl_cnode_t* hcl_makecnodefalse (hcl_t* hcl, int flags, const hcl_loc_t* loc, const hcl_oocs_t* tok);
hcl_cnode_t* hcl_makecnodeself (hcl_t* hcl, const hcl_loc_t* loc, const hcl_oocs_t* tok); hcl_cnode_t* hcl_makecnodeself (hcl_t* hcl, int flags, const hcl_loc_t* loc, const hcl_oocs_t* tok);
hcl_cnode_t* hcl_makecnodesuper (hcl_t* hcl, const hcl_loc_t* loc, const hcl_oocs_t* tok); hcl_cnode_t* hcl_makecnodesuper (hcl_t* hcl, int flags, const hcl_loc_t* loc, const hcl_oocs_t* tok);
hcl_cnode_t* hcl_makecnodeellipsis (hcl_t* hcl, const hcl_loc_t* loc, const hcl_oocs_t* tok); hcl_cnode_t* hcl_makecnodeellipsis (hcl_t* hcl, int flags, const hcl_loc_t* loc, const hcl_oocs_t* tok);
hcl_cnode_t* hcl_makecnodetrpcolons (hcl_t* hcl, const hcl_loc_t* loc, const hcl_oocs_t* tok); hcl_cnode_t* hcl_makecnodetrpcolons (hcl_t* hcl, int flags, const hcl_loc_t* loc, const hcl_oocs_t* tok);
hcl_cnode_t* hcl_makecnodedcstar (hcl_t* hcl, const hcl_loc_t* loc, const hcl_oocs_t* tok); hcl_cnode_t* hcl_makecnodedcstar (hcl_t* hcl, int flags, const hcl_loc_t* loc, const hcl_oocs_t* tok);
hcl_cnode_t* hcl_makecnodecharlit (hcl_t* hcl, const hcl_loc_t* loc, const hcl_oocs_t* tok, const hcl_ooch_t v); hcl_cnode_t* hcl_makecnodecharlit (hcl_t* hcl, int flags, const hcl_loc_t* loc, const hcl_oocs_t* tok, const hcl_ooch_t v);
hcl_cnode_t* hcl_makecnodesymbol (hcl_t* hcl, const hcl_loc_t* loc, const hcl_oocs_t* tok); hcl_cnode_t* hcl_makecnodesymbol (hcl_t* hcl, int flags, const hcl_loc_t* loc, const hcl_oocs_t* tok);
hcl_cnode_t* hcl_makecnodedsymbol (hcl_t* hcl, const hcl_loc_t* loc, const hcl_oocs_t* tok); hcl_cnode_t* hcl_makecnodedsymbol (hcl_t* hcl, int flags, const hcl_loc_t* loc, const hcl_oocs_t* tok);
hcl_cnode_t* hcl_makecnodestrlit (hcl_t* hcl, const hcl_loc_t* loc, const hcl_oocs_t* tok); hcl_cnode_t* hcl_makecnodestrlit (hcl_t* hcl, int flags, const hcl_loc_t* loc, const hcl_oocs_t* tok);
hcl_cnode_t* hcl_makecnodenumlit (hcl_t* hcl, const hcl_loc_t* loc, const hcl_oocs_t* tok); hcl_cnode_t* hcl_makecnodenumlit (hcl_t* hcl, int flags, const hcl_loc_t* loc, const hcl_oocs_t* tok);
hcl_cnode_t* hcl_makecnoderadnumlit (hcl_t* hcl, const hcl_loc_t* loc, const hcl_oocs_t* tok); hcl_cnode_t* hcl_makecnoderadnumlit (hcl_t* hcl, int flags, const hcl_loc_t* loc, const hcl_oocs_t* tok);
hcl_cnode_t* hcl_makecnodefpdeclit (hcl_t* hcl, const hcl_loc_t* loc, const hcl_oocs_t* tok); hcl_cnode_t* hcl_makecnodefpdeclit (hcl_t* hcl, int flags, const hcl_loc_t* loc, const hcl_oocs_t* tok);
hcl_cnode_t* hcl_makecnodesmptrlit (hcl_t* hcl, const hcl_loc_t* loc, const hcl_oocs_t* tok, hcl_oow_t v); hcl_cnode_t* hcl_makecnodesmptrlit (hcl_t* hcl, int flags, const hcl_loc_t* loc, const hcl_oocs_t* tok, hcl_oow_t v);
hcl_cnode_t* hcl_makecnodeerrlit (hcl_t* hcl, const hcl_loc_t* loc, const hcl_oocs_t* tok, hcl_ooi_t v); hcl_cnode_t* hcl_makecnodeerrlit (hcl_t* hcl, int flags, const hcl_loc_t* loc, const hcl_oocs_t* tok, hcl_ooi_t v);
hcl_cnode_t* hcl_makecnodecons (hcl_t* hcl, const hcl_loc_t* loc, const hcl_oocs_t* tok, hcl_cnode_t* car, hcl_cnode_t* cdr); 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);
hcl_cnode_t* hcl_makecnodeelist (hcl_t* hcl, const hcl_loc_t* loc, hcl_concode_t type); hcl_cnode_t* hcl_makecnodeelist (hcl_t* hcl, int flags, const hcl_loc_t* loc, hcl_concode_t type);
hcl_cnode_t* hcl_makecnodeshell (hcl_t* hcl, const hcl_loc_t* loc, hcl_cnode_t* obj); hcl_cnode_t* hcl_makecnodeshell (hcl_t* hcl, int flags, const hcl_loc_t* loc, hcl_cnode_t* obj);
void hcl_freesinglecnode (hcl_t* hcl, hcl_cnode_t* c); void hcl_freesinglecnode (hcl_t* hcl, hcl_cnode_t* c);
hcl_oow_t hcl_countcnodecons (hcl_t* hcl, hcl_cnode_t* cons); hcl_oow_t hcl_countcnodecons (hcl_t* hcl, hcl_cnode_t* cons);
void hcl_dumpcnode (hcl_t* hcl, hcl_cnode_t* c, int newline); void hcl_dumpcnode (hcl_t* hcl, hcl_cnode_t* c, int newline);

View File

@ -657,7 +657,7 @@ static const hcl_ooch_t* add_sr_name (hcl_t* hcl, const hcl_oocs_t* name)
static HCL_INLINE int enter_list (hcl_t* hcl, const hcl_loc_t* loc, int flagv) static HCL_INLINE int enter_list (hcl_t* hcl, const hcl_loc_t* loc, int flagv)
{ {
hcl_rstl_t* rstl; hcl_rstl_t* rstl;
rstl = hcl_callocmem(hcl, HCL_SIZEOF(*rstl)); rstl = (hcl_rstl_t*)hcl_callocmem(hcl, HCL_SIZEOF(*rstl));
if (HCL_UNLIKELY(!rstl)) return -1; if (HCL_UNLIKELY(!rstl)) return -1;
rstl->loc = *loc; rstl->loc = *loc;
rstl->flagv = flagv; rstl->flagv = flagv;
@ -716,11 +716,12 @@ static HCL_INLINE hcl_cnode_t* leave_list (hcl_t* hcl, hcl_loc_t* list_loc, int*
{ {
HCL_ASSERT (hcl, HCL_CNODE_IS_CONS(head)); HCL_ASSERT (hcl, HCL_CNODE_IS_CONS(head));
HCL_CNODE_CONS_CONCODE(head) = concode; HCL_CNODE_CONS_CONCODE(head) = concode;
if (fv & AUTO_FORGED) HCL_CNODE_GET_FLAGS(head) |= HCL_CNODE_AUTO_FORGED;
return head; return head;
} }
/* the list is empty */ /* the list is empty */
return hcl_makecnodeelist(hcl, &loc, concode); return hcl_makecnodeelist(hcl, ((fv & AUTO_FORGED)? HCL_CNODE_AUTO_FORGED: 0), &loc, concode);
} }
static HCL_INLINE int can_dot_list (hcl_t* hcl) static HCL_INLINE int can_dot_list (hcl_t* hcl)
@ -836,7 +837,7 @@ static int chain_to_list (hcl_t* hcl, hcl_cnode_t* obj, hcl_loc_t* loc)
* use a shell node to wrap the actual object list node head * use a shell node to wrap the actual object list node head
* for the compiler. * for the compiler.
*/ */
shell = hcl_makecnodeshell(hcl, HCL_CNODE_GET_LOC(obj), obj); shell = hcl_makecnodeshell(hcl, 0, HCL_CNODE_GET_LOC(obj), obj);
if (HCL_UNLIKELY(!shell)) return -1; if (HCL_UNLIKELY(!shell)) return -1;
tail->u.cons.cdr = shell; tail->u.cons.cdr = shell;
@ -880,7 +881,7 @@ static int chain_to_list (hcl_t* hcl, hcl_cnode_t* obj, hcl_loc_t* loc)
fake_tok_ptr = &fake_tok; fake_tok_ptr = &fake_tok;
} }
cons = hcl_makecnodecons(hcl, (loc? loc: HCL_CNODE_GET_LOC(obj)), fake_tok_ptr, obj, HCL_NULL); cons = hcl_makecnodecons(hcl, 0, (loc? loc: HCL_CNODE_GET_LOC(obj)), fake_tok_ptr, obj, HCL_NULL);
if (HCL_UNLIKELY(!cons)) return -1; if (HCL_UNLIKELY(!cons)) return -1;
if (rstl->count <= 0) if (rstl->count <= 0)
@ -1323,35 +1324,35 @@ static int feed_process_token (hcl_t* hcl)
} }
case HCL_TOK_NIL: case HCL_TOK_NIL:
frd->obj = hcl_makecnodenil(hcl, TOKEN_LOC(hcl), TOKEN_NAME(hcl)); frd->obj = hcl_makecnodenil(hcl, 0, TOKEN_LOC(hcl), TOKEN_NAME(hcl));
goto auto_xlist; goto auto_xlist;
case HCL_TOK_TRUE: case HCL_TOK_TRUE:
frd->obj = hcl_makecnodetrue(hcl, TOKEN_LOC(hcl), TOKEN_NAME(hcl)); frd->obj = hcl_makecnodetrue(hcl, 0, TOKEN_LOC(hcl), TOKEN_NAME(hcl));
goto auto_xlist; goto auto_xlist;
case HCL_TOK_FALSE: case HCL_TOK_FALSE:
frd->obj = hcl_makecnodefalse(hcl, TOKEN_LOC(hcl), TOKEN_NAME(hcl)); frd->obj = hcl_makecnodefalse(hcl, 0, TOKEN_LOC(hcl), TOKEN_NAME(hcl));
goto auto_xlist; goto auto_xlist;
case HCL_TOK_SELF: case HCL_TOK_SELF:
frd->obj = hcl_makecnodeself(hcl, TOKEN_LOC(hcl), TOKEN_NAME(hcl)); frd->obj = hcl_makecnodeself(hcl, 0, TOKEN_LOC(hcl), TOKEN_NAME(hcl));
goto auto_xlist; goto auto_xlist;
case HCL_TOK_SUPER: case HCL_TOK_SUPER:
frd->obj = hcl_makecnodesuper(hcl, TOKEN_LOC(hcl), TOKEN_NAME(hcl)); frd->obj = hcl_makecnodesuper(hcl, 0, TOKEN_LOC(hcl), TOKEN_NAME(hcl));
goto auto_xlist; goto auto_xlist;
case HCL_TOK_ELLIPSIS: case HCL_TOK_ELLIPSIS:
frd->obj = hcl_makecnodeellipsis(hcl, TOKEN_LOC(hcl), TOKEN_NAME(hcl)); frd->obj = hcl_makecnodeellipsis(hcl, 0, TOKEN_LOC(hcl), TOKEN_NAME(hcl));
goto auto_xlist; goto auto_xlist;
case HCL_TOK_TRPCOLONS: case HCL_TOK_TRPCOLONS:
frd->obj = hcl_makecnodetrpcolons(hcl, TOKEN_LOC(hcl), TOKEN_NAME(hcl)); frd->obj = hcl_makecnodetrpcolons(hcl, 0, TOKEN_LOC(hcl), TOKEN_NAME(hcl));
goto auto_xlist; goto auto_xlist;
case HCL_TOK_DCSTAR: case HCL_TOK_DCSTAR:
frd->obj = hcl_makecnodedcstar(hcl, TOKEN_LOC(hcl), TOKEN_NAME(hcl)); frd->obj = hcl_makecnodedcstar(hcl, 0, TOKEN_LOC(hcl), TOKEN_NAME(hcl));
goto auto_xlist; goto auto_xlist;
case HCL_TOK_SMPTRLIT: case HCL_TOK_SMPTRLIT:
@ -1372,7 +1373,7 @@ static int feed_process_token (hcl_t* hcl)
goto oops; goto oops;
} }
frd->obj = hcl_makecnodesmptrlit(hcl, TOKEN_LOC(hcl), TOKEN_NAME(hcl), v); frd->obj = hcl_makecnodesmptrlit(hcl, 0, TOKEN_LOC(hcl), TOKEN_NAME(hcl), v);
goto auto_xlist; goto auto_xlist;
} }
@ -1394,24 +1395,24 @@ static int feed_process_token (hcl_t* hcl)
} }
} }
frd->obj = hcl_makecnodeerrlit(hcl, TOKEN_LOC(hcl), TOKEN_NAME(hcl), v); frd->obj = hcl_makecnodeerrlit(hcl, 0, TOKEN_LOC(hcl), TOKEN_NAME(hcl), v);
goto auto_xlist; goto auto_xlist;
} }
case HCL_TOK_CHARLIT: case HCL_TOK_CHARLIT:
frd->obj = hcl_makecnodecharlit(hcl, TOKEN_LOC(hcl), TOKEN_NAME(hcl), TOKEN_NAME_CHAR(hcl, 0)); frd->obj = hcl_makecnodecharlit(hcl, 0, TOKEN_LOC(hcl), TOKEN_NAME(hcl), TOKEN_NAME_CHAR(hcl, 0));
goto auto_xlist; goto auto_xlist;
case HCL_TOK_NUMLIT: case HCL_TOK_NUMLIT:
frd->obj = hcl_makecnodenumlit(hcl, TOKEN_LOC(hcl), TOKEN_NAME(hcl)); frd->obj = hcl_makecnodenumlit(hcl, 0, TOKEN_LOC(hcl), TOKEN_NAME(hcl));
goto auto_xlist; goto auto_xlist;
case HCL_TOK_RADNUMLIT: case HCL_TOK_RADNUMLIT:
frd->obj = hcl_makecnoderadnumlit(hcl, TOKEN_LOC(hcl), TOKEN_NAME(hcl)); frd->obj = hcl_makecnoderadnumlit(hcl, 0, TOKEN_LOC(hcl), TOKEN_NAME(hcl));
goto auto_xlist; goto auto_xlist;
case HCL_TOK_FPDECLIT: case HCL_TOK_FPDECLIT:
frd->obj = hcl_makecnodefpdeclit(hcl, TOKEN_LOC(hcl), TOKEN_NAME(hcl)); frd->obj = hcl_makecnodefpdeclit(hcl, 0, TOKEN_LOC(hcl), TOKEN_NAME(hcl));
goto auto_xlist; goto auto_xlist;
/* /*
@ -1421,15 +1422,15 @@ static int feed_process_token (hcl_t* hcl)
*/ */
case HCL_TOK_STRLIT: case HCL_TOK_STRLIT:
frd->obj = hcl_makecnodestrlit(hcl, TOKEN_LOC(hcl), TOKEN_NAME(hcl)); frd->obj = hcl_makecnodestrlit(hcl, 0, TOKEN_LOC(hcl), TOKEN_NAME(hcl));
goto auto_xlist; goto auto_xlist;
case HCL_TOK_IDENT: case HCL_TOK_IDENT:
frd->obj = hcl_makecnodesymbol(hcl, TOKEN_LOC(hcl), TOKEN_NAME(hcl)); frd->obj = hcl_makecnodesymbol(hcl, 0, TOKEN_LOC(hcl), TOKEN_NAME(hcl));
goto auto_xlist; goto auto_xlist;
case HCL_TOK_IDENT_DOTTED: case HCL_TOK_IDENT_DOTTED:
frd->obj = hcl_makecnodedsymbol(hcl, TOKEN_LOC(hcl), TOKEN_NAME(hcl)); frd->obj = hcl_makecnodedsymbol(hcl, 0, TOKEN_LOC(hcl), TOKEN_NAME(hcl));
goto auto_xlist; goto auto_xlist;
auto_xlist: auto_xlist:

View File

@ -9,6 +9,7 @@ check_SCRIPTS = \
va-01.hcl va-01.hcl
check_ERRORS = \ check_ERRORS = \
do-01.err \
feed-01.err \ feed-01.err \
var-01.err \ var-01.err \
var-02.err \ var-02.err \

View File

@ -480,6 +480,7 @@ check_SCRIPTS = \
va-01.hcl va-01.hcl
check_ERRORS = \ check_ERRORS = \
do-01.err \
feed-01.err \ feed-01.err \
var-01.err \ var-01.err \
var-02.err \ var-02.err \

3
t/do-01.err Normal file
View File

@ -0,0 +1,3 @@
## if `do` is not enclosed in `( )`, variable declaration is prohibited
(do | k | (set k 10))
do | k | {set k 10;}; ##ERROR: syntax error - variable declaration disallowed