implement iseq, tests

Signed-off-by: Ava Hahn <ava@aidanis.online>
This commit is contained in:
Ava Hahn 2023-03-02 12:48:26 -08:00
parent 5ce0a8e8b2
commit cb83fa5655
Signed by untrusted user who does not match committer: affine
GPG key ID: 3A4645B8CF806069
6 changed files with 134 additions and 25 deletions

View file

@ -49,7 +49,7 @@ pub enum Type {
* I was going to call it Cell and then I learned about
* how important RefCells were in Rust
*/
#[derive(Debug, Default)]
#[derive(Debug, Default, PartialEq)]
pub struct Seg {
/* "Contents of Address Register"
* Historical way of referring to the first value in a cell.
@ -251,6 +251,23 @@ impl fmt::Display for Ctr {
}
}
impl PartialEq for Ctr {
fn eq(&self, other: &Self) -> bool {
match (self, other) {
(Ctr::Symbol(r), Ctr::Symbol(l)) => *r == *l,
(Ctr::String(r), Ctr::String(l)) => *r == *l,
(Ctr::Bool(r), Ctr::Bool(l)) => *r == *l,
(Ctr::Seg(r), Ctr::Seg(l)) => *r == *l,
(Ctr::None, Ctr::None) => true,
(Ctr::Integer(r), Ctr::Integer(l)) => *r == *l,
(Ctr::Float(r), Ctr::Float(l)) => *r == *l,
(Ctr::Integer(r), Ctr::Float(l)) => *r < f64::MAX as i128 && *r as f64 == *l,
(Ctr::Float(r), Ctr::Integer(l)) => *l < f64::MAX as i128 && *r == *l as f64,
_ => false,
}
}
}
impl fmt::Display for Seg {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", seg_to_string(self, true))