fix: add support for return types in micro wacc calls
This commit is contained in:
parent
e23ef8da48
commit
d6aa83a2ea
@ -5,16 +5,19 @@ import cats.data.NonEmptyList
|
|||||||
object microWacc {
|
object microWacc {
|
||||||
import wacc.types._
|
import wacc.types._
|
||||||
|
|
||||||
sealed trait CallTarget
|
sealed trait CallTarget(val retTy: SemType)
|
||||||
sealed trait Expr(val ty: SemType)
|
sealed trait Expr(val ty: SemType)
|
||||||
sealed trait LValue
|
sealed trait LValue extends Expr
|
||||||
|
|
||||||
// Atomic expressions
|
// Atomic expressions
|
||||||
case class IntLiter(v: Int) extends Expr(KnownType.Int)
|
case class IntLiter(v: Int) extends Expr(KnownType.Int)
|
||||||
case class BoolLiter(v: Boolean) extends Expr(KnownType.Bool)
|
case class BoolLiter(v: Boolean) extends Expr(KnownType.Bool)
|
||||||
case class CharLiter(v: Char) extends Expr(KnownType.Char)
|
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) 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)
|
case class ArrayElem(name: Ident, indices: NonEmptyList[Expr])(ty: SemType)
|
||||||
extends Expr(ty)
|
extends Expr(ty)
|
||||||
with LValue
|
with LValue
|
||||||
@ -48,17 +51,18 @@ object microWacc {
|
|||||||
// Statements
|
// Statements
|
||||||
sealed trait Stmt
|
sealed trait Stmt
|
||||||
|
|
||||||
enum Builtin extends CallTarget {
|
object Builtin {
|
||||||
case Read
|
case object ReadInt extends CallTarget(KnownType.Int)
|
||||||
case Free
|
case object ReadChar extends CallTarget(KnownType.Char)
|
||||||
case Exit
|
case object Print extends CallTarget(?)
|
||||||
case Print
|
case object Exit extends CallTarget(?)
|
||||||
|
case object Free extends CallTarget(?)
|
||||||
}
|
}
|
||||||
|
|
||||||
case class Assign(lhs: LValue, rhs: Expr) extends Stmt
|
case class Assign(lhs: LValue, rhs: Expr) extends Stmt
|
||||||
case class If(cond: Expr, thenBranch: List[Stmt], elseBranch: List[Stmt]) 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 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
|
case class Return(expr: Expr) extends Stmt
|
||||||
|
|
||||||
// Program
|
// Program
|
||||||
|
Loading…
x
Reference in New Issue
Block a user