From ede316cec35c687ccf51da28994675c08bf9cfd8 Mon Sep 17 00:00:00 2001 From: VegOwOtenks Date: Tue, 10 Sep 2024 00:23:53 +0200 Subject: [PATCH] Int Branching instructions --- src/jvm.rs | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/src/jvm.rs b/src/jvm.rs index a189ab8..8f71b86 100644 --- a/src/jvm.rs +++ b/src/jvm.rs @@ -13,7 +13,7 @@ use crate::constantpool::{ ConstantPoolInfo, ConstantClassInfo, ConstantUtf8Info use crate::heap_area::{ HeapArea, FieldValue, ObjectReference, CompartmentEntry }; use crate::iterators::{ ClassMethodIterator, ClassFieldIterator }; use crate::native_methods; -use crate::native_methods::{ EntryPoint, ignore_call }; +use crate::native_methods::EntryPoint; use crate::native_registry::NativeRegistry; use crate::stackframe; use crate::stackframe::{ StackFrame, StackValue, OperandStack }; @@ -681,8 +681,8 @@ impl JVM { } 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_1 = wrap_stackframe_error(class, method, frame.operand_stack.pop_int(0))?; if value_1 == value_2 { frame.instruction_pointer -= offset as u32; @@ -691,8 +691,8 @@ impl JVM { } 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_1 = wrap_stackframe_error(class, method, frame.operand_stack.pop_int(0))?; if value_1 != value_2 { 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) => { 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); wrap_stackframe_error(class, method, frame.operand_stack.push(StackValue::Reference(string_obj_ref)))?; - }, + } ConstantPoolInfo::Float(_) => { // TODO: Handle error instead of unwrap let float_constant = class.gather_float(index as u16).unwrap(); 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()); todo!()