Skip to content

Commit

Permalink
Split into simplify and apply
Browse files Browse the repository at this point in the history
  • Loading branch information
voltrevo committed Jun 29, 2023
1 parent 76bc24f commit bbb0a9f
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions valuescript_compiler/src/optimization/simplify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit bbb0a9f

Please sign in to comment.