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 Index {
44 object: Box<Expr>,
45 row: Box<Expr>,
46 col: Box<Expr>,
47 },
48 NodeId,
50 Propagate {
54 expr: Box<Expr>,
55 },
56 TritTensorLiteral(Vec<i8>),
58 StructLiteral {
60 name: String,
61 fields: Vec<(String, Expr)>,
62 },
63}
64
65#[derive(Debug, Clone, Copy, PartialEq)]
66pub enum BinOp {
67 Add,
68 Sub,
69 Mul,
70 Div,
71 Mod,
72 Equal,
73 NotEqual,
74 Less,
75 Greater,
76 LessEqual,
77 GreaterEqual,
78 And,
79 Or,
80}
81
82#[derive(Debug, Clone, Copy, PartialEq)]
83pub enum UnOp {
84 Neg,
85}
86
87#[derive(Debug, Clone, PartialEq)]
88pub enum Stmt {
89 Let {
90 name: String,
91 ty: Type,
92 value: Expr,
93 },
94 IfTernary {
95 condition: Expr,
96 on_pos: Box<Stmt>, on_zero: Box<Stmt>, on_neg: Box<Stmt>, },
100 Match {
101 condition: Expr,
102 arms: Vec<(Pattern, Stmt)>,
103 },
104 ForIn {
106 var: String,
107 iter: Expr,
108 body: Box<Stmt>,
109 },
110 WhileTernary {
112 condition: Expr,
113 on_pos: Box<Stmt>,
114 on_zero: Box<Stmt>,
115 on_neg: Box<Stmt>,
116 },
117 Loop {
119 body: Box<Stmt>,
120 },
121 Break,
122 Continue,
123 Block(Vec<Stmt>),
124 Return(Expr),
125 Expr(Expr),
126 Decorated {
127 directive: String,
128 stmt: Box<Stmt>,
129 },
130 Use {
132 path: Vec<String>,
133 },
134 FromImport {
136 spec: ImportSpec,
137 },
138 Send {
140 target: Expr,
141 message: Expr,
142 },
143 FieldSet {
145 object: String,
146 field: String,
147 value: Expr,
148 },
149 IndexSet {
151 object: String,
152 row: Expr,
153 col: Expr,
154 value: Expr,
155 },
156 Set {
158 name: String,
159 value: Expr,
160 },
161}
162
163#[derive(Debug, Clone, PartialEq)]
164pub enum Pattern {
165 Int(i64),
166 Trit(i8),
167 Float(f64),
168}
169
170#[derive(Debug, Clone, PartialEq)]
171pub enum Type {
172 Trit,
173 TritTensor { dims: Vec<usize> },
174 Int,
175 IntTensor { dims: Vec<usize> },
176 Bool,
177 Float,
178 FloatTensor { dims: Vec<usize> },
179 String,
180 Named(String),
182 AgentRef,
184}
185
186#[derive(Debug, Clone, PartialEq)]
187pub struct Function {
188 pub name: String,
189 pub params: Vec<(String, Type)>,
190 pub return_type: Type,
191 pub body: Vec<Stmt>,
192 pub directive: Option<String>,
193}
194
195#[derive(Debug, Clone, PartialEq)]
197pub struct StructDef {
198 pub name: String,
199 pub fields: Vec<(String, Type)>,
200}
201
202#[derive(Debug, Clone, PartialEq)]
205pub struct AgentDef {
206 pub name: String,
207 pub methods: Vec<Function>,
208}
209
210#[derive(Debug, Clone, PartialEq)]
212pub enum ImportSource {
213 Module(Vec<String>),
215 File(String),
217}
218
219#[derive(Debug, Clone, PartialEq)]
221pub enum ImportNames {
222 Wildcard,
224 Named(Vec<String>),
226}
227
228#[derive(Debug, Clone, PartialEq)]
230pub struct ImportSpec {
231 pub source: ImportSource,
232 pub names: ImportNames,
233}
234
235#[derive(Debug, Clone, PartialEq)]
236pub struct Program {
237 pub imports: Vec<Vec<String>>,
239 pub import_specs: Vec<ImportSpec>,
241 pub structs: Vec<StructDef>,
242 pub agents: Vec<AgentDef>,
243 pub functions: Vec<Function>,
244}