Tableswitch implementation
This commit is contained in:
parent
b053461e74
commit
d7d159d115
2 changed files with 66 additions and 2 deletions
32
src/jvm.rs
32
src/jvm.rs
|
@ -701,7 +701,14 @@ impl JVM {
|
|||
let element = self.heap_area.object_area.get_array_element(array_reference, element_index);
|
||||
|
||||
wrap_stackframe_error(class, method, frame.operand_stack.push_field_value(element))?;
|
||||
},
|
||||
}
|
||||
|
||||
Instruction::AndInt() => {
|
||||
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))?;
|
||||
|
||||
wrap_stackframe_error(class, method, frame.operand_stack.push(StackValue::Int(value_1 & value_2)))?;
|
||||
}
|
||||
|
||||
Instruction::BranchAlways(branch_offset) => {
|
||||
frame.instruction_pointer -= offset as u32;
|
||||
|
@ -1323,6 +1330,9 @@ impl JVM {
|
|||
load_local_float(class, method, frame, 3)?;
|
||||
}
|
||||
|
||||
Instruction::LoadLocalInt(index) => {
|
||||
load_local_int(class, method, frame, index as usize)?;
|
||||
}
|
||||
Instruction::LoadLocalInt0() => {
|
||||
load_local_int(class, method, frame, 0)?;
|
||||
}
|
||||
|
@ -1737,6 +1747,26 @@ impl JVM {
|
|||
wrap_stackframe_error(class, method, frame.store_local(3, StackValue::Reference(reference)))?;
|
||||
}
|
||||
|
||||
Instruction::TableSwitch(default, low, high, offsets) => {
|
||||
let index = wrap_stackframe_error(class, method, frame.operand_stack.pop_int(0))?;
|
||||
|
||||
frame.instruction_pointer -= offset as u32;
|
||||
if index < low || index > high {
|
||||
frame.instruction_pointer = if default < 0 { frame.instruction_pointer - default.abs() as u32} else { frame.instruction_pointer + default.abs() as u32};
|
||||
} else {
|
||||
let offset_index = index - low;
|
||||
let jump_offset = offsets[offset_index as usize];
|
||||
frame.instruction_pointer = if jump_offset < 0 { frame.instruction_pointer - jump_offset.abs() as u32} else { frame.instruction_pointer + jump_offset.abs() as u32};
|
||||
}
|
||||
}
|
||||
|
||||
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))?;
|
||||
|
||||
wrap_stackframe_error(class, method, frame.operand_stack.push(StackValue::Int(value_1 ^ value_2)))?;
|
||||
}
|
||||
|
||||
_ => {
|
||||
return Err(Error::RunTimeError(format!("Opcode not implemented yet: {:?}", instruction)))
|
||||
},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue