I need to make smaller commits

This commit is contained in:
vegowotenks 2024-09-10 00:17:17 +02:00
parent 64eef60c4e
commit 0c54a1d7e1
8 changed files with 377 additions and 83 deletions

View file

@ -74,6 +74,32 @@ impl OperandStack {
}
}
}
pub fn pop_computational_2(&mut self, index: usize) -> Result<FieldValue, Error> {
let absolute_index = self.depth as usize - 1 - index;
let value_top = self.stack[absolute_index];
let value_bot = self.stack[absolute_index - 1];
self.depth -= 2;
match (value_bot, value_top) {
(StackValue::Long0(l0), StackValue::Long1(l1)) => {
let l0_bytes = l0.to_ne_bytes();
let l1_bytes = l1.to_ne_bytes();
let concat_bytes = [l0_bytes[0], l0_bytes[1], l0_bytes[2], l0_bytes[3], l1_bytes[0], l1_bytes[1], l1_bytes[2], l1_bytes[3]];
Ok(FieldValue::Long(i64::from_ne_bytes(concat_bytes)))
}
(StackValue::Double0(d0), StackValue::Double1(d1)) => {
let d0_bytes = d0.to_ne_bytes();
let d1_bytes = d1.to_ne_bytes();
let concat_bytes = [d0_bytes[0], d0_bytes[1], d0_bytes[2], d0_bytes[3], d1_bytes[0], d1_bytes[1], d1_bytes[2], d1_bytes[3]];
Ok(FieldValue::Double(f64::from_ne_bytes(concat_bytes)))
}
_ => Err(Error::LocalError(format!("Mismatched type at index {index} of the function operand stack, expected type with computational type 2 but found '{value_bot:?}, {value_top:?}'")))
}
}
pub fn pop_computational_1(&mut self, index: usize) -> Result<StackValue, Error> {
let absolute_index = self.depth as usize - 1 - index;