Implemented Exception Throwing fith specific catchers
This commit is contained in:
parent
796e52241d
commit
fc0d11c1e1
8 changed files with 351 additions and 12 deletions
|
@ -44,6 +44,24 @@ impl EntryPoint {
|
|||
struct JavaLangClass {}
|
||||
|
||||
impl JavaLangClass {
|
||||
|
||||
fn is_array(jvm: &mut JVM) -> Result<JVMCallbackOperation, Error> {
|
||||
let frame = {
|
||||
let frame_index = jvm.stack_frames.len() - 1;
|
||||
&mut jvm.stack_frames[frame_index]
|
||||
};
|
||||
let this = frame.load_local_reference(0).unwrap();
|
||||
let class_class_index = jvm.heap_area.object_area.get_object_class_index(this);
|
||||
|
||||
let component_type = jvm.heap_area.object_area.get_object_field(
|
||||
this,
|
||||
"componentType",
|
||||
class_class_index,
|
||||
&jvm.class_store,
|
||||
)?;
|
||||
Ok(JVMCallbackOperation::ReturnFrame(FieldValue::Boolean(component_type.expect_reference() == ObjectReference::NULL)))
|
||||
}
|
||||
|
||||
pub fn get_primitive_class(jvm: &mut JVM) -> Result<JVMCallbackOperation, Error> {
|
||||
let frame = {
|
||||
let frame_index = jvm.stack_frames.len() - 1;
|
||||
|
@ -330,6 +348,81 @@ impl JavaLangDouble {
|
|||
}
|
||||
}
|
||||
|
||||
struct JavaLangObject {}
|
||||
|
||||
impl JavaLangObject {
|
||||
|
||||
fn get_class(jvm: &mut JVM) -> Result<JVMCallbackOperation, Error> {
|
||||
let frame = {
|
||||
let frame_index = jvm.stack_frames.len() - 1;
|
||||
&mut jvm.stack_frames[frame_index]
|
||||
};
|
||||
let this = frame.load_local_reference(0).unwrap();
|
||||
|
||||
let class_reference = jvm.heap_area.object_area.get_reference_class_ref(this, &jvm.class_store);
|
||||
|
||||
Ok(JVMCallbackOperation::ReturnFrame(FieldValue::Reference(class_reference)))
|
||||
}
|
||||
|
||||
fn hashcode(jvm: &mut JVM) -> Result<JVMCallbackOperation, Error> {
|
||||
let frame = {
|
||||
let frame_index = jvm.stack_frames.len() - 1;
|
||||
&mut jvm.stack_frames[frame_index]
|
||||
};
|
||||
if frame.operand_stack.capacity() == 1 {
|
||||
frame.operand_stack.grow(2);
|
||||
frame.operand_stack.push(StackValue::Int(91)).unwrap();
|
||||
} else {
|
||||
let new_hashcode_part = frame.operand_stack.pop_int(0).unwrap();
|
||||
let old_hashcode_part = frame.operand_stack.pop_int(0).unwrap();
|
||||
let combined_hashcode = old_hashcode_part.wrapping_mul(37).wrapping_add(new_hashcode_part);
|
||||
frame.operand_stack.push(StackValue::Int(combined_hashcode)).unwrap();
|
||||
}
|
||||
|
||||
let this = frame.load_local_reference(0).unwrap();
|
||||
let this_pointer = &this as *const _;
|
||||
|
||||
return Ok(JVMCallbackOperation::ReturnFrame(FieldValue::Int(this_pointer as i32)))
|
||||
|
||||
//let this_field_count = jvm.heap_area.object_area.get_object_field_count(this);
|
||||
|
||||
//Ok(if this_field_count > frame.instruction_pointer as usize {
|
||||
// let current_field = jvm.heap_area.object_area.get_object_field_at(this, frame.instruction_pointer as usize);
|
||||
// let caller_frame = match current_field.value {
|
||||
// FieldValue::Boolean(b) => {
|
||||
// // TODO: Maybe load the class
|
||||
// let (boolean_class_file, boolean_class_index) = jvm.class_store.get_class(&String::from("java/lang/Boolean")).unwrap();
|
||||
// StackFrame::new(
|
||||
// boolean_class_file,
|
||||
// boolean_class_index,
|
||||
// boolean_class_file.resolve_method_index("hashCode", "(Z)I").unwrap(),
|
||||
// &[StackValue::Boolean(b)]
|
||||
// )
|
||||
// },
|
||||
// FieldValue::Byte(_) => todo!(),
|
||||
// FieldValue::Char(_) => todo!(),
|
||||
// FieldValue::Short(_) => todo!(),
|
||||
// FieldValue::Int(_) => todo!(),
|
||||
// FieldValue::Float(_) => todo!(),
|
||||
// FieldValue::Reference(r) => {
|
||||
// if jvm.heap_area.object_area.is_array_reference(r) {
|
||||
|
||||
// } else {
|
||||
|
||||
// }
|
||||
// },
|
||||
// FieldValue::Double(_) => todo!(),
|
||||
// FieldValue::Long(_) => todo!(),
|
||||
// };
|
||||
|
||||
// JVMCallbackOperation::PushFrame(caller_frame)
|
||||
//} else {
|
||||
// let hashcode = frame.operand_stack.pop_int(0).unwrap();
|
||||
// JVMCallbackOperation::ReturnFrame(FieldValue::Int(hashcode))
|
||||
//})
|
||||
}
|
||||
}
|
||||
|
||||
struct JavaLangRuntime {}
|
||||
|
||||
impl JavaLangRuntime {
|
||||
|
@ -1136,7 +1229,7 @@ pub fn function_for(class_name: &str, m: &crate::classfile::MethodInfo) -> Resul
|
|||
argument_types: Box::new([]),
|
||||
return_type: AbstractTypeDescription { array_level: 0, kind: AbstractTypeKind::Boolean()},
|
||||
},
|
||||
todo_call
|
||||
JavaLangClass::is_array
|
||||
),
|
||||
|
||||
(
|
||||
|
@ -1299,7 +1392,7 @@ pub fn function_for(class_name: &str, m: &crate::classfile::MethodInfo) -> Resul
|
|||
argument_types: Box::new([]),
|
||||
return_type: AbstractTypeDescription { array_level: 0, kind: AbstractTypeKind::Classname(String::from("java/lang/Class"))},
|
||||
},
|
||||
todo_call
|
||||
JavaLangObject::get_class
|
||||
),
|
||||
|
||||
(
|
||||
|
@ -1309,7 +1402,7 @@ pub fn function_for(class_name: &str, m: &crate::classfile::MethodInfo) -> Resul
|
|||
argument_types: Box::new([]),
|
||||
return_type: AbstractTypeDescription { array_level: 0, kind: AbstractTypeKind::Int()},
|
||||
},
|
||||
todo_call
|
||||
JavaLangObject::hashcode
|
||||
),
|
||||
|
||||
(
|
||||
|
@ -3435,6 +3528,75 @@ pub fn function_for(class_name: &str, m: &crate::classfile::MethodInfo) -> Resul
|
|||
},
|
||||
todo_call
|
||||
),
|
||||
|
||||
(
|
||||
"java/lang/Module",
|
||||
"defineModule0",
|
||||
MethodDescriptor {
|
||||
argument_types: Box::new([
|
||||
AbstractTypeDescription { array_level: 0, kind: AbstractTypeKind::Classname("java/lang/Module".to_string())},
|
||||
AbstractTypeDescription { array_level: 0, kind: AbstractTypeKind::Boolean()},
|
||||
AbstractTypeDescription { array_level: 0, kind: AbstractTypeKind::Classname("java/lang/String".to_string())},
|
||||
AbstractTypeDescription { array_level: 0, kind: AbstractTypeKind::Classname("java/lang/String".to_string())},
|
||||
AbstractTypeDescription { array_level: 1, kind: AbstractTypeKind::Classname("java/lang/Object".to_string())},
|
||||
]),
|
||||
return_type: AbstractTypeDescription { array_level: 0, kind: AbstractTypeKind::Void() },
|
||||
},
|
||||
todo_call
|
||||
),
|
||||
|
||||
(
|
||||
"java/lang/Module",
|
||||
"addReads0",
|
||||
MethodDescriptor {
|
||||
argument_types: Box::new([
|
||||
AbstractTypeDescription { array_level: 0, kind: AbstractTypeKind::Classname("java/lang/Module".to_string())},
|
||||
AbstractTypeDescription { array_level: 0, kind: AbstractTypeKind::Classname("java/lang/Module".to_string())},
|
||||
]),
|
||||
return_type: AbstractTypeDescription { array_level: 0, kind: AbstractTypeKind::Void() },
|
||||
},
|
||||
todo_call
|
||||
),
|
||||
|
||||
(
|
||||
"java/lang/Module",
|
||||
"addExports0",
|
||||
MethodDescriptor {
|
||||
argument_types: Box::new([
|
||||
AbstractTypeDescription { array_level: 0, kind: AbstractTypeKind::Classname("java/lang/Module".to_string())},
|
||||
AbstractTypeDescription { array_level: 0, kind: AbstractTypeKind::Classname("java/lang/String".to_string())},
|
||||
AbstractTypeDescription { array_level: 0, kind: AbstractTypeKind::Classname("java/lang/Module".to_string())},
|
||||
]),
|
||||
return_type: AbstractTypeDescription { array_level: 0, kind: AbstractTypeKind::Void() },
|
||||
},
|
||||
todo_call
|
||||
),
|
||||
|
||||
(
|
||||
"java/lang/Module",
|
||||
"addExportsToAll0",
|
||||
MethodDescriptor {
|
||||
argument_types: Box::new([
|
||||
AbstractTypeDescription { array_level: 0, kind: AbstractTypeKind::Classname("java/lang/Module".to_string())},
|
||||
AbstractTypeDescription { array_level: 0, kind: AbstractTypeKind::Classname("java/lang/String".to_string())},
|
||||
]),
|
||||
return_type: AbstractTypeDescription { array_level: 0, kind: AbstractTypeKind::Void() },
|
||||
},
|
||||
todo_call
|
||||
),
|
||||
|
||||
(
|
||||
"java/lang/Module",
|
||||
"addExportsToAllUnnamed0",
|
||||
MethodDescriptor {
|
||||
argument_types: Box::new([
|
||||
AbstractTypeDescription { array_level: 0, kind: AbstractTypeKind::Classname("java/lang/Module".to_string())},
|
||||
AbstractTypeDescription { array_level: 0, kind: AbstractTypeKind::Classname("java/lang/String".to_string())},
|
||||
]),
|
||||
return_type: AbstractTypeDescription { array_level: 0, kind: AbstractTypeKind::Void() },
|
||||
},
|
||||
todo_call
|
||||
),
|
||||
];
|
||||
|
||||
for (classname, methodname, methoddescriptor, binding) in native_mappings {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue