1
0
mirror of https://github.com/KarolS/millfork.git synced 2024-11-06 06:06:31 +00:00

Cache AST typing

This commit is contained in:
Karol Stasiak 2018-12-26 01:26:12 +01:00
parent bf5639761b
commit 9669e4d87d
2 changed files with 5 additions and 1 deletions

View File

@ -194,6 +194,7 @@ object AbstractExpressionCompiler {
} }
def getExpressionType(env: Environment, log: Logger, expr: Expression): Type = { def getExpressionType(env: Environment, log: Logger, expr: Expression): Type = {
if (expr.typeCache ne null) expr.typeCache
val b = env.get[Type]("byte") val b = env.get[Type]("byte")
val bool = env.get[Type]("bool$") val bool = env.get[Type]("bool$")
val boolTrue = env.get[Type]("true$") val boolTrue = env.get[Type]("true$")
@ -236,7 +237,7 @@ object AbstractExpressionCompiler {
val v = env.get[Type]("void") val v = env.get[Type]("void")
val w = env.get[Type]("word") val w = env.get[Type]("word")
expr match { val t = expr match {
case LiteralExpression(value, size) => case LiteralExpression(value, size) =>
size match { size match {
case 1 => b case 1 => b
@ -330,6 +331,8 @@ object AbstractExpressionCompiler {
lookupFunction(env, log, f).returnType lookupFunction(env, log, f).returnType
} }
} }
expr.typeCache = t
t
} }
def checkIndexType(ctx: CompilationContext, pointy: Pointy, index: Expression): Unit = { def checkIndexType(ctx: CompilationContext, pointy: Pointy, index: Expression): Unit = {

View File

@ -33,6 +33,7 @@ sealed trait Expression extends Node {
def getPointies: Seq[String] def getPointies: Seq[String]
def isPure: Boolean def isPure: Boolean
def getAllIdentifiers: Set[String] def getAllIdentifiers: Set[String]
@transient var typeCache: Type = _
} }
case class ConstantArrayElementExpression(constant: Constant) extends Expression { case class ConstantArrayElementExpression(constant: Constant) extends Expression {