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

Accept bytes as LHS for >>>>

This commit is contained in:
Karol Stasiak 2018-12-21 22:36:53 +01:00
parent d62901fb51
commit 02e91070aa
3 changed files with 33 additions and 5 deletions

View File

@ -865,9 +865,16 @@ object MosExpressionCompiler extends AbstractExpressionCompiler[AssemblyLine] {
case 2 => PseudoregisterBuiltIns.compileWordBitOpsToAX(ctx, params, EOR)
}
case ">>>>" =>
val (l, r, 2) = assertArithmeticBinary(ctx, params)
zeroExtend = true
BuiltIns.compileNonetOps(ctx, l, r)
val (l, r, size) = assertArithmeticBinary(ctx, params)
size match {
case 2 =>
zeroExtend = true
BuiltIns.compileNonetOps(ctx, l, r)
case 1 =>
zeroExtend = true
BuiltIns.compileShiftOps(LSR, ctx, l ,r)
case _ => ???
}
case "<<" =>
val (l, r, size) = assertArithmeticBinary(ctx, params)
size match {

View File

@ -644,8 +644,14 @@ object Z80ExpressionCompiler extends AbstractExpressionCompiler[ZLine] {
case 2 => targetifyHL(ctx, target, ZBuiltIns.compile16BitOperation(ctx, XOR, params))
}
case ">>>>" =>
val (l, r, 2) = assertArithmeticBinary(ctx, params)
targetifyA(ctx, target, compileToHL(ctx, l) ++ Z80Shifting.compileNonetShiftRight(ctx, r), isSigned = false)
val (l, r, size) = assertArithmeticBinary(ctx, params)
size match {
case 2 =>
targetifyA (ctx, target, compileToHL (ctx, l) ++ Z80Shifting.compileNonetShiftRight (ctx, r), isSigned = false)
case 1 =>
targetifyA(ctx, target, Z80Shifting.compile8BitShift(ctx, l, r, left = false), isSigned = false)
case _ => ???
}
case "<<" =>
val (l, r, size) = assertArithmeticBinary(ctx, params)
size match {

View File

@ -29,6 +29,21 @@ class NonetSuite extends FunSuite with Matchers {
}
}
test("Nonet operations on bytes") {
EmuUnoptimizedCrossPlatformRun(Cpu.Mos, Cpu.Z80, Cpu.Intel8080, Cpu.Sharp)(
"""
| byte output @$c000
|
| noinline byte five() { return 5}
| noinline byte one() { return 1 }
| void main () {
| output = five() >>>> one()
| }
""".stripMargin) { m =>
m.readByte(0xc000) should equal(2)
}
}
test("Nonet left shift") {
EmuCrossPlatformBenchmarkRun(Cpu.Mos, Cpu.Z80, Cpu.Intel8080, Cpu.Sharp)(
"""