diff --git a/test-files/snippets/analysis/labels.txt b/test-files/snippets/analysis/labels.txt index fe1826b..0bd3a7c 100644 --- a/test-files/snippets/analysis/labels.txt +++ b/test-files/snippets/analysis/labels.txt @@ -2,4 +2,5 @@ Lbl RE Menu("MY TERRIBLE GAME","PLAY",PL,"EXIT",0,"PLEASE LEAVE",0,"RESTART",RE Lbl PL Goto 0 -Lbl 0 \ No newline at end of file +Lbl 0 +Lbl PL \ No newline at end of file diff --git a/ti-basic-optimizer/src/analyze/control_flow/labels.rs b/ti-basic-optimizer/src/analyze/control_flow/labels.rs index 168870f..af7d9a0 100644 --- a/ti-basic-optimizer/src/analyze/control_flow/labels.rs +++ b/ti-basic-optimizer/src/analyze/control_flow/labels.rs @@ -11,7 +11,7 @@ impl Program { pub fn label_declarations(&self) -> BTreeMap { let mut declarations = BTreeMap::new(); - for (idx, line) in self.lines.iter().enumerate() { + for (idx, line) in self.lines.iter().enumerate().rev() { if let Command::ControlFlow(ControlFlow::Lbl(name)) = line { declarations.insert(*name, idx); }