57 lines
846 B
Rust
57 lines
846 B
Rust
pub type Ident = String;
|
|
|
|
#[derive(Debug, Clone)]
|
|
pub enum Statement {
|
|
Assign {
|
|
target: Location,
|
|
source: Box<Expression>,
|
|
},
|
|
Call {
|
|
callee: Ident,
|
|
args: Vec<Expression>,
|
|
},
|
|
Local {
|
|
name: Ident,
|
|
init: Option<Box<Expression>>,
|
|
},
|
|
}
|
|
|
|
#[derive(Debug, Clone)]
|
|
pub enum Location {
|
|
Variable {
|
|
name: Ident,
|
|
},
|
|
Field {
|
|
table: Box<Location>,
|
|
index: Box<Expression>,
|
|
},
|
|
}
|
|
|
|
#[derive(Debug, Clone)]
|
|
pub enum Expression {
|
|
Constant(Constant),
|
|
Variable(Location),
|
|
Call {
|
|
callee: Ident,
|
|
args: Vec<Expression>,
|
|
},
|
|
Function(Function),
|
|
}
|
|
|
|
#[derive(Debug, Clone, Default)]
|
|
pub struct Function {
|
|
pub name: Option<Ident>,
|
|
pub args: Vec<Ident>,
|
|
pub body: Vec<Statement>,
|
|
pub ret: Option<Box<Expression>>,
|
|
}
|
|
|
|
#[derive(Debug, Clone, Default)]
|
|
pub enum Constant {
|
|
#[default]
|
|
Nil,
|
|
Boolean(bool),
|
|
Number(i64),
|
|
String(String),
|
|
}
|