diff --git a/src/class.rs b/src/class.rs index cd855a7..fb3fe82 100644 --- a/src/class.rs +++ b/src/class.rs @@ -20,7 +20,6 @@ static mut CLASSDEFS: Lazy>>> = Lazy::new(|| // Vm keeps ownership of the class and hands out Arc references to it pub fn get_class( vm: &mut Vm, - _calling_class_name: Option<&str>, class_name: &str, ) -> Result>, Error> { // println!("get_class {}", class_name); @@ -52,7 +51,7 @@ pub fn get_class( .map(|n| n.to_owned()); { if let Some(super_class_name) = super_class_name { - if let Ok(super_class) = get_class(vm, Some(class_name), &super_class_name) { + if let Ok(super_class) = get_class(vm, &super_class_name) { clone2.borrow_mut().super_class = Some(super_class); } else { unreachable!() diff --git a/src/main.rs b/src/main.rs index 85e6db3..78eecd3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,7 +9,7 @@ fn main() -> Result<(), Error> { // let main_class = "Inheritance"; let main_class = "testclasses.Main"; - vm.execute(None, main_class, "main([Ljava/lang/String;)V", vec![]) + vm.execute( main_class, "main([Ljava/lang/String;)V", vec![]) .unwrap(); Ok(()) } diff --git a/src/vm.rs b/src/vm.rs index a32b5da..8fcbbc1 100644 --- a/src/vm.rs +++ b/src/vm.rs @@ -92,12 +92,11 @@ impl Vm { /// contains unsafe, as I think that mimics not-synchronized memory access in the original JVM pub fn execute( &mut self, - calling_class_name: Option<&str>, class_name: &str, method_name: &str, args: Vec, ) -> Result { - let class = get_class(self, calling_class_name, class_name)?; + let class = get_class(self, class_name)?; self.execute_class(class, method_name, args) } @@ -198,7 +197,6 @@ impl Vm { //TODO let stringclass = get_class( self, - Some(&this_class.borrow().name), "java/lang/String", ) .unwrap(); @@ -357,7 +355,7 @@ impl Vm { let that_class_name_index = borrow.cp_class_ref(class_index).unwrap(); let that_class_name = borrow.cp_utf8(that_class_name_index).unwrap(); - let that = get_class(self, Some(&borrow.name), that_class_name.as_str())?; + let that = get_class(self, that_class_name.as_str())?; let that_borrow = that.borrow(); let (_, val_index) = that_borrow .static_field_mapping @@ -397,7 +395,7 @@ impl Vm { .1 } else { let that = - get_class(self, Some(&borrow.name), that_class_name.as_str())?; + get_class(self, that_class_name.as_str())?; let that_borrow = that.borrow(); that_borrow .static_field_mapping @@ -466,7 +464,6 @@ impl Vm { } args.insert(0, self.current_frame().pop()?); let return_value = self.execute( - Some(this_class.borrow().name.as_str()), &invocation.class_name, &invocation.method.name, args, @@ -492,7 +489,6 @@ impl Vm { args.insert(0, copy(self.current_frame().pop()?)); } let returnvalue = self.execute( - Some(this_class.borrow().name.as_str()), &invocation.class_name, &invocation.method.name, args, @@ -512,7 +508,7 @@ impl Vm { let borrow = this_class.borrow(); let class_name_index = borrow.cp_class_ref(class_index).unwrap(); let class_name = borrow.cp_utf8(class_name_index).unwrap(); - let class_to_instantiate = get_class(self, Some(&borrow.name), class_name)?; + let class_to_instantiate = get_class(self, class_name)?; let object = unsafe_ref(ObjectRef::Object(Box::new(Vm::new_instance( class_to_instantiate, @@ -525,7 +521,7 @@ impl Vm { let borrow = this_class.borrow(); let class_name_index = borrow.cp_class_ref(class_index).unwrap(); let class_name = borrow.cp_utf8(class_name_index).unwrap(); - let arraytype = get_class(self, Some(&borrow.name), class_name)?; + let arraytype = get_class(self, class_name)?; let count = self.current_frame().pop()?; if let I32(count) = *count.get() { // why does pop()?.get() give weird results? diff --git a/tests/class_tests.rs b/tests/class_tests.rs index 508e24c..c46a277 100644 --- a/tests/class_tests.rs +++ b/tests/class_tests.rs @@ -5,7 +5,7 @@ mod test { #[test] fn if_cmp() { let mut vm = Vm::new("tests"); - let c = get_class(&mut vm, None, "testclasses.IfCmp").unwrap(); + let c = get_class(&mut vm, "testclasses.IfCmp").unwrap(); let ret = vm.execute_class(c, "i_is_1()Z", vec![]).unwrap(); unsafe { if let Value::I32(b) = *ret.get() { @@ -21,7 +21,7 @@ mod test { #[test] fn consts() { let mut vm = Vm::new("tests"); - let c = get_class(&mut vm, None, "testclasses.Const").unwrap(); + let c = get_class(&mut vm, "testclasses.Const").unwrap(); let ret = vm .execute_class(c, "hello()Ljava/lang/String;", vec![]) .unwrap();