Skip to content

Commit

Permalink
more updates to eval
Browse files Browse the repository at this point in the history
  • Loading branch information
Toyz committed Jan 3, 2025
1 parent ef998fe commit cca5636
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,18 @@ impl RgbSum {
const fn new(r: u8, b: u8, g: u8) -> Self {
Self { r, g, b }
}

const fn new_red(r: u8) -> Self {
Self { r, g: 0, b: 0 }
}

const fn new_green(g: u8) -> Self {
Self { r: 0, g, b: 0 }
}

const fn new_blue(b: u8) -> Self {
Self { r: 0, g: 0, b }
}
}

impl From<[u8; 3]> for RgbSum {
Expand Down Expand Up @@ -217,9 +229,9 @@ pub fn eval(
}

Token::RGBColor((token, num)) => match token {
'R' => stack.push(RgbSum::new(num, 0, 0)),
'G' => stack.push(RgbSum::new(0, num, 0)),
'B' => stack.push(RgbSum::new(0, 0, num)),
'R' => stack.push(RgbSum::new_red(num)),
'G' => stack.push(RgbSum::new_blue(num)),
'B' => stack.push(RgbSum::new_green(num)),
_ => return Err(format!("Unexpected token: {:?}", token)),
},

Expand Down

0 comments on commit cca5636

Please sign in to comment.