aboutsummaryrefslogtreecommitdiff
path: root/miscutils/bc.c
diff options
context:
space:
mode:
Diffstat (limited to 'miscutils/bc.c')
-rw-r--r--miscutils/bc.c18
1 files changed, 13 insertions, 5 deletions
diff --git a/miscutils/bc.c b/miscutils/bc.c
index 1e8056c01..e497b0d02 100644
--- a/miscutils/bc.c
+++ b/miscutils/bc.c
@@ -6020,6 +6020,9 @@ static BC_STATUS zbc_program_return(char inst)
6020 BcInstPtr *ip = bc_vec_top(&G.prog.exestack); 6020 BcInstPtr *ip = bc_vec_top(&G.prog.exestack);
6021 6021
6022 if (inst == XC_INST_RET) { 6022 if (inst == XC_INST_RET) {
6023 // bc needs this for e.g. RESULT_CONSTANT ("return 5")
6024 // because bc constants are per-function.
6025 // TODO: maybe avoid if value is already RESULT_TEMP?
6023 BcStatus s; 6026 BcStatus s;
6024 BcNum *num; 6027 BcNum *num;
6025 BcResult *operand = bc_vec_top(&G.prog.results); 6028 BcResult *operand = bc_vec_top(&G.prog.results);
@@ -6458,7 +6461,17 @@ static BC_STATUS zxc_program_exec(void)
6458 6461
6459 dbg_exec("inst at %zd:%d results.len:%d", ip->inst_idx - 1, inst, G.prog.results.len); 6462 dbg_exec("inst at %zd:%d results.len:%d", ip->inst_idx - 1, inst, G.prog.results.len);
6460 switch (inst) { 6463 switch (inst) {
6464 case XC_INST_RET:
6465 if (IS_DC) { // end of '?' reached
6466 bc_vec_pop(&G.prog.exestack);
6467 goto read_updated_ip;
6468 }
6469 // bc: fall through
6461#if ENABLE_BC 6470#if ENABLE_BC
6471 case BC_INST_RET0:
6472 dbg_exec("BC_INST_RET[0]:");
6473 s = zbc_program_return(inst);
6474 goto read_updated_ip;
6462 case BC_INST_JUMP_ZERO: { 6475 case BC_INST_JUMP_ZERO: {
6463 BcNum *num; 6476 BcNum *num;
6464 bool zero; 6477 bool zero;
@@ -6495,11 +6508,6 @@ static BC_STATUS zxc_program_exec(void)
6495 dbg_exec("BC_INST_HALT:"); 6508 dbg_exec("BC_INST_HALT:");
6496 QUIT_OR_RETURN_TO_MAIN; 6509 QUIT_OR_RETURN_TO_MAIN;
6497 break; 6510 break;
6498 case XC_INST_RET:
6499 case BC_INST_RET0:
6500 dbg_exec("BC_INST_RET[0]:");
6501 s = zbc_program_return(inst);
6502 goto read_updated_ip;
6503 case XC_INST_BOOL_OR: 6511 case XC_INST_BOOL_OR:
6504 case XC_INST_BOOL_AND: 6512 case XC_INST_BOOL_AND:
6505#endif // ENABLE_BC 6513#endif // ENABLE_BC