ThrowException .-.

This commit is contained in:
VegOwOtenks 2024-11-07 14:41:00 +01:00
parent 45d0aa66e5
commit 6b03cab14d
4 changed files with 14 additions and 5 deletions

View file

@ -251,6 +251,7 @@ impl Bytecode {
0xBC => (Instruction::NewPrimitiveArray(self.bytes[offset+1]), 2),
0xBD => (Instruction::NewArray((self.bytes[offset+1] as u16) << 8 | self.bytes[offset+2] as u16), 3),
0xBE => (Instruction::ArrayLength(), 1),
0xBF => (Instruction::ThrowException(), 1),
0xC0 => (Instruction::CheckCast((self.bytes[offset+1] as u16) << 8 | self.bytes[offset+2] as u16), 3),
0xC1 => (Instruction::InstanceOf((self.bytes[offset+1] as u16) << 8 | self.bytes[offset+2] as u16), 3),
@ -446,6 +447,7 @@ pub enum Instruction {
NewPrimitiveArray(u8) = 0xBC, // make a primitive array
NewArray(u16) = 0xBD, // Create a new array from a constant-pool component class reference
ArrayLength() = 0xBE, // Get length from array reference
ThrowException() = 0xBF, // throw the exception
CheckCast(u16) = 0xC0, // throw exception on fail
InstanceOf(u16) = 0xC1, // push integer result for success

View file

@ -194,7 +194,7 @@ impl JavaClassFile {
pub fn find_method_index(&self, name: &String) -> Option<usize> {
for (index, method_info) in self.methods.iter().enumerate() {
for (index, method_info) in (&self.methods).into_iter().enumerate() {
if method_info.name == *name {
return Some(index);
}
@ -377,7 +377,7 @@ impl JavaClassFile {
}
pub fn sourcefile(&self) -> Result<Option<&String>, Error> {
match self.attributes.into_iter()
match (&self.attributes).into_iter()
.filter_map(|attribute| match &attribute.data {
AttributeData::SourceFile(data) => Some(data),
_ => None,
@ -1103,7 +1103,7 @@ impl MethodInfo {
pub fn get_bytecode_linenumber(&self, bytecode_index: u16) -> Option<u16> {
let linenumbertable = match self.attributes
.into_iter()
.iter()
.filter_map(|a| match &a.data {
AttributeData::LineNumberTable(data) => Some(data),
_ => None,
@ -1112,7 +1112,7 @@ impl MethodInfo {
Some(a) => a,
None => return None,
};
linenumbertable.entries.into_iter()
linenumbertable.entries.iter()
.take_while(|entry| entry.start_pc < bytecode_index)
.map(|entry| entry.line_number)
.last()

View file

@ -2278,6 +2278,13 @@ impl JVM {
}
}
Instruction::ThrowException() => {
let exception = wrap_stackframe_error(class, method, frame.operand_stack.pop_reference(0))?;
if exception == ObjectReference::NULL {
}
}
Instruction::XorInt() => {
let value_1 = wrap_stackframe_error(class, method, frame.operand_stack.pop_int(0))?;
let value_2 = wrap_stackframe_error(class, method, frame.operand_stack.pop_int(0))?;

View file

@ -422,7 +422,7 @@ impl JavaLangThrowable {
let sourcefile = class_file.sourcefile()?;
let sourcefile_string = match sourcefile {
Some(string) => jvm.heap_area.make_handmade_string(string, &jvm.class_store),
None => jvm.heap_area.static_area.get(&String::from("StackTraceElement"), &String::from("UNKNOWN_SOURCE"), AbstractTypeDescription::class_type("java/lang/String")).unwrap().expect_reference(),
None => jvm.heap_area.static_area.get(&String::from("java/lang/StackTraceElement"), &String::from("UNKNOWN_SOURCE"), AbstractTypeDescription::class_type("java/lang/String")).unwrap().expect_reference(),
};
jvm.heap_area.object_area.set_object_field(