Skip to content

Commit

Permalink
InstructionSelector --> Instruction
Browse files Browse the repository at this point in the history
  • Loading branch information
dannywillems committed Nov 16, 2023
1 parent a7c65d4 commit d1f0d6c
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions optimism/src/mips/interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,31 +99,32 @@ pub enum ITypeInstruction {
}


// InstructionSelectors
#[derive(Clone, Copy, Default, Debug, Serialize, Deserialize)]
pub struct InstructionSelectors<T> {
pub r_type: RTypeInstructionSelectors<T>,
pub j_type: JTypeInstructionSelectors<T>,
pub i_type: ITypeInstructionSelectors<T>,
}

impl<A> Index<InstructionSelector> for InstructionSelectors<A> {
impl<A> Index<Instruction> for InstructionSelectors<A> {
type Output = A;

fn index(&self, idx: InstructionSelector) -> &Self::Output {
fn index(&self, idx: Instruction) -> &Self::Output {
match idx {
InstructionSelector::RType(instr) => &self.r_type[instr],
InstructionSelector::JType(instr) => &self.j_type[instr],
InstructionSelector::IType(instr) => &self.i_type[instr],
Instruction::RType(instr) => &self.r_type[instr],
Instruction::JType(instr) => &self.j_type[instr],
Instruction::IType(instr) => &self.i_type[instr],
}
}
}

impl<A> IndexMut<InstructionSelector> for InstructionSelectors<A> {
fn index_mut(&mut self, idx: InstructionSelector) -> &mut Self::Output {
impl<A> IndexMut<Instruction> for InstructionSelectors<A> {
fn index_mut(&mut self, idx: Instruction) -> &mut Self::Output {
match idx {
InstructionSelector::RType(instr) => &mut self.r_type[instr],
InstructionSelector::JType(instr) => &mut self.j_type[instr],
InstructionSelector::IType(instr) => &mut self.i_type[instr],
Instruction::RType(instr) => &mut self.r_type[instr],
Instruction::JType(instr) => &mut self.j_type[instr],
Instruction::IType(instr) => &mut self.i_type[instr],
}
}
}
Expand Down Expand Up @@ -270,7 +271,7 @@ impl<A> IndexMut<RTypeInstruction> for RTypeInstructionSelectors<A> {
RTypeInstruction::Nor => &mut self.nor,
RTypeInstruction::SetLessThan => &mut self.set_less_than,
RTypeInstruction::SetLessThanUnsigned => &mut self.set_less_than_unsigned,
_ => /* TODO */ assert!(false)
_ => /* TODO */ panic!("Not implemented")
}
}
}
Expand Down Expand Up @@ -765,15 +766,15 @@ impl<A> ITypeInstructionSelectors<A> {
}
}

impl IntoEnumIterator for InstructionSelector {
impl IntoEnumIterator for Instruction {
// The underlying type is inexpressible, due to the function types :|
type Iterator = Box<dyn Iterator<Item = Self>>;
fn iter() -> Self::Iterator {
Box::new(
RTypeInstruction::iter()
.map(&InstructionSelector::RType)
.chain(JTypeInstruction::iter().map(&InstructionSelector::JType))
.chain(ITypeInstruction::iter().map(&InstructionSelector::IType)),
.map(&Instruction::RType)
.chain(JTypeInstruction::iter().map(&Instruction::JType))
.chain(ITypeInstruction::iter().map(&Instruction::IType)),
)
}
}
Expand Down

0 comments on commit d1f0d6c

Please sign in to comment.