From 62f79388bdaf1d9be7ddb6c44945cd049755bebe Mon Sep 17 00:00:00 2001 From: Karol Stasiak Date: Tue, 9 Jul 2019 22:03:53 +0200 Subject: [PATCH] Slowly move towards removing the `farword` alias --- docs/lang/types.md | 2 +- .../compiler/AbstractExpressionCompiler.scala | 2 +- .../compiler/z80/Z80ExpressionCompiler.scala | 8 +-- src/main/scala/millfork/env/Environment.scala | 1 - src/main/scala/millfork/parser/MfParser.scala | 6 +- .../scala/millfork/test/FarwordTest.scala | 64 +++++++++---------- src/test/scala/millfork/test/LongTest.scala | 16 ++--- 7 files changed, 49 insertions(+), 50 deletions(-) diff --git a/docs/lang/types.md b/docs/lang/types.md index 3bfcd6b7..4b839417 100644 --- a/docs/lang/types.md +++ b/docs/lang/types.md @@ -12,7 +12,7 @@ Millfork puts extra limitations on which types can be used in which contexts. (alias: `int16`) * `int24` – 3-byte value of undefined signedness, defaulting to unsigned -(alias: `farword`; this alias is deprecated and might be removed in the future) +(alias: `farword`; this alias is deprecated and will be removed in the future) * `long` – 4-byte value of undefined signedness, defaulting to unsigned (alias: `int32`) diff --git a/src/main/scala/millfork/compiler/AbstractExpressionCompiler.scala b/src/main/scala/millfork/compiler/AbstractExpressionCompiler.scala index 0b6d1a49..343a5cfb 100644 --- a/src/main/scala/millfork/compiler/AbstractExpressionCompiler.scala +++ b/src/main/scala/millfork/compiler/AbstractExpressionCompiler.scala @@ -257,7 +257,7 @@ object AbstractExpressionCompiler { size match { case 1 => b case 2 => w - case 3 => env.get[Type]("farword") + case 3 => env.get[Type]("int24") case 4 => env.get[Type]("long") } case GeneratedConstantExpression(_, typ) => typ diff --git a/src/main/scala/millfork/compiler/z80/Z80ExpressionCompiler.scala b/src/main/scala/millfork/compiler/z80/Z80ExpressionCompiler.scala index 1a78bbda..bf8fcc86 100644 --- a/src/main/scala/millfork/compiler/z80/Z80ExpressionCompiler.scala +++ b/src/main/scala/millfork/compiler/z80/Z80ExpressionCompiler.scala @@ -323,7 +323,7 @@ object Z80ExpressionCompiler extends AbstractExpressionCompiler[ZLine] { ZLine.ldAbs8(A, v, 2), ZLine.ld8(E, A)) } case ZExpressionTarget.DEHL => - // TODO: signed farwords + // TODO: signed int24s if (ctx.options.flag(CompilationFlag.EmitIntel8080Opcodes)) { List(ZLine.ldAbs16(HL, v), ZLine.ldAbs8(A, v, 2), ZLine.ld8(E, A), ZLine.ldImm8(D, 0)) } else { @@ -337,7 +337,7 @@ object Z80ExpressionCompiler extends AbstractExpressionCompiler[ZLine] { case 4 => target match { case ZExpressionTarget.NOTHING => Nil case ZExpressionTarget.DEHL => - // TODO: signed farwords + // TODO: signed int24s if (ctx.options.flag(CompilationFlag.EmitZ80Opcodes)) { List(ZLine.ldAbs16(HL, v), ZLine.ldAbs16(DE, v.toAddress + 2)) } else if (ctx.options.flag(CompilationFlag.EmitIntel8080Opcodes)) { @@ -377,7 +377,7 @@ object Z80ExpressionCompiler extends AbstractExpressionCompiler[ZLine] { List(ZLine.ldViaIxy(x, L, v.baseOffset), ZLine.ldViaIxy(x, H, v.baseOffset + 1), ZLine.ldImm16(DE, 0)) } case 3 => target match { - // TODO: signed farwords + // TODO: signed int24s case ZExpressionTarget.NOTHING => Nil case ZExpressionTarget.EHL => List(ZLine.ldViaIxy(x, L, v.baseOffset), ZLine.ldViaIxy(x, H, v.baseOffset + 1), ZLine.ldViaIxy(x, E, v.baseOffset + 2)) @@ -420,7 +420,7 @@ object Z80ExpressionCompiler extends AbstractExpressionCompiler[ZLine] { loadHL ++ List(ZLine.ld8(A,MEM_HL), ZLine.register(INC_16, HL), ZLine.ld8(H, MEM_HL), ZLine.ld8(L, A), ZLine.ldImm16(DE, 0)) } case 3 => target match { - // TODO: signed farwords + // TODO: signed int24s case ZExpressionTarget.NOTHING => Nil case ZExpressionTarget.EHL => loadHL2 ++ List( diff --git a/src/main/scala/millfork/env/Environment.scala b/src/main/scala/millfork/env/Environment.scala index 2f7d3bfd..3be0ff94 100644 --- a/src/main/scala/millfork/env/Environment.scala +++ b/src/main/scala/millfork/env/Environment.scala @@ -437,7 +437,6 @@ class Environment(val parent: Option[Environment], val prefix: String, val cpuFa addThing(BasicPlainType("int128", 16), None) val p = DerivedPlainType("pointer", w, isSigned = false, isPointy = true) addThing(p, None) - // addThing(DerivedPlainType("farpointer", get[PlainType]("farword"), isSigned = false), None) addThing(DerivedPlainType("ubyte", b, isSigned = false, isPointy = false), None) addThing(DerivedPlainType("sbyte", b, isSigned = true, isPointy = false), None) addThing(Alias("unsigned8", "ubyte"), None) diff --git a/src/main/scala/millfork/parser/MfParser.scala b/src/main/scala/millfork/parser/MfParser.scala index 3525c822..f12e2daa 100644 --- a/src/main/scala/millfork/parser/MfParser.scala +++ b/src/main/scala/millfork/parser/MfParser.scala @@ -577,10 +577,10 @@ object MfParser { val doubleQuotedString: P[List[Char]] = P("\"" ~/ CharsWhile(c => c != '\"' && c != '\n' && c != '\r').?.! ~ "\"").map(_.toList) - def size(value: Long, wordLiteral: Boolean, farwordLiteral: Boolean, longLiteral: Boolean): Int = { + def size(value: Long, wordLiteral: Boolean, int24Literal: Boolean, int32Literal: Boolean): Int = { val w = value > 255 || value < -0x80 || wordLiteral - val f = value > 0xffff || value < -0x8000 || farwordLiteral - val l = value > 0xffffff || value < -0x800000 || longLiteral + val f = value > 0xffff || value < -0x8000 || int24Literal + val l = value > 0xffffff || value < -0x800000 || int32Literal if (l) 4 else if (f) 3 else if (w) 2 else 1 } diff --git a/src/test/scala/millfork/test/FarwordTest.scala b/src/test/scala/millfork/test/FarwordTest.scala index be7e0a3d..908f8fbe 100644 --- a/src/test/scala/millfork/test/FarwordTest.scala +++ b/src/test/scala/millfork/test/FarwordTest.scala @@ -9,12 +9,12 @@ import org.scalatest.{FunSuite, Matchers} */ class FarwordTest extends FunSuite with Matchers { - test("Farword assignment") { + test("Int24 assignment") { EmuCrossPlatformBenchmarkRun(Cpu.Mos, Cpu.Z80, Cpu.Intel8080, Cpu.Sharp, Cpu.Intel8086)( """ - | farword output3 @$c000 - | farword output2 @$c004 - | farword output1 @$c008 + | int24 output3 @$c000 + | int24 output2 @$c004 + | int24 output1 @$c008 | void main () { | output3 = $223344 | output2 = $223344 @@ -28,11 +28,11 @@ class FarwordTest extends FunSuite with Matchers { m.readMedium(0xc008) should equal(0x55) } } - test("Farword assignment 2") { + test("Int24 assignment 2") { EmuCrossPlatformBenchmarkRun(Cpu.Mos, Cpu.Z80, Cpu.Intel8080, Cpu.Sharp, Cpu.Intel8086)( """ - | farword output3 @$c000 - | farword output2 @$c004 + | int24 output3 @$c000 + | int24 output2 @$c004 | word output1 @$c008 | void main () { | word w @@ -52,11 +52,11 @@ class FarwordTest extends FunSuite with Matchers { } } - test("Farword assignment 3") { + test("Int24 assignment 3") { EmuCrossPlatformBenchmarkRun(Cpu.Mos, Cpu.Z80, Cpu.Intel8080, Cpu.Sharp, Cpu.Intel8086)( """ - | farword output0 @$c000 - | farword output1 @$c003 + | int24 output0 @$c000 + | int24 output1 @$c003 | void main () { | output0 = $112233 | output1 = $112233 @@ -69,13 +69,13 @@ class FarwordTest extends FunSuite with Matchers { m.readMedium(0xc003) should equal(0x111122) } } - test("Farword addition") { + test("Int24 addition") { EmuCrossPlatformBenchmarkRun(Cpu.Mos, Cpu.Z80, Cpu.Intel8080, Cpu.Sharp, Cpu.Intel8086)( """ - | farword output @$c000 + | int24 output @$c000 | void main () { | word w - | farword l + | int24 l | byte b | w = $8000 | b = $8 @@ -89,10 +89,10 @@ class FarwordTest extends FunSuite with Matchers { m.readMedium(0xc000) should equal(0x58008) } } - test("Farword addition 2") { + test("Int24 addition 2") { EmuCrossPlatformBenchmarkRun(Cpu.Mos, Cpu.Z80, Cpu.Intel8080, Cpu.Sharp, Cpu.Intel8086)( """ - | farword output @$c000 + | int24 output @$c000 | void main () { | output = 0 | output += $50000 @@ -103,13 +103,13 @@ class FarwordTest extends FunSuite with Matchers { m.readMedium(0xc000) should equal(0x58008) } } - test("Farword subtraction") { + test("Int24 subtraction") { EmuCrossPlatformBenchmarkRun(Cpu.Mos, Cpu.Z80, Cpu.Intel8080, Cpu.Sharp, Cpu.Intel8086)( """ - | farword output @$c000 + | int24 output @$c000 | void main () { | word w - | farword l + | int24 l | byte b | w = $8000 | b = $8 @@ -123,10 +123,10 @@ class FarwordTest extends FunSuite with Matchers { m.readMedium(0xc000) should equal(0) } } - test("Farword subtraction 2") { + test("Int24 subtraction 2") { EmuCrossPlatformBenchmarkRun(Cpu.Mos, Cpu.Z80, Cpu.Intel8080, Cpu.Sharp, Cpu.Intel8086)( """ - | farword output @$c000 + | int24 output @$c000 | void main () { | output = $58008 | output -= $50000 @@ -137,10 +137,10 @@ class FarwordTest extends FunSuite with Matchers { m.readMedium(0xc000) should equal(0) } } - test("Farword subtraction 3") { + test("Int24 subtraction 3") { EmuCrossPlatformBenchmarkRun(Cpu.Mos, Cpu.Z80, Cpu.Intel8080, Cpu.Sharp, Cpu.Intel8086)( """ - | farword output @$c000 + | int24 output @$c000 | void main () { | output = $58008 | output -= w() @@ -157,10 +157,10 @@ class FarwordTest extends FunSuite with Matchers { } } - test("Farword AND") { + test("Int24 AND") { EmuCrossPlatformBenchmarkRun(Cpu.Mos, Cpu.Z80, Cpu.Intel8080, Cpu.Sharp, Cpu.Intel8086)( """ - | farword output @$c000 + | int24 output @$c000 | void main () { | output = $FFFFFF | output &= w() @@ -177,16 +177,16 @@ class FarwordTest extends FunSuite with Matchers { } } - test("Farword INC/DEC") { + test("Int24 INC/DEC") { EmuCrossPlatformBenchmarkRun(Cpu.Mos, Cpu.Z80, Cpu.Intel8080, Cpu.Sharp, Cpu.Intel8086)( """ - | farword output0 @$c000 - | farword output1 @$c004 - | farword output2 @$c008 - | farword output3 @$c00c - | farword output4 @$c010 - | farword output5 @$c014 - | farword output6 @$c018 + | int24 output0 @$c000 + | int24 output1 @$c004 + | int24 output2 @$c008 + | int24 output3 @$c00c + | int24 output4 @$c010 + | int24 output5 @$c014 + | int24 output6 @$c018 | void main () { | output0 = 0 | output1 = $FF diff --git a/src/test/scala/millfork/test/LongTest.scala b/src/test/scala/millfork/test/LongTest.scala index aea2126b..e78f3173 100644 --- a/src/test/scala/millfork/test/LongTest.scala +++ b/src/test/scala/millfork/test/LongTest.scala @@ -259,9 +259,9 @@ class LongTest extends FunSuite with Matchers { | long output5 @$c014 | long output6 @$c018 | - | farword f0 @$c020 - | farword f1 @$c023 - | farword f2 @$c026 + | int24 f0 @$c020 + | int24 f1 @$c023 + | int24 f2 @$c026 | void main () { | output0 = ll($91929394) | output1 = lf($929394) @@ -278,7 +278,7 @@ class LongTest extends FunSuite with Matchers { | long ll(long param) { | return param | } - | long lf(farword param) { + | long lf(int24 param) { | return param | } | long lw(word param) { @@ -287,13 +287,13 @@ class LongTest extends FunSuite with Matchers { | long lb(byte param) { | return param | } - | farword ff(farword param) { + | int24 ff(int24 param) { | return param | } - | farword fw(word param) { + | int24 fw(word param) { | return param | } - | farword fb(byte param) { + | int24 fb(byte param) { | return param | } """.stripMargin) { m => @@ -329,7 +329,7 @@ class LongTest extends FunSuite with Matchers { | int64 xl(long param) { | return param | } - | int64 xf(farword param) { + | int64 xf(int24 param) { | return param | } | int64 xw(word param) {