tamer: NIR->xmli: Ceil, Floor expressions
Small break from templates for something easier. I have COVID-19, so I'll use that as my excuse for wanting to be more lazy. The real reason is to see some more concrete progress and ensure that patterns hold for simple expressions before further refactoring. But, before I proceed with such refactoring, I really ought to approach something that requires a NIR desugaring step, like case statements. DEV-13708main
parent
b9f0fada51
commit
0aa69c079d
|
@ -94,6 +94,10 @@ pub enum ExprOp {
|
|||
Sum,
|
||||
/// Product (×)
|
||||
Product,
|
||||
// Ceiling (⌈)
|
||||
Ceil,
|
||||
// Floor (⌊)
|
||||
Floor,
|
||||
/// Logical conjunction (∧)
|
||||
Conj,
|
||||
/// Logical disjunction (∨)
|
||||
|
@ -107,6 +111,8 @@ impl Display for ExprOp {
|
|||
match self {
|
||||
Sum => write!(f, "sum (+)"),
|
||||
Product => write!(f, "product (×)"),
|
||||
Ceil => write!(f, "ceiling (⌈)"),
|
||||
Floor => write!(f, "floor (⌊)"),
|
||||
Conj => write!(f, "conjunctive (∧)"),
|
||||
Disj => write!(f, "disjunctive (∨)"),
|
||||
}
|
||||
|
|
|
@ -263,7 +263,9 @@ impl<'a> TreeContext<'a> {
|
|||
ExprOp::Sum => (QN_RATE, QN_YIELDS),
|
||||
ExprOp::Conj => (QN_CLASSIFY, QN_AS),
|
||||
|
||||
ExprOp::Product | ExprOp::Disj => todo!("stmt: {expr:?}"),
|
||||
ExprOp::Product | ExprOp::Ceil | ExprOp::Floor | ExprOp::Disj => {
|
||||
todo!("stmt: {expr:?}")
|
||||
}
|
||||
};
|
||||
|
||||
let ispan = ident.span();
|
||||
|
@ -363,6 +365,8 @@ fn expr_ele(expr: &Expr, depth: Depth) -> Xirf {
|
|||
let qname = match expr.op() {
|
||||
Sum => QN_C_SUM,
|
||||
Product => QN_C_PRODUCT,
|
||||
Ceil => QN_C_CEIL,
|
||||
Floor => QN_C_FLOOR,
|
||||
Conj => QN_ALL,
|
||||
Disj => QN_ANY,
|
||||
};
|
||||
|
|
|
@ -187,6 +187,10 @@ pub enum NirEntity {
|
|||
Sum,
|
||||
/// Product (Π) expression.
|
||||
Product,
|
||||
/// Ceiling (⌈) expression.
|
||||
Ceil,
|
||||
/// Floor (⌊) expression.
|
||||
Floor,
|
||||
|
||||
// Classification.
|
||||
Classify,
|
||||
|
@ -221,6 +225,8 @@ impl Display for NirEntity {
|
|||
Rate => write!(f, "rate block"),
|
||||
Sum => write!(f, "sum (∑) expression"),
|
||||
Product => write!(f, "product (Π) expression"),
|
||||
Ceil => write!(f, "ceiling (⌈) expression"),
|
||||
Floor => write!(f, "floor (⌊) expression"),
|
||||
|
||||
Classify => write!(f, "classification"),
|
||||
All => write!(f, "conjunctive (∧) expression"),
|
||||
|
|
|
@ -81,6 +81,12 @@ impl ParseState for NirToAir {
|
|||
(Ready, Nir::Open(NirEntity::Product, span)) => {
|
||||
Transition(Ready).ok(Air::ExprOpen(ExprOp::Product, span))
|
||||
}
|
||||
(Ready, Nir::Open(NirEntity::Ceil, span)) => {
|
||||
Transition(Ready).ok(Air::ExprOpen(ExprOp::Ceil, span))
|
||||
}
|
||||
(Ready, Nir::Open(NirEntity::Floor, span)) => {
|
||||
Transition(Ready).ok(Air::ExprOpen(ExprOp::Floor, span))
|
||||
}
|
||||
(Ready, Nir::Open(NirEntity::Classify | NirEntity::All, span)) => {
|
||||
Transition(Ready).ok(Air::ExprOpen(ExprOp::Conj, span))
|
||||
}
|
||||
|
@ -102,6 +108,8 @@ impl ParseState for NirToAir {
|
|||
NirEntity::Rate
|
||||
| NirEntity::Sum
|
||||
| NirEntity::Product
|
||||
| NirEntity::Ceil
|
||||
| NirEntity::Floor
|
||||
| NirEntity::Classify
|
||||
| NirEntity::All
|
||||
| NirEntity::Any,
|
||||
|
|
|
@ -788,18 +788,22 @@ ele_parse! {
|
|||
};
|
||||
|
||||
/// Ceiling (⌈_x_⌉) expression.
|
||||
CeilExpr := QN_C_CEIL {
|
||||
CeilExpr := QN_C_CEIL(_, ospan) {
|
||||
@ {
|
||||
QN_LABEL => TodoAttr,
|
||||
} => Todo,
|
||||
} => NirEntity::Ceil.open(ospan),
|
||||
/(cspan) => NirEntity::Ceil.close(cspan),
|
||||
|
||||
CalcExpr,
|
||||
};
|
||||
|
||||
/// Floor (⌊_x_⌋) expression.
|
||||
FloorExpr := QN_C_FLOOR {
|
||||
FloorExpr := QN_C_FLOOR(_, ospan) {
|
||||
@ {
|
||||
QN_LABEL => TodoAttr,
|
||||
} => Todo,
|
||||
} => NirEntity::Floor.open(ospan),
|
||||
/(cspan) => NirEntity::Floor.close(cspan),
|
||||
|
||||
CalcExpr,
|
||||
};
|
||||
|
||||
|
|
|
@ -21,5 +21,13 @@
|
|||
<c:sum />
|
||||
</c:product>
|
||||
</rate>
|
||||
|
||||
<rate yields="ceilFloor">
|
||||
<c:ceil>
|
||||
<c:floor>
|
||||
<c:sum />
|
||||
</c:floor>
|
||||
</c:ceil>
|
||||
</rate>
|
||||
</package>
|
||||
|
||||
|
|
|
@ -21,5 +21,13 @@
|
|||
<c:sum />
|
||||
</c:product>
|
||||
</rate>
|
||||
|
||||
<rate yields="ceilFloor">
|
||||
<c:ceil>
|
||||
<c:floor>
|
||||
<c:sum />
|
||||
</c:floor>
|
||||
</c:ceil>
|
||||
</rate>
|
||||
</package>
|
||||
|
||||
|
|
Loading…
Reference in New Issue