mirror of
https://github.com/voltrevo/ValueScript.git
synced 2026-04-18 03:00:27 -04:00
Split into simplify and apply
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user