diff --git a/src/optimizer/fwd_bak_merger.rs b/src/optimizer/fwd_bak_merger.rs index 869568a..2bce49f 100644 --- a/src/optimizer/fwd_bak_merger.rs +++ b/src/optimizer/fwd_bak_merger.rs @@ -37,7 +37,7 @@ fn create_fwd_bak_instructions_from_total(total: i64) -> Vec { instructions } -fn get_total_count_fwd_bak(instructions: &[Instruction], start: usize) -> (i64, usize) { +const fn get_total_count_fwd_bak(instructions: &[Instruction], start: usize) -> (i64, usize) { let mut total: i64 = 0; let mut j = start; while j < instructions.len() { diff --git a/src/optimizer/inc_dec_merger.rs b/src/optimizer/inc_dec_merger.rs index a53137b..6eff21d 100644 --- a/src/optimizer/inc_dec_merger.rs +++ b/src/optimizer/inc_dec_merger.rs @@ -37,7 +37,7 @@ fn create_inc_dec_instructions_from_total(total: i64) -> Vec { instructions } -fn get_total_count_inc_dec(instructions: &[Instruction], start: usize) -> (i64, usize) { +const fn get_total_count_inc_dec(instructions: &[Instruction], start: usize) -> (i64, usize) { let mut total: i64 = 0; let mut j = start; while j < instructions.len() { diff --git a/src/parser.rs b/src/parser.rs index b92cb92..9ef62e0 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -71,14 +71,14 @@ impl Parser { result } - fn argument_conversion(argument: u8) -> u8 { + const fn argument_conversion(argument: u8) -> u8 { match argument { 0 => 10, v => v, } } - fn check_if_eif_mismatch(instructions: &[Instruction]) -> Option { + const fn check_if_eif_mismatch(instructions: &[Instruction]) -> Option { // check for matching if/eif let mut i = 0; while i < instructions.len() { @@ -137,7 +137,7 @@ impl Parser { None } - fn get_instruction_name(instruction: &u8) -> Option<&'static str> { + const fn get_instruction_name(instruction: &u8) -> Option<&'static str> { match instruction { 0 => Some("END"), 1 => Some("IF"), @@ -431,7 +431,14 @@ mod test { #[test] fn test_nested_if_eif_match() { - let instructions = vec![Instruction::IF, Instruction::RND, Instruction::IF, Instruction::RND, Instruction::EIF, Instruction::EIF]; + let instructions = vec![ + Instruction::IF, + Instruction::RND, + Instruction::IF, + Instruction::RND, + Instruction::EIF, + Instruction::EIF, + ]; let result = Parser::check_if_eif_mismatch(&instructions); assert!(result.is_none()); } @@ -449,7 +456,14 @@ mod test { let result = Parser::check_if_eif_mismatch(&instructions); assert!(result.is_some()); - let instructions = vec![Instruction::IF, Instruction::IF, Instruction::IF, Instruction::EIF, Instruction::RND, Instruction::EIF]; + let instructions = vec![ + Instruction::IF, + Instruction::IF, + Instruction::IF, + Instruction::EIF, + Instruction::RND, + Instruction::EIF, + ]; let result = Parser::check_if_eif_mismatch(&instructions); assert!(result.is_some()); }