mirror of
https://github.com/KarolS/millfork.git
synced 2025-01-12 03:30:09 +00:00
6502: always fold constants
This commit is contained in:
parent
0843970410
commit
4d64bbafac
@ -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 {
|
||||
|
23
src/test/scala/millfork/test/ConstantSuite.scala
Normal file
23
src/test/scala/millfork/test/ConstantSuite.scala
Normal 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 => }
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user