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 Index {
43 object: Box<Expr>,
44 row: Box<Expr>,
45 col: Box<Expr>,
46 },
47 NodeId,
49 Propagate {
53 expr: Box<Expr>,
54 },
55}
56
57#[derive(Debug, Clone, Copy, PartialEq)]
58pub enum BinOp {
59 Add,
60 Sub,
61 Mul,
62 Equal,
63 NotEqual,
64 Less,
65 Greater,
66 And,
67 Or,
68}
69
70#[derive(Debug, Clone, Copy, PartialEq)]
71pub enum UnOp {
72 Neg,
73}
74
75#[derive(Debug, Clone, PartialEq)]
76pub enum Stmt {
77 Let {
78 name: String,
79 ty: Type,
80 value: Expr,
81 },
82 IfTernary {
83 condition: Expr,
84 on_pos: Box<Stmt>, on_zero: Box<Stmt>, on_neg: Box<Stmt>, },
88 Match {
89 condition: Expr,
90 arms: Vec<(i8, Stmt)>,
91 },
92 ForIn {
94 var: String,
95 iter: Expr,
96 body: Box<Stmt>,
97 },
98 WhileTernary {
100 condition: Expr,
101 on_pos: Box<Stmt>,
102 on_zero: Box<Stmt>,
103 on_neg: Box<Stmt>,
104 },
105 Loop {
107 body: Box<Stmt>,
108 },
109 Break,
110 Continue,
111 Block(Vec<Stmt>),
112 Return(Expr),
113 Expr(Expr),
114 Decorated {
115 directive: String,
116 stmt: Box<Stmt>,
117 },
118 Use {
120 path: Vec<String>,
121 },
122 Send {
124 target: Expr,
125 message: Expr,
126 },
127 FieldSet {
129 object: String,
130 field: String,
131 value: Expr,
132 },
133 IndexSet {
135 object: String,
136 row: Expr,
137 col: Expr,
138 value: Expr,
139 },
140}
141
142#[derive(Debug, Clone, PartialEq)]
143pub enum Type {
144 Trit,
145 TritTensor { dims: Vec<usize> },
146 Int,
147 Bool,
148 Float,
149 String,
150 Named(String),
152 AgentRef,
154}
155
156#[derive(Debug, Clone, PartialEq)]
157pub struct Function {
158 pub name: String,
159 pub params: Vec<(String, Type)>,
160 pub return_type: Type,
161 pub body: Vec<Stmt>,
162}
163
164#[derive(Debug, Clone, PartialEq)]
166pub struct StructDef {
167 pub name: String,
168 pub fields: Vec<(String, Type)>,
169}
170
171#[derive(Debug, Clone, PartialEq)]
174pub struct AgentDef {
175 pub name: String,
176 pub methods: Vec<Function>,
177}
178
179#[derive(Debug, Clone, PartialEq)]
180pub struct Program {
181 pub imports: Vec<Vec<String>>,
182 pub structs: Vec<StructDef>,
183 pub agents: Vec<AgentDef>,
184 pub functions: Vec<Function>,
185}