From b40c8d50b63c2d786a7ed1e64f903dabab991ced Mon Sep 17 00:00:00 2001 From: Ry Date: Sun, 22 Jan 2023 17:22:24 -0800 Subject: [PATCH] Error and exit if a label is defined more than once Fixes issue #2 --- src/main.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main.rs b/src/main.rs index b834ba2..5dcad23 100644 --- a/src/main.rs +++ b/src/main.rs @@ -356,6 +356,11 @@ fn main() { for node in ast.unwrap() { if let AstNode::LabelDefine {name, ..} = node { let mut address_table = LABEL_ADDRESSES.lock().unwrap(); + if let Some(_) = address_table.get(&name) { + // this label already exists, print an error and exit + println!("Label \"{}\" was defined more than once!", name); + exit(1); + } address_table.insert(name.clone(), (current_address, false)); std::mem::drop(address_table); } else if let AstNode::Constant {name, address} = node {