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<(i64, 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 Type {
165 Trit,
166 TritTensor { dims: Vec<usize> },
167 Int,
168 Bool,
169 Float,
170 String,
171 Named(String),
173 AgentRef,
175}
176
177#[derive(Debug, Clone, PartialEq)]
178pub struct Function {
179 pub name: String,
180 pub params: Vec<(String, Type)>,
181 pub return_type: Type,
182 pub body: Vec<Stmt>,
183 pub directive: Option<String>,
184}
185
186#[derive(Debug, Clone, PartialEq)]
188pub struct StructDef {
189 pub name: String,
190 pub fields: Vec<(String, Type)>,
191}
192
193#[derive(Debug, Clone, PartialEq)]
196pub struct AgentDef {
197 pub name: String,
198 pub methods: Vec<Function>,
199}
200
201#[derive(Debug, Clone, PartialEq)]
203pub enum ImportSource {
204 Module(Vec<String>),
206 File(String),
208}
209
210#[derive(Debug, Clone, PartialEq)]
212pub enum ImportNames {
213 Wildcard,
215 Named(Vec<String>),
217}
218
219#[derive(Debug, Clone, PartialEq)]
221pub struct ImportSpec {
222 pub source: ImportSource,
223 pub names: ImportNames,
224}
225
226#[derive(Debug, Clone, PartialEq)]
227pub struct Program {
228 pub imports: Vec<Vec<String>>,
230 pub import_specs: Vec<ImportSpec>,
232 pub structs: Vec<StructDef>,
233 pub agents: Vec<AgentDef>,
234 pub functions: Vec<Function>,
235}