From 2c9a3f7cbda8e70a7468524d8aed71374a71cb9f Mon Sep 17 00:00:00 2001 From: Karol Stasiak Date: Fri, 31 Jul 2020 13:31:07 +0200 Subject: [PATCH] Add ENCODING_NOLOWER --- docs/lang/preprocessor.md | 2 ++ src/main/scala/millfork/Platform.scala | 1 + src/main/scala/millfork/parser/TextCodec.scala | 11 +++++++++++ 3 files changed, 14 insertions(+) diff --git a/docs/lang/preprocessor.md b/docs/lang/preprocessor.md index 66154206..d6711ff4 100644 --- a/docs/lang/preprocessor.md +++ b/docs/lang/preprocessor.md @@ -58,6 +58,8 @@ The following features are defined based on the chosen CPU and compilation optio * `ENCODING_SAME` - 1 if the encodings `default` and `src` are the same, 0 otherwise. +* `ENCODING_NOLOWER` – 1 if the `default` encoding does not support lowercase ASCII letters. + * `DECIMALS_SAME` - 1 if the encodings `default` and `src` have the same string terminator and decimal digits `'0'`-`'9'`, 0 otherwise. * `NULLCHAR_SAME` - 1 if the encodings `default` and `src` have the same string terminator, 0 otherwise. diff --git a/src/main/scala/millfork/Platform.scala b/src/main/scala/millfork/Platform.scala index 4a8d670f..163d29b7 100644 --- a/src/main/scala/millfork/Platform.scala +++ b/src/main/scala/millfork/Platform.scala @@ -318,6 +318,7 @@ object Platform { log.fatal(s"Invalid label file format: `$debugOutputFormatName`")) val builtInFeatures = builtInCpuFeatures(cpu) ++ Map( + "ENCODING_NOLOWER" -> toLong(codec.supportsLowercase), "ENCODING_SAME" -> toLong(codec.name == srcCodec.name), "DECIMALS_SAME" -> toLong(codec.stringTerminator == srcCodec.stringTerminator && (0 to 9).forall{c => codec.encodeDigit(c) == srcCodec.encodeDigit(c) diff --git a/src/main/scala/millfork/parser/TextCodec.scala b/src/main/scala/millfork/parser/TextCodec.scala index ab0d1729..e37dc008 100644 --- a/src/main/scala/millfork/parser/TextCodec.scala +++ b/src/main/scala/millfork/parser/TextCodec.scala @@ -15,6 +15,8 @@ import millfork.node.Position final case class TextCodecWithFlags(codec: TextCodec, nullTerminated: Boolean, lengthPrefixed: Boolean, lenient: Boolean) sealed trait TextCodec { + val supportsLowercase: Boolean + def name: String def stringTerminator: List[Int] @@ -126,6 +128,8 @@ class UnicodeTextCodec(override val name: String, val charset: Charset, override else if (by == 0) '.' else '?' } + + override val supportsLowercase: Boolean = true } class TableTextCodec(override val name: String, @@ -180,6 +184,11 @@ class TableTextCodec(override val name: String, if (codePoints.forall(isPrintable)) f"`$s%s` ($u%s)" else u } + + private def supportsChar(c: Char): Boolean = { + decompositions.contains(c) || directDecompositions.contains(c) || map.indexOf(c) >= 0 + } + private def encodeChar(log: Logger, position: Option[Position], c: Char, options: CompilationOptions, lenient: Boolean): Option[List[Int]] = { if (decompositions.contains(c)) { Some(decompositions(c).toList.flatMap(x => encodeChar(log, position, x, options, lenient).getOrElse(List(x.toInt)))) @@ -271,6 +280,8 @@ class TableTextCodec(override val name: String, if (i < 0) throw new IllegalStateException(s"For some reason, there is no digit $digit in the $name encoding?") List(i) } + + override val supportsLowercase: Boolean = 'a' to 'z' forall(c => supportsChar(c)) } object TextCodec {