Int Branching instructions
This commit is contained in:
parent
0c54a1d7e1
commit
ede316cec3
1 changed files with 21 additions and 5 deletions
26
src/jvm.rs
26
src/jvm.rs
|
@ -13,7 +13,7 @@ use crate::constantpool::{ ConstantPoolInfo, ConstantClassInfo, ConstantUtf8Info
|
||||||
use crate::heap_area::{ HeapArea, FieldValue, ObjectReference, CompartmentEntry };
|
use crate::heap_area::{ HeapArea, FieldValue, ObjectReference, CompartmentEntry };
|
||||||
use crate::iterators::{ ClassMethodIterator, ClassFieldIterator };
|
use crate::iterators::{ ClassMethodIterator, ClassFieldIterator };
|
||||||
use crate::native_methods;
|
use crate::native_methods;
|
||||||
use crate::native_methods::{ EntryPoint, ignore_call };
|
use crate::native_methods::EntryPoint;
|
||||||
use crate::native_registry::NativeRegistry;
|
use crate::native_registry::NativeRegistry;
|
||||||
use crate::stackframe;
|
use crate::stackframe;
|
||||||
use crate::stackframe::{ StackFrame, StackValue, OperandStack };
|
use crate::stackframe::{ StackFrame, StackValue, OperandStack };
|
||||||
|
@ -681,8 +681,8 @@ impl JVM {
|
||||||
}
|
}
|
||||||
|
|
||||||
Instruction::BranchIntEquality(branch_offset) => {
|
Instruction::BranchIntEquality(branch_offset) => {
|
||||||
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))?;
|
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 {
|
if value_1 == value_2 {
|
||||||
frame.instruction_pointer -= offset as u32;
|
frame.instruction_pointer -= offset as u32;
|
||||||
|
@ -691,8 +691,8 @@ impl JVM {
|
||||||
}
|
}
|
||||||
|
|
||||||
Instruction::BranchIntInequality(branch_offset) => {
|
Instruction::BranchIntInequality(branch_offset) => {
|
||||||
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))?;
|
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 {
|
if value_1 != value_2 {
|
||||||
frame.instruction_pointer -= offset as u32;
|
frame.instruction_pointer -= offset as u32;
|
||||||
|
@ -700,6 +700,16 @@ impl JVM {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Instruction::BranchIntLessEquals(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::BranchNonNull(branch_offset) => {
|
Instruction::BranchNonNull(branch_offset) => {
|
||||||
let test_value = wrap_stackframe_error(class, method, frame.operand_stack.pop_reference(0))?;
|
let test_value = wrap_stackframe_error(class, method, frame.operand_stack.pop_reference(0))?;
|
||||||
|
|
||||||
|
@ -1046,13 +1056,19 @@ impl JVM {
|
||||||
let string_obj_ref = self.heap_area.make_handmade_string(string_constant, &self.class_store);
|
let string_obj_ref = self.heap_area.make_handmade_string(string_constant, &self.class_store);
|
||||||
|
|
||||||
wrap_stackframe_error(class, method, frame.operand_stack.push(StackValue::Reference(string_obj_ref)))?;
|
wrap_stackframe_error(class, method, frame.operand_stack.push(StackValue::Reference(string_obj_ref)))?;
|
||||||
},
|
}
|
||||||
ConstantPoolInfo::Float(_) => {
|
ConstantPoolInfo::Float(_) => {
|
||||||
// TODO: Handle error instead of unwrap
|
// TODO: Handle error instead of unwrap
|
||||||
let float_constant = class.gather_float(index as u16).unwrap();
|
let float_constant = class.gather_float(index as u16).unwrap();
|
||||||
|
|
||||||
wrap_stackframe_error(class, method, frame.operand_stack.push(StackValue::Float(float_constant)))?;
|
wrap_stackframe_error(class, method, frame.operand_stack.push(StackValue::Float(float_constant)))?;
|
||||||
},
|
}
|
||||||
|
ConstantPoolInfo::Integer(int_data) => {
|
||||||
|
// TODO: Handle error instead of unwrap
|
||||||
|
let int_constant = int_data.value;
|
||||||
|
|
||||||
|
wrap_stackframe_error(class, method, frame.operand_stack.push(StackValue::Int(int_constant)))?;
|
||||||
|
}
|
||||||
_ => {
|
_ => {
|
||||||
println!("{:?}", class.pool_entry(index as u16).unwrap());
|
println!("{:?}", class.pool_entry(index as u16).unwrap());
|
||||||
todo!()
|
todo!()
|
||||||
|
|
Loading…
Reference in a new issue