diff options
-rw-r--r-- | miscutils/bc.c | 16 | ||||
-rwxr-xr-x | testsuite/bc.tests | 27 |
2 files changed, 32 insertions, 11 deletions
diff --git a/miscutils/bc.c b/miscutils/bc.c index 925950d78..af57b3d6c 100644 --- a/miscutils/bc.c +++ b/miscutils/bc.c | |||
@@ -4175,7 +4175,7 @@ static BC_STATUS zbc_parse_while(BcParse *p) | |||
4175 | BcStatus s; | 4175 | BcStatus s; |
4176 | BcInstPtr ip; | 4176 | BcInstPtr ip; |
4177 | size_t *label; | 4177 | size_t *label; |
4178 | size_t n; | 4178 | size_t cond_idx; |
4179 | 4179 | ||
4180 | s = zbc_lex_next(&p->l); | 4180 | s = zbc_lex_next(&p->l); |
4181 | if (s) RETURN_STATUS(s); | 4181 | if (s) RETURN_STATUS(s); |
@@ -4183,10 +4183,10 @@ static BC_STATUS zbc_parse_while(BcParse *p) | |||
4183 | s = zbc_lex_next(&p->l); | 4183 | s = zbc_lex_next(&p->l); |
4184 | if (s) RETURN_STATUS(s); | 4184 | if (s) RETURN_STATUS(s); |
4185 | 4185 | ||
4186 | ip.idx = p->func->labels.len; | 4186 | cond_idx = p->func->labels.len; |
4187 | 4187 | ||
4188 | bc_vec_push(&p->func->labels, &p->func->code.len); | 4188 | bc_vec_push(&p->func->labels, &p->func->code.len); |
4189 | bc_vec_push(&p->conds, &ip.idx); | 4189 | bc_vec_push(&p->conds, &cond_idx); |
4190 | 4190 | ||
4191 | ip.idx = p->func->labels.len; | 4191 | ip.idx = p->func->labels.len; |
4192 | ip.func = 1; | 4192 | ip.func = 1; |
@@ -4209,15 +4209,9 @@ static BC_STATUS zbc_parse_while(BcParse *p) | |||
4209 | s = zbc_parse_stmt_fail_if_bare_NLINE(p, false, "while"); | 4209 | s = zbc_parse_stmt_fail_if_bare_NLINE(p, false, "while"); |
4210 | if (s) RETURN_STATUS(s); | 4210 | if (s) RETURN_STATUS(s); |
4211 | 4211 | ||
4212 | n = *((size_t *) bc_vec_top(&p->conds)); | 4212 | dbg_lex("%s:%d BC_INST_JUMP to %d", __func__, __LINE__, cond_idx); |
4213 | bc_parse_push(p, BC_INST_JUMP); | ||
4214 | bc_parse_pushIndex(p, n); | ||
4215 | |||
4216 | label = bc_vec_top(&p->conds); | ||
4217 | |||
4218 | dbg_lex("%s:%d BC_INST_JUMP to %d", __func__, __LINE__, *label); | ||
4219 | bc_parse_push(p, BC_INST_JUMP); | 4213 | bc_parse_push(p, BC_INST_JUMP); |
4220 | bc_parse_pushIndex(p, *label); | 4214 | bc_parse_pushIndex(p, cond_idx); |
4221 | 4215 | ||
4222 | label = bc_vec_item(&p->func->labels, ip.idx); | 4216 | label = bc_vec_item(&p->func->labels, ip.idx); |
4223 | dbg_lex("%s:%d rewriting label: %d -> %d", __func__, __LINE__, *label, p->func->code.len); | 4217 | dbg_lex("%s:%d rewriting label: %d -> %d", __func__, __LINE__, *label, p->func->code.len); |
diff --git a/testsuite/bc.tests b/testsuite/bc.tests index 987461ebb..0690e9c6f 100755 --- a/testsuite/bc.tests +++ b/testsuite/bc.tests | |||
@@ -107,6 +107,33 @@ if(1) { | |||
107 | 99 | 107 | 99 |
108 | " | 108 | " |
109 | 109 | ||
110 | testing "bc continue in if" \ | ||
111 | "bc" \ | ||
112 | "\ | ||
113 | 11 | ||
114 | 21 | ||
115 | 11 | ||
116 | 31 | ||
117 | 99 | ||
118 | " \ | ||
119 | "" "\ | ||
120 | i=2 | ||
121 | while(i--) { | ||
122 | 11 | ||
123 | if(i) { | ||
124 | 21 | ||
125 | continue | ||
126 | 22 | ||
127 | } else { | ||
128 | 31 | ||
129 | continue | ||
130 | 32 | ||
131 | } | ||
132 | 12 | ||
133 | } | ||
134 | 99 | ||
135 | " | ||
136 | |||
110 | tar xJf bc_large.tar.xz | 137 | tar xJf bc_large.tar.xz |
111 | 138 | ||
112 | for f in bc*.bc; do | 139 | for f in bc*.bc; do |