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}
59
60#[derive(Debug, Clone, Copy, PartialEq)]
61pub enum BinOp {
62 Add,
63 Sub,
64 Mul,
65 Div,
66 Mod,
67 Equal,
68 NotEqual,
69 Less,
70 Greater,
71 LessEqual,
72 GreaterEqual,
73 And,
74 Or,
75}
76
77#[derive(Debug, Clone, Copy, PartialEq)]
78pub enum UnOp {
79 Neg,
80}
81
82#[derive(Debug, Clone, PartialEq)]
83pub enum Stmt {
84 Let {
85 name: String,
86 ty: Type,
87 value: Expr,
88 },
89 IfTernary {
90 condition: Expr,
91 on_pos: Box<Stmt>, on_zero: Box<Stmt>, on_neg: Box<Stmt>, },
95 Match {
96 condition: Expr,
97 arms: Vec<(i64, Stmt)>,
98 },
99 ForIn {
101 var: String,
102 iter: Expr,
103 body: Box<Stmt>,
104 },
105 WhileTernary {
107 condition: Expr,
108 on_pos: Box<Stmt>,
109 on_zero: Box<Stmt>,
110 on_neg: Box<Stmt>,
111 },
112 Loop {
114 body: Box<Stmt>,
115 },
116 Break,
117 Continue,
118 Block(Vec<Stmt>),
119 Return(Expr),
120 Expr(Expr),
121 Decorated {
122 directive: String,
123 stmt: Box<Stmt>,
124 },
125 Use {
127 path: Vec<String>,
128 },
129 Send {
131 target: Expr,
132 message: Expr,
133 },
134 FieldSet {
136 object: String,
137 field: String,
138 value: Expr,
139 },
140 IndexSet {
142 object: String,
143 row: Expr,
144 col: Expr,
145 value: Expr,
146 },
147 Set {
149 name: String,
150 value: Expr,
151 },
152}
153
154#[derive(Debug, Clone, PartialEq)]
155pub enum Type {
156 Trit,
157 TritTensor { dims: Vec<usize> },
158 Int,
159 Bool,
160 Float,
161 String,
162 Named(String),
164 AgentRef,
166}
167
168#[derive(Debug, Clone, PartialEq)]
169pub struct Function {
170 pub name: String,
171 pub params: Vec<(String, Type)>,
172 pub return_type: Type,
173 pub body: Vec<Stmt>,
174 pub directive: Option<String>,
175}
176
177#[derive(Debug, Clone, PartialEq)]
179pub struct StructDef {
180 pub name: String,
181 pub fields: Vec<(String, Type)>,
182}
183
184#[derive(Debug, Clone, PartialEq)]
187pub struct AgentDef {
188 pub name: String,
189 pub methods: Vec<Function>,
190}
191
192#[derive(Debug, Clone, PartialEq)]
193pub struct Program {
194 pub imports: Vec<Vec<String>>,
195 pub structs: Vec<StructDef>,
196 pub agents: Vec<AgentDef>,
197 pub functions: Vec<Function>,
198}