Split into simplify and apply

This commit is contained in:
Andrew Morris
2023-06-29 16:22:20 +10:00
parent 76bc24f4fb
commit bbb0a9ffaf

View File

@@ -21,22 +21,36 @@ impl FnState {
fn clear(&mut self) {
*self = Self::default();
}
}
fn simplify_fn(mut state: FnState, fn_: &mut Function) {
for line in &mut fn_.body {
fn simplify_line(&self, line: &mut FnLine) {
match line {
FnLine::Instruction(instr) => {
if let Instruction::RequireMutableThis = instr {
if state.mutable_this_established {
if self.mutable_this_established {
*line = FnLine::Comment(line.to_string());
} else {
state.mutable_this_established = true;
}
}
}
FnLine::Label(..) => state.clear(),
FnLine::Label(..) | FnLine::Empty | FnLine::Comment(..) => {}
}
}
fn apply_line(&mut self, line: &FnLine) {
match line {
FnLine::Instruction(instr) => {
if let Instruction::RequireMutableThis = instr {
self.mutable_this_established = true;
}
}
FnLine::Label(..) => self.clear(),
FnLine::Empty | FnLine::Comment(..) => {}
}
}
}
fn simplify_fn(mut state: FnState, fn_: &mut Function) {
for line in &mut fn_.body {
state.simplify_line(line);
state.apply_line(line);
}
}