#[derive(Debug, Clone, PartialEq)]
pub enum Type {
U64,
U128,
U256,
Address,
Bool,
Mapping(Box<Type>, Box<Type>),
Array(Box<Type>),
Struct(String),
}
impl Type {
pub fn is_scalar(&self) -> bool {
matches!(
self,
Type::U64 | Type::U128 | Type::U256 | Type::Address | Type::Bool
)
}
}
#[derive(Debug, Clone)]
pub struct FieldDef {
pub name: String,
pub ty: Type,
}
#[derive(Debug, Clone)]
pub struct StructDef {
pub name: String,
pub fields: Vec<FieldDef>,
}
#[derive(Debug, Clone)]
pub struct StorageDecl {
pub name: String,
pub ty: Type,
pub commutative: bool,
}
#[derive(Debug, Clone)]
pub struct ErrorDecl {
pub name: String,
}
#[derive(Debug, Clone)]
pub struct Param {
pub name: String,
pub ty: Type,
pub owned: bool,
}
#[derive(Debug, Clone)]
pub struct FnDef {
pub name: String,
pub public: bool,
pub params: Vec<Param>,
pub ret: Option<Vec<Type>>,
pub body: Vec<Stmt>,
}
#[derive(Debug, Clone)]
pub struct InitDef {
pub params: Vec<Param>,
pub body: Vec<Stmt>,
}
#[derive(Debug, Clone)]
pub struct CellDef {
pub name: String,
pub structs: Vec<StructDef>,
pub errors: Vec<ErrorDecl>,
pub storage: Vec<StorageDecl>,
pub init: Option<InitDef>,
pub fns: Vec<FnDef>,
}
#[derive(Debug, Clone)]
pub enum Stmt {
Let {
name: String,
ty: Option<Type>,
expr: Expr,
},
Assign { target: LValue, expr: Expr },
AssignAdd { target: LValue, expr: Expr },
AssignSub { target: LValue, expr: Expr },
AssignMul { target: LValue, expr: Expr },
AssignDiv { target: LValue, expr: Expr },
Require { expr: Expr },
Revert { error: String },
Return { exprs: Vec<Expr> },
Emit {
event: String,
fields: Vec<(String, Expr)>,
},
If {
cond: Expr,
then: Vec<Stmt>,
else_: Vec<Stmt>,
},
While { cond: Expr, body: Vec<Stmt> },
For {
var: String,
start: Expr,
end: Expr,
body: Vec<Stmt>,
},
Loop { body: Vec<Stmt> },
Break,
Continue,
Expr(Expr),
}
#[derive(Debug, Clone)]
pub enum LValue {
Var(String),
Index { base: String, key: Box<Expr> },
Field { base: String, field: String },
}
#[derive(Debug, Clone)]
pub enum Expr {
Int(u128),
Bytes(Vec<u8>),
Var(String),
Index {
base: Box<Expr>,
key: Box<Expr>,
},
Field {
base: Box<Expr>,
field: String,
},
Caller,
Owner,
Height,
Timestamp,
Value,
Bin {
op: BinOp,
lhs: Box<Expr>,
rhs: Box<Expr>,
},
Not(Box<Expr>),
CallCell {
cell: Box<Expr>,
method: String,
args: Vec<Expr>,
ret: Option<Type>,
},
TokenBalance {
token: Box<Expr>,
account: Box<Expr>,
},
TokenTransfer {
token: Box<Expr>,
from: Box<Expr>,
to: Box<Expr>,
amount: Box<Expr>,
},
TokenMint {
token: Box<Expr>,
to: Box<Expr>,
amount: Box<Expr>,
},
TokenBurn {
token: Box<Expr>,
owner: Box<Expr>,
amount: Box<Expr>,
},
Hash(Box<Expr>),
Call {
name: String,
args: Vec<Expr>,
},
AccordRequest {
url: Box<Expr>,
method: Box<Expr>,
body: Box<Expr>,
},
AccordRead {
request_id: Box<Expr>,
},
SelfAddr,
}
#[derive(Debug, Clone, PartialEq)]
pub enum BinOp {
Add,
Sub,
Mul,
Div,
Rem,
And,
Or,
Xor,
Shl,
Shr,
Eq,
Ne,
Lt,
Le,
Gt,
Ge,
LogicAnd,
LogicOr,
}