diff --git a/src/main.rs b/src/main.rs index eeb59ad..fa62a62 100644 --- a/src/main.rs +++ b/src/main.rs @@ -24,11 +24,11 @@ use std::io; // 0x1d: LERP (lerp n-2 to n-1 by n alpha) // 0x1e: MIN // 0x1f: MAX - + fn main() { println!("Slipcode | Skye Terran, 2021\n"); - let mut instructions: Vec = vec![0x01, 0xbf, 0x80, 0x00, 0x00, 0x01, 0x42, 0x65, 0x51, 0xec, 0x02, 0x10]; + let mut instructions: Vec = vec![0x01, 0xbf, 0x80, 0x00, 0x00, 0x01, 0x42, 0x65, 0x51, 0xec, 0x02, 0x10, 0x04, 0x10, 0x04, 0x19, 0x11]; let mut values: Vec = vec![]; execute(&mut instructions, &mut values); @@ -86,8 +86,10 @@ fn execute(instructions: &mut Vec, values: &mut Vec) { 0x01 => is_literal = true, 0x02 => swap(values), 0x03 => del(values), + 0x04 => copy(values), 0x10 => add(values), 0x11 => sub(values), + 0x19 => floor(values), _ => break } if !is_literal { @@ -132,6 +134,18 @@ fn del(values: &mut Vec) { values.pop(); } +fn copy(values: &mut Vec) { + println!("COPY"); + let a_opt = values.pop(); + if a_opt.is_some() { + let a = a_opt.unwrap(); + values.push(a); + values.push(a); + } else { + println!("Not enough values."); + } +} + fn swap(values: &mut Vec) { println!("SWAP"); let b_opt = values.pop(); @@ -146,6 +160,16 @@ fn swap(values: &mut Vec) { } } +fn floor(values: &mut Vec) { + println!("FLOOR"); + let a_opt = values.pop(); + if a_opt.is_some() { + let a = a_opt.unwrap(); + let a = a.floor(); + values.push(a); + } +} + fn as_u32_be(array: &[u8; 4]) -> u32 { ((array[0] as u32) << 24) + ((array[1] as u32) << 16) +