aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--miscutils/bc.c21
1 files changed, 12 insertions, 9 deletions
diff --git a/miscutils/bc.c b/miscutils/bc.c
index 2feaf7bf3..aeb29a971 100644
--- a/miscutils/bc.c
+++ b/miscutils/bc.c
@@ -6715,7 +6715,6 @@ static BC_STATUS zbc_program_exec(void)
6715 BcInstPtr *ip = bc_vec_top(&G.prog.stack); 6715 BcInstPtr *ip = bc_vec_top(&G.prog.stack);
6716 BcFunc *func = bc_program_func(ip->func); 6716 BcFunc *func = bc_program_func(ip->func);
6717 char *code = func->code.v; 6717 char *code = func->code.v;
6718 bool cond = false;
6719 6718
6720 while (ip->idx < func->code.len) { 6719 while (ip->idx < func->code.len) {
6721 BcStatus s = BC_STATUS_SUCCESS; 6720 BcStatus s = BC_STATUS_SUCCESS;
@@ -6723,17 +6722,22 @@ static BC_STATUS zbc_program_exec(void)
6723 6722
6724 switch (inst) { 6723 switch (inst) {
6725#if ENABLE_BC 6724#if ENABLE_BC
6726 case BC_INST_JUMP_ZERO: 6725 case BC_INST_JUMP_ZERO: {
6726 bool zero;
6727 s = zbc_program_prep(&ptr, &num); 6727 s = zbc_program_prep(&ptr, &num);
6728 if (s) RETURN_STATUS(s); 6728 if (s) RETURN_STATUS(s);
6729 cond = !bc_num_cmp(num, &G.prog.zero); 6729 zero = (bc_num_cmp(num, &G.prog.zero) == 0);
6730 bc_vec_pop(&G.prog.results); 6730 bc_vec_pop(&G.prog.results);
6731 // Fallthrough. 6731 if (!zero) {
6732 bc_program_index(code, &ip->idx);
6733 break;
6734 }
6735 // else: fall through
6736 }
6732 case BC_INST_JUMP: { 6737 case BC_INST_JUMP: {
6733 size_t *addr;
6734 size_t idx = bc_program_index(code, &ip->idx); 6738 size_t idx = bc_program_index(code, &ip->idx);
6735 addr = bc_vec_item(&func->labels, idx); 6739 size_t *addr = bc_vec_item(&func->labels, idx);
6736 if (inst == BC_INST_JUMP || cond) ip->idx = *addr; 6740 ip->idx = *addr;
6737 break; 6741 break;
6738 } 6742 }
6739 case BC_INST_CALL: 6743 case BC_INST_CALL:
@@ -6851,8 +6855,7 @@ static BC_STATUS zbc_program_exec(void)
6851 break; 6855 break;
6852 case BC_INST_EXECUTE: 6856 case BC_INST_EXECUTE:
6853 case BC_INST_EXEC_COND: 6857 case BC_INST_EXEC_COND:
6854 cond = inst == BC_INST_EXEC_COND; 6858 s = zbc_program_execStr(code, &ip->idx, inst == BC_INST_EXEC_COND);
6855 s = zbc_program_execStr(code, &ip->idx, cond);
6856 break; 6859 break;
6857 case BC_INST_PRINT_STACK: { 6860 case BC_INST_PRINT_STACK: {
6858 size_t idx; 6861 size_t idx;