Skip to content

Commit

Permalink
bugfix: only the first occurance of a label counts
Browse files Browse the repository at this point in the history
Because `insert` updates on repeated insertions, this is probably the easiest way.
  • Loading branch information
rpitasky committed Sep 8, 2024
1 parent 9b5af03 commit 1c79eef
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
3 changes: 2 additions & 1 deletion test-files/snippets/analysis/labels.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Lbl 0
Lbl PL
2 changes: 1 addition & 1 deletion ti-basic-optimizer/src/analyze/control_flow/labels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ impl Program {
pub fn label_declarations(&self) -> BTreeMap<LabelName, usize> {
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);
}
Expand Down

0 comments on commit 1c79eef

Please sign in to comment.