mirror of
https://github.com/KarolS/millfork.git
synced 2026-04-26 10:20:51 +00:00
6502: always fold constants
This commit is contained in:
@@ -344,6 +344,14 @@ object MosExpressionCompiler extends AbstractExpressionCompiler[AssemblyLine] {
|
|||||||
|
|
||||||
def compile(ctx: CompilationContext, expr: Expression, exprTypeAndVariable: Option[(Type, Variable)], branches: BranchSpec): List[AssemblyLine] = {
|
def compile(ctx: CompilationContext, expr: Expression, exprTypeAndVariable: Option[(Type, Variable)], branches: BranchSpec): List[AssemblyLine] = {
|
||||||
val env = ctx.env
|
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 b = env.get[Type]("byte")
|
||||||
val w = env.get[Type]("word")
|
val w = env.get[Type]("word")
|
||||||
expr match {
|
expr match {
|
||||||
|
|||||||
@@ -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 => }
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user