use std::marker::PhantomData;
use crate::{
Boolean, LowerCompatible,
expression::Expression,
lower::{Instructions, LowerCtx},
};
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum PostfixOperator {
Null { negated: bool },
False,
True,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum UnaryOperator {
Not,
}
pub struct Unary<L, T> {
lhs: L,
op: UnaryOperator,
marker: PhantomData<T>,
}
pub fn not<E, T>(e: E) -> Unary<E, T>
where
T: Boolean,
E: LowerCompatible<T>,
{
Unary {
lhs: e,
op: UnaryOperator::Not,
marker: PhantomData,
}
}
#[qraft_expression_macro::as_expression]
impl<L, T> Expression for Unary<L, T>
where
T: Boolean,
L: LowerCompatible<T>,
{
type Type = T;
fn lower(&self, ctx: &mut LowerCtx) -> usize {
let rhs = self.lhs.lower_compatible(ctx);
ctx.instrs.push_unary(self.op, rhs);
rhs + 1
}
}