I dont know, I changed things

This commit is contained in:
vegowotenks 2024-11-02 09:10:42 +01:00
parent 43ceaa95bb
commit 3fd30b80b6
5 changed files with 98 additions and 10 deletions

View file

@ -744,6 +744,16 @@ impl JVM {
}
}
Instruction::BranchIntGreaterThan(branch_offset) => {
let value_2 = wrap_stackframe_error(class, method, frame.operand_stack.pop_int(0))?;
let value_1 = wrap_stackframe_error(class, method, frame.operand_stack.pop_int(0))?;
if value_1 > value_2 {
frame.instruction_pointer -= offset as u32;
frame.instruction_pointer = if branch_offset < 0 { frame.instruction_pointer - branch_offset.abs() as u32} else { frame.instruction_pointer + branch_offset.abs() as u32};
}
}
Instruction::BranchIntInequality(branch_offset) => {
let value_2 = wrap_stackframe_error(class, method, frame.operand_stack.pop_int(0))?;
let value_1 = wrap_stackframe_error(class, method, frame.operand_stack.pop_int(0))?;
@ -1208,11 +1218,20 @@ impl JVM {
return Ok(JVMCallbackOperation::InitClass(supplied_class_name.to_string()));
}
let supplied_descriptor: MethodDescriptor = supplied_descriptor_string.try_into()?;
// TODO: Throw exception on fail
let (callee_class_file, callee_class_index) = self.class_store.get_class(supplied_class_name)?;
// TODO: Throw exception on fail
let callee_method_index = callee_class_file.find_method_index(supplied_method_name).unwrap();
// TODO: Throw exception on fail
let callee_method_info = &callee_class_file.methods[callee_method_index];
let (callee_class_index, callee_method_index, callee_method_info) = match ClassMethodIterator::new(callee_class_index, &self.class_store)
.filter(|(_, _, minfo)| minfo.name == *supplied_method_name)
.filter(|(_, _, minfo)| minfo.descriptor == supplied_descriptor)
.next() {
Some(m) => m,
None => {
// TODO: Throw exception
return Err(Error::RunTimeError(format!("InvokeStatic: Failed to find requested method '{}' with descriptor '{}' in the class '{}'", supplied_method_name, supplied_descriptor_string, supplied_class_name)));
}
};
if ! (callee_method_info.access_flags & MethodAccessFlag::Static) {
// TODO: Throw IncompatibleClassChangeError
@ -1225,8 +1244,6 @@ impl JVM {
)));
}
let supplied_descriptor: MethodDescriptor = supplied_descriptor_string.try_into()?;
// TODO: Throw exception on fail
if supplied_descriptor != callee_method_info.descriptor {
// TODO: Throw exception on fail
@ -1618,6 +1635,7 @@ impl JVM {
const CHAR: u8 = 5;
const BYTE: u8 = 8;
const INT: u8 = 10;
let array_ref = match array_type {
BYTE => {
let array_ref = self.heap_area.make_primitive_byte_array(array_capacity as usize, &self.class_store);
@ -1631,6 +1649,12 @@ impl JVM {
array_ref
}
INT => {
let array_ref = self.heap_area.make_primitive_int_array(array_capacity as usize, &self.class_store);
array_ref
}
_ => todo!()
};
@ -1877,6 +1901,16 @@ impl JVM {
}
}
Instruction::StoreIntoIArray() => {
let value = wrap_stackframe_error(class, method, frame.operand_stack.pop_int(0))?;
let index = wrap_stackframe_error(class, method, frame.operand_stack.pop_int(0))?;
let array_ref = wrap_stackframe_error(class, method, frame.operand_stack.pop_reference(0))?;
// TODO: Type checking
self.heap_area.object_area.set_array_element(array_ref, index as usize, FieldValue::Int(value));
}
Instruction::StoreIntoRArray() => {
let value = wrap_stackframe_error(class, method, frame.operand_stack.pop_reference(0))?;
let index = wrap_stackframe_error(class, method, frame.operand_stack.pop_int(0))?;
@ -1926,6 +1960,14 @@ impl JVM {
wrap_stackframe_error(class, method, frame.store_local(3, StackValue::Int(int)))?;
}
Instruction::StoreLocalLong(index) => {
let long1 = wrap_stackframe_error(class, method, frame.operand_stack.pop_long1(0))?;
let long0 = wrap_stackframe_error(class, method, frame.operand_stack.pop_long0(0))?;
wrap_stackframe_error(class, method, frame.store_local(index as u16, StackValue::Long0(long0)))?;
wrap_stackframe_error(class, method, frame.store_local(index as u16 + 1, StackValue::Long1(long1)))?;
}
Instruction::StoreLocalReference(index) => {
let reference = wrap_stackframe_error(class, method, frame.operand_stack.pop_reference(0))?;
@ -2043,12 +2085,12 @@ fn fill_arguments(class: &JavaClassFile, method: &MethodInfo, arguments: &mut Ve
},
AbstractTypeKind::Char() => {
arguments.push_front(
StackValue::Char(
StackValue::Int(
wrap_stackframe_error(
class,
method,
stack.pop_char(0)
)?
)? as i32
)
)
},