mirror of
https://github.com/erg-lang/erg.git
synced 2025-08-04 02:39:20 +00:00
feat: add Predicate::General{Less, Greater, Not}Equal
This commit is contained in:
parent
8350ad0581
commit
06a4a6e5fc
10 changed files with 304 additions and 18 deletions
|
@ -2609,6 +2609,37 @@ impl Context {
|
|||
(lhs, rhs) => Ok(Predicate::general_eq(lhs, rhs)),
|
||||
}
|
||||
}
|
||||
Predicate::GeneralNotEqual { lhs, rhs } => {
|
||||
match (self.eval_pred(*lhs)?, self.eval_pred(*rhs)?) {
|
||||
(Predicate::Value(lhs), Predicate::Value(rhs)) => {
|
||||
Ok(Predicate::Value(ValueObj::Bool(lhs != rhs)))
|
||||
}
|
||||
(lhs, rhs) => Ok(Predicate::general_ne(lhs, rhs)),
|
||||
}
|
||||
}
|
||||
Predicate::GeneralGreaterEqual { lhs, rhs } => {
|
||||
match (self.eval_pred(*lhs)?, self.eval_pred(*rhs)?) {
|
||||
(Predicate::Value(lhs), Predicate::Value(rhs)) => {
|
||||
let Some(ValueObj::Bool(res)) = lhs.try_ge(rhs) else {
|
||||
// TODO:
|
||||
return feature_error!(self, Location::Unknown, "evaluating >=");
|
||||
};
|
||||
Ok(Predicate::Value(ValueObj::Bool(res)))
|
||||
}
|
||||
(lhs, rhs) => Ok(Predicate::general_ge(lhs, rhs)),
|
||||
}
|
||||
}
|
||||
Predicate::GeneralLessEqual { lhs, rhs } => {
|
||||
match (self.eval_pred(*lhs)?, self.eval_pred(*rhs)?) {
|
||||
(Predicate::Value(lhs), Predicate::Value(rhs)) => {
|
||||
let Some(ValueObj::Bool(res)) = lhs.try_le(rhs) else {
|
||||
return feature_error!(self, Location::Unknown, "evaluating <=");
|
||||
};
|
||||
Ok(Predicate::Value(ValueObj::Bool(res)))
|
||||
}
|
||||
(lhs, rhs) => Ok(Predicate::general_le(lhs, rhs)),
|
||||
}
|
||||
}
|
||||
Predicate::Equal { lhs, rhs } => Ok(Predicate::eq(lhs, self.eval_tp(rhs)?)),
|
||||
Predicate::NotEqual { lhs, rhs } => Ok(Predicate::ne(lhs, self.eval_tp(rhs)?)),
|
||||
Predicate::LessEqual { lhs, rhs } => Ok(Predicate::le(lhs, self.eval_tp(rhs)?)),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue