feat(parser,ir,backend): Support array
This commit is contained in:
@@ -17,7 +17,12 @@ pub struct VarDeclStmt {
|
||||
pub struct VarDeclStmtValue {
|
||||
pub name: String,
|
||||
pub name_span: Span,
|
||||
pub dimensions: Vec<ArrayDimension>,
|
||||
}
|
||||
|
||||
pub struct ArrayDimension {
|
||||
pub value: Option<Expr>,
|
||||
pub span: Span,
|
||||
}
|
||||
|
||||
pub struct FuncDeclStmt {
|
||||
@@ -89,6 +94,10 @@ pub struct Expr {
|
||||
pub enum ExprValue {
|
||||
IntLit(i64),
|
||||
Var(String),
|
||||
ArrayAccess {
|
||||
array: Box<Expr>,
|
||||
index: Box<Expr>,
|
||||
},
|
||||
BinaryOp {
|
||||
lhs: Box<Expr>,
|
||||
op: BinaryOp,
|
||||
@@ -159,6 +168,7 @@ impl From<TypeIdent> for Type {
|
||||
pub struct Param {
|
||||
pub name: String,
|
||||
pub param_type: Type,
|
||||
pub dimensions: Vec<ArrayDimension>,
|
||||
pub name_span: Span,
|
||||
pub type_span: Span,
|
||||
}
|
||||
@@ -190,6 +200,12 @@ impl fmt::Display for VarDeclStmtValue {
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for ArrayDimension {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "ArrayDimension")
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for FuncDeclStmt {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "{} {}", self.return_type, self.name)
|
||||
@@ -256,6 +272,7 @@ impl fmt::Display for ExprValue {
|
||||
match self {
|
||||
ExprValue::IntLit(value) => write!(f, "IntLit({})", value),
|
||||
ExprValue::Var(name) => write!(f, "Var({})", name),
|
||||
ExprValue::ArrayAccess { .. } => write!(f, "ArrayAccess"),
|
||||
ExprValue::BinaryOp { op, .. } => write!(f, "BinaryOp({})", op),
|
||||
ExprValue::FuncCall(name, _) => write!(f, "FuncCall({})", name),
|
||||
ExprValue::Assign { .. } => write!(f, "Assign"),
|
||||
|
||||
Reference in New Issue
Block a user