1#[derive(Debug, Clone, PartialEq)]
2pub enum Expr {
3 TritLiteral(i8),
4 IntLiteral(i64),
5 FloatLiteral(f64),
6 StringLiteral(String),
7 Ident(String),
8 BinaryOp {
9 op: BinOp,
10 lhs: Box<Expr>,
11 rhs: Box<Expr>,
12 },
13 UnaryOp {
14 op: UnOp,
15 expr: Box<Expr>,
16 },
17 Call {
18 callee: String,
19 args: Vec<Expr>,
20 },
21 FieldAccess {
23 object: Box<Expr>,
24 field: String,
25 },
26 Cast {
28 expr: Box<Expr>,
29 ty: Type,
30 },
31 Spawn {
34 agent_name: String,
35 node_addr: Option<String>,
37 },
38 Await {
40 target: Box<Expr>,
41 },
42 Slice {
44 object: Box<Expr>,
45 start: Box<Expr>,
46 end: Box<Expr>,
47 stride: Box<Expr>,
48 },
49 Index {
51 object: Box<Expr>,
52 row: Box<Expr>,
53 col: Box<Expr>,
54 },
55 NodeId,
57 Propagate {
61 expr: Box<Expr>,
62 },
63 TritTensorLiteral(Vec<i8>),
65 StructLiteral {
67 name: String,
68 fields: Vec<(String, Expr)>,
69 },
70}
71
72#[derive(Debug, Clone, Copy, PartialEq)]
73pub enum BinOp {
74 Add,
75 Sub,
76 Mul,
77 Div,
78 Mod,
79 Equal,
80 NotEqual,
81 Less,
82 Greater,
83 LessEqual,
84 GreaterEqual,
85 And,
86 Or,
87}
88
89#[derive(Debug, Clone, Copy, PartialEq)]
90pub enum UnOp {
91 Neg,
92}
93
94#[derive(Debug, Clone, PartialEq)]
95pub enum Stmt {
96 Let {
97 name: String,
98 ty: Type,
99 value: Expr,
100 },
101 IfTernary {
102 condition: Expr,
103 on_pos: Box<Stmt>, on_zero: Box<Stmt>, on_neg: Box<Stmt>, },
107 Match {
108 condition: Expr,
109 arms: Vec<(Pattern, Stmt)>,
110 },
111 ForIn {
113 var: String,
114 iter: Expr,
115 body: Box<Stmt>,
116 },
117 WhileTernary {
119 condition: Expr,
120 on_pos: Box<Stmt>,
121 on_zero: Box<Stmt>,
122 on_neg: Box<Stmt>,
123 },
124 Loop {
126 body: Box<Stmt>,
127 },
128 Break,
129 Continue,
130 Block(Vec<Stmt>),
131 Return(Expr),
132 Expr(Expr),
133 Decorated {
134 directive: String,
135 stmt: Box<Stmt>,
136 },
137 Use {
139 path: Vec<String>,
140 },
141 FromImport {
143 spec: ImportSpec,
144 },
145 Send {
147 target: Expr,
148 message: Expr,
149 },
150 FieldSet {
152 object: String,
153 field: String,
154 value: Expr,
155 },
156 IndexSet {
158 object: String,
159 row: Expr,
160 col: Expr,
161 value: Expr,
162 },
163 Set {
165 name: String,
166 value: Expr,
167 },
168}
169
170#[derive(Debug, Clone, PartialEq)]
171pub enum Pattern {
172 Int(i64),
173 Trit(i8),
174 Float(f64),
175 Wildcard,
176}
177
178#[derive(Debug, Clone, PartialEq)]
179pub enum Type {
180 Trit,
181 TritTensor { dims: Vec<usize> },
182 PackedTritTensor { dims: Vec<usize> },
183 Int,
184 IntTensor { dims: Vec<usize> },
185 Bool,
186 Float,
187 FloatTensor { dims: Vec<usize> },
188 String,
189 Named(String),
191 AgentRef,
193}
194
195#[derive(Debug, Clone, PartialEq)]
196pub struct Function {
197 pub name: String,
198 pub params: Vec<(String, Type)>,
199 pub return_type: Type,
200 pub body: Vec<Stmt>,
201 pub directive: Option<String>,
202}
203
204#[derive(Debug, Clone, PartialEq)]
206pub struct StructDef {
207 pub name: String,
208 pub fields: Vec<(String, Type)>,
209}
210
211#[derive(Debug, Clone, PartialEq)]
214pub struct AgentDef {
215 pub name: String,
216 pub methods: Vec<Function>,
217}
218
219#[derive(Debug, Clone, PartialEq)]
221pub enum ImportSource {
222 Module(Vec<String>),
224 File(String),
226}
227
228#[derive(Debug, Clone, PartialEq)]
230pub enum ImportNames {
231 Wildcard,
233 Named(Vec<String>),
235}
236
237#[derive(Debug, Clone, PartialEq)]
239pub struct ImportSpec {
240 pub source: ImportSource,
241 pub names: ImportNames,
242}
243
244#[derive(Debug, Clone, PartialEq)]
245pub struct Program {
246 pub imports: Vec<Vec<String>>,
248 pub import_specs: Vec<ImportSpec>,
250 pub structs: Vec<StructDef>,
251 pub agents: Vec<AgentDef>,
252 pub functions: Vec<Function>,
253}