self->ir_func = NULL;
self->curblock = NULL;
- self->breakblock = NULL;
- self->continueblock = NULL;
+ self->breakblocks = NULL;
+ self->continueblocks = NULL;
vtype->hasvalue = true;
vtype->constval.vfunc = self;
for (i = 0; i < vec_size(self->blocks); ++i)
ast_delete(self->blocks[i]);
vec_free(self->blocks);
+ vec_free(self->breakblocks);
+ vec_free(self->continueblocks);
mem_d(self);
}
ir_block *bcontinue = NULL;
ir_block *bbreak = NULL;
- ir_block *old_bcontinue = NULL;
- ir_block *old_bbreak = NULL;
-
ir_block *tmpblock = NULL;
(void)lvalue;
/* enter */
func->curblock = bbody;
- old_bbreak = func->breakblock;
- old_bcontinue = func->continueblock;
- func->breakblock = bbreak;
- func->continueblock = bcontinue;
- if (!func->continueblock)
- func->continueblock = bbody;
+ vec_push(func->breakblocks, bbreak);
+ if (bcontinue)
+ vec_push(func->continueblocks, bcontinue);
+ else
+ vec_push(func->continueblocks, bbody);
/* generate */
if (self->body) {
}
end_bbody = func->curblock;
- func->breakblock = old_bbreak;
- func->continueblock = old_bcontinue;
+ vec_pop(func->breakblocks);
+ vec_pop(func->continueblocks);
}
/* post-loop-condition */
self->expression.outr = (ir_value*)1;
if (self->is_continue)
- target = func->continueblock;
+ target = func->continueblocks[vec_size(func->continueblocks)-1-self->levels];
else
- target = func->breakblock;
+ target = func->breakblocks[vec_size(func->breakblocks)-1-self->levels];
if (!target) {
compile_error(ast_ctx(self), "%s is lacking a target block", (self->is_continue ? "continue" : "break"));
ir_value *dummy = NULL;
ir_value *irop = NULL;
- ir_block *old_break = NULL;
ir_block *bout = NULL;
ir_block *bfall = NULL;
size_t bout_id;
return false;
/* setup the break block */
- old_break = func->breakblock;
- func->breakblock = bout;
+ vec_push(func->breakblocks, bout);
/* Now create all cases */
for (c = 0; c < vec_size(self->cases); ++c) {
func->curblock = bout;
/* restore the break block */
- func->breakblock = old_break;
+ vec_pop(func->breakblocks);
/* Move 'bout' to the end, it's nicer */
vec_remove(func->ir_func->blocks, bout_id, 1);