diff --git a/src/main/wacc/Frontend/microWacc.scala b/src/main/wacc/Frontend/microWacc.scala index 1faf3a8..88e43f2 100644 --- a/src/main/wacc/Frontend/microWacc.scala +++ b/src/main/wacc/Frontend/microWacc.scala @@ -5,16 +5,19 @@ import cats.data.NonEmptyList object microWacc { import wacc.types._ - sealed trait CallTarget + sealed trait CallTarget(val retTy: SemType) sealed trait Expr(val ty: SemType) - sealed trait LValue + sealed trait LValue extends Expr // Atomic expressions 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 Ident(name: String)(identTy: SemType) extends Expr(identTy) with CallTarget with LValue + case class Ident(name: String)(identTy: SemType) + extends Expr(identTy) + with CallTarget(identTy) + with LValue case class ArrayElem(name: Ident, indices: NonEmptyList[Expr])(ty: SemType) extends Expr(ty) with LValue @@ -48,17 +51,18 @@ object microWacc { // Statements sealed trait Stmt - enum Builtin extends CallTarget { - case Read - case Free - case Exit - case Print + object Builtin { + case object ReadInt extends CallTarget(KnownType.Int) + case object ReadChar extends CallTarget(KnownType.Char) + case object Print extends CallTarget(?) + case object Exit extends CallTarget(?) + case object Free extends CallTarget(?) } case class Assign(lhs: LValue, rhs: Expr) extends Stmt case class If(cond: Expr, thenBranch: List[Stmt], elseBranch: List[Stmt]) extends Stmt case class While(cond: Expr, body: List[Stmt]) extends Stmt - case class Call(target: CallTarget, args: List[Expr]) extends Stmt + case class Call(target: CallTarget, args: List[Expr]) extends Stmt with Expr(target.retTy) case class Return(expr: Expr) extends Stmt // Program