Lines Matching +full:clang +full:- +full:format

4  * SPDX-License-Identifier: BSD-2-Clause
6 * Copyright (c) 2018-2024 Gavin D. Howard and contributors.
62 assert(r->t != BC_RESULT_VOID); in bc_program_type_num()
79 if (BC_ERR((r->t != BC_RESULT_ARRAY) != (!t))) bc_err(BC_ERR_EXEC_TYPE); in bc_program_type_match()
86 * see the development manual (manuals/development.md#bytecode-indices).
116 return *((char**) bc_vec_item(&p->strs, n->scale)); in bc_program_string()
134 bc_vec_push(p->globals_v + i, p->globals + i); in bc_program_prepGlobals()
138 bc_rand_push(&p->rng); in bc_program_prepGlobals()
158 BcVec* v = p->globals_v + i; in bc_program_popGlobals()
159 bc_vec_npop(v, reset ? v->len - 1 : 1); in bc_program_popGlobals()
160 p->globals[i] = BC_PROG_GLOBAL(v); in bc_program_popGlobals()
164 bc_rand_pop(&p->rng, reset); in bc_program_popGlobals()
181 assert(vec->size == sizeof(uchar)); in bc_program_dereference()
185 vidx = bc_program_index(vec->v, &i); in bc_program_dereference()
186 nidx = bc_program_index(vec->v, &i); in bc_program_dereference()
188 v = bc_vec_item(bc_vec_item(&p->arrs, vidx), nidx); in bc_program_dereference()
191 assert(v->size != sizeof(uchar)); in bc_program_dereference()
215 bc_vec_push(&p->results, &res); in bc_program_pushBigdig()
227 if (bc_map_insert(&p->str_map, str, p->strs.len, &idx)) in bc_program_addString()
230 BcId* id = bc_vec_item(&p->str_map, idx); in bc_program_addString()
233 idx = id->idx; in bc_program_addString()
236 str_ptr = bc_vec_pushEmpty(&p->strs); in bc_program_addString()
240 *str_ptr = id->name; in bc_program_addString()
244 BcId* id = bc_vec_item(&p->str_map, idx); in bc_program_addString()
245 idx = id->idx; in bc_program_addString()
261 v = var ? &p->vars : &p->arrs; in bc_program_search()
262 map = var ? &p->var_map : &p->arr_map; in bc_program_search()
268 if (bc_map_insert(map, name, v->len, &i)) in bc_program_search()
274 return ((BcId*) bc_vec_item(map, i))->idx; in bc_program_search()
288 const BcVec* v = (type == BC_TYPE_VAR) ? &p->vars : &p->arrs; in bc_program_vec()
311 // is one of the most heavily-used, and eliminating the initialization in bc_program_num()
316 switch (r->t) in bc_program_num()
327 n = &r->d.n; in bc_program_num()
336 BcType type = (r->t == BC_RESULT_VAR) ? BC_TYPE_VAR : BC_TYPE_ARRAY; in bc_program_num()
339 v = bc_program_vec(p, r->d.loc.loc, type); in bc_program_num()
345 if (r->t == BC_RESULT_ARRAY_ELEM) in bc_program_num()
347 size_t idx = r->d.loc.idx; in bc_program_num()
349 v = bc_vec_item(v, r->d.loc.stack_idx); in bc_program_num()
358 if (v->size == sizeof(uchar)) v = bc_program_dereference(p, v); in bc_program_num()
362 assert(v->size == sizeof(BcNum)); in bc_program_num()
369 if (v->len <= idx) in bc_program_num()
386 n = bc_vec_item(v, r->d.loc.stack_idx); in bc_program_num()
400 n = &vm->zero; in bc_program_num()
406 n = &vm->one; in bc_program_num()
422 n = &p->last; in bc_program_num()
428 // This is here in GCC to quiet the "maybe-uninitialized" warning. in bc_program_num()
451 *r = bc_vec_item_rev(&p->results, idx); in bc_program_operand()
454 if (BC_ERR((*r)->t == BC_RESULT_VOID)) bc_err(BC_ERR_EXEC_VOID_VAL); in bc_program_operand()
486 if (BC_ERR(!BC_PROG_STACK(&p->results, idx + 2))) in bc_program_binPrep()
493 assert(BC_PROG_STACK(&p->results, idx + 2)); in bc_program_binPrep()
499 lt = (*l)->t; in bc_program_binPrep()
503 assert(lt != BC_RESULT_VOID && (*r)->t != BC_RESULT_VOID); in bc_program_binPrep()
509 if (lt == (*r)->t && (lt == BC_RESULT_VAR || lt == BC_RESULT_ARRAY_ELEM)) in bc_program_binPrep()
561 // This is the min non-allowable result type. dc allows strings. in bc_program_assignPrep()
562 min = BC_RESULT_TEMP - ((unsigned int) (BC_IS_BC)); in bc_program_assignPrep()
567 lt = (*l)->t; in bc_program_assignPrep()
574 good = ((*r)->t == BC_RESULT_STR && lt <= BC_RESULT_ARRAY_ELEM); in bc_program_assignPrep()
576 assert(BC_PROG_STR(*rn) || (*r)->t != BC_RESULT_STR); in bc_program_assignPrep()
601 if (BC_ERR(!BC_PROG_STACK(&p->results, idx + 1))) in bc_program_prep()
608 assert(BC_PROG_STACK(&p->results, idx + 1)); in bc_program_prep()
624 BcResult* res = bc_vec_pushEmpty(&p->results); in bc_program_prepResult()
646 BcConst* c = bc_vec_item(&p->consts, bc_program_index(code, bgn)); in bc_program_const()
650 if (c->base != base) in bc_program_const()
653 if (c->num.num == NULL) in bc_program_const()
656 size_t len = strlen(c->val) + (BC_DIGIT_CLAMP == 0); in bc_program_const()
659 bc_num_init(&c->num, BC_NUM_RDX(len)); in bc_program_const()
663 else bc_num_zero(&c->num); in bc_program_const()
666 bc_num_parse(&c->num, c->val, base); in bc_program_const()
668 c->base = base; in bc_program_const()
673 bc_num_createCopy(&r->d.n, &c->num); in bc_program_const()
691 size_t idx = inst - BC_INST_POWER; in bc_program_op()
702 bc_num_init(&res->d.n, bc_program_opReqs[idx](n1, n2, BC_PROG_SCALE(p))); in bc_program_op()
710 bc_program_ops[idx](n1, n2, &res->d.n, BC_PROG_SCALE(p)); in bc_program_op()
727 BcFunc* f = bc_vec_item(&p->fns, BC_PROG_READ); in bc_program_read()
731 for (i = 0; i < p->stack.len; ++i) in bc_program_read()
733 BcInstPtr* ip_ptr = bc_vec_item(&p->stack, i); in bc_program_read()
734 if (ip_ptr->func == BC_PROG_READ) bc_err(BC_ERR_EXEC_REC_READ); in bc_program_read()
740 file = vm->file; in bc_program_read()
741 mode = vm->mode; in bc_program_read()
745 vm->mode = BC_MODE_FILE; in bc_program_read()
747 if (!BC_PARSE_IS_INITED(&vm->read_prs, p)) in bc_program_read()
754 bc_parse_init(&vm->read_prs, p, BC_PROG_READ); in bc_program_read()
758 bc_vec_init(&vm->read_buf, sizeof(char), BC_DTOR_NONE); in bc_program_read()
764 bc_parse_updateFunc(&vm->read_prs, BC_PROG_READ); in bc_program_read()
768 bc_vec_empty(&vm->read_buf); in bc_program_read()
776 bc_lex_file(&vm->read_prs.l, bc_program_stdin_name); in bc_program_read()
777 bc_vec_popAll(&f->code); in bc_program_read()
780 if (!BC_R) s = bc_read_line(&vm->read_buf, ""); in bc_program_read()
781 else s = bc_read_line(&vm->read_buf, BC_VM_READ_PROMPT); in bc_program_read()
787 bc_parse_text(&vm->read_prs, vm->read_buf.v, BC_MODE_FILE); in bc_program_read()
789 vm->expr(&vm->read_prs, BC_PARSE_NOREAD | BC_PARSE_NEEDVAL); in bc_program_read()
794 if (BC_ERR(vm->read_prs.l.t != BC_LEX_NLINE && in bc_program_read()
795 vm->read_prs.l.t != BC_LEX_EOF)) in bc_program_read()
808 ip.len = p->results.len; in bc_program_read()
811 f = bc_vec_item(&p->fns, BC_PROG_READ); in bc_program_read()
814 bc_vec_pushByte(&f->code, vm->read_ret); in bc_program_read()
818 bc_vec_push(&p->stack, &ip); in bc_program_read()
825 bc_vec_push(&p->tail_calls, &temp); in bc_program_read()
831 vm->mode = (uchar) mode; in bc_program_read()
832 vm->file = file; in bc_program_read()
845 BcRand rand = bc_rand_int(&p->rng); in bc_program_rand()
853 BcResult* r = bc_vec_top(&p->results); in bc_program_rand()
854 assert(BC_NUM_RDX_VALID_NP(r->d.n)); in bc_program_rand()
868 size_t len = vm->nchars + strlen(str); in bc_program_printChars()
873 bc_file_puts(&vm->fout, bc_flush_save, str); in bc_program_printChars()
881 vm->nchars = len > UINT16_MAX ? UINT16_MAX : (uint16_t) len; in bc_program_printChars()
910 if (c == '\\' && i != len - 1) in bc_program_printString()
925 vm->nchars = UINT16_MAX; in bc_program_printString()
930 c = bc_program_esc_seqs[(size_t) (ptr - bc_program_esc_chars)]; in bc_program_printString()
964 if (BC_ERR(!BC_PROG_STACK(&p->results, idx + 1))) in bc_program_print()
971 assert(BC_PROG_STACK(&p->results, idx + 1)); in bc_program_print()
973 r = bc_vec_item_rev(&p->results, idx); in bc_program_print()
980 if (r->t == BC_RESULT_VOID) in bc_program_print()
983 bc_vec_pop(&p->results); in bc_program_print()
1002 if (BC_IS_BC) bc_num_copy(&p->last, n); in bc_program_print()
1008 bc_file_flush(&vm->fout, bc_flush_save); in bc_program_print()
1024 if (BC_PROGRAM_POP(pop)) bc_vec_pop(&p->results); in bc_program_print()
1030 bc_num_copy(&r->d.n, n); in bc_program_negate()
1031 if (BC_NUM_NONZERO(&r->d.n)) BC_NUM_NEG_TGL_NP(r->d.n); in bc_program_negate()
1037 if (!bc_num_cmpZero(n)) bc_num_one(&r->d.n); in bc_program_not()
1044 bc_num_copy(&r->d.n, n); in bc_program_trunc()
1045 bc_num_truncate(&r->d.n, n->scale); in bc_program_trunc()
1067 bc_num_init(&res->d.n, num->len); in bc_program_unary()
1072 bc_program_unarys[inst - BC_INST_NEG](res, num); in bc_program_unary()
1162 bc_num_init(&res->d.n, BC_NUM_DEF_SIZE); in bc_program_logical()
1166 if (cond) bc_num_one(&res->d.n); in bc_program_logical()
1185 assert(BC_PROG_STACK(&p->results, 1 + !push)); in bc_program_assignStr()
1186 assert(num != NULL && num->num == NULL && num->cap == 0); in bc_program_assignStr()
1192 bc_vec_npop(&p->results, 1 + !push); in bc_program_assignStr()
1220 if (BC_ERR(!BC_PROG_STACK(&p->results, 1))) bc_err(BC_ERR_EXEC_STACK); in bc_program_copyToVar()
1224 assert(BC_PROG_STACK(&p->results, 1)); in bc_program_copyToVar()
1241 if (ptr->t == BC_RESULT_STR) in bc_program_copyToVar()
1278 ref = (v->size == sizeof(BcNum) && t == BC_TYPE_REF); in bc_program_copyToVar()
1285 ref_size = (v->size == sizeof(uchar)); in bc_program_copyToVar()
1302 bc_vec_pushIndex(rv, ptr->d.loc.loc); in bc_program_copyToVar()
1303 bc_vec_pushIndex(rv, ptr->d.loc.stack_idx); in bc_program_copyToVar()
1307 else bc_vec_npush(rv, v->len * sizeof(uchar), v->v); in bc_program_copyToVar()
1312 bc_vec_pop(&p->results); in bc_program_copyToVar()
1336 bc_vec_pop(&p->results); in bc_program_copyToVar()
1358 max = vm->maxes[BC_PROG_GLOBALS_SCALE]; in bc_program_assignBuiltin()
1362 v = p->globals_v + BC_PROG_GLOBALS_SCALE; in bc_program_assignBuiltin()
1366 ptr_t = p->globals + BC_PROG_GLOBALS_SCALE; in bc_program_assignBuiltin()
1376 max = vm->maxes[obase + BC_PROG_GLOBALS_IBASE]; in bc_program_assignBuiltin()
1380 v = p->globals_v + BC_PROG_GLOBALS_IBASE + obase; in bc_program_assignBuiltin()
1384 ptr_t = p->globals + BC_PROG_GLOBALS_IBASE + obase; in bc_program_assignBuiltin()
1414 bc_num_rng(val, &p->rng); in bc_program_assignSeed()
1437 assert(left->t != BC_RESULT_STR); in bc_program_assign()
1440 if (right->t == BC_RESULT_STR) in bc_program_assign()
1452 if (left->t == BC_RESULT_ARRAY_ELEM) in bc_program_assign()
1463 bc_vec_npop(&p->results, 2); in bc_program_assign()
1471 BcVec* v = bc_program_vec(p, left->d.loc.loc, BC_TYPE_VAR); in bc_program_assign()
1484 bc_vec_push(&p->results, &res); in bc_program_assign()
1489 // By using bc_program_assignStr(), we short-circuited this, so return. in bc_program_assign()
1505 if (right->t == BC_RESULT_TEMP || right->t >= BC_RESULT_IBASE) in bc_program_assign()
1512 right->t = BC_RESULT_ZERO; in bc_program_assign()
1522 // If we get here, we are doing a math assignment (+=, -=, etc.). So in bc_program_assign()
1535 inst -= (BC_INST_ASSIGN_POWER_NO_VAL - BC_INST_ASSIGN_POWER); in bc_program_assign()
1543 bc_program_ops[inst - BC_INST_ASSIGN_POWER](l, r, l, scale); in bc_program_assign()
1547 ob = (left->t == BC_RESULT_OBASE); in bc_program_assign()
1548 sc = (left->t == BC_RESULT_SCALE); in bc_program_assign()
1550 // The globals need special handling, especially the non-seed ones. The in bc_program_assign()
1552 if (ob || sc || left->t == BC_RESULT_IBASE) in bc_program_assign()
1561 else if (left->t == BC_RESULT_SEED) bc_program_assignSeed(p, l); in bc_program_assign()
1572 bc_vec_npop(&p->results, 2); in bc_program_assign()
1573 bc_vec_push(&p->results, &res); in bc_program_assign()
1575 else bc_vec_npop(&p->results, 2); in bc_program_assign()
1605 r.d.loc.stack_idx = v->len - 1; in bc_program_pushVar()
1616 if (BC_ERR(!BC_PROG_STACK(v, 2 - copy))) in bc_program_pushVar()
1618 const char* name = bc_map_name(&p->var_map, idx); in bc_program_pushVar()
1622 assert(BC_PROG_STACK(v, 2 - copy)); in bc_program_pushVar()
1636 bc_vec_push(&p->results, &r); in bc_program_pushVar()
1656 bc_vec_push(&p->results, &r); in bc_program_pushVar()
1684 r.d.loc.stack_idx = v->len - 1; in bc_program_pushArray()
1690 bc_vec_push(&p->results, &r); in bc_program_pushArray()
1705 bc_vec_pop(&p->results); in bc_program_pushArray()
1706 bc_vec_push(&p->results, &r); in bc_program_pushArray()
1743 bc_vec_push(&p->results, &res); in bc_program_incdec()
1748 bc_vec_push(&p->results, &copy); in bc_program_incdec()
1788 f = bc_vec_item(&p->fns, ip.func); in bc_program_call()
1791 if (BC_ERR(!f->code.len)) bc_verr(BC_ERR_EXEC_UNDEF_FUNC, f->name); in bc_program_call()
1792 if (BC_ERR(nargs != f->nparams)) in bc_program_call()
1794 bc_verr(BC_ERR_EXEC_PARAMS, f->nparams, nargs); in bc_program_call()
1798 ip.len = p->results.len - nargs; in bc_program_call()
1800 assert(BC_PROG_STACK(&p->results, nargs)); in bc_program_call()
1808 arg = bc_vec_top(&p->results); in bc_program_call()
1809 if (BC_ERR(arg->t == BC_RESULT_VOID)) bc_err(BC_ERR_EXEC_VOID_VAL); in bc_program_call()
1812 a = bc_vec_item(&f->autos, nargs - 1 - i); in bc_program_call()
1815 bc_program_copyToVar(p, a->idx, a->type); in bc_program_call()
1821 for (; i < f->autos.len; ++i) in bc_program_call()
1824 a = bc_vec_item(&f->autos, i); in bc_program_call()
1825 v = bc_program_vec(p, a->idx, a->type); in bc_program_call()
1828 if (a->type == BC_TYPE_VAR) in bc_program_call()
1837 assert(a->type == BC_TYPE_ARRAY); in bc_program_call()
1845 bc_vec_push(&p->stack, &ip); in bc_program_call()
1865 ip = bc_vec_top(&p->stack); in bc_program_return()
1869 nresults = p->results.len - ip->len; in bc_program_return()
1872 assert(BC_PROG_STACK(&p->stack, 2)); in bc_program_return()
1876 assert(BC_PROG_STACK(&p->results, ip->len + (inst == BC_INST_RET))); in bc_program_return()
1879 f = bc_vec_item(&p->fns, ip->func); in bc_program_return()
1897 res->t = BC_RESULT_STR; in bc_program_return()
1900 memcpy(&res->d.n, num, sizeof(BcNum)); in bc_program_return()
1906 bc_num_createCopy(&res->d.n, num); in bc_program_return()
1910 else if (inst == BC_INST_RET_VOID) res->t = BC_RESULT_VOID; in bc_program_return()
1916 bc_num_init(&res->d.n, BC_NUM_DEF_SIZE); in bc_program_return()
1922 for (i = 0; i < f->autos.len; ++i) in bc_program_return()
1924 BcAuto* a = bc_vec_item(&f->autos, i); in bc_program_return()
1925 BcVec* v = bc_program_vec(p, a->idx, a->type); in bc_program_return()
1939 bc_vec_pop(&p->stack); in bc_program_return()
1967 if (BC_IS_DC && BC_ERR(!BC_PROG_STACK(&p->results, 1))) in bc_program_builtin()
1973 assert(BC_PROG_STACK(&p->results, 1)); in bc_program_builtin()
1990 if (inst == BC_INST_SQRT) bc_num_sqrt(num, &res->d.n, BC_PROG_SCALE(p)); in bc_program_builtin()
1997 bc_num_createCopy(&res->d.n, num); in bc_program_builtin()
2001 BC_NUM_NEG_CLR_NP(res->d.n); in bc_program_builtin()
2012 bc_num_init(&res->d.n, BC_NUM_DEF_SIZE); in bc_program_builtin()
2023 if (cond) bc_num_one(&res->d.n); in bc_program_builtin()
2033 bc_num_init(&res->d.n, num->len - BC_NUM_RDX_VAL(num)); in bc_program_builtin()
2037 bc_num_irand(num, &res->d.n, &p->rng); in bc_program_builtin()
2051 if (opd->t == BC_RESULT_ARRAY) in bc_program_builtin()
2062 if (BC_IS_BC && v->size == sizeof(uchar)) in bc_program_builtin()
2068 assert(v->size == sizeof(BcNum)); in bc_program_builtin()
2070 val = (BcBigDig) v->len; in bc_program_builtin()
2100 bc_num_createFromBigdig(&res->d.n, val); in bc_program_builtin()
2124 bc_vec_grow(&p->results, 2); in bc_program_divmod()
2139 bc_num_init(&res->d.n, req); in bc_program_divmod()
2140 bc_num_init(&res2->d.n, req); in bc_program_divmod()
2145 bc_num_divmod(n1, n2, &res2->d.n, &res->d.n, BC_PROG_SCALE(p)); in bc_program_divmod()
2168 if (BC_IS_DC && BC_ERR(!BC_PROG_STACK(&p->results, 3))) in bc_program_modexp()
2175 assert(BC_PROG_STACK(&p->results, 3)); in bc_program_modexp()
2188 if (r1->t == BC_RESULT_ARRAY_ELEM && (r1->t == r2->t || r1->t == r3->t)) in bc_program_modexp()
2195 bc_num_init(&res->d.n, n3->len); in bc_program_modexp()
2199 bc_num_modexp(n1, n2, n3, &res->d.n); in bc_program_modexp()
2212 bc_num_copy(&p->asciify, n); in bc_program_asciifyNum()
2215 bc_num_truncate(&p->asciify, p->asciify.scale); in bc_program_asciifyNum()
2216 BC_NUM_NEG_CLR(&p->asciify); in bc_program_asciifyNum()
2220 bc_num_mod(&p->asciify, &p->strmb, &p->asciify, 0); in bc_program_asciifyNum()
2225 return (uchar) bc_num_bigdig2(&p->asciify); in bc_program_asciifyNum()
2245 if (BC_ERR(!BC_PROG_STACK(&p->results, 1))) bc_err(BC_ERR_EXEC_STACK); in bc_program_asciify()
2247 assert(BC_PROG_STACK(&p->results, 1)); in bc_program_asciify()
2253 assert(BC_IS_BC || r->t != BC_RESULT_ARRAY); in bc_program_asciify()
2257 if (r->t == BC_RESULT_ARRAY) in bc_program_asciify()
2268 if (v->size == sizeof(uchar)) in bc_program_asciify()
2273 assert(v->size == sizeof(BcNum)); in bc_program_asciify()
2277 temp_str = bc_vm_malloc(v->len + 1); in bc_program_asciify()
2282 for (i = 0; i < v->len; ++i) in bc_program_asciify()
2296 temp_str[v->len] = '\0'; in bc_program_asciify()
2336 bc_vec_pop(&p->results); in bc_program_asciify()
2337 bc_vec_push(&p->results, &res); in bc_program_asciify()
2358 if (BC_ERR(!BC_PROG_STACK(&p->results, 1))) bc_err(BC_ERR_EXEC_STACK); in bc_program_printStream()
2360 assert(BC_PROG_STACK(&p->results, 1)); in bc_program_printStream()
2372 bc_vec_pop(&p->results); in bc_program_printStream()
2391 bc_program_pushBigdig(p, (BcBigDig) v->len, BC_RESULT_TEMP); in bc_program_regStackLen()
2401 bc_program_pushBigdig(p, (BcBigDig) p->results.len, BC_RESULT_TEMP); in bc_program_stackLen()
2420 assert(p->stack.len == p->tail_calls.len); in bc_program_nquit()
2429 bc_vec_pop(&p->results); in bc_program_nquit()
2433 for (i = 0; val && i < p->tail_calls.len; ++i) in bc_program_nquit()
2436 size_t calls = *((size_t*) bc_vec_item_rev(&p->tail_calls, i)) + 1; in bc_program_nquit()
2440 else val -= (BcBigDig) calls; in bc_program_nquit()
2444 if (i == p->stack.len) in bc_program_nquit()
2446 vm->status = BC_STATUS_QUIT; in bc_program_nquit()
2456 bc_vec_npop(&p->stack, i); in bc_program_nquit()
2457 bc_vec_npop(&p->tail_calls, i); in bc_program_nquit()
2469 size_t i, amt, len = p->tail_calls.len; in bc_program_execStackLen()
2475 amt += *((size_t*) bc_vec_item(&p->tail_calls, i)); in bc_program_execStackLen()
2501 assert(p->stack.len == p->tail_calls.len); in bc_program_execStr()
2504 if (BC_ERR(!BC_PROG_STACK(&p->results, 1))) bc_err(BC_ERR_EXEC_STACK); in bc_program_execStr()
2506 assert(BC_PROG_STACK(&p->results, 1)); in bc_program_execStr()
2526 exec = (r->d.n.len != 0); in bc_program_execStr()
2550 // In non-conditional situations, only the top of stack can be executed, in bc_program_execStr()
2553 assert(r->t != BC_RESULT_VAR); in bc_program_execStr()
2555 if (r->t != BC_RESULT_STR) return; in bc_program_execStr()
2567 f = bc_vec_item(&p->fns, fidx); in bc_program_execStr()
2570 if (!f->code.len) in bc_program_execStr()
2574 if (!BC_PARSE_IS_INITED(&vm->read_prs, p)) in bc_program_execStr()
2576 bc_parse_init(&vm->read_prs, p, fidx); in bc_program_execStr()
2580 bc_vec_init(&vm->read_buf, sizeof(char), BC_DTOR_NONE); in bc_program_execStr()
2584 else bc_parse_updateFunc(&vm->read_prs, fidx); in bc_program_execStr()
2586 bc_lex_file(&vm->read_prs.l, vm->file); in bc_program_execStr()
2593 bc_parse_text(&vm->read_prs, str, BC_MODE_FILE); in bc_program_execStr()
2596 vm->expr(&vm->read_prs, BC_PARSE_NOCALL); in bc_program_execStr()
2602 assert(vm->read_prs.l.t == BC_LEX_EOF); in bc_program_execStr()
2609 ip.len = p->results.len; in bc_program_execStr()
2615 bc_vec_pop(&p->results); in bc_program_execStr()
2620 if (p->stack.len > 1 && *bgn == len - 1 && code[*bgn] == BC_INST_POP_EXEC) in bc_program_execStr()
2622 size_t* call_ptr = bc_vec_top(&p->tail_calls); in bc_program_execStr()
2629 bc_vec_pop(&p->stack); in bc_program_execStr()
2632 else bc_vec_push(&p->tail_calls, &ip.idx); in bc_program_execStr()
2635 bc_vec_push(&p->stack, &ip); in bc_program_execStr()
2644 f = bc_vec_item(&p->fns, fidx); in bc_program_execStr()
2647 bc_vec_popAll(&f->code); in bc_program_execStr()
2650 bc_vec_pop(&p->results); in bc_program_execStr()
2663 for (idx = 0; idx < p->results.len; ++idx) in bc_program_printStack()
2684 t = inst - BC_INST_IBASE + BC_RESULT_IBASE; in bc_program_pushGlobal()
2685 bc_program_pushBigdig(p, p->globals[inst - BC_INST_IBASE], t); in bc_program_pushGlobal()
2708 val = (BcBigDig) vm->line_len; in bc_program_globalSetting()
2740 res->t = BC_RESULT_SEED; in bc_program_pushSeed()
2745 bc_num_init(&res->d.n, 2 * BC_RAND_NUM_SIZE); in bc_program_pushSeed()
2749 bc_num_createFromRNG(&res->d.n, &p->rng); in bc_program_pushSeed()
2768 f = bc_vec_pushEmpty(&p->fns); in bc_program_addFunc()
2769 bc_func_init(f, id_ptr->name); in bc_program_addFunc()
2784 new = bc_map_insert(&p->fn_map, name, p->fns.len, &idx); in bc_program_insertFunc()
2785 id_ptr = (BcId*) bc_vec_item(&p->fn_map, idx); in bc_program_insertFunc()
2786 idx = id_ptr->idx; in bc_program_insertFunc()
2798 BcFunc* func = bc_vec_item(&p->fns, idx); in bc_program_insertFunc()
2822 bc_vec_free(p->globals_v + i); in bc_program_free()
2826 bc_vec_free(&p->fns); in bc_program_free()
2827 bc_vec_free(&p->fn_map); in bc_program_free()
2828 bc_vec_free(&p->vars); in bc_program_free()
2829 bc_vec_free(&p->var_map); in bc_program_free()
2830 bc_vec_free(&p->arrs); in bc_program_free()
2831 bc_vec_free(&p->arr_map); in bc_program_free()
2832 bc_vec_free(&p->results); in bc_program_free()
2833 bc_vec_free(&p->stack); in bc_program_free()
2834 bc_vec_free(&p->consts); in bc_program_free()
2835 bc_vec_free(&p->const_map); in bc_program_free()
2836 bc_vec_free(&p->strs); in bc_program_free()
2837 bc_vec_free(&p->str_map); in bc_program_free()
2839 bc_num_free(&p->asciify); in bc_program_free()
2842 if (BC_IS_BC) bc_num_free(&p->last); in bc_program_free()
2846 bc_rand_free(&p->rng); in bc_program_free()
2850 if (BC_IS_DC) bc_vec_free(&p->tail_calls); in bc_program_free()
2875 bc_vec_init(p->globals_v + i, sizeof(BcBigDig), BC_DTOR_NONE); in bc_program_init()
2876 bc_vec_push(p->globals_v + i, &val); in bc_program_init()
2879 p->globals[i] = val; in bc_program_init()
2883 // dc-only setup. in bc_program_init()
2886 bc_vec_init(&p->tail_calls, sizeof(size_t), BC_DTOR_NONE); in bc_program_init()
2890 bc_vec_push(&p->tail_calls, &i); in bc_program_init()
2894 bc_num_setup(&p->strmb, p->strmb_num, BC_NUM_BIGDIG_LOG10); in bc_program_init()
2895 bc_num_bigdig2num(&p->strmb, BC_NUM_STREAM_BASE); in bc_program_init()
2897 bc_num_init(&p->asciify, BC_NUM_DEF_SIZE); in bc_program_init()
2903 bc_rand_init(&p->rng); in bc_program_init()
2907 if (BC_IS_BC) bc_num_init(&p->last, BC_NUM_DEF_SIZE); in bc_program_init()
2911 bc_vec_init(&p->fns, sizeof(BcFunc), BC_DTOR_FUNC); in bc_program_init()
2913 bc_vec_init(&p->fns, sizeof(BcFunc), BC_DTOR_NONE); in bc_program_init()
2915 bc_map_init(&p->fn_map); in bc_program_init()
2919 bc_vec_init(&p->vars, sizeof(BcVec), BC_DTOR_VEC); in bc_program_init()
2920 bc_map_init(&p->var_map); in bc_program_init()
2922 bc_vec_init(&p->arrs, sizeof(BcVec), BC_DTOR_VEC); in bc_program_init()
2923 bc_map_init(&p->arr_map); in bc_program_init()
2925 bc_vec_init(&p->results, sizeof(BcResult), BC_DTOR_RESULT); in bc_program_init()
2928 bc_vec_init(&p->stack, sizeof(BcInstPtr), BC_DTOR_NONE); in bc_program_init()
2929 bc_vec_push(&p->stack, &ip); in bc_program_init()
2931 bc_vec_init(&p->consts, sizeof(BcConst), BC_DTOR_CONST); in bc_program_init()
2932 bc_map_init(&p->const_map); in bc_program_init()
2933 bc_vec_init(&p->strs, sizeof(char*), BC_DTOR_NONE); in bc_program_init()
2934 bc_map_init(&p->str_map); in bc_program_init()
2942 max_digits = bc_vm_numDigits(p->stack.len - 1); in bc_program_printStackTrace()
2944 for (i = 0; i < p->stack.len; ++i) in bc_program_printStackTrace()
2946 BcInstPtr* ip = bc_vec_item_rev(&p->stack, i); in bc_program_printStackTrace()
2947 BcFunc* f = bc_vec_item(&p->fns, ip->func); in bc_program_printStackTrace()
2952 bc_file_puts(&vm->ferr, bc_flush_none, " "); in bc_program_printStackTrace()
2954 for (j = 0; j < max_digits - digits; ++j) in bc_program_printStackTrace()
2956 bc_file_putchar(&vm->ferr, bc_flush_none, ' '); in bc_program_printStackTrace()
2959 bc_file_printf(&vm->ferr, "%zu: %s", i, f->name); in bc_program_printStackTrace()
2962 if (BC_IS_BC && ip->func != BC_PROG_MAIN && ip->func != BC_PROG_READ) in bc_program_printStackTrace()
2964 bc_file_puts(&vm->ferr, bc_flush_none, "()"); in bc_program_printStackTrace()
2968 bc_file_putchar(&vm->ferr, bc_flush_none, '\n'); in bc_program_printStackTrace()
2981 bc_vec_npop(&p->stack, p->stack.len - 1); in bc_program_reset()
2985 if (BC_IS_DC) bc_vec_npop(&p->tail_calls, p->tail_calls.len - 1); in bc_program_reset()
2993 if (BC_IS_BC || !BC_I) bc_vec_popAll(&p->results); in bc_program_reset()
3000 f = bc_vec_item(&p->fns, BC_PROG_MAIN); in bc_program_reset()
3001 bc_vec_npop(&f->code, f->code.len); in bc_program_reset()
3004 ip = bc_vec_top(&p->stack); in bc_program_reset()
3011 bc_file_printf(&vm->fout, "%s", bc_program_ready_msg); in bc_program_reset()
3012 bc_file_flush(&vm->fout, bc_flush_err); in bc_program_reset()
3016 vm->sig = 0; in bc_program_reset()
3042 #pragma GCC diagnostic ignored "-Wpedantic" in bc_program_exec()
3046 #pragma clang diagnostic ignored "-Wgnu-label-as-value" in bc_program_exec()
3053 #pragma clang diagnostic warning "-Wgnu-label-as-value" in bc_program_exec()
3057 #pragma GCC diagnostic warning "-Wpedantic" in bc_program_exec()
3062 func = (BcFunc*) bc_vec_item(&p->fns, BC_PROG_MAIN); in bc_program_exec()
3063 bc_vec_pushByte(&func->code, BC_INST_INVALID); in bc_program_exec()
3068 ip = bc_vec_top(&p->stack); in bc_program_exec()
3069 func = (BcFunc*) bc_vec_item(&p->fns, ip->func); in bc_program_exec()
3070 code = func->code.v; in bc_program_exec()
3075 jmp_bufs_len = vm->jmp_bufs.len; in bc_program_exec()
3080 while (ip->idx < func->code.len) in bc_program_exec()
3088 #pragma GCC diagnostic ignored "-Wpedantic" in bc_program_exec()
3092 #pragma clang diagnostic ignored "-Wgnu-label-as-value" in bc_program_exec()
3100 inst = (uchar) code[(ip->idx)++]; in bc_program_exec()
3105 bc_file_printf(&vm->ferr, "inst: %s\n", bc_inst_names[inst]); in bc_program_exec()
3106 bc_file_flush(&vm->ferr, bc_flush_none); in bc_program_exec()
3116 // clang-format off in bc_program_exec()
3118 // clang-format on in bc_program_exec()
3123 bc_vec_pop(&p->results); in bc_program_exec()
3130 // clang-format off in bc_program_exec()
3132 // clang-format on in bc_program_exec()
3134 idx = bc_program_index(code, &ip->idx); in bc_program_exec()
3140 size_t* addr = bc_vec_item(&func->labels, idx); in bc_program_exec()
3147 ip->idx = *addr; in bc_program_exec()
3153 // clang-format off in bc_program_exec()
3155 // clang-format on in bc_program_exec()
3159 bc_program_call(p, code, &ip->idx); in bc_program_exec()
3164 ip = bc_vec_top(&p->stack); in bc_program_exec()
3165 func = bc_vec_item(&p->fns, ip->func); in bc_program_exec()
3166 code = func->code.v; in bc_program_exec()
3172 // clang-format off in bc_program_exec()
3175 // clang-format on in bc_program_exec()
3181 // clang-format off in bc_program_exec()
3183 // clang-format on in bc_program_exec()
3185 vm->status = BC_STATUS_QUIT; in bc_program_exec()
3193 // clang-format off in bc_program_exec()
3197 // clang-format on in bc_program_exec()
3204 ip = bc_vec_top(&p->stack); in bc_program_exec()
3205 func = bc_vec_item(&p->fns, ip->func); in bc_program_exec()
3206 code = func->code.v; in bc_program_exec()
3213 // clang-format off in bc_program_exec()
3222 // clang-format on in bc_program_exec()
3228 // clang-format off in bc_program_exec()
3230 // clang-format on in bc_program_exec()
3234 bc_file_flush(&vm->fout, bc_flush_save); in bc_program_exec()
3241 ip = bc_vec_top(&p->stack); in bc_program_exec()
3242 func = bc_vec_item(&p->fns, ip->func); in bc_program_exec()
3243 code = func->code.v; in bc_program_exec()
3250 // clang-format off in bc_program_exec()
3252 // clang-format on in bc_program_exec()
3259 // clang-format off in bc_program_exec()
3266 // clang-format on in bc_program_exec()
3268 BcBigDig dig = vm->maxes[inst - BC_INST_MAXIBASE]; in bc_program_exec()
3273 // clang-format off in bc_program_exec()
3282 // clang-format on in bc_program_exec()
3288 // clang-format off in bc_program_exec()
3290 // clang-format on in bc_program_exec()
3292 bc_program_pushVar(p, code, &ip->idx, false, false); in bc_program_exec()
3296 // clang-format off in bc_program_exec()
3299 // clang-format on in bc_program_exec()
3301 bc_program_pushArray(p, code, &ip->idx, inst); in bc_program_exec()
3305 // clang-format off in bc_program_exec()
3309 // clang-format on in bc_program_exec()
3316 // clang-format off in bc_program_exec()
3318 // clang-format on in bc_program_exec()
3325 // clang-format off in bc_program_exec()
3335 // clang-format on in bc_program_exec()
3341 // clang-format off in bc_program_exec()
3343 // clang-format on in bc_program_exec()
3350 ip = bc_vec_top(&p->stack); in bc_program_exec()
3351 func = bc_vec_item(&p->fns, ip->func); in bc_program_exec()
3352 code = func->code.v; in bc_program_exec()
3358 // clang-format off in bc_program_exec()
3360 // clang-format on in bc_program_exec()
3362 bc_program_const(p, code, &ip->idx); in bc_program_exec()
3366 // clang-format off in bc_program_exec()
3372 // clang-format on in bc_program_exec()
3374 r.t = BC_RESULT_ZERO + (inst - BC_INST_ZERO); in bc_program_exec()
3375 bc_vec_push(&p->results, &r); in bc_program_exec()
3379 // clang-format off in bc_program_exec()
3385 // clang-format on in bc_program_exec()
3391 bc_file_flush(&vm->fout, bc_flush_save); in bc_program_exec()
3396 // clang-format off in bc_program_exec()
3398 // clang-format on in bc_program_exec()
3403 r.d.n.scale = bc_program_index(code, &ip->idx); in bc_program_exec()
3404 bc_vec_push(&p->results, &r); in bc_program_exec()
3408 // clang-format off in bc_program_exec()
3420 // clang-format on in bc_program_exec()
3426 // clang-format off in bc_program_exec()
3432 // clang-format on in bc_program_exec()
3438 // clang-format off in bc_program_exec()
3465 // clang-format on in bc_program_exec()
3471 // clang-format off in bc_program_exec()
3473 // clang-format on in bc_program_exec()
3479 if (BC_ERR(!BC_PROG_STACK(&p->results, 1))) in bc_program_exec()
3486 assert(BC_PROG_STACK(&p->results, 1)); in bc_program_exec()
3488 bc_vec_pop(&p->results); in bc_program_exec()
3493 // clang-format off in bc_program_exec()
3495 // clang-format on in bc_program_exec()
3500 if (BC_ERR(!BC_PROG_STACK(&p->results, 2))) in bc_program_exec()
3505 assert(BC_PROG_STACK(&p->results, 2)); in bc_program_exec()
3508 ptr = bc_vec_item_rev(&p->results, 0); in bc_program_exec()
3509 ptr2 = bc_vec_item_rev(&p->results, 1); in bc_program_exec()
3522 // clang-format off in bc_program_exec()
3524 // clang-format on in bc_program_exec()
3530 // clang-format off in bc_program_exec()
3532 // clang-format on in bc_program_exec()
3538 // clang-format off in bc_program_exec()
3540 // clang-format on in bc_program_exec()
3547 // clang-format off in bc_program_exec()
3549 // clang-format on in bc_program_exec()
3552 assert(BC_PROG_STACK(&p->stack, 2)); in bc_program_exec()
3555 bc_vec_pop(&p->stack); in bc_program_exec()
3556 bc_vec_pop(&p->tail_calls); in bc_program_exec()
3561 ip = bc_vec_top(&p->stack); in bc_program_exec()
3562 func = bc_vec_item(&p->fns, ip->func); in bc_program_exec()
3563 code = func->code.v; in bc_program_exec()
3569 // clang-format off in bc_program_exec()
3572 // clang-format on in bc_program_exec()
3576 bc_program_execStr(p, code, &ip->idx, cond, func->code.len); in bc_program_exec()
3581 ip = bc_vec_top(&p->stack); in bc_program_exec()
3582 func = bc_vec_item(&p->fns, ip->func); in bc_program_exec()
3583 code = func->code.v; in bc_program_exec()
3589 // clang-format off in bc_program_exec()
3591 // clang-format on in bc_program_exec()
3597 // clang-format off in bc_program_exec()
3599 // clang-format on in bc_program_exec()
3601 bc_vec_popAll(&p->results); in bc_program_exec()
3605 // clang-format off in bc_program_exec()
3607 // clang-format on in bc_program_exec()
3609 bc_program_regStackLen(p, code, &ip->idx); in bc_program_exec()
3613 // clang-format off in bc_program_exec()
3615 // clang-format on in bc_program_exec()
3621 // clang-format off in bc_program_exec()
3623 // clang-format on in bc_program_exec()
3626 if (BC_ERR(!BC_PROG_STACK(&p->results, 1))) in bc_program_exec()
3631 assert(BC_PROG_STACK(&p->results, 1)); in bc_program_exec()
3634 ptr = bc_vec_top(&p->results); in bc_program_exec()
3640 bc_vec_push(&p->results, &r); in bc_program_exec()
3647 // clang-format off in bc_program_exec()
3650 // clang-format on in bc_program_exec()
3653 bc_program_pushVar(p, code, &ip->idx, true, copy); in bc_program_exec()
3657 // clang-format off in bc_program_exec()
3659 // clang-format on in bc_program_exec()
3661 idx = bc_program_index(code, &ip->idx); in bc_program_exec()
3666 // clang-format off in bc_program_exec()
3669 // clang-format on in bc_program_exec()
3676 ip = bc_vec_top(&p->stack); in bc_program_exec()
3677 func = bc_vec_item(&p->fns, ip->func); in bc_program_exec()
3678 code = func->code.v; in bc_program_exec()
3684 // clang-format off in bc_program_exec()
3686 // clang-format on in bc_program_exec()
3694 // clang-format off in bc_program_exec()
3696 // clang-format on in bc_program_exec()
3714 #pragma clang diagnostic warning "-Wgnu-label-as-value" in bc_program_exec()
3718 #pragma GCC diagnostic warning "-Wpedantic" in bc_program_exec()
3727 assert(jmp_bufs_len == vm->jmp_bufs.len); in bc_program_exec()
3742 bc_file_putchar(&vm->ferr, bc_flush_none, '\n'); in bc_program_exec()
3746 s = bc_file_flushErr(&vm->ferr, bc_flush_err); in bc_program_exec()
3747 if (BC_ERR(s != BC_STATUS_SUCCESS && vm->status == BC_STATUS_SUCCESS)) in bc_program_exec()
3749 vm->status = (sig_atomic_t) s; in bc_program_exec()
3761 bc_file_puts(&vm->fout, bc_flush_err, "-------------- Stack ----------\n"); in bc_program_printStackDebug()
3763 bc_file_puts(&vm->fout, bc_flush_err, "-------------- Stack End ------\n"); in bc_program_printStackDebug()
3788 s = *((char**) bc_vec_item(&p->strs, idx)); in bc_program_printStr()
3799 bc_vm_printf("Inst[%zu]: %s [%lu]; ", *bgn - 1, bc_inst_names[inst], in bc_program_printInst()
3811 BcConst* c = bc_vec_item(&p->consts, idx); in bc_program_printInst()
3812 bc_vm_printf("(%s)", c->val); in bc_program_printInst()
3832 for (i = 0; i < p->fns.len; ++i) in bc_program_code()
3837 f = bc_vec_item(&p->fns, ip.func); in bc_program_code()
3838 code = f->code.v; in bc_program_code()
3841 while (ip.idx < f->code.len) in bc_program_code()
3845 bc_file_puts(&vm->fout, bc_flush_err, "\n\n"); in bc_program_code()