removed obsolete parameter
This commit is contained in:
parent
ae143cd50d
commit
9949c7c9ac
4 changed files with 9 additions and 14 deletions
|
|
@ -20,7 +20,6 @@ static mut CLASSDEFS: Lazy<HashMap<String, Arc<RefCell<Class>>>> = Lazy::new(||
|
||||||
// Vm keeps ownership of the class and hands out Arc references to it
|
// Vm keeps ownership of the class and hands out Arc references to it
|
||||||
pub fn get_class(
|
pub fn get_class(
|
||||||
vm: &mut Vm,
|
vm: &mut Vm,
|
||||||
_calling_class_name: Option<&str>,
|
|
||||||
class_name: &str,
|
class_name: &str,
|
||||||
) -> Result<Arc<RefCell<Class>>, Error> {
|
) -> Result<Arc<RefCell<Class>>, Error> {
|
||||||
// println!("get_class {}", class_name);
|
// println!("get_class {}", class_name);
|
||||||
|
|
@ -52,7 +51,7 @@ pub fn get_class(
|
||||||
.map(|n| n.to_owned());
|
.map(|n| n.to_owned());
|
||||||
{
|
{
|
||||||
if let Some(super_class_name) = super_class_name {
|
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);
|
clone2.borrow_mut().super_class = Some(super_class);
|
||||||
} else {
|
} else {
|
||||||
unreachable!()
|
unreachable!()
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ fn main() -> Result<(), Error> {
|
||||||
// let main_class = "Inheritance";
|
// let main_class = "Inheritance";
|
||||||
let main_class = "testclasses.Main";
|
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();
|
.unwrap();
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
14
src/vm.rs
14
src/vm.rs
|
|
@ -92,12 +92,11 @@ impl Vm {
|
||||||
/// contains unsafe, as I think that mimics not-synchronized memory access in the original JVM
|
/// contains unsafe, as I think that mimics not-synchronized memory access in the original JVM
|
||||||
pub fn execute(
|
pub fn execute(
|
||||||
&mut self,
|
&mut self,
|
||||||
calling_class_name: Option<&str>,
|
|
||||||
class_name: &str,
|
class_name: &str,
|
||||||
method_name: &str,
|
method_name: &str,
|
||||||
args: Vec<UnsafeValue>,
|
args: Vec<UnsafeValue>,
|
||||||
) -> Result<UnsafeValue, Error> {
|
) -> Result<UnsafeValue, Error> {
|
||||||
let class = get_class(self, calling_class_name, class_name)?;
|
let class = get_class(self, class_name)?;
|
||||||
self.execute_class(class, method_name, args)
|
self.execute_class(class, method_name, args)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -198,7 +197,6 @@ impl Vm {
|
||||||
//TODO
|
//TODO
|
||||||
let stringclass = get_class(
|
let stringclass = get_class(
|
||||||
self,
|
self,
|
||||||
Some(&this_class.borrow().name),
|
|
||||||
"java/lang/String",
|
"java/lang/String",
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
@ -357,7 +355,7 @@ impl Vm {
|
||||||
|
|
||||||
let that_class_name_index = borrow.cp_class_ref(class_index).unwrap();
|
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_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 that_borrow = that.borrow();
|
||||||
let (_, val_index) = that_borrow
|
let (_, val_index) = that_borrow
|
||||||
.static_field_mapping
|
.static_field_mapping
|
||||||
|
|
@ -397,7 +395,7 @@ impl Vm {
|
||||||
.1
|
.1
|
||||||
} else {
|
} else {
|
||||||
let that =
|
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();
|
let that_borrow = that.borrow();
|
||||||
that_borrow
|
that_borrow
|
||||||
.static_field_mapping
|
.static_field_mapping
|
||||||
|
|
@ -466,7 +464,6 @@ impl Vm {
|
||||||
}
|
}
|
||||||
args.insert(0, self.current_frame().pop()?);
|
args.insert(0, self.current_frame().pop()?);
|
||||||
let return_value = self.execute(
|
let return_value = self.execute(
|
||||||
Some(this_class.borrow().name.as_str()),
|
|
||||||
&invocation.class_name,
|
&invocation.class_name,
|
||||||
&invocation.method.name,
|
&invocation.method.name,
|
||||||
args,
|
args,
|
||||||
|
|
@ -492,7 +489,6 @@ impl Vm {
|
||||||
args.insert(0, copy(self.current_frame().pop()?));
|
args.insert(0, copy(self.current_frame().pop()?));
|
||||||
}
|
}
|
||||||
let returnvalue = self.execute(
|
let returnvalue = self.execute(
|
||||||
Some(this_class.borrow().name.as_str()),
|
|
||||||
&invocation.class_name,
|
&invocation.class_name,
|
||||||
&invocation.method.name,
|
&invocation.method.name,
|
||||||
args,
|
args,
|
||||||
|
|
@ -512,7 +508,7 @@ impl Vm {
|
||||||
let borrow = this_class.borrow();
|
let borrow = this_class.borrow();
|
||||||
let class_name_index = borrow.cp_class_ref(class_index).unwrap();
|
let class_name_index = borrow.cp_class_ref(class_index).unwrap();
|
||||||
let class_name = borrow.cp_utf8(class_name_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(
|
let object = unsafe_ref(ObjectRef::Object(Box::new(Vm::new_instance(
|
||||||
class_to_instantiate,
|
class_to_instantiate,
|
||||||
|
|
@ -525,7 +521,7 @@ impl Vm {
|
||||||
let borrow = this_class.borrow();
|
let borrow = this_class.borrow();
|
||||||
let class_name_index = borrow.cp_class_ref(class_index).unwrap();
|
let class_name_index = borrow.cp_class_ref(class_index).unwrap();
|
||||||
let class_name = borrow.cp_utf8(class_name_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()?;
|
let count = self.current_frame().pop()?;
|
||||||
if let I32(count) = *count.get() {
|
if let I32(count) = *count.get() {
|
||||||
// why does pop()?.get() give weird results?
|
// why does pop()?.get() give weird results?
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ mod test {
|
||||||
#[test]
|
#[test]
|
||||||
fn if_cmp() {
|
fn if_cmp() {
|
||||||
let mut vm = Vm::new("tests");
|
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();
|
let ret = vm.execute_class(c, "i_is_1()Z", vec![]).unwrap();
|
||||||
unsafe {
|
unsafe {
|
||||||
if let Value::I32(b) = *ret.get() {
|
if let Value::I32(b) = *ret.get() {
|
||||||
|
|
@ -21,7 +21,7 @@ mod test {
|
||||||
#[test]
|
#[test]
|
||||||
fn consts() {
|
fn consts() {
|
||||||
let mut vm = Vm::new("tests");
|
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
|
let ret = vm
|
||||||
.execute_class(c, "hello()Ljava/lang/String;", vec![])
|
.execute_class(c, "hello()Ljava/lang/String;", vec![])
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue