diff options
author | Gavin Howard <gavin@yzena.com> | 2021-07-21 22:38:14 -0600 |
---|---|---|
committer | Gavin Howard <gavin@yzena.com> | 2021-07-21 22:38:50 -0600 |
commit | 6df6339ebbe11b03cb03c4dd4871eaabf3cd6a9a (patch) | |
tree | 08270917dad5c20bd30bb97397d7f693e79708ff /src | |
parent | 43e76ead0b22ed4430d5e6d8110430527f37c00a (diff) | |
download | platform_external_bc-6df6339ebbe11b03cb03c4dd4871eaabf3cd6a9a.tar.gz platform_external_bc-6df6339ebbe11b03cb03c4dd4871eaabf3cd6a9a.tar.bz2 platform_external_bc-6df6339ebbe11b03cb03c4dd4871eaabf3cd6a9a.zip |
Make a bc-only build build
Signed-off-by: Gavin Howard <gavin@yzena.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/bc_parse.c | 1 | ||||
-rw-r--r-- | src/num.c | 8 | ||||
-rw-r--r-- | src/program.c | 136 |
3 files changed, 73 insertions, 72 deletions
diff --git a/src/bc_parse.c b/src/bc_parse.c index f5139e11..5d9359af 100644 --- a/src/bc_parse.c +++ b/src/bc_parse.c @@ -798,6 +798,7 @@ static void bc_parse_print(BcParse *p, BcLexType type) { } t = p->l.t; + } while (true); // If we have a comma but no token, that's bad. @@ -2383,7 +2383,7 @@ static void bc_num_putchar(int c, bool bslash) { bc_vm_putchar(c, bc_flush_save); } -#if DC_ENABLED && !BC_ENABLE_LIBRARY +#if !BC_ENABLE_LIBRARY /** * Prints a character for a number's digit. This is for printing for dc's P @@ -2404,7 +2404,7 @@ static void bc_num_printChar(size_t n, size_t len, bool rdx, bool bslash) { bc_vm_putchar((uchar) n, bc_flush_save); } -#endif // DC_ENABLED && !BC_ENABLE_LIBRARY +#endif // !BC_ENABLE_LIBRARY /** * Prints a series of characters for large bases. This is for printing in bases @@ -3001,13 +3001,13 @@ static void bc_num_printBase(BcNum *restrict n, BcBigDig base, bool newline) { n->rdx = BC_NUM_NEG_VAL(n, neg); } -#if DC_ENABLED && !BC_ENABLE_LIBRARY +#if !BC_ENABLE_LIBRARY void bc_num_stream(BcNum *restrict n) { bc_num_printNum(n, BC_NUM_STREAM_BASE, 1, bc_num_printChar, false); } -#endif // DC_ENABLED && !BC_ENABLE_LIBRARY +#endif // !BC_ENABLE_LIBRARY void bc_num_setup(BcNum *restrict n, BcDig *restrict num, size_t cap) { assert(n != NULL); diff --git a/src/program.c b/src/program.c index 817f8cb8..671f5af8 100644 --- a/src/program.c +++ b/src/program.c @@ -1972,32 +1972,6 @@ static void bc_program_modexp(BcProgram *p) { bc_program_retire(p, 1, 3); } -#if DC_ENABLED - -/** - * Gets the length of a register in dc and pushes it onto the results stack. - * @param p The program. - * @param code The bytecode vector to pull the register's index out of. - * @param bgn An in/out parameter; the start of the index in the bytecode - * vector, and will be updated to point after the index on return. - */ -static void bc_program_regStackLen(BcProgram *p, const char *restrict code, - size_t *restrict bgn) -{ - size_t idx = bc_program_index(code, bgn); - BcVec *v = bc_program_vec(p, idx, BC_TYPE_VAR); - - bc_program_pushBigdig(p, (BcBigDig) v->len, BC_RESULT_TEMP); -} - -/** - * Pushes the length of the results stack onto the results stack. - * @param p The program. - */ -static void bc_program_stackLen(BcProgram *p) { - bc_program_pushBigdig(p, (BcBigDig) p->results.len, BC_RESULT_TEMP); -} - /** * Asciifies a number for dc. This is a helper for bc_program_asciify(). * @param p The program. @@ -2121,6 +2095,32 @@ static void bc_program_printStream(BcProgram *p) { bc_vec_pop(&p->results); } +#if DC_ENABLED + +/** + * Gets the length of a register in dc and pushes it onto the results stack. + * @param p The program. + * @param code The bytecode vector to pull the register's index out of. + * @param bgn An in/out parameter; the start of the index in the bytecode + * vector, and will be updated to point after the index on return. + */ +static void bc_program_regStackLen(BcProgram *p, const char *restrict code, + size_t *restrict bgn) +{ + size_t idx = bc_program_index(code, bgn); + BcVec *v = bc_program_vec(p, idx, BC_TYPE_VAR); + + bc_program_pushBigdig(p, (BcBigDig) v->len, BC_RESULT_TEMP); +} + +/** + * Pushes the length of the results stack onto the results stack. + * @param p The program. + */ +static void bc_program_stackLen(BcProgram *p) { + bc_program_pushBigdig(p, (BcBigDig) p->results.len, BC_RESULT_TEMP); +} + /** * Pops a certain number of elements off the execution stack. * @param p The program. @@ -2811,6 +2811,20 @@ void bc_program_exec(BcProgram *p) { break; } + case BC_INST_ASCIIFY: + { + bc_program_asciify(p, ip->func); + + // Because we changed the execution stack and where we are + // executing, we have to update all of this. + ip = bc_vec_top(&p->stack); + func = bc_vec_item(&p->fns, ip->func); + code = func->code.v; + bc_program_setVecs(p, func); + + break; + } + case BC_INST_NUM: { bc_program_const(p, code, &ip->idx); @@ -2927,6 +2941,28 @@ void bc_program_exec(BcProgram *p) { break; } + case BC_INST_SWAP: + { + BcResult *ptr2; + + // Check the stack. + if (BC_ERR(!BC_PROG_STACK(&p->results, 2))) + bc_err(BC_ERR_EXEC_STACK); + + assert(BC_PROG_STACK(&p->results, 2)); + + // Get the two items. + ptr = bc_vec_item_rev(&p->results, 0); + ptr2 = bc_vec_item_rev(&p->results, 1); + + // Swap. It's just easiest to do it this way. + memcpy(&r, ptr, sizeof(BcResult)); + memcpy(ptr, ptr2, sizeof(BcResult)); + memcpy(ptr2, &r, sizeof(BcResult)); + + break; + } + case BC_INST_MODEXP: { bc_program_modexp(p); @@ -2939,6 +2975,12 @@ void bc_program_exec(BcProgram *p) { break; } + case BC_INST_PRINT_STREAM: + { + bc_program_printStream(p); + break; + } + #if DC_ENABLED case BC_INST_POP_EXEC: { @@ -3022,48 +3064,6 @@ void bc_program_exec(BcProgram *p) { break; } - case BC_INST_SWAP: - { - BcResult *ptr2; - - // Check the stack. - if (BC_ERR(!BC_PROG_STACK(&p->results, 2))) - bc_err(BC_ERR_EXEC_STACK); - - assert(BC_PROG_STACK(&p->results, 2)); - - // Get the two items. - ptr = bc_vec_item_rev(&p->results, 0); - ptr2 = bc_vec_item_rev(&p->results, 1); - - // Swap. It's just easiest to do it this way. - memcpy(&r, ptr, sizeof(BcResult)); - memcpy(ptr, ptr2, sizeof(BcResult)); - memcpy(ptr2, &r, sizeof(BcResult)); - - break; - } - - case BC_INST_ASCIIFY: - { - bc_program_asciify(p, ip->func); - - // Because we changed the execution stack and where we are - // executing, we have to update all of this. - ip = bc_vec_top(&p->stack); - func = bc_vec_item(&p->fns, ip->func); - code = func->code.v; - bc_program_setVecs(p, func); - - break; - } - - case BC_INST_PRINT_STREAM: - { - bc_program_printStream(p); - break; - } - case BC_INST_LOAD: case BC_INST_PUSH_VAR: { |