Update value.rs

This commit is contained in:
Shunsuke Shibayama 2022-12-26 23:29:50 +09:00
parent f0ecf59af1
commit 9daad37fb6

View file

@ -902,10 +902,18 @@ impl ValueObj {
TyParam::value(arr.len()).mutate(), TyParam::value(arr.len()).mutate(),
], ],
), ),
Self::Dict(_dict) => todo!(), Self::Dict(dict) => poly(
Self::Code(_) => Type::Code, "Dict!",
Self::None => Type::NoneType, vec![TyParam::Dict(
other => panic!("{other} object cannot be mutated"), dict.iter()
.map(|(k, v)| (TyParam::value(k.clone()), TyParam::value(v.clone())))
.collect(),
)],
),
other => {
log!(err "{other} object cannot be mutated");
other.class()
}
}, },
Self::Illegal => Type::Failure, Self::Illegal => Type::Failure,
} }
@ -913,9 +921,9 @@ impl ValueObj {
pub fn try_cmp(&self, other: &Self) -> Option<Ordering> { pub fn try_cmp(&self, other: &Self) -> Option<Ordering> {
match (self, other) { match (self, other) {
(l, r) if l.is_num() && r.is_num() => f64::try_from(l) (l, r) if l.is_num() && r.is_num() => {
.unwrap() f64::try_from(l).ok()?.partial_cmp(&f64::try_from(r).ok()?)
.partial_cmp(&f64::try_from(r).unwrap()), }
(Self::Inf, n) | (n, Self::NegInf) if n.is_num() => Some(Ordering::Greater), (Self::Inf, n) | (n, Self::NegInf) if n.is_num() => Some(Ordering::Greater),
(n, Self::Inf) | (Self::NegInf, n) if n.is_num() => Some(Ordering::Less), (n, Self::Inf) | (Self::NegInf, n) if n.is_num() => Some(Ordering::Less),
(Self::NegInf, Self::Inf) => Some(Ordering::Less), (Self::NegInf, Self::Inf) => Some(Ordering::Less),