Somewhat recursive string construction

This commit is contained in:
VegOwOtenks 2024-09-05 00:33:14 +02:00
parent 4dabd6c3a8
commit 3c4921aa54
9 changed files with 1130 additions and 185 deletions

View file

@ -48,6 +48,19 @@ impl OperandStack {
Ok(())
}
pub fn pop_computational_1(&mut self, index: usize) -> Result<StackValue, Error> {
let absolute_index = self.depth as usize - 1 - index;
let value = self.stack[absolute_index];
self.depth -= 1;
match value {
StackValue::Long0(_) | StackValue::Long1(_) | StackValue::Double0(_) | StackValue::Double1(_) => {
Err(Error::LocalError(format!("Mismatched type at index {} of the function operand stack, expected type with computational type 1 but found '{:?}'", index, value)))
},
_ => Ok(value),
}
}
pub fn pop_boolean(&mut self, index: usize) -> Result<bool, Error> {
let absolute_index = self.depth as usize - 1 - index;
@ -239,6 +252,14 @@ impl StackFrame {
}
}
pub fn load_local_reference(&self, index: u16) -> Result<ObjectReference, Error> {
let local = self.locals[index as usize];
match local {
StackValue::Reference(r) => Ok(r),
_ => Err(Error::LocalError(format!("Mismatched type at index {} of the function locals, expected Reference but found '{:?}'", index, local)))
}
}
pub fn store_local(&mut self, index: u16, value: StackValue) -> Result<(), Error> {
let field = self.locals.get_mut(index as usize);
match field {