Skip to content

Commit

Permalink
save
Browse files Browse the repository at this point in the history
  • Loading branch information
mio-19 committed Oct 25, 2024
1 parent c5ec665 commit 85950a7
Showing 1 changed file with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import scala.meta._
import chester.syntax.core._
object Scala {
case class ScalaContext()
def compileExpr(term: core.Term)(implicit ctx: ScalaContext = null): meta.Tree = term match {
def compileExpr(term: core.Term)(implicit ctx: ScalaContext = null): meta.Term = term match {
case IntegerTerm(i, _) => {
require(i.isValidInt)
Lit.Int(i.toInt)
Expand All @@ -18,7 +18,21 @@ object Scala {
case UnitTerm(_) => Lit.Unit()
case _ => throw new NotImplementedError(s"not implemented ${term.getClass.getName} $term")
}
def compileTy(ty: core.Term)(implicit ctx: ScalaContext = null): meta.Type = ty match {
case IntegerType(_) => meta.Type.Name("Int")
case IntType(_) => meta.Type.Name("Int")
case StringType(_) => meta.Type.Name("String")
case SymbolType(_) => meta.Type.Name("Symbol")
case _ => throw new NotImplementedError(s"not implemented ${ty.getClass.getName} $ty")
}
def compileStmt(stmt: core.StmtTerm)(implicit ctx: ScalaContext = null): meta.Stat = stmt match {
case LetStmtTerm(localv, value, ty, m) =>
Defn.Val(
mods = Nil,
pats = List(meta.Pat.Var(name = meta.Term.Name(localv.name))),
decltpe = Some(compileTy(ty)),
rhs = compileExpr(value)
)
case _ => throw new NotImplementedError(s"not implemented ${stmt.getClass.getName} $stmt")
}
}

0 comments on commit 85950a7

Please sign in to comment.