1#[derive(Debug, Clone, PartialEq)]
2pub enum Expr {
3 TritLiteral(i8),
4 IntLiteral(i64),
5 StringLiteral(String),
6 Ident(String),
7 BinaryOp {
8 op: BinOp,
9 lhs: Box<Expr>,
10 rhs: Box<Expr>,
11 },
12 UnaryOp {
13 op: UnOp,
14 expr: Box<Expr>,
15 },
16 Call {
17 callee: String,
18 args: Vec<Expr>,
19 },
20 FieldAccess {
22 object: Box<Expr>,
23 field: String,
24 },
25 Cast {
27 expr: Box<Expr>,
28 ty: Type,
29 },
30 Spawn {
33 agent_name: String,
34 node_addr: Option<String>,
36 },
37 Await {
39 target: Box<Expr>,
40 },
41 NodeId,
43}
44
45#[derive(Debug, Clone, Copy, PartialEq)]
46pub enum BinOp {
47 Add,
48 Sub,
49 Mul,
50 Equal,
51 NotEqual,
52 And,
53 Or,
54}
55
56#[derive(Debug, Clone, Copy, PartialEq)]
57pub enum UnOp {
58 Neg,
59}
60
61#[derive(Debug, Clone, PartialEq)]
62pub enum Stmt {
63 Let {
64 name: String,
65 ty: Type,
66 value: Expr,
67 },
68 IfTernary {
69 condition: Expr,
70 on_pos: Box<Stmt>, on_zero: Box<Stmt>, on_neg: Box<Stmt>, },
74 Match {
75 condition: Expr,
76 arms: Vec<(i8, Stmt)>,
77 },
78 ForIn {
80 var: String,
81 iter: Expr,
82 body: Box<Stmt>,
83 },
84 WhileTernary {
86 condition: Expr,
87 on_pos: Box<Stmt>,
88 on_zero: Box<Stmt>,
89 on_neg: Box<Stmt>,
90 },
91 Loop {
93 body: Box<Stmt>,
94 },
95 Break,
96 Continue,
97 Block(Vec<Stmt>),
98 Return(Expr),
99 Expr(Expr),
100 Decorated {
101 directive: String,
102 stmt: Box<Stmt>,
103 },
104 Use {
106 path: Vec<String>,
107 },
108 Send {
110 target: Expr,
111 message: Expr,
112 },
113 FieldSet {
115 object: String,
116 field: String,
117 value: Expr,
118 },
119}
120
121#[derive(Debug, Clone, PartialEq)]
122pub enum Type {
123 Trit,
124 TritTensor { dims: Vec<usize> },
125 Int,
126 Bool,
127 Float,
128 String,
129 Named(String),
131 AgentRef,
133}
134
135#[derive(Debug, Clone, PartialEq)]
136pub struct Function {
137 pub name: String,
138 pub params: Vec<(String, Type)>,
139 pub return_type: Type,
140 pub body: Vec<Stmt>,
141}
142
143#[derive(Debug, Clone, PartialEq)]
145pub struct StructDef {
146 pub name: String,
147 pub fields: Vec<(String, Type)>,
148}
149
150#[derive(Debug, Clone, PartialEq)]
153pub struct AgentDef {
154 pub name: String,
155 pub methods: Vec<Function>,
156}
157
158#[derive(Debug, Clone, PartialEq)]
159pub struct Program {
160 pub structs: Vec<StructDef>,
161 pub agents: Vec<AgentDef>,
162 pub functions: Vec<Function>,
163}