#[derive(Debug, Clone, PartialEq)]
pub enum Expr {
TritLiteral(i8),
IntLiteral(i64),
FloatLiteral(f64),
StringLiteral(String),
Ident(String),
BinaryOp {
op: BinOp,
lhs: Box<Expr>,
rhs: Box<Expr>,
},
UnaryOp {
op: UnOp,
expr: Box<Expr>,
},
Call {
callee: String,
args: Vec<Expr>,
},
FieldAccess {
object: Box<Expr>,
field: String,
},
Cast {
expr: Box<Expr>,
ty: Type,
},
Spawn {
agent_name: String,
node_addr: Option<String>,
},
Await {
target: Box<Expr>,
},
Slice {
object: Box<Expr>,
start: Box<Expr>,
end: Box<Expr>,
stride: Box<Expr>,
},
Index {
object: Box<Expr>,
row: Box<Expr>,
col: Box<Expr>,
},
NodeId,
Propagate {
expr: Box<Expr>,
},
TritTensorLiteral(Vec<i8>),
StructLiteral {
name: String,
fields: Vec<(String, Expr)>,
},
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum BinOp {
Add,
Sub,
Mul,
Div,
Mod,
Equal,
NotEqual,
Less,
Greater,
LessEqual,
GreaterEqual,
And,
Or,
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum UnOp {
Neg,
}
#[derive(Debug, Clone, PartialEq)]
pub enum Stmt {
Let {
name: String,
ty: Type,
value: Expr,
},
IfTernary {
condition: Expr,
on_pos: Box<Stmt>, on_zero: Box<Stmt>, on_neg: Box<Stmt>, },
Match {
condition: Expr,
arms: Vec<(Pattern, Stmt)>,
},
ForIn {
var: String,
iter: Expr,
body: Box<Stmt>,
},
WhileTernary {
condition: Expr,
on_pos: Box<Stmt>,
on_zero: Box<Stmt>,
on_neg: Box<Stmt>,
},
Loop {
body: Box<Stmt>,
},
Break,
Continue,
Block(Vec<Stmt>),
Return(Expr),
Expr(Expr),
Decorated {
directive: String,
stmt: Box<Stmt>,
},
Use {
path: Vec<String>,
},
FromImport {
spec: ImportSpec,
},
Send {
target: Expr,
message: Expr,
},
FieldSet {
object: String,
field: String,
value: Expr,
},
IndexSet {
object: String,
row: Expr,
col: Expr,
value: Expr,
},
Set {
name: String,
value: Expr,
},
}
#[derive(Debug, Clone, PartialEq)]
pub enum Pattern {
Int(i64),
Trit(i8),
Float(f64),
Wildcard,
}
#[derive(Debug, Clone, PartialEq)]
pub enum Type {
Trit,
TritTensor { dims: Vec<usize> },
PackedTritTensor { dims: Vec<usize> },
Int,
IntTensor { dims: Vec<usize> },
Bool,
Float,
FloatTensor { dims: Vec<usize> },
String,
Named(String),
AgentRef,
}
#[derive(Debug, Clone, PartialEq)]
pub struct Function {
pub name: String,
pub params: Vec<(String, Type)>,
pub return_type: Type,
pub body: Vec<Stmt>,
pub directive: Option<String>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct StructDef {
pub name: String,
pub fields: Vec<(String, Type)>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct AgentDef {
pub name: String,
pub methods: Vec<Function>,
}
#[derive(Debug, Clone, PartialEq)]
pub enum ImportSource {
Module(Vec<String>),
File(String),
}
#[derive(Debug, Clone, PartialEq)]
pub enum ImportNames {
Wildcard,
Named(Vec<String>),
}
#[derive(Debug, Clone, PartialEq)]
pub struct ImportSpec {
pub source: ImportSource,
pub names: ImportNames,
}
#[derive(Debug, Clone, PartialEq)]
pub struct Program {
pub imports: Vec<Vec<String>>,
pub import_specs: Vec<ImportSpec>,
pub structs: Vec<StructDef>,
pub agents: Vec<AgentDef>,
pub functions: Vec<Function>,
}