mirror of
https://github.com/KarolS/millfork.git
synced 2025-02-06 01:30:13 +00:00
6502: Fix sign extension when type casting
This commit is contained in:
parent
d760683ea5
commit
778d04ce21
@ -1635,7 +1635,9 @@ object MosExpressionCompiler extends AbstractExpressionCompiler[AssemblyLine] {
|
||||
env.maybeGet[Type](f.functionName) match {
|
||||
case Some(typ) =>
|
||||
val sourceType = validateTypeCastAndGetSourceExpressionType(ctx, typ, params)
|
||||
val newExprTypeAndVariable = exprTypeAndVariable.map(i => sourceType -> i._2)
|
||||
val newExprTypeAndVariable = exprTypeAndVariable.map { i =>
|
||||
(if (i._1.size == sourceType.size) i._1 else sourceType) -> i._2
|
||||
}
|
||||
return compile(ctx, params.head, newExprTypeAndVariable, branches)
|
||||
case None =>
|
||||
// fallthrough to the lookup below
|
||||
|
@ -1,7 +1,7 @@
|
||||
package millfork.test
|
||||
|
||||
import millfork.Cpu
|
||||
import millfork.test.emu.EmuCrossPlatformBenchmarkRun
|
||||
import millfork.test.emu.{EmuCrossPlatformBenchmarkRun, EmuUnoptimizedCrossPlatformRun}
|
||||
import org.scalatest.{FunSuite, Matchers}
|
||||
|
||||
/**
|
||||
@ -69,4 +69,32 @@ class SignExtensionSuite extends FunSuite with Matchers {
|
||||
m.readWord(0xc000) should equal(440)
|
||||
}
|
||||
}
|
||||
|
||||
test("Byte to Word") {
|
||||
EmuUnoptimizedCrossPlatformRun(Cpu.Mos, Cpu.Z80)("""
|
||||
| word output @$c000
|
||||
| void main () {
|
||||
| sbyte b
|
||||
| b = -1
|
||||
| memory_barrier()
|
||||
| output = byte(b)
|
||||
| }
|
||||
""".stripMargin){m =>
|
||||
m.readWord(0xc000) should equal(0x00ff)
|
||||
}
|
||||
}
|
||||
|
||||
test("Byte to Word 2") {
|
||||
EmuUnoptimizedCrossPlatformRun(Cpu.Mos, Cpu.Z80)("""
|
||||
| word output @$c000
|
||||
| void main () {
|
||||
| sbyte b
|
||||
| b = -1
|
||||
| memory_barrier()
|
||||
| output = word(byte(b))
|
||||
| }
|
||||
""".stripMargin){m =>
|
||||
m.readWord(0xc000) should equal(0x00ff)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user