| 
					
				 | 
			
			
				@@ -136,19 +136,6 @@ impl<'a> Compiler<'a> { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         }) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    pub fn remove_dead_code(opcodes: Vec<OpCode>) -> Vec<OpCode> { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        let mut new_opcodes = opcodes; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        loop { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            let (new_opcodes_, has_changed) = optimizations::remove_dead_code(new_opcodes); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            new_opcodes = new_opcodes_; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            if !has_changed { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        new_opcodes 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     pub fn optimize(opcodes: Vec<OpCode>) -> (Vec<OpCode>, bool) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         vec![ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             optimizations::assign_unique_register_addresses, 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -156,6 +143,7 @@ impl<'a> Compiler<'a> { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             optimizations::remove_unused_values, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             optimizations::calculate_static_values, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             optimizations::remove_useless_jumps, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            optimizations::remove_dead_code, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             //optimizations::move_load_top, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         ] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         .into_iter() 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -167,19 +155,20 @@ impl<'a> Compiler<'a> { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     /// Returns a list of Addresses that are labeled in the opcodes list. This function is required 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     /// to resolve any jump in the compiler 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    pub fn labels_to_addr(opcodes: &[OpCode]) -> HashMap<Addr, Addr> { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    pub fn labels_to_addr(opcodes: &[OpCode]) -> HashMap<Addr, (Addr, Addr)> { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         let mut pos_without_labels = 0; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         opcodes 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             .iter() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            .map(|opcode| match opcode { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                OpCode::LABEL(label) => (opcode, pos_without_labels), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            .enumerate() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            .map(|(actual_pos, opcode)| match opcode { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                OpCode::LABEL(label) => (opcode, pos_without_labels, actual_pos), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 _ => { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     pos_without_labels = pos_without_labels + 1usize; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    (opcode, pos_without_labels - 1) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    (opcode, pos_without_labels - 1, actual_pos) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             }) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            .filter_map(|(opcode, pos)| match opcode { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                OpCode::LABEL(id) => Some((*id, pos.into())), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            .filter_map(|(opcode, pos_without_label, pos)| match opcode { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                OpCode::LABEL(id) => Some((*id, (pos_without_label.into(), pos.into()))), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 _ => None, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             }) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             .collect::<HashMap<_, _>>() 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -195,20 +184,23 @@ impl<'a> Compiler<'a> { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 // Rewrite JMP to not use labels but instead addresses 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 Ok(match opcode { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     OpCode::JMP(label) => OpCode::JMP( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        *labels_to_addr 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        labels_to_addr 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                             .get(&label) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            .map(|addr| addr.0) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                             .ok_or(Error::UnknownLabel(*label))?, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     ), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     OpCode::JEQ(register, label) => OpCode::JEQ( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                         register, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        *labels_to_addr 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        labels_to_addr 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                             .get(&label) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            .map(|addr| addr.0) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                             .ok_or(Error::UnknownLabel(*label))?, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     ), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     OpCode::JNE(register, label) => OpCode::JNE( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                         register, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        *labels_to_addr 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        labels_to_addr 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                             .get(&label) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            .map(|addr| addr.0) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                             .ok_or(Error::UnknownLabel(*label))?, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     ), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     opcode => opcode, 
			 |