feat: pass stmt position information to microwacc
This commit is contained in:
@@ -3,6 +3,7 @@ package wacc
|
||||
import cats.data.Chain
|
||||
|
||||
object microWacc {
|
||||
import wacc.ast.Position
|
||||
import wacc.types._
|
||||
|
||||
sealed trait CallTarget(val retTy: SemType)
|
||||
@@ -13,7 +14,7 @@ object microWacc {
|
||||
case class IntLiter(v: Int) extends Expr(KnownType.Int)
|
||||
case class BoolLiter(v: Boolean) extends Expr(KnownType.Bool)
|
||||
case class CharLiter(v: Char) extends Expr(KnownType.Char)
|
||||
case class ArrayLiter(elems: List[Expr])(ty: SemType) extends Expr(ty)
|
||||
case class ArrayLiter(elems: List[Expr])(ty: SemType, val pos: Position) extends Expr(ty)
|
||||
case class NullLiter()(ty: SemType) extends Expr(ty)
|
||||
case class Ident(name: String, uid: Int)(identTy: SemType)
|
||||
extends Expr(identTy)
|
||||
@@ -65,7 +66,9 @@ object microWacc {
|
||||
}
|
||||
|
||||
// Statements
|
||||
sealed trait Stmt
|
||||
sealed trait Stmt {
|
||||
val pos: Position
|
||||
}
|
||||
|
||||
case class Builtin(val name: String)(retTy: SemType) extends CallTarget(retTy) {
|
||||
override def toString(): String = name
|
||||
@@ -79,11 +82,14 @@ object microWacc {
|
||||
object PrintCharArray extends Builtin("printCharArray")(?)
|
||||
}
|
||||
|
||||
case class Assign(lhs: LValue, rhs: Expr) extends Stmt
|
||||
case class If(cond: Expr, thenBranch: Chain[Stmt], elseBranch: Chain[Stmt]) extends Stmt
|
||||
case class While(cond: Expr, body: Chain[Stmt]) extends Stmt
|
||||
case class Call(target: CallTarget, args: List[Expr]) extends Stmt with Expr(target.retTy)
|
||||
case class Return(expr: Expr) extends Stmt
|
||||
case class Assign(lhs: LValue, rhs: Expr)(val pos: Position) extends Stmt
|
||||
case class If(cond: Expr, thenBranch: Chain[Stmt], elseBranch: Chain[Stmt])(val pos: Position)
|
||||
extends Stmt
|
||||
case class While(cond: Expr, body: Chain[Stmt])(val pos: Position) extends Stmt
|
||||
case class Call(target: CallTarget, args: List[Expr])(val pos: Position)
|
||||
extends Stmt
|
||||
with Expr(target.retTy)
|
||||
case class Return(expr: Expr)(val pos: Position) extends Stmt
|
||||
|
||||
// Program
|
||||
case class FuncDecl(name: Ident, params: List[Ident], body: Chain[Stmt])
|
||||
|
||||
Reference in New Issue
Block a user