size_t nchars;
} BcProgram;
-#define BC_PROG_STACK(s, n) ((s)->len >= ((size_t) n))
-
#define BC_PROG_MAIN (0)
#define BC_PROG_READ (1)
#if ENABLE_DC
# define COMMA_SUCCESS ,BC_STATUS_SUCCESS
#endif
+#define STACK_HAS_MORE_THAN(s, n) ((s)->len > ((size_t)(n)))
+#define STACK_HAS_EQUAL_OR_MORE_THAN(s, n) ((s)->len >= ((size_t)(n)))
+
#define BC_NUM_NEG(n, neg) ((((ssize_t)(n)) ^ -((ssize_t)(neg))) + (neg))
#define BC_NUM_ONE(n) ((n)->len == 1 && (n)->rdx == 0 && (n)->num[0] == 1)
#define BC_NUM_INT(n) ((n)->len - (n)->rdx)
bool hex;
BcResultType lt, rt;
- if (!BC_PROG_STACK(&G.prog.results, 2))
+ if (!STACK_HAS_MORE_THAN(&G.prog.results, 1))
RETURN_STATUS(bc_error_stack_has_too_few_elements());
*r = bc_vec_item_rev(&G.prog.results, 0);
{
BcStatus s;
- if (!BC_PROG_STACK(&G.prog.results, 1))
+ if (!STACK_HAS_MORE_THAN(&G.prog.results, 0))
RETURN_STATUS(bc_error_stack_has_too_few_elements());
*r = bc_vec_top(&G.prog.results);
BcNum *num;
bool pop = inst != BC_INST_PRINT;
- if (!BC_PROG_STACK(&G.prog.results, idx + 1))
+ if (!STACK_HAS_MORE_THAN(&G.prog.results, idx))
RETURN_STATUS(bc_error_stack_has_too_few_elements());
r = bc_vec_item_rev(&G.prog.results, idx);
res.t = BC_RESULT_STR;
if (!push) {
- if (!BC_PROG_STACK(&G.prog.results, 2))
+ if (!STACK_HAS_MORE_THAN(&G.prog.results, 1))
RETURN_STATUS(bc_error_stack_has_too_few_elements());
bc_vec_pop(v);
bc_vec_pop(&G.prog.results);
BcVec *v;
BcNum *n;
- if (!BC_PROG_STACK(&G.prog.results, 1))
+ if (!STACK_HAS_MORE_THAN(&G.prog.results, 0))
RETURN_STATUS(bc_error_stack_has_too_few_elements());
ptr = bc_vec_top(&G.prog.results);
BcNum *num = bc_vec_top(v);
free(name);
- if (!BC_PROG_STACK(v, 2 - copy)) {
+ if (!STACK_HAS_MORE_THAN(v, 1 - copy)) {
RETURN_STATUS(bc_error_stack_has_too_few_elements());
}
size_t i;
BcInstPtr *ip = bc_vec_top(&G.prog.exestack);
- if (!BC_PROG_STACK(&G.prog.results, ip->len + inst == BC_INST_RET))
+ if (!STACK_HAS_EQUAL_OR_MORE_THAN(&G.prog.results, ip->len + (inst == BC_INST_RET)))
RETURN_STATUS(bc_error_stack_has_too_few_elements());
f = bc_program_func(ip->func);
BcResult res;
bool len = inst == BC_INST_LENGTH;
- if (!BC_PROG_STACK(&G.prog.results, 1))
+ if (!STACK_HAS_MORE_THAN(&G.prog.results, 0))
RETURN_STATUS(bc_error_stack_has_too_few_elements());
opnd = bc_vec_top(&G.prog.results);
BcResult *r1, *r2, *r3, res;
BcNum *n1, *n2, *n3;
- if (!BC_PROG_STACK(&G.prog.results, 3))
+ if (!STACK_HAS_MORE_THAN(&G.prog.results, 2))
RETURN_STATUS(bc_error_stack_has_too_few_elements());
s = zbc_program_binOpPrep(&r2, &n2, &r3, &n3, false);
if (s) RETURN_STATUS(s);
size_t len = G.prog.strs.len, idx;
unsigned long val;
- if (!BC_PROG_STACK(&G.prog.results, 1))
+ if (!STACK_HAS_MORE_THAN(&G.prog.results, 0))
RETURN_STATUS(bc_error_stack_has_too_few_elements());
r = bc_vec_top(&G.prog.results);
size_t idx;
char *str;
- if (!BC_PROG_STACK(&G.prog.results, 1))
+ if (!STACK_HAS_MORE_THAN(&G.prog.results, 0))
RETURN_STATUS(bc_error_stack_has_too_few_elements());
r = bc_vec_top(&G.prog.results);
BcInstPtr ip;
size_t fidx, sidx;
- if (!BC_PROG_STACK(&G.prog.results, 1))
+ if (!STACK_HAS_MORE_THAN(&G.prog.results, 0))
RETURN_STATUS(bc_error_stack_has_too_few_elements());
r = bc_vec_top(&G.prog.results);
break;
case BC_INST_POP:
dbg_exec("BC_INST_POP:");
- if (!BC_PROG_STACK(&G.prog.results, 1))
+ if (!STACK_HAS_MORE_THAN(&G.prog.results, 0))
s = bc_error_stack_has_too_few_elements();
else
bc_vec_pop(&G.prog.results);
bc_program_stackLen();
break;
case BC_INST_DUPLICATE:
- if (!BC_PROG_STACK(&G.prog.results, 1))
+ if (!STACK_HAS_MORE_THAN(&G.prog.results, 0))
RETURN_STATUS(bc_error_stack_has_too_few_elements());
ptr = bc_vec_top(&G.prog.results);
bc_result_copy(&r, ptr);
break;
case BC_INST_SWAP: {
BcResult *ptr2;
- if (!BC_PROG_STACK(&G.prog.results, 2))
+ if (!STACK_HAS_MORE_THAN(&G.prog.results, 1))
RETURN_STATUS(bc_error_stack_has_too_few_elements());
ptr = bc_vec_item_rev(&G.prog.results, 0);
ptr2 = bc_vec_item_rev(&G.prog.results, 1);
break;
}
case BC_INST_QUIT:
- dbg_exec("BC_INST_NEG:");
+ dbg_exec("BC_INST_QUIT:");
if (G.prog.exestack.len <= 2)
QUIT_OR_RETURN_TO_MAIN;
bc_vec_npop(&G.prog.exestack, 2);