Skip to content

Commit

Permalink
refactor: 💡 Change NotExistentCell to ValueNotSet
Browse files Browse the repository at this point in the history
  • Loading branch information
kamack38 committed Jan 24, 2024
1 parent 59bb24f commit 6a30efd
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions src/parser/operand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,10 @@ pub enum CellOperand {

#[derive(Error, Debug, PartialEq, Eq)]
pub enum ExpandError {
#[error("Cell {0} does not exist or its value wasn't set.")]
NotExistentCell(usize),
#[error("Value `{0}` in cell `{1}` could not be converted to a tape index.")]
ConvertError(i32, usize),
// #[error("Tried reading from cell with address `{0}`, which wasn't set.")]
// ValueNotSet(usize),
#[error("Tried reading from cell with address `{0}`, which was never set.")]
ValueNotSet(usize),
}

impl Operand {
Expand All @@ -42,13 +40,13 @@ impl Operand {
ValueInCell(cell) => Ok(tape
.get(*cell)
.and_then(|val| val.as_ref())
.ok_or(ExpandError::NotExistentCell(*cell))?),
.ok_or(ExpandError::ValueNotSet(*cell))?),
ValueOfValueInCell(cell) => tape
.get(
CellAddress::try_from(
tape.get(*cell)
.ok_or(ExpandError::NotExistentCell(*cell))?
.ok_or(ExpandError::NotExistentCell(*cell))?,
.ok_or(ExpandError::ValueNotSet(*cell))?
.ok_or(ExpandError::ValueNotSet(*cell))?,
)
.map_err(|_| {
ExpandError::ConvertError(
Expand All @@ -59,7 +57,7 @@ impl Operand {
)
.and_then(|val| val.as_ref())
.ok_or_else(|| {
ExpandError::NotExistentCell(
ExpandError::ValueNotSet(
CellAddress::try_from(
tape.get(*cell).expect("Would've failed before").unwrap(),
)
Expand All @@ -77,8 +75,8 @@ impl CellOperand {
AddressOfCell(cell) => Ok(*cell),
AddressOfCellInCell(cell) => CellAddress::try_from(
tape.get(*cell)
.ok_or(ExpandError::NotExistentCell(*cell))?
.ok_or(ExpandError::NotExistentCell(*cell))?,
.ok_or(ExpandError::ValueNotSet(*cell))?
.ok_or(ExpandError::ValueNotSet(*cell))?,
)
.map_err(|_| {
ExpandError::ConvertError(
Expand Down

0 comments on commit 6a30efd

Please sign in to comment.