Skip to content

Commit

Permalink
style(ir): refactor local indices
Browse files Browse the repository at this point in the history
  • Loading branch information
henryhchchc committed Oct 3, 2024
1 parent 1525ec9 commit 58f9752
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
8 changes: 5 additions & 3 deletions src/ir/generator/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,9 @@ impl MokaIRGenerator<'_> {
LOr => binary_op_math::<DUAL_SLOT>(frame, def, MathOperation::BitwiseOr)?,
LXor => binary_op_math::<DUAL_SLOT>(frame, def, MathOperation::BitwiseXor)?,
IInc(idx, constant) => {
let base = frame.get_local::<SINGLE_SLOT>(*idx)?;
frame.set_local::<SINGLE_SLOT>(*idx, def.as_argument())?;
let idx = (*idx).into();
let base = frame.get_local::<SINGLE_SLOT>(idx)?;
frame.set_local::<SINGLE_SLOT>(idx, def.as_argument())?;
let math_op = MathOperation::Increment(base, *constant);
IR::Definition {
value: def,
Expand Down Expand Up @@ -403,7 +404,8 @@ impl MokaIRGenerator<'_> {
}
}
Ret(idx) => {
let return_address = frame.get_local::<SINGLE_SLOT>(*idx)?;
let idx = (*idx).into();
let return_address = frame.get_local::<SINGLE_SLOT>(idx)?;
IR::SubroutineRet(return_address)
}
Wide(WideInstruction::Ret(idx)) => {
Expand Down
8 changes: 4 additions & 4 deletions src/ir/generator/jvm_frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,9 @@ impl JvmStackFrame {

pub(super) fn get_local<const SLOT: SlotWidth>(
&self,
idx: impl Into<u16>,
idx: u16,
) -> Result<Operand, ExecutionError> {
let idx = usize::from(idx.into());
let idx = usize::from(idx);
let lower_slot = self
.local_variables
.get(idx)
Expand All @@ -201,10 +201,10 @@ impl JvmStackFrame {

pub(super) fn set_local<const SLOT: SlotWidth>(
&mut self,
idx: impl Into<u16>,
idx: u16,
value: Operand,
) -> Result<(), ExecutionError> {
let idx = usize::from(idx.into());
let idx = usize::from(idx);
let lower_slot = self
.local_variables
.get_mut(idx)
Expand Down

0 comments on commit 58f9752

Please sign in to comment.