From 202d7692bc70eefa26c0ee5d01a8ad279073e8ac Mon Sep 17 00:00:00 2001 From: VegOwOtenks Date: Wed, 11 Sep 2024 00:36:55 +0200 Subject: [PATCH] Implement ConvertIntToChar --- src/bytecode.rs | 2 ++ src/jvm.rs | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/src/bytecode.rs b/src/bytecode.rs index 21185ff..38247c2 100644 --- a/src/bytecode.rs +++ b/src/bytecode.rs @@ -88,6 +88,7 @@ impl Bytecode { 0x82 => (Instruction::XorInt(), 1), 0x84 => (Instruction::IncrementLocalInt(self.bytes[offset+1], i8::from_be_bytes([self.bytes[offset+2]])), 3), + 0x92 => (Instruction::ConvertIntToChar(), 1), 0x95 => (Instruction::CompareFloatL(), 1), 0x96 => (Instruction::CompareFloatG(), 1), 0x99 => { @@ -334,6 +335,7 @@ pub enum Instruction { XorInt() = 0x82, // value, value => xor IncrementLocalInt(u8, i8) = 0x84, // increment local variable by constant i8 + ConvertIntToChar() = 0x92, // truncate int to 16 bits CompareFloatL() = 0x95, // compare float, push -1 if one is NaN CompareFloatG() = 0x96, // compare float, push 1 if one is NaN BranchZero(i16) = 0x99, // branch if value == 0 diff --git a/src/jvm.rs b/src/jvm.rs index 108a53a..731cb5f 100644 --- a/src/jvm.rs +++ b/src/jvm.rs @@ -914,6 +914,13 @@ impl JVM { wrap_stackframe_error(class, method, frame.operand_stack.push(StackValue::Int(comparison_result)))?; } + Instruction::ConvertIntToChar() => { + let int_value = wrap_stackframe_error(class, method, frame.operand_stack.pop_int(0))?; + let char_value = int_value & 0x0000FFFF; + + frame.operand_stack.push(StackValue::Int(char_value)).unwrap(); + } + Instruction::DivideInt() => { // TODO: Obey all the rules let quotient = wrap_stackframe_error(class, method, frame.operand_stack.pop_int(0))?;