1
0
mirror of https://github.com/KarolS/millfork.git synced 2025-01-01 06:29:53 +00:00

Add ENCODING_NOLOWER

This commit is contained in:
Karol Stasiak 2020-07-31 13:31:07 +02:00
parent 2905e99521
commit 2c9a3f7cbd
3 changed files with 14 additions and 0 deletions

View File

@ -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.

View File

@ -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)

View File

@ -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 {