1
0
mirror of https://github.com/KarolS/millfork.git synced 2024-07-05 09:28:54 +00:00

6502: always fold constants

This commit is contained in:
Karol Stasiak 2018-12-27 14:16:34 +01:00
parent 0843970410
commit 4d64bbafac
2 changed files with 31 additions and 0 deletions

View File

@ -344,6 +344,14 @@ object MosExpressionCompiler extends AbstractExpressionCompiler[AssemblyLine] {
def compile(ctx: CompilationContext, expr: Expression, exprTypeAndVariable: Option[(Type, Variable)], branches: BranchSpec): List[AssemblyLine] = {
val env = ctx.env
env.eval(expr) match {
case Some(value) =>
return exprTypeAndVariable.fold(noop) { case (exprType, target) =>
assertCompatible(exprType, target.typ)
compileConstant(ctx, value, target)
}
case _ =>
}
val b = env.get[Type]("byte")
val w = env.get[Type]("word")
expr match {

View File

@ -0,0 +1,23 @@
package millfork.test
import millfork.Cpu
import millfork.test.emu.EmuUnoptimizedCrossPlatformRun
import org.scalatest.{FunSuite, Matchers}
/**
* @author Karol Stasiak
*/
class ConstantSuite extends FunSuite with Matchers {
test("Constants should fold") {
EmuUnoptimizedCrossPlatformRun(Cpu.Mos, Cpu.Z80)(
"""
| array Sieve[4]
| array __screen[4]
| byte vic_mem
| void main() {
| vic_mem = lo( ((Sieve.addr >> 10) & 8) | ((__screen.addr >> 6) & $f0) )
| }
""".stripMargin){m => }
}
}