mirror of
https://github.com/RustPython/Parser.git
synced 2025-07-19 02:55:50 +00:00
Fix break to contain end label
This commit is contained in:
parent
3bf931fbb0
commit
6760d21399
1 changed files with 8 additions and 9 deletions
|
@ -761,13 +761,14 @@ impl Compiler {
|
||||||
self.switch_to_block(after_block);
|
self.switch_to_block(after_block);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Break => {
|
Break => match self.ctx.loop_data {
|
||||||
if self.ctx.loop_data.is_some() {
|
Some((_, end)) => {
|
||||||
self.emit(Instruction::Break);
|
self.emit(Instruction::Break { target: end });
|
||||||
} else {
|
}
|
||||||
|
None => {
|
||||||
return Err(self.error_loc(CompileErrorType::InvalidBreak, statement.location));
|
return Err(self.error_loc(CompileErrorType::InvalidBreak, statement.location));
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
Continue => match self.ctx.loop_data {
|
Continue => match self.ctx.loop_data {
|
||||||
Some((start, _)) => {
|
Some((start, _)) => {
|
||||||
self.emit(Instruction::Continue { target: start });
|
self.emit(Instruction::Continue { target: start });
|
||||||
|
@ -1373,8 +1374,7 @@ impl Compiler {
|
||||||
|
|
||||||
self.compile_jump_if(test, false, else_block)?;
|
self.compile_jump_if(test, false, else_block)?;
|
||||||
|
|
||||||
let was_in_loop = self.ctx.loop_data;
|
let was_in_loop = self.ctx.loop_data.replace((while_block, after_block));
|
||||||
self.ctx.loop_data = Some((while_block, after_block));
|
|
||||||
self.compile_statements(body)?;
|
self.compile_statements(body)?;
|
||||||
self.ctx.loop_data = was_in_loop;
|
self.ctx.loop_data = was_in_loop;
|
||||||
self.emit(Instruction::Jump {
|
self.emit(Instruction::Jump {
|
||||||
|
@ -1487,8 +1487,7 @@ impl Compiler {
|
||||||
self.compile_store(target)?;
|
self.compile_store(target)?;
|
||||||
};
|
};
|
||||||
|
|
||||||
let was_in_loop = self.ctx.loop_data;
|
let was_in_loop = self.ctx.loop_data.replace((for_block, after_block));
|
||||||
self.ctx.loop_data = Some((for_block, after_block));
|
|
||||||
self.compile_statements(body)?;
|
self.compile_statements(body)?;
|
||||||
self.ctx.loop_data = was_in_loop;
|
self.ctx.loop_data = was_in_loop;
|
||||||
self.emit(Instruction::Jump { target: for_block });
|
self.emit(Instruction::Jump { target: for_block });
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue