} BcFunc;
typedef enum BcResultType {
- BC_RESULT_TEMP,
+ XC_RESULT_TEMP,
- BC_RESULT_VAR,
- BC_RESULT_ARRAY_ELEM,
- BC_RESULT_ARRAY,
+ XC_RESULT_VAR,
+ XC_RESULT_ARRAY_ELEM,
+ XC_RESULT_ARRAY,
- BC_RESULT_STR,
+ XC_RESULT_STR,
- //code uses "inst - XC_INST_IBASE + BC_RESULT_IBASE" construct,
- BC_RESULT_IBASE, // relative order should match for: XC_INST_IBASE
- BC_RESULT_OBASE, // relative order should match for: XC_INST_OBASE
- BC_RESULT_SCALE, // relative order should match for: XC_INST_SCALE
+ //code uses "inst - XC_INST_IBASE + XC_RESULT_IBASE" construct,
+ XC_RESULT_IBASE, // relative order should match for: XC_INST_IBASE
+ XC_RESULT_OBASE, // relative order should match for: XC_INST_OBASE
+ XC_RESULT_SCALE, // relative order should match for: XC_INST_SCALE
IF_BC(BC_RESULT_LAST,) // relative order should match for: BC_INST_LAST
- BC_RESULT_CONSTANT,
- BC_RESULT_ONE,
+ XC_RESULT_CONSTANT,
+ IF_BC(BC_RESULT_ONE,)
} BcResultType;
typedef union BcResultData {
#define BC_PROG_STR(n) (!(n)->num && !(n)->cap)
#define BC_PROG_NUM(r, n) \
- ((r)->t != BC_RESULT_ARRAY && (r)->t != BC_RESULT_STR && !BC_PROG_STR(n))
+ ((r)->t != XC_RESULT_ARRAY && (r)->t != XC_RESULT_STR && !BC_PROG_STR(n))
#define BC_FLAG_W (1 << 0)
#define BC_FLAG_V (1 << 1)
d->t = src->t;
switch (d->t) {
- case BC_RESULT_TEMP:
- case BC_RESULT_IBASE:
- case BC_RESULT_SCALE:
- case BC_RESULT_OBASE:
+ case XC_RESULT_TEMP:
+ case XC_RESULT_IBASE:
+ case XC_RESULT_SCALE:
+ case XC_RESULT_OBASE:
bc_num_init(&d->d.n, src->d.n.len);
bc_num_copy(&d->d.n, &src->d.n);
break;
- case BC_RESULT_VAR:
- case BC_RESULT_ARRAY:
- case BC_RESULT_ARRAY_ELEM:
+ case XC_RESULT_VAR:
+ case XC_RESULT_ARRAY:
+ case XC_RESULT_ARRAY_ELEM:
d->d.id.name = xstrdup(src->d.id.name);
break;
- case BC_RESULT_CONSTANT:
+ case XC_RESULT_CONSTANT:
IF_BC(case BC_RESULT_LAST:)
- case BC_RESULT_ONE:
- case BC_RESULT_STR:
+ IF_BC(case BC_RESULT_ONE:)
+ case XC_RESULT_STR:
memcpy(&d->d.n, &src->d.n, sizeof(BcNum));
break;
}
BcResult *r = (BcResult *) result;
switch (r->t) {
- case BC_RESULT_TEMP:
- case BC_RESULT_IBASE:
- case BC_RESULT_SCALE:
- case BC_RESULT_OBASE:
+ case XC_RESULT_TEMP:
+ case XC_RESULT_IBASE:
+ case XC_RESULT_SCALE:
+ case XC_RESULT_OBASE:
bc_num_free(&r->d.n);
break;
- case BC_RESULT_VAR:
- case BC_RESULT_ARRAY:
- case BC_RESULT_ARRAY_ELEM:
+ case XC_RESULT_VAR:
+ case XC_RESULT_ARRAY:
+ case XC_RESULT_ARRAY_ELEM:
free(r->d.id.name);
break;
default:
static BC_STATUS zbc_program_num(BcResult *r, BcNum **num, bool hex)
{
switch (r->t) {
- case BC_RESULT_STR:
- case BC_RESULT_TEMP:
- case BC_RESULT_IBASE:
- case BC_RESULT_SCALE:
- case BC_RESULT_OBASE:
+ case XC_RESULT_STR:
+ case XC_RESULT_TEMP:
+ case XC_RESULT_IBASE:
+ case XC_RESULT_SCALE:
+ case XC_RESULT_OBASE:
*num = &r->d.n;
break;
- case BC_RESULT_CONSTANT: {
+ case XC_RESULT_CONSTANT: {
BcStatus s;
char *str;
unsigned base_t;
RETURN_STATUS(s);
}
*num = &r->d.n;
- r->t = BC_RESULT_TEMP;
+ r->t = XC_RESULT_TEMP;
break;
}
- case BC_RESULT_VAR:
- case BC_RESULT_ARRAY:
- case BC_RESULT_ARRAY_ELEM: {
+ case XC_RESULT_VAR:
+ case XC_RESULT_ARRAY:
+ case XC_RESULT_ARRAY_ELEM: {
BcVec *v;
- v = bc_program_search(r->d.id.name, r->t == BC_RESULT_VAR);
+ v = bc_program_search(r->d.id.name, r->t == XC_RESULT_VAR);
- if (r->t == BC_RESULT_ARRAY_ELEM) {
+ if (r->t == XC_RESULT_ARRAY_ELEM) {
v = bc_vec_top(v);
if (v->len <= r->d.id.idx) bc_array_expand(v, r->d.id.idx + 1);
*num = bc_vec_item(v, r->d.id.idx);
lt = (*l)->t;
rt = (*r)->t;
- hex = assign && (lt == BC_RESULT_IBASE || lt == BC_RESULT_OBASE);
+ hex = assign && (lt == XC_RESULT_IBASE || lt == XC_RESULT_OBASE);
s = zbc_program_num(*l, ln, false);
if (s) RETURN_STATUS(s);
// We run this again under these conditions in case any vector has been
// reallocated out from under the BcNums or arrays we had.
- if (lt == rt && (lt == BC_RESULT_VAR || lt == BC_RESULT_ARRAY_ELEM)) {
+ if (lt == rt && (lt == XC_RESULT_VAR || lt == XC_RESULT_ARRAY_ELEM)) {
s = zbc_program_num(*l, ln, false);
if (s) RETURN_STATUS(s);
}
- if (!BC_PROG_NUM((*l), (*ln)) && (!assign || (*l)->t != BC_RESULT_VAR))
+ if (!BC_PROG_NUM((*l), (*ln)) && (!assign || (*l)->t != XC_RESULT_VAR))
RETURN_STATUS(bc_error_variable_is_wrong_type());
if (!assign && !BC_PROG_NUM((*r), (*ln)))
RETURN_STATUS(bc_error_variable_is_wrong_type());
static void bc_program_binOpRetire(BcResult *r)
{
- r->t = BC_RESULT_TEMP;
+ r->t = XC_RESULT_TEMP;
bc_vec_pop(&G.prog.results);
bc_result_pop_and_push(r);
}
} else {
char *str;
- idx = (r->t == BC_RESULT_STR) ? r->d.id.idx : num->rdx;
+ idx = (r->t == XC_RESULT_STR) ? r->d.id.idx : num->rdx;
str = *bc_program_str(idx);
if (inst == XC_INST_PRINT_STR) {
bc_num_copy(&res.d.n, num);
if (res.d.n.len) res.d.n.neg = !res.d.n.neg;
- bc_program_retire(&res, BC_RESULT_TEMP);
+ bc_program_retire(&res, XC_RESULT_TEMP);
RETURN_STATUS(s);
}
memset(&n2, 0, sizeof(BcNum));
n2.rdx = res.d.id.idx = r->d.id.idx;
- res.t = BC_RESULT_STR;
+ res.t = XC_RESULT_STR;
if (!push) {
if (!STACK_HAS_MORE_THAN(&G.prog.results, 1))
RETURN_STATUS(bc_error_stack_has_too_few_elements());
ptr = bc_vec_top(&G.prog.results);
- if ((ptr->t == BC_RESULT_ARRAY) != !var)
+ if ((ptr->t == XC_RESULT_ARRAY) != !var)
RETURN_STATUS(bc_error_variable_is_wrong_type());
v = bc_program_search(name, var);
#if ENABLE_DC
- if (ptr->t == BC_RESULT_STR && !var)
+ if (ptr->t == XC_RESULT_STR && !var)
RETURN_STATUS(bc_error_variable_is_wrong_type());
- if (ptr->t == BC_RESULT_STR)
+ if (ptr->t == XC_RESULT_STR)
RETURN_STATUS(zdc_program_assignStr(ptr, v, true));
#endif
s = zbc_program_binOpPrep(&left, &l, &right, &r, assign);
if (s) RETURN_STATUS(s);
- ib = left->t == BC_RESULT_IBASE;
- sc = left->t == BC_RESULT_SCALE;
+ ib = left->t == XC_RESULT_IBASE;
+ sc = left->t == XC_RESULT_SCALE;
#if ENABLE_DC
- if (right->t == BC_RESULT_STR) {
+ if (right->t == XC_RESULT_STR) {
BcVec *v;
- if (left->t != BC_RESULT_VAR)
+ if (left->t != XC_RESULT_VAR)
RETURN_STATUS(bc_error_variable_is_wrong_type());
v = bc_program_search(left->d.id.name, true);
}
#endif
- if (left->t == BC_RESULT_CONSTANT || left->t == BC_RESULT_TEMP)
+ if (left->t == XC_RESULT_CONSTANT || left->t == XC_RESULT_TEMP)
RETURN_STATUS(bc_error("bad assignment:"
" left side must be variable"
" or array element"
bc_num_copy(l, r);
#endif
- if (ib || sc || left->t == BC_RESULT_OBASE) {
+ if (ib || sc || left->t == XC_RESULT_OBASE) {
static const char *const msg[] = {
- "bad ibase; must be [2,16]", //BC_RESULT_IBASE
- "bad obase; must be [2,"BC_MAX_OBASE_STR"]", //BC_RESULT_OBASE
- "bad scale; must be [0,"BC_MAX_SCALE_STR"]", //BC_RESULT_SCALE
+ "bad ibase; must be [2,16]", //XC_RESULT_IBASE
+ "bad obase; must be [2,"BC_MAX_OBASE_STR"]", //XC_RESULT_OBASE
+ "bad scale; must be [0,"BC_MAX_SCALE_STR"]", //XC_RESULT_SCALE
};
size_t *ptr;
size_t max;
s = zbc_num_ulong(l, &val);
if (s) RETURN_STATUS(s);
- s = left->t - BC_RESULT_IBASE;
+ s = left->t - XC_RESULT_IBASE;
if (sc) {
max = BC_MAX_SCALE;
ptr = &G.prog.scale;
BcResult r;
char *name = bc_program_name(code, bgn);
- r.t = BC_RESULT_VAR;
+ r.t = XC_RESULT_VAR;
r.d.id.name = name;
#if ENABLE_DC
}
if (!BC_PROG_STR(num)) {
- r.t = BC_RESULT_TEMP;
+ r.t = XC_RESULT_TEMP;
bc_num_init_DEF_SIZE(&r.d.n);
bc_num_copy(&r.d.n, num);
} else {
- r.t = BC_RESULT_STR;
+ r.t = XC_RESULT_STR;
r.d.id.idx = num->rdx;
}
r.d.id.name = bc_program_name(code, bgn);
if (inst == XC_INST_ARRAY) {
- r.t = BC_RESULT_ARRAY;
+ r.t = XC_RESULT_ARRAY;
bc_vec_push(&G.prog.results, &r);
} else {
BcResult *operand;
}
r.d.id.idx = (size_t) temp;
- bc_program_retire(&r, BC_RESULT_ARRAY_ELEM);
+ bc_program_retire(&r, XC_RESULT_ARRAY_ELEM);
}
err:
if (s) free(r.d.id.name);
if (s) RETURN_STATUS(s);
if (inst == BC_INST_INC_POST || inst == BC_INST_DEC_POST) {
- copy.t = BC_RESULT_TEMP;
+ copy.t = XC_RESULT_TEMP;
bc_num_init(©.d.n, num->len);
bc_num_copy(©.d.n, num);
}
a = bc_vec_item(&func->autos, nparams - 1 - i);
arg = bc_vec_top(&G.prog.results);
- if ((!a->idx) != (arg->t == BC_RESULT_ARRAY) || arg->t == BC_RESULT_STR)
+ if ((!a->idx) != (arg->t == XC_RESULT_ARRAY) || arg->t == XC_RESULT_STR)
RETURN_STATUS(bc_error_variable_is_wrong_type());
s = zbc_program_copyToVar(a->name, a->idx);
RETURN_STATUS(bc_error_stack_has_too_few_elements());
f = bc_program_func(ip->func);
- res.t = BC_RESULT_TEMP;
+ res.t = XC_RESULT_TEMP;
if (inst == XC_INST_RET) {
BcStatus s;
if (inst == XC_INST_SQRT)
s = zbc_num_sqrt(num, &res.d.n, G.prog.scale);
#if ENABLE_BC
- else if (len != 0 && opnd->t == BC_RESULT_ARRAY) {
+ else if (len != 0 && opnd->t == XC_RESULT_ARRAY) {
bc_num_ulong2num(&res.d.n, (unsigned long) ((BcVec *) num)->len);
}
#endif
#if ENABLE_DC
else if (len != 0 && !BC_PROG_NUM(opnd, num)) {
char **str;
- size_t idx = opnd->t == BC_RESULT_STR ? opnd->d.id.idx : num->rdx;
+ size_t idx = opnd->t == XC_RESULT_STR ? opnd->d.id.idx : num->rdx;
str = bc_program_str(idx);
bc_num_ulong2num(&res.d.n, strlen(*str));
bc_num_ulong2num(&res.d.n, len ? bc_program_len(num) : bc_program_scale(num));
}
- bc_program_retire(&res, BC_RESULT_TEMP);
+ bc_program_retire(&res, XC_RESULT_TEMP);
RETURN_STATUS(s);
}
if (s) goto err;
bc_program_binOpRetire(&res2);
- res.t = BC_RESULT_TEMP;
+ res.t = XC_RESULT_TEMP;
bc_vec_push(&G.prog.results, &res);
RETURN_STATUS(s);
RETURN_STATUS(bc_error_variable_is_wrong_type());
// Make sure that the values have their pointers updated, if necessary.
- if (r1->t == BC_RESULT_VAR || r1->t == BC_RESULT_ARRAY_ELEM) {
+ if (r1->t == XC_RESULT_VAR || r1->t == XC_RESULT_ARRAY_ELEM) {
if (r1->t == r2->t) {
s = zbc_program_num(r2, &n2, false);
if (s) RETURN_STATUS(s);
BcResult res;
size_t len = G.prog.results.len;
- res.t = BC_RESULT_TEMP;
+ res.t = XC_RESULT_TEMP;
bc_num_init_DEF_SIZE(&res.d.n);
bc_num_ulong2num(&res.d.n, len);
bc_num_free(&n);
} else {
char *sp;
- idx = (r->t == BC_RESULT_STR) ? r->d.id.idx : num->rdx;
+ idx = (r->t == XC_RESULT_STR) ? r->d.id.idx : num->rdx;
sp = *bc_program_str(idx);
c = sp[0];
}
//str[1] = '\0'; - already is
bc_vec_push(&G.prog.strs, &str);
dup:
- res.t = BC_RESULT_STR;
+ res.t = XC_RESULT_STR;
res.d.id.idx = idx;
bc_result_pop_and_push(&res);
s = zbc_num_printNum(n, 0x100, 1, dc_num_printChar);
} else {
char *str;
- idx = (r->t == BC_RESULT_STR) ? r->d.id.idx : n->rdx;
+ idx = (r->t == XC_RESULT_STR) ? r->d.id.idx : n->rdx;
str = *bc_program_str(idx);
fputs(str, stdout);
}
sidx = n->rdx;
} else {
- if (r->t == BC_RESULT_STR) {
+ if (r->t == XC_RESULT_STR) {
sidx = r->d.id.idx;
- } else if (r->t == BC_RESULT_VAR) {
+ } else if (r->t == XC_RESULT_VAR) {
BcNum *n;
s = zbc_program_num(r, &n, false);
if (s || !BC_PROG_STR(n)) goto exit;
BcResult res;
unsigned long val;
- res.t = inst - XC_INST_IBASE + BC_RESULT_IBASE;
+ res.t = inst - XC_INST_IBASE + XC_RESULT_IBASE;
if (inst == XC_INST_IBASE)
val = (unsigned long) G.prog.ib_t;
else if (inst == XC_INST_SCALE)
break;
case XC_INST_NUM:
dbg_exec("XC_INST_NUM:");
- r.t = BC_RESULT_CONSTANT;
+ r.t = XC_RESULT_CONSTANT;
r.d.id.idx = bc_program_index(code, &ip->inst_idx);
bc_vec_push(&G.prog.results, &r);
break;
break;
case XC_INST_STR:
dbg_exec("XC_INST_STR:");
- r.t = BC_RESULT_STR;
+ r.t = XC_RESULT_STR;
r.d.id.idx = bc_program_index(code, &ip->inst_idx);
bc_vec_push(&G.prog.results, &r);
break;
if (bc_num_cmp(num, &G.prog.zero) == 0)
bc_num_one(&r.d.n);
//else bc_num_zero(&r.d.n); - already is
- bc_program_retire(&r, BC_RESULT_TEMP);
+ bc_program_retire(&r, XC_RESULT_TEMP);
break;
}
case XC_INST_NEG: