Skip to content

Commit

Permalink
constify
Browse files Browse the repository at this point in the history
  • Loading branch information
mztikk committed Nov 5, 2024
1 parent 1d339f6 commit 4ad7d31
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/optimizer/fwd_bak_merger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ fn create_fwd_bak_instructions_from_total(total: i64) -> Vec<Instruction> {
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() {
Expand Down
2 changes: 1 addition & 1 deletion src/optimizer/inc_dec_merger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ fn create_inc_dec_instructions_from_total(total: i64) -> Vec<Instruction> {
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() {
Expand Down
24 changes: 19 additions & 5 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ParseError> {
const fn check_if_eif_mismatch(instructions: &[Instruction]) -> Option<ParseError> {
// check for matching if/eif
let mut i = 0;
while i < instructions.len() {
Expand Down Expand Up @@ -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"),
Expand Down Expand Up @@ -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());
}
Expand All @@ -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());
}
Expand Down

0 comments on commit 4ad7d31

Please sign in to comment.