return s;
}
-static BcStatus bc_parse_read(BcParse *p)
+static BC_STATUS zbc_parse_read(BcParse *p)
{
BcStatus s;
s = zbc_lex_next(&p->l);
- if (s) return s;
- if (p->l.t.t != BC_LEX_LPAREN) return bc_error_bad_token();
+ if (s) RETURN_STATUS(s);
+ if (p->l.t.t != BC_LEX_LPAREN) RETURN_STATUS(bc_error_bad_token());
s = zbc_lex_next(&p->l);
- if (s) return s;
- if (p->l.t.t != BC_LEX_RPAREN) return bc_error_bad_token();
+ if (s) RETURN_STATUS(s);
+ if (p->l.t.t != BC_LEX_RPAREN) RETURN_STATUS(bc_error_bad_token());
bc_parse_push(p, BC_INST_READ);
- return zbc_lex_next(&p->l);
+ RETURN_STATUS(zbc_lex_next(&p->l));
}
+#if ERRORS_ARE_FATAL
+# define zbc_parse_read(...) (zbc_parse_read(__VA_ARGS__), BC_STATUS_SUCCESS)
+#endif
static BcStatus bc_parse_builtin(BcParse *p, BcLexType type, uint8_t flags,
BcInst *prev)
return s;
}
-static BcStatus bc_parse_minus(BcParse *p, BcInst *prev, size_t ops_bgn,
+static BC_STATUS zbc_parse_minus(BcParse *p, BcInst *prev, size_t ops_bgn,
bool rparen, size_t *nexprs)
{
BcStatus s;
BcInst etype = *prev;
s = zbc_lex_next(&p->l);
- if (s) return s;
+ if (s) RETURN_STATUS(s);
type = rparen || etype == BC_INST_INC_POST || etype == BC_INST_DEC_POST ||
(etype >= BC_INST_NUM && etype <= BC_INST_SQRT) ?
else
s = zbc_parse_operator(p, type, ops_bgn, nexprs, false);
- return s;
+ RETURN_STATUS(s);
}
+#if ERRORS_ARE_FATAL
+# define zbc_parse_minus(...) (zbc_parse_minus(__VA_ARGS__), BC_STATUS_SUCCESS)
+#endif
-static BcStatus bc_parse_string(BcParse *p, char inst)
+static BC_STATUS zbc_parse_string(BcParse *p, char inst)
{
char *str = xstrdup(p->l.t.v.v);
bc_vec_push(&G.prog.strs, &str);
bc_parse_push(p, inst);
- return zbc_lex_next(&p->l);
+ RETURN_STATUS(zbc_lex_next(&p->l));
}
+#if ERRORS_ARE_FATAL
+# define zbc_parse_string(...) (zbc_parse_string(__VA_ARGS__), BC_STATUS_SUCCESS)
+#endif
static BcStatus bc_parse_print(BcParse *p)
{
while (type != BC_LEX_SCOLON && type != BC_LEX_NLINE) {
if (type == BC_LEX_STR) {
- s = bc_parse_string(p, BC_INST_PRINT_POP);
+ s = zbc_parse_string(p, BC_INST_PRINT_POP);
if (s) return s;
} else {
s = bc_parse_expr(p, 0, bc_parse_next_print);
return s;
}
-static BcStatus bc_parse_endBody(BcParse *p, bool brace)
+static BC_STATUS zbc_parse_endBody(BcParse *p, bool brace)
{
BcStatus s = BC_STATUS_SUCCESS;
if (p->flags.len <= 1 || (brace && p->nbraces == 0))
- return bc_error_bad_token();
+ RETURN_STATUS(bc_error_bad_token());
if (brace) {
-
- if (p->l.t.t == BC_LEX_RBRACE) {
- if (!p->nbraces) return bc_error_bad_token();
- --p->nbraces;
- s = zbc_lex_next(&p->l);
- if (s) return s;
- }
- else
- return bc_error_bad_token();
+ if (p->l.t.t != BC_LEX_RBRACE)
+ RETURN_STATUS(bc_error_bad_token());
+ if (!p->nbraces)
+ RETURN_STATUS(bc_error_bad_token());
+ --p->nbraces;
+ s = zbc_lex_next(&p->l);
+ if (s) RETURN_STATUS(s);
}
if (BC_PARSE_IF(p)) {
-
uint8_t *flag_ptr;
while (p->l.t.t == BC_LEX_NLINE) {
s = zbc_lex_next(&p->l);
- if (s) return s;
+ if (s) RETURN_STATUS(s);
}
bc_vec_pop(&p->flags);
ERROR_RETURN(s =) zbc_parse_else(p);
}
else if (BC_PARSE_ELSE(p)) {
-
BcInstPtr *ip;
size_t *label;
bc_vec_pop(&p->flags);
}
else {
-
BcInstPtr *ip = bc_vec_top(&p->exits);
size_t *label = bc_vec_top(&p->conds);
bc_vec_pop(&p->conds);
}
- return s;
+ RETURN_STATUS(s);
}
+#if ERRORS_ARE_FATAL
+# define zbc_parse_endBody(...) (zbc_parse_endBody(__VA_ARGS__), BC_STATUS_SUCCESS)
+#endif
static void bc_parse_startBody(BcParse *p, uint8_t flags)
{
return BC_STATUS_SUCCESS;
}
-static BcStatus bc_parse_loopExit(BcParse *p, BcLexType type)
+static BC_STATUS zbc_parse_loopExit(BcParse *p, BcLexType type)
{
BcStatus s;
size_t i;
BcInstPtr *ip;
- if (!BC_PARSE_LOOP(p)) return bc_error_bad_token();
+ if (!BC_PARSE_LOOP(p)) RETURN_STATUS(bc_error_bad_token());
if (type == BC_LEX_KEY_BREAK) {
-
- if (p->exits.len == 0) return bc_error_bad_token();
+ if (p->exits.len == 0) RETURN_STATUS(bc_error_bad_token());
i = p->exits.len - 1;
ip = bc_vec_item(&p->exits, i);
- while (!ip->func && i < p->exits.len) ip = bc_vec_item(&p->exits, i--);
- if (i >= p->exits.len && !ip->func) return bc_error_bad_token();
+ while (!ip->func && i < p->exits.len)
+ ip = bc_vec_item(&p->exits, i--);
+ if (i >= p->exits.len && !ip->func)
+ RETURN_STATUS(bc_error_bad_token());
i = ip->idx;
}
bc_parse_pushIndex(p, i);
s = zbc_lex_next(&p->l);
- if (s) return s;
+ if (s) RETURN_STATUS(s);
if (p->l.t.t != BC_LEX_SCOLON && p->l.t.t != BC_LEX_NLINE)
- return bc_error_bad_token();
+ RETURN_STATUS(bc_error_bad_token());
- return zbc_lex_next(&p->l);
+ RETURN_STATUS(zbc_lex_next(&p->l));
}
+#if ERRORS_ARE_FATAL
+# define zbc_parse_loopExit(...) (zbc_parse_loopExit(__VA_ARGS__), BC_STATUS_SUCCESS)
+#endif
-static BcStatus bc_parse_func(BcParse *p)
+static BC_STATUS zbc_parse_func(BcParse *p)
{
BcStatus s;
bool var, comma = false;
char *name;
s = zbc_lex_next(&p->l);
- if (s) return s;
+ if (s) RETURN_STATUS(s);
if (p->l.t.t != BC_LEX_NAME)
- return bc_error("bad function definition");
+ RETURN_STATUS(bc_error("bad function definition"));
name = xstrdup(p->l.t.v.v);
bc_parse_addFunc(p, name, &p->fidx);
s = zbc_lex_next(&p->l);
- if (s) return s;
+ if (s) RETURN_STATUS(s);
if (p->l.t.t != BC_LEX_LPAREN)
- return bc_error("bad function definition");
+ RETURN_STATUS(bc_error("bad function definition"));
s = zbc_lex_next(&p->l);
- if (s) return s;
+ if (s) RETURN_STATUS(s);
while (p->l.t.t != BC_LEX_RPAREN) {
-
if (p->l.t.t != BC_LEX_NAME)
- return bc_error("bad function definition");
+ RETURN_STATUS(bc_error("bad function definition"));
++p->func->nparams;
var = p->l.t.t != BC_LEX_LBRACKET;
if (!var) {
-
s = zbc_lex_next(&p->l);
if (s) goto err;
if (s) goto err;
}
- if (comma) return bc_error("bad function definition");
+ if (comma) RETURN_STATUS(bc_error("bad function definition"));
flags = BC_PARSE_FLAG_FUNC | BC_PARSE_FLAG_FUNC_INNER | BC_PARSE_FLAG_BODY;
bc_parse_startBody(p, flags);
s = zbc_lex_next(&p->l);
- if (s) return s;
+ if (s) RETURN_STATUS(s);
if (p->l.t.t != BC_LEX_LBRACE)
s = bc_POSIX_requires("the left brace be on the same line as the function header");
- return s;
+ RETURN_STATUS(s);
err:
free(name);
- return s;
+ RETURN_STATUS(s);
}
+#if ERRORS_ARE_FATAL
+# define zbc_parse_func(...) (zbc_parse_func(__VA_ARGS__), BC_STATUS_SUCCESS)
+#endif
-static BcStatus bc_parse_auto(BcParse *p)
+static BC_STATUS zbc_parse_auto(BcParse *p)
{
BcStatus s;
bool comma, var, one;
char *name;
- if (!p->auto_part) return bc_error_bad_token();
+ if (!p->auto_part) RETURN_STATUS(bc_error_bad_token());
+
s = zbc_lex_next(&p->l);
- if (s) return s;
+ if (s) RETURN_STATUS(s);
p->auto_part = comma = false;
one = p->l.t.t == BC_LEX_NAME;
while (p->l.t.t == BC_LEX_NAME) {
-
name = xstrdup(p->l.t.v.v);
s = zbc_lex_next(&p->l);
if (s) goto err;
var = p->l.t.t != BC_LEX_LBRACKET;
if (!var) {
-
s = zbc_lex_next(&p->l);
if (s) goto err;
if (s) goto err;
}
- if (comma) return bc_error("bad function definition");
- if (!one) return bc_error("no auto variable found");
+ if (comma) RETURN_STATUS(bc_error("bad function definition"));
+ if (!one) RETURN_STATUS(bc_error("no auto variable found"));
if (p->l.t.t != BC_LEX_NLINE && p->l.t.t != BC_LEX_SCOLON)
- return bc_error_bad_token();
+ RETURN_STATUS(bc_error_bad_token());
- return zbc_lex_next(&p->l);
+ RETURN_STATUS(zbc_lex_next(&p->l));
err:
free(name);
- return s;
+ RETURN_STATUS(s);
}
+#if ERRORS_ARE_FATAL
+# define zbc_parse_auto(...) (zbc_parse_auto(__VA_ARGS__), BC_STATUS_SUCCESS)
+#endif
-static BcStatus bc_parse_body(BcParse *p, bool brace)
+static BC_STATUS zbc_parse_body(BcParse *p, bool brace)
{
BcStatus s = BC_STATUS_SUCCESS;
uint8_t *flag_ptr = bc_vec_top(&p->flags);
*flag_ptr &= ~(BC_PARSE_FLAG_BODY);
if (*flag_ptr & BC_PARSE_FLAG_FUNC_INNER) {
+ if (!brace) RETURN_STATUS(bc_error_bad_token());
- if (!brace) return bc_error_bad_token();
p->auto_part = p->l.t.t != BC_LEX_KEY_AUTO;
if (!p->auto_part) {
- s = bc_parse_auto(p);
- if (s) return s;
+ s = zbc_parse_auto(p);
+ if (s) RETURN_STATUS(s);
}
if (p->l.t.t == BC_LEX_NLINE) s = zbc_lex_next(&p->l);
}
else {
s = bc_parse_stmt(p);
- if (!s && !brace) s = bc_parse_endBody(p, false);
+ if (!s && !brace) s = zbc_parse_endBody(p, false);
}
- return s;
+ RETURN_STATUS(s);
}
+#if ERRORS_ARE_FATAL
+# define zbc_parse_body(...) (zbc_parse_body(__VA_ARGS__), BC_STATUS_SUCCESS)
+#endif
static BcStatus bc_parse_stmt(BcParse *p)
{
s = zbc_lex_next(&p->l);
if (s) return s;
- return bc_parse_body(p, true);
+ return zbc_parse_body(p, true);
}
case BC_LEX_KEY_AUTO:
{
- return bc_parse_auto(p);
+ return zbc_parse_auto(p);
}
default:
return BC_STATUS_SUCCESS;
}
else if (BC_PARSE_BODY(p))
- return bc_parse_body(p, false);
+ return zbc_parse_body(p, false);
break;
}
case BC_LEX_RBRACE:
{
- s = bc_parse_endBody(p, true);
+ s = zbc_parse_endBody(p, true);
break;
}
case BC_LEX_STR:
{
- s = bc_parse_string(p, BC_INST_PRINT_STR);
+ s = zbc_parse_string(p, BC_INST_PRINT_STR);
break;
}
case BC_LEX_KEY_BREAK:
case BC_LEX_KEY_CONTINUE:
{
- s = bc_parse_loopExit(p, p->l.t.t);
+ s = zbc_parse_loopExit(p, p->l.t.t);
break;
}
s = p->flags.len > 0 ? bc_error("block end could not be found") : bc_error("end of file");
else if (p->l.t.t == BC_LEX_KEY_DEFINE) {
if (!BC_PARSE_CAN_EXEC(p)) return bc_error_bad_token();
- s = bc_parse_func(p);
+ s = zbc_parse_func(p);
}
else
s = bc_parse_stmt(p);
case BC_LEX_OP_MINUS:
{
- s = bc_parse_minus(p, &prev, ops_bgn, rprn, &nexprs);
+ s = zbc_parse_minus(p, &prev, ops_bgn, rprn, &nexprs);
rprn = get_token = false;
bin_last = prev == BC_INST_MINUS;
break;
else if (flags & BC_PARSE_NOREAD)
s = bc_error_nested_read_call();
else
- s = bc_parse_read(p);
+ s = zbc_parse_read(p);
paren_expr = true;
rprn = get_token = bin_last = false;
#define DC_PARSE_BUF_LEN ((int) (sizeof(uint32_t) * CHAR_BIT))
-static BcStatus dc_parse_register(BcParse *p)
+static BC_STATUS zdc_parse_register(BcParse *p)
{
BcStatus s;
char *name;
s = zbc_lex_next(&p->l);
- if (s) return s;
- if (p->l.t.t != BC_LEX_NAME) return bc_error_bad_token();
+ if (s) RETURN_STATUS(s);
+ if (p->l.t.t != BC_LEX_NAME) RETURN_STATUS(bc_error_bad_token());
name = xstrdup(p->l.t.v.v);
bc_parse_pushName(p, name);
- return s;
+ RETURN_STATUS(s);
}
+#if ERRORS_ARE_FATAL
+# define zdc_parse_register(...) (zdc_parse_register(__VA_ARGS__), BC_STATUS_SUCCESS)
+#endif
static BC_STATUS zdc_parse_string(BcParse *p)
{
# define zdc_parse_string(...) (zdc_parse_string(__VA_ARGS__), BC_STATUS_SUCCESS)
#endif
-static BcStatus dc_parse_mem(BcParse *p, uint8_t inst, bool name, bool store)
+static BC_STATUS zdc_parse_mem(BcParse *p, uint8_t inst, bool name, bool store)
{
BcStatus s;
bc_parse_push(p, inst);
if (name) {
- s = dc_parse_register(p);
- if (s) return s;
+ s = zdc_parse_register(p);
+ if (s) RETURN_STATUS(s);
}
if (store) {
bc_parse_push(p, BC_INST_POP);
}
- return zbc_lex_next(&p->l);
+ RETURN_STATUS(zbc_lex_next(&p->l));
}
+#if ERRORS_ARE_FATAL
+# define zdc_parse_mem(...) (zdc_parse_mem(__VA_ARGS__), BC_STATUS_SUCCESS)
+#endif
-static BcStatus dc_parse_cond(BcParse *p, uint8_t inst)
+static BC_STATUS zdc_parse_cond(BcParse *p, uint8_t inst)
{
BcStatus s;
bc_parse_push(p, inst);
bc_parse_push(p, BC_INST_EXEC_COND);
- s = dc_parse_register(p);
- if (s) return s;
+ s = zdc_parse_register(p);
+ if (s) RETURN_STATUS(s);
s = zbc_lex_next(&p->l);
- if (s) return s;
+ if (s) RETURN_STATUS(s);
if (p->l.t.t == BC_LEX_ELSE) {
- s = dc_parse_register(p);
- if (s) return s;
+ s = zdc_parse_register(p);
+ if (s) RETURN_STATUS(s);
s = zbc_lex_next(&p->l);
}
else
bc_parse_push(p, BC_PARSE_STREND);
- return s;
+ RETURN_STATUS(s);
}
+#if ERRORS_ARE_FATAL
+# define zdc_parse_cond(...) (zdc_parse_cond(__VA_ARGS__), BC_STATUS_SUCCESS)
+#endif
-static BcStatus dc_parse_token(BcParse *p, BcLexType t, uint8_t flags)
+static BC_STATUS zdc_parse_token(BcParse *p, BcLexType t, uint8_t flags)
{
BcStatus s = BC_STATUS_SUCCESS;
BcInst prev;
bool assign, get_token = false;
switch (t) {
-
case BC_LEX_OP_REL_EQ:
case BC_LEX_OP_REL_LE:
case BC_LEX_OP_REL_GE:
case BC_LEX_OP_REL_NE:
case BC_LEX_OP_REL_LT:
case BC_LEX_OP_REL_GT:
- {
- s = dc_parse_cond(p, t - BC_LEX_OP_REL_EQ + BC_INST_REL_EQ);
+ s = zdc_parse_cond(p, t - BC_LEX_OP_REL_EQ + BC_INST_REL_EQ);
break;
- }
-
case BC_LEX_SCOLON:
case BC_LEX_COLON:
- {
- s = dc_parse_mem(p, BC_INST_ARRAY_ELEM, true, t == BC_LEX_COLON);
+ s = zdc_parse_mem(p, BC_INST_ARRAY_ELEM, true, t == BC_LEX_COLON);
break;
- }
-
case BC_LEX_STR:
- {
s = zdc_parse_string(p);
break;
- }
-
case BC_LEX_NEG:
case BC_LEX_NUMBER:
- {
if (t == BC_LEX_NEG) {
s = zbc_lex_next(&p->l);
- if (s) return s;
+ if (s) RETURN_STATUS(s);
if (p->l.t.t != BC_LEX_NUMBER)
- return bc_error_bad_token();
+ RETURN_STATUS(bc_error_bad_token());
}
-
bc_parse_number(p, &prev, &p->nbraces);
-
if (t == BC_LEX_NEG) bc_parse_push(p, BC_INST_NEG);
get_token = true;
-
break;
- }
-
case BC_LEX_KEY_READ:
- {
if (flags & BC_PARSE_NOREAD)
s = bc_error_nested_read_call();
else
bc_parse_push(p, BC_INST_READ);
get_token = true;
break;
- }
-
case BC_LEX_OP_ASSIGN:
case BC_LEX_STORE_PUSH:
- {
assign = t == BC_LEX_OP_ASSIGN;
inst = assign ? BC_INST_VAR : BC_INST_PUSH_TO_VAR;
- s = dc_parse_mem(p, inst, true, assign);
+ s = zdc_parse_mem(p, inst, true, assign);
break;
- }
-
case BC_LEX_LOAD:
case BC_LEX_LOAD_POP:
- {
inst = t == BC_LEX_LOAD_POP ? BC_INST_PUSH_VAR : BC_INST_LOAD;
- s = dc_parse_mem(p, inst, true, false);
+ s = zdc_parse_mem(p, inst, true, false);
break;
- }
-
case BC_LEX_STORE_IBASE:
case BC_LEX_STORE_SCALE:
case BC_LEX_STORE_OBASE:
- {
inst = t - BC_LEX_STORE_IBASE + BC_INST_IBASE;
- s = dc_parse_mem(p, inst, false, true);
+ s = zdc_parse_mem(p, inst, false, true);
break;
- }
-
default:
- {
s = bc_error_bad_token();
get_token = true;
break;
- }
}
if (!s && get_token) s = zbc_lex_next(&p->l);
- return s;
+ RETURN_STATUS(s);
}
+#if ERRORS_ARE_FATAL
+# define zdc_parse_token(...) (zdc_parse_token(__VA_ARGS__), BC_STATUS_SUCCESS)
+#endif
-static BcStatus dc_parse_expr(BcParse *p, uint8_t flags)
+static BC_STATUS zdc_parse_expr(BcParse *p, uint8_t flags)
{
BcStatus s = BC_STATUS_SUCCESS;
BcInst inst;
if (flags & BC_PARSE_NOCALL) p->nbraces = G.prog.results.len;
for (t = p->l.t.t; !s && t != BC_LEX_EOF; t = p->l.t.t) {
-
inst = dc_parse_insts[t];
if (inst != BC_INST_INVALID) {
bc_parse_push(p, inst);
s = zbc_lex_next(&p->l);
- }
- else
- s = dc_parse_token(p, t, flags);
+ } else
+ s = zdc_parse_token(p, t, flags);
}
if (!s && p->l.t.t == BC_LEX_EOF && (flags & BC_PARSE_NOCALL))
bc_parse_push(p, BC_INST_POP_EXEC);
- return s;
+ RETURN_STATUS(s);
}
+#if ERRORS_ARE_FATAL
+# define zdc_parse_expr(...) (zdc_parse_expr(__VA_ARGS__), BC_STATUS_SUCCESS)
+#endif
static FAST_FUNC BcStatus dc_parse_parse(BcParse *p)
{
if (p->l.t.t == BC_LEX_EOF)
s = bc_error("end of file");
else
- s = dc_parse_expr(p, 0);
+ s = zdc_parse_expr(p, 0);
if (s || G_interrupt) {
bc_parse_reset(p);
if (IS_BC) {
IF_BC(return bc_parse_expression(p, flags);)
} else {
- IF_DC(return dc_parse_expr(p, flags);)
+ IF_DC(return zdc_parse_expr(p, flags);)
}
}