All branch/jump and set instructions impl

Signed-off-by: Rachel <508861+Ryex@users.noreply.github.com>
This commit is contained in:
Rachel
2024-03-25 15:54:03 -07:00
parent 93b5a7c4bf
commit e9df98a4c2
3 changed files with 1845 additions and 140 deletions

View File

@@ -223,6 +223,38 @@ impl Operand {
&Operand::DeviceSpec { .. } => Err(interpreter::ICError::DeviceNotValue),
}
}
pub fn get_device_id(
&self,
ic: &interpreter::IC,
) -> Result<(Option<u16>, Option<u32>), interpreter::ICError> {
match &self {
&Operand::DeviceSpec { device, channel } => match device {
Device::Db => Ok((Some(ic.id), *channel)),
Device::Numbered(p) => {
let dp = ic
.pins
.get(*p as usize)
.ok_or(interpreter::ICError::DeviceIndexOutOfRange(*p as f64))
.copied()?;
Ok((dp, *channel))
}
Device::Indirect {
indirection,
target,
} => {
let val = ic.get_register(*indirection, *target)?;
let dp = ic
.pins
.get(val as usize)
.ok_or(interpreter::ICError::DeviceIndexOutOfRange(val))
.copied()?;
Ok((dp, *channel))
}
},
&Operand::Identifier(id) => ic.get_ident_device_id(&id.name),
_ => Err(interpreter::ICError::ValueNotDevice),
}
}
}
impl FromStr for Operand {

File diff suppressed because it is too large Load Diff

View File

@@ -129,6 +129,7 @@ dependencies = [
"phf_codegen",
"regex",
"strum_macros",
"thiserror",
]
[[package]]
@@ -337,6 +338,26 @@ dependencies = [
"unicode-ident",
]
[[package]]
name = "thiserror"
version = "1.0.58"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "03468839009160513471e86a034bb2c5c0e4baae3b43f79ffc55c4a5427b3297"
dependencies = [
"thiserror-impl",
]
[[package]]
name = "thiserror-impl"
version = "1.0.58"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c61f3ba182994efc43764a46c018c347bc492c79f024e705f46567b418f6d4f7"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "unicode-ident"
version = "1.0.12"