pub use t_ree::expression::{Binding, Literal, MatchPattern};
pub use t_ree::operator;
use crate::declaration::Parameter;
use crate::types::{ConstExpression, GenericArgument, Type};
use t_ree::operator::{BinaryOperator, UnaryOperator};
#[derive(Clone, Debug)]
pub struct Expression {
pub kind: ExpressionKind,
pub resolved_type: Type,
}
impl Expression {
pub fn new(kind: ExpressionKind, resolved_type: Type) -> Self {
Self {
kind,
resolved_type,
}
}
}
#[derive(Clone, Debug)]
pub struct Block {
pub statements: Vec<Statement>,
pub result: Option<Box<Expression>>,
}
impl Block {
pub fn empty() -> Self {
Self {
statements: Vec::new(),
result: None,
}
}
pub fn expression(expression: Expression) -> Self {
Self {
statements: Vec::new(),
result: Some(Box::new(expression)),
}
}
}
#[derive(Clone, Debug)]
pub struct MatchArm {
pub pattern: MatchPattern,
pub body: Block,
}
#[derive(Clone, Debug)]
pub enum Statement {
Expression(Expression),
Let {
name: String,
binding: Binding,
declared_type: Option<Type>,
value: Expression,
line: u32,
},
Assign(Expression, Expression),
Return(Option<Expression>),
Label {
name: String,
parameters: Vec<Parameter>,
initial_arguments: Vec<Expression>,
},
Jump {
label: String,
arguments: Vec<Expression>,
},
While {
condition: Expression,
body: Block,
},
Defer(Box<Self>),
}
#[derive(Clone, Debug)]
pub enum ExpressionKind {
Literal(Literal),
Variable(String),
BinaryOperation(BinaryOperator, Box<Expression>, Box<Expression>),
UnaryOperation(UnaryOperator, Box<Expression>),
Call(Box<Expression>, Vec<Expression>),
Field(Box<Expression>, String),
Index(Box<Expression>, Box<Expression>),
Specialize(Box<Expression>, Vec<GenericArgument>),
Dereference(Box<Expression>),
Convert(Box<Expression>, Type),
SizeOf(Type),
TypeConstruction(String, Vec<GenericArgument>, Vec<(String, Expression)>),
Eval(Box<Expression>),
ArrayLiteral(Vec<Expression>),
ArrayRepeat(Box<Expression>, ConstExpression),
TupleLiteral(Vec<Expression>),
Block(Block),
If {
condition: Box<Expression>,
then_branch: Block,
else_branch: Option<Block>,
},
Match {
value: Box<Expression>,
arms: Vec<MatchArm>,
},
Replace(Box<Expression>, Box<Expression>),
Print(Vec<Expression>),
}