v->v = xmalloc(esize * BC_VEC_START_CAP);
}
+static void bc_char_vec_init(BcVec *v)
+{
+ bc_vec_init(v, sizeof(char), NULL);
+}
+
static void bc_vec_expand(BcVec *v, size_t req)
{
if (v->cap < req) {
}
}
+static void bc_vec_pop_all(BcVec *v)
+{
+ bc_vec_npop(v, v->len);
+}
+
static void bc_vec_push(BcVec *v, const void *data)
{
if (v->len + 1 > v->cap) bc_vec_grow(v, 1);
static void bc_vec_string(BcVec *v, size_t len, const char *str)
{
- bc_vec_npop(v, v->len);
+ bc_vec_pop_all(v);
bc_vec_expand(v, len + 1);
memcpy(v->v, str, len);
v->len = len;
static void bc_vec_free(void *vec)
{
BcVec *v = (BcVec *) vec;
- bc_vec_npop(v, v->len);
+ bc_vec_pop_all(v);
free(v->v);
}
char c;
bad_chars = 0;
- bc_vec_npop(vec, vec->len);
+ bc_vec_pop_all(vec);
fflush_and_check();
#if ENABLE_FEATURE_BC_SIGNALS
static void bc_func_init(BcFunc *f)
{
- bc_vec_init(&f->code, sizeof(char), NULL);
+ bc_char_vec_init(&f->code);
bc_vec_init(&f->autos, sizeof(BcId), bc_id_free);
bc_vec_init(&f->labels, sizeof(size_t), NULL);
f->nparams = 0;
{
size_t i;
- bc_vec_npop(d, d->len);
+ bc_vec_pop_all(d);
bc_vec_expand(d, s->cap);
d->len = s->len;
if (len > BC_MAX_NUM)
return bc_error("number too long: must be [1, BC_NUM_MAX]");
- bc_vec_npop(&l->t.v, l->t.v.len);
+ bc_vec_pop_all(&l->t.v);
bc_vec_expand(&l->t.v, len + 1);
bc_vec_push(&l->t.v, &start);
static void bc_lex_init(BcLex *l, BcLexNext next)
{
l->next = next;
- bc_vec_init(&l->t.v, sizeof(char), NULL);
+ bc_char_vec_init(&l->t.v);
}
static void bc_lex_free(BcLex *l)
s = bc_lex_name(l);
}
else {
- bc_vec_npop(&l->t.v, l->t.v.len);
+ bc_vec_pop_all(&l->t.v);
bc_vec_pushByte(&l->t.v, l->buf[l->i - 1]);
bc_vec_pushByte(&l->t.v, '\0');
l->t.t = BC_LEX_NAME;
char c;
l->t.t = BC_LEX_STR;
- bc_vec_npop(&l->t.v, l->t.v.len);
+ bc_vec_pop_all(&l->t.v);
for (c = l->buf[i]; c != 0 && depth; c = l->buf[++i]) {
static void bc_parse_reset(BcParse *p)
{
if (p->fidx != BC_PROG_MAIN) {
-
p->func->nparams = 0;
- bc_vec_npop(&p->func->code, p->func->code.len);
- bc_vec_npop(&p->func->autos, p->func->autos.len);
- bc_vec_npop(&p->func->labels, p->func->labels.len);
+ bc_vec_pop_all(&p->func->code);
+ bc_vec_pop_all(&p->func->autos);
+ bc_vec_pop_all(&p->func->labels);
bc_parse_updateFunc(p, BC_PROG_MAIN);
}
p->auto_part = (p->nbraces = 0);
bc_vec_npop(&p->flags, p->flags.len - 1);
- bc_vec_npop(&p->exits, p->exits.len);
- bc_vec_npop(&p->conds, p->conds.len);
- bc_vec_npop(&p->ops, p->ops.len);
+ bc_vec_pop_all(&p->exits);
+ bc_vec_pop_all(&p->conds);
+ bc_vec_pop_all(&p->ops);
bc_program_reset();
}
return bc_error("read() call inside of a read() call");
}
- bc_vec_npop(&f->code, f->code.len);
- bc_vec_init(&buf, sizeof(char), NULL);
+ bc_vec_pop_all(&f->code);
+ bc_char_vec_init(&buf);
s = bc_read_line(&buf, "read> ");
if (s) goto io_err;
err:
bc_parse_free(&prs);
f = bc_vec_item(&G.prog.fns, fidx);
- bc_vec_npop(&f->code, f->code.len);
+ bc_vec_pop_all(&f->code);
exit:
bc_vec_pop(&G.prog.results);
return s;
// We need to reset these, so the function can be repopulated.
func->nparams = 0;
- bc_vec_npop(&func->autos, func->autos.len);
- bc_vec_npop(&func->code, func->code.len);
- bc_vec_npop(&func->labels, func->labels.len);
+ bc_vec_pop_all(&func->autos);
+ bc_vec_pop_all(&func->code);
+ bc_vec_pop_all(&func->labels);
}
else {
bc_func_init(&f);
BcInstPtr *ip;
bc_vec_npop(&G.prog.stack, G.prog.stack.len - 1);
- bc_vec_npop(&G.prog.results, G.prog.results.len);
+ bc_vec_pop_all(&G.prog.results);
f = bc_vec_item(&G.prog.fns, 0);
ip = bc_vec_top(&G.prog.stack);
case BC_INST_CLEAR_STACK:
{
- bc_vec_npop(&G.prog.results, G.prog.results.len);
+ bc_vec_pop_all(&G.prog.results);
break;
}
G.prog.file = bc_program_stdin_name;
bc_lex_file(&G.prs.l, bc_program_stdin_name);
- bc_vec_init(&buffer, sizeof(char), NULL);
- bc_vec_init(&buf, sizeof(char), NULL);
+ bc_char_vec_init(&buffer);
+ bc_char_vec_init(&buf);
bc_vec_pushByte(&buffer, '\0');
// This loop is complex because the vm tries not to send any lines that end
fputs("ready for more input\n", stderr);
}
- bc_vec_npop(&buffer, buffer.len);
+ bc_vec_pop_all(&buffer);
}
if (str) {