From db76c8d7f4c6cfda20aa716800131f47c67bcb81 Mon Sep 17 00:00:00 2001 From: meisl Date: Tue, 13 Jul 2021 09:51:34 +0200 Subject: [PATCH] -/* remove IStringEncoding as param in compilerAst, and all other uses that were only because of that. For good measure we also turn on *all* compiler tests with examples (they do take some time). Note that the total *mentions* of IStringEncoding in the entire project went down from ~50 to 6, only 3 of which are *actual uses* (the others are 2 imports and 1 supertype ref in ICompilationTarget : IStringEncoding)! --- compiler/src/prog8/compiler/Compiler.kt | 14 +- .../optimizer/ConstantFoldingOptimizer.kt | 3 +- compiler/src/prog8/optimizer/Extensions.kt | 2 +- compiler/test/Helpers.kt | 11 - compiler/test/TestCompilerOnExamples.kt | 2 +- .../src/prog8/ast/antlr/Antlr2Kotlin.kt | 202 ++- compilerAst/src/prog8/parser/ModuleParsing.kt | 2 - compilerAst/src/prog8/parser/Petscii.kt | 1171 ----------------- .../src/prog8/parser/PetsciiEncoding.kt | 24 - compilerAst/src/prog8/parser/Prog8Parser.kt | 2 +- .../src/prog8/parser/ThrowTodoEncoding.kt | 16 - compilerAst/test/Helpers.kt | 11 - compilerAst/test/TestModuleImporter.kt | 14 +- 13 files changed, 115 insertions(+), 1359 deletions(-) delete mode 100644 compilerAst/src/prog8/parser/Petscii.kt delete mode 100644 compilerAst/src/prog8/parser/PetsciiEncoding.kt delete mode 100644 compilerAst/src/prog8/parser/ThrowTodoEncoding.kt diff --git a/compiler/src/prog8/compiler/Compiler.kt b/compiler/src/prog8/compiler/Compiler.kt index a32d2b5fb..2fb3f03eb 100644 --- a/compiler/src/prog8/compiler/Compiler.kt +++ b/compiler/src/prog8/compiler/Compiler.kt @@ -1,6 +1,9 @@ package prog8.compiler -import prog8.ast.* +import prog8.ast.AstToSourceCode +import prog8.ast.IBuiltinFunctions +import prog8.ast.IMemSizer +import prog8.ast.Program import prog8.ast.base.AstException import prog8.ast.base.Position import prog8.ast.expressions.Expression @@ -171,13 +174,12 @@ private fun parseImports(filepath: Path, errors: IErrorReporter, compTarget: ICompilationTarget, libdirs: List): Triple> { - val compilationTargetName = compTarget.name - println("Compiler target: $compilationTargetName. Parsing...") + println("Compiler target: ${compTarget.name}. Parsing...") val bf = BuiltinFunctionsFacade(BuiltinFunctions) val programAst = Program(moduleName(filepath.fileName), mutableListOf(), bf, compTarget) bf.program = programAst - val importer = ModuleImporter(programAst, compTarget, compilationTargetName, libdirs) + val importer = ModuleImporter(programAst, compTarget.name, libdirs) importer.importModule(filepath) errors.report() @@ -190,7 +192,7 @@ private fun parseImports(filepath: Path, throw ParsingFailedError("${programAst.modules.first().position} BASIC launcher requires output type PRG.") // depending on the machine and compiler options we may have to include some libraries - for(lib in compTarget.machine.importLibs(compilerOptions, compilationTargetName)) + for(lib in compTarget.machine.importLibs(compilerOptions, compTarget.name)) importer.importLibraryModule(lib) // always import prog8_lib and math @@ -266,7 +268,7 @@ private fun processAst(programAst: Program, errors: IErrorReporter, compilerOpti programAst.checkIdentifiers(errors, compilerOptions) errors.report() // TODO: turning char literals into UBYTEs via an encoding should really happen in code gen - but for that we'd need DataType.CHAR - programAst.charLiteralsToUByteLiterals(errors, compilerOptions.compTarget as IStringEncoding) + programAst.charLiteralsToUByteLiterals(errors, compilerOptions.compTarget) errors.report() programAst.constantFold(errors, compilerOptions.compTarget) errors.report() diff --git a/compiler/src/prog8/optimizer/ConstantFoldingOptimizer.kt b/compiler/src/prog8/optimizer/ConstantFoldingOptimizer.kt index abe9ce509..9b6fc280a 100644 --- a/compiler/src/prog8/optimizer/ConstantFoldingOptimizer.kt +++ b/compiler/src/prog8/optimizer/ConstantFoldingOptimizer.kt @@ -9,11 +9,10 @@ import prog8.ast.statements.ForLoop import prog8.ast.statements.VarDecl import prog8.ast.walk.AstWalker import prog8.ast.walk.IAstModification -import prog8.compiler.target.ICompilationTarget import kotlin.math.pow -internal class ConstantFoldingOptimizer(private val program: Program, private val compTarget: ICompilationTarget) : AstWalker() { +internal class ConstantFoldingOptimizer(private val program: Program) : AstWalker() { override fun before(memread: DirectMemoryRead, parent: Node): Iterable { // @( &thing ) --> thing diff --git a/compiler/src/prog8/optimizer/Extensions.kt b/compiler/src/prog8/optimizer/Extensions.kt index 89bd8910f..b69be66a7 100644 --- a/compiler/src/prog8/optimizer/Extensions.kt +++ b/compiler/src/prog8/optimizer/Extensions.kt @@ -21,7 +21,7 @@ internal fun Program.constantFold(errors: IErrorReporter, compTarget: ICompilati if(errors.noErrors()) { valuetypefixer.applyModifications() - val optimizer = ConstantFoldingOptimizer(this, compTarget) + val optimizer = ConstantFoldingOptimizer(this) optimizer.visit(this) while (errors.noErrors() && optimizer.applyModifications() > 0) { optimizer.visit(this) diff --git a/compiler/test/Helpers.kt b/compiler/test/Helpers.kt index 0ea41bf05..48f745b2d 100644 --- a/compiler/test/Helpers.kt +++ b/compiler/test/Helpers.kt @@ -6,7 +6,6 @@ import java.nio.file.Path import prog8.ast.IBuiltinFunctions import prog8.ast.IMemSizer -import prog8.ast.IStringEncoding import prog8.ast.base.DataType import prog8.ast.base.Position import prog8.ast.expressions.Expression @@ -127,16 +126,6 @@ fun mapCombinations(dim1: Iterable, dim2: Iterable, dim3: }.toList() -val DummyEncoding = object : IStringEncoding { - override fun encodeString(str: String, altEncoding: Boolean): List { - throw Exception("just a dummy - should not be called") - } - - override fun decodeString(bytes: List, altEncoding: Boolean): String { - throw Exception("just a dummy - should not be called") - } -} - val DummyFunctions = object : IBuiltinFunctions { override val names: Set = emptySet() override val purefunctionNames: Set = emptySet() diff --git a/compiler/test/TestCompilerOnExamples.kt b/compiler/test/TestCompilerOnExamples.kt index 361d5f174..a98e2bade 100644 --- a/compiler/test/TestCompilerOnExamples.kt +++ b/compiler/test/TestCompilerOnExamples.kt @@ -54,7 +54,7 @@ class TestCompilerOnExamples { } @TestFactory - @Disabled +// @Disabled fun bothCx16AndC64() = mapCombinations( dim1 = listOf( "animals", diff --git a/compilerAst/src/prog8/ast/antlr/Antlr2Kotlin.kt b/compilerAst/src/prog8/ast/antlr/Antlr2Kotlin.kt index ed6a10c2c..2a695dee6 100644 --- a/compilerAst/src/prog8/ast/antlr/Antlr2Kotlin.kt +++ b/compilerAst/src/prog8/ast/antlr/Antlr2Kotlin.kt @@ -2,26 +2,16 @@ package prog8.ast.antlr import org.antlr.v4.runtime.ParserRuleContext import org.antlr.v4.runtime.tree.TerminalNode -import prog8.ast.IStringEncoding -import prog8.ast.Module import prog8.ast.base.* import prog8.ast.expressions.* import prog8.ast.statements.* import prog8.parser.Prog8ANTLRParser -import prog8.parser.SourceCode /***************** Antlr Extension methods to create AST ****************/ private data class NumericLiteral(val number: Number, val datatype: DataType) -internal fun Prog8ANTLRParser.ModuleContext.toAst(name: String, source: SourceCode, encoding: IStringEncoding) : Module { - val nameWithoutSuffix = if(name.endsWith(".p8")) name.substringBeforeLast('.') else name - val directives = this.directive().map { it.toAst() } - val blocks = this.block().map { it.toAst(isInLibrary = source.isFromResources, encoding) } - return Module(nameWithoutSuffix, (directives + blocks).toMutableList(), toPosition(), source) -} - private fun ParserRuleContext.toPosition() : Position { /* val customTokensource = this.start.tokenSource as? CustomLexer @@ -38,11 +28,11 @@ private fun ParserRuleContext.toPosition() : Position { return Position(filename, start.line, start.charPositionInLine, stop.charPositionInLine + stop.text.length) } -internal fun Prog8ANTLRParser.BlockContext.toAst(isInLibrary: Boolean, encoding: IStringEncoding) : Block { +internal fun Prog8ANTLRParser.BlockContext.toAst(isInLibrary: Boolean) : Block { val blockstatements = block_statement().map { when { - it.variabledeclaration()!=null -> it.variabledeclaration().toAst(encoding) - it.subroutinedeclaration()!=null -> it.subroutinedeclaration().toAst(encoding) + it.variabledeclaration()!=null -> it.variabledeclaration().toAst() + it.subroutinedeclaration()!=null -> it.subroutinedeclaration().toAst() it.directive()!=null -> it.directive().toAst() it.inlineasm()!=null -> it.inlineasm().toAst() it.labeldef()!=null -> it.labeldef().toAst() @@ -52,11 +42,11 @@ internal fun Prog8ANTLRParser.BlockContext.toAst(isInLibrary: Boolean, encoding: return Block(identifier().text, integerliteral()?.toAst()?.number?.toInt(), blockstatements.toMutableList(), isInLibrary, toPosition()) } -private fun Prog8ANTLRParser.Statement_blockContext.toAst(encoding: IStringEncoding): MutableList = - statement().asSequence().map { it.toAst(encoding) }.toMutableList() +private fun Prog8ANTLRParser.Statement_blockContext.toAst(): MutableList = + statement().asSequence().map { it.toAst() }.toMutableList() -private fun Prog8ANTLRParser.VariabledeclarationContext.toAst(encoding: IStringEncoding) : Statement { - vardecl()?.let { return it.toAst(encoding) } +private fun Prog8ANTLRParser.VariabledeclarationContext.toAst() : Statement { + vardecl()?.let { return it.toAst() } varinitializer()?.let { val vd = it.vardecl() @@ -64,9 +54,9 @@ private fun Prog8ANTLRParser.VariabledeclarationContext.toAst(encoding: IStringE VarDeclType.VAR, vd.datatype()?.toAst() ?: DataType.UNDEFINED, if (vd.ZEROPAGE() != null) ZeropageWish.PREFER_ZEROPAGE else ZeropageWish.DONTCARE, - vd.arrayindex()?.toAst(encoding), + vd.arrayindex()?.toAst(), vd.varname.text, - it.expression().toAst(encoding), + it.expression().toAst(), vd.ARRAYSIG() != null || vd.arrayindex() != null, false, vd.SHARED()!=null, @@ -81,9 +71,9 @@ private fun Prog8ANTLRParser.VariabledeclarationContext.toAst(encoding: IStringE VarDeclType.CONST, vd.datatype()?.toAst() ?: DataType.UNDEFINED, if (vd.ZEROPAGE() != null) ZeropageWish.PREFER_ZEROPAGE else ZeropageWish.DONTCARE, - vd.arrayindex()?.toAst(encoding), + vd.arrayindex()?.toAst(), vd.varname.text, - cvarinit.expression().toAst(encoding), + cvarinit.expression().toAst(), vd.ARRAYSIG() != null || vd.arrayindex() != null, false, vd.SHARED() != null, @@ -98,9 +88,9 @@ private fun Prog8ANTLRParser.VariabledeclarationContext.toAst(encoding: IStringE VarDeclType.MEMORY, vd.datatype()?.toAst() ?: DataType.UNDEFINED, if (vd.ZEROPAGE() != null) ZeropageWish.PREFER_ZEROPAGE else ZeropageWish.DONTCARE, - vd.arrayindex()?.toAst(encoding), + vd.arrayindex()?.toAst(), vd.varname.text, - mvarinit.expression().toAst(encoding), + mvarinit.expression().toAst(), vd.ARRAYSIG() != null || vd.arrayindex() != null, false, vd.SHARED()!=null, @@ -111,33 +101,33 @@ private fun Prog8ANTLRParser.VariabledeclarationContext.toAst(encoding: IStringE throw FatalAstException("weird variable decl $this") } -private fun Prog8ANTLRParser.SubroutinedeclarationContext.toAst(encoding: IStringEncoding) : Subroutine { +private fun Prog8ANTLRParser.SubroutinedeclarationContext.toAst() : Subroutine { return when { - subroutine()!=null -> subroutine().toAst(encoding) - asmsubroutine()!=null -> asmsubroutine().toAst(encoding) + subroutine()!=null -> subroutine().toAst() + asmsubroutine()!=null -> asmsubroutine().toAst() romsubroutine()!=null -> romsubroutine().toAst() else -> throw FatalAstException("weird subroutine decl $this") } } -private fun Prog8ANTLRParser.StatementContext.toAst(encoding: IStringEncoding) : Statement { - val vardecl = variabledeclaration()?.toAst(encoding) +private fun Prog8ANTLRParser.StatementContext.toAst() : Statement { + val vardecl = variabledeclaration()?.toAst() if(vardecl!=null) return vardecl assignment()?.let { - return Assignment(it.assign_target().toAst(encoding), it.expression().toAst(encoding), it.toPosition()) + return Assignment(it.assign_target().toAst(), it.expression().toAst(), it.toPosition()) } augassignment()?.let { // replace A += X with A = A + X - val target = it.assign_target().toAst(encoding) + val target = it.assign_target().toAst() val oper = it.operator.text.substringBefore('=') - val expression = BinaryExpression(target.toExpression(), oper, it.expression().toAst(encoding), it.expression().toPosition()) - return Assignment(it.assign_target().toAst(encoding), expression, it.toPosition()) + val expression = BinaryExpression(target.toExpression(), oper, it.expression().toAst(), it.expression().toPosition()) + return Assignment(it.assign_target().toAst(), expression, it.toPosition()) } postincrdecr()?.let { - return PostIncrDecr(it.assign_target().toAst(encoding), it.operator.text, it.toPosition()) + return PostIncrDecr(it.assign_target().toAst(), it.operator.text, it.toPosition()) } val directive = directive()?.toAst() @@ -149,49 +139,49 @@ private fun Prog8ANTLRParser.StatementContext.toAst(encoding: IStringEncoding) : val jump = unconditionaljump()?.toAst() if(jump!=null) return jump - val fcall = functioncall_stmt()?.toAst(encoding) + val fcall = functioncall_stmt()?.toAst() if(fcall!=null) return fcall - val ifstmt = if_stmt()?.toAst(encoding) + val ifstmt = if_stmt()?.toAst() if(ifstmt!=null) return ifstmt - val returnstmt = returnstmt()?.toAst(encoding) + val returnstmt = returnstmt()?.toAst() if(returnstmt!=null) return returnstmt - val subroutine = subroutinedeclaration()?.toAst(encoding) + val subroutine = subroutinedeclaration()?.toAst() if(subroutine!=null) return subroutine val asm = inlineasm()?.toAst() if(asm!=null) return asm - val branchstmt = branch_stmt()?.toAst(encoding) + val branchstmt = branch_stmt()?.toAst() if(branchstmt!=null) return branchstmt - val forloop = forloop()?.toAst(encoding) + val forloop = forloop()?.toAst() if(forloop!=null) return forloop - val untilloop = untilloop()?.toAst(encoding) + val untilloop = untilloop()?.toAst() if(untilloop!=null) return untilloop - val whileloop = whileloop()?.toAst(encoding) + val whileloop = whileloop()?.toAst() if(whileloop!=null) return whileloop - val repeatloop = repeatloop()?.toAst(encoding) + val repeatloop = repeatloop()?.toAst() if(repeatloop!=null) return repeatloop val breakstmt = breakstmt()?.toAst() if(breakstmt!=null) return breakstmt - val whenstmt = whenstmt()?.toAst(encoding) + val whenstmt = whenstmt()?.toAst() if(whenstmt!=null) return whenstmt throw FatalAstException("unprocessed source text (are we missing ast conversion rules for parser elements?): $text") } -private fun Prog8ANTLRParser.AsmsubroutineContext.toAst(encoding: IStringEncoding): Subroutine { +private fun Prog8ANTLRParser.AsmsubroutineContext.toAst(): Subroutine { val inline = this.inline()!=null val subdecl = asmsub_decl().toAst() - val statements = statement_block()?.toAst(encoding) ?: mutableListOf() + val statements = statement_block()?.toAst() ?: mutableListOf() return Subroutine(subdecl.name, subdecl.parameters, subdecl.returntypes, subdecl.asmParameterRegisters, subdecl.asmReturnvaluesRegisters, subdecl.asmClobbers, null, true, inline, statements, toPosition()) @@ -272,28 +262,28 @@ private fun Prog8ANTLRParser.Asmsub_paramsContext.toAst(): List AssignTarget(identifier.toAst(), null, null, toPosition()) - arrayindexed()!=null -> AssignTarget(null, arrayindexed().toAst(encoding), null, toPosition()) - directmemory()!=null -> AssignTarget(null, null, DirectMemoryWrite(directmemory().expression().toAst(encoding), toPosition()), toPosition()) + arrayindexed()!=null -> AssignTarget(null, arrayindexed().toAst(), null, toPosition()) + directmemory()!=null -> AssignTarget(null, null, DirectMemoryWrite(directmemory().expression().toAst(), toPosition()), toPosition()) else -> AssignTarget(scoped_identifier()?.toAst(), null, null, toPosition()) } } @@ -345,8 +335,8 @@ private fun Prog8ANTLRParser.ClobberContext.toAst() : Set { private fun Prog8ANTLRParser.DatatypeContext.toAst() = DataType.valueOf(text.uppercase()) -private fun Prog8ANTLRParser.ArrayindexContext.toAst(encoding: IStringEncoding) : ArrayIndex = - ArrayIndex(expression().toAst(encoding), toPosition()) +private fun Prog8ANTLRParser.ArrayindexContext.toAst() : ArrayIndex = + ArrayIndex(expression().toAst(), toPosition()) internal fun Prog8ANTLRParser.DirectiveContext.toAst() : Directive = Directive(directivename.text, directivearg().map { it.toAst() }, toPosition()) @@ -354,7 +344,7 @@ internal fun Prog8ANTLRParser.DirectiveContext.toAst() : Directive = private fun Prog8ANTLRParser.DirectiveargContext.toAst() : DirectiveArg { val str = stringliteral() if(str?.ALT_STRING_ENCODING() != null) - throw AstException("${toPosition()} can't use alternate string encodings for directive arguments") + throw AstException("${toPosition()} can't use alternate string s for directive arguments") return DirectiveArg(stringliteral()?.text, identifier()?.text, integerliteral()?.toAst()?.number?.toInt(), toPosition()) } @@ -410,7 +400,7 @@ private fun Prog8ANTLRParser.IntegerliteralContext.toAst(): NumericLiteral { } } -private fun Prog8ANTLRParser.ExpressionContext.toAst(encoding: IStringEncoding) : Expression { +private fun Prog8ANTLRParser.ExpressionContext.toAst() : Expression { val litval = literalvalue() if(litval!=null) { @@ -433,7 +423,7 @@ private fun Prog8ANTLRParser.ExpressionContext.toAst(encoding: IStringEncoding) litval.stringliteral()!=null -> litval.stringliteral().toAst() litval.charliteral()!=null -> litval.charliteral().toAst() litval.arrayliteral()!=null -> { - val array = litval.arrayliteral().toAst(encoding) + val array = litval.arrayliteral().toAst() // the actual type of the arraysize can not yet be determined here (missing namespace & heap) // the ConstantFold takes care of that and converts the type if needed. ArrayLiteralValue(InferredTypes.InferredType.unknown(), array, position = litval.toPosition()) @@ -447,31 +437,31 @@ private fun Prog8ANTLRParser.ExpressionContext.toAst(encoding: IStringEncoding) return scoped_identifier().toAst() if(bop!=null) - return BinaryExpression(left.toAst(encoding), bop.text, right.toAst(encoding), toPosition()) + return BinaryExpression(left.toAst(), bop.text, right.toAst(), toPosition()) if(prefix!=null) - return PrefixExpression(prefix.text, expression(0).toAst(encoding), toPosition()) + return PrefixExpression(prefix.text, expression(0).toAst(), toPosition()) - val funcall = functioncall()?.toAst(encoding) + val funcall = functioncall()?.toAst() if(funcall!=null) return funcall if (rangefrom!=null && rangeto!=null) { val defaultstep = if(rto.text == "to") 1 else -1 - val step = rangestep?.toAst(encoding) ?: NumericLiteralValue(DataType.UBYTE, defaultstep, toPosition()) - return RangeExpr(rangefrom.toAst(encoding), rangeto.toAst(encoding), step, toPosition()) + val step = rangestep?.toAst() ?: NumericLiteralValue(DataType.UBYTE, defaultstep, toPosition()) + return RangeExpr(rangefrom.toAst(), rangeto.toAst(), step, toPosition()) } if(childCount==3 && children[0].text=="(" && children[2].text==")") - return expression(0).toAst(encoding) // expression within ( ) + return expression(0).toAst() // expression within ( ) if(arrayindexed()!=null) - return arrayindexed().toAst(encoding) + return arrayindexed().toAst() if(typecast()!=null) - return TypecastExpression(expression(0).toAst(encoding), typecast().datatype().toAst(), false, toPosition()) + return TypecastExpression(expression(0).toAst(), typecast().datatype().toAst(), false, toPosition()) if(directmemory()!=null) - return DirectMemoryRead(directmemory().expression().toAst(encoding), toPosition()) + return DirectMemoryRead(directmemory().expression().toAst(), toPosition()) if(addressof()!=null) return AddressOf(addressof().scoped_identifier().toAst(), toPosition()) @@ -485,13 +475,13 @@ private fun Prog8ANTLRParser.CharliteralContext.toAst(): CharLiteral = private fun Prog8ANTLRParser.StringliteralContext.toAst(): StringLiteralValue = StringLiteralValue(unescape(this.STRING().text, toPosition()), ALT_STRING_ENCODING()!=null, toPosition()) -private fun Prog8ANTLRParser.ArrayindexedContext.toAst(encoding: IStringEncoding): ArrayIndexedExpression { +private fun Prog8ANTLRParser.ArrayindexedContext.toAst(): ArrayIndexedExpression { return ArrayIndexedExpression(scoped_identifier().toAst(), - arrayindex().toAst(encoding), + arrayindex().toAst(), toPosition()) } -private fun Prog8ANTLRParser.Expression_listContext.toAst(encoding: IStringEncoding) = expression().map{ it.toAst(encoding) } +private fun Prog8ANTLRParser.Expression_listContext.toAst() = expression().map{ it.toAst() } private fun Prog8ANTLRParser.IdentifierContext.toAst() : IdentifierReference = IdentifierReference(listOf(text), toPosition()) @@ -507,27 +497,27 @@ private fun Prog8ANTLRParser.BooleanliteralContext.toAst() = when(text) { else -> throw FatalAstException(text) } -private fun Prog8ANTLRParser.ArrayliteralContext.toAst(encoding: IStringEncoding) : Array = - expression().map { it.toAst(encoding) }.toTypedArray() +private fun Prog8ANTLRParser.ArrayliteralContext.toAst() : Array = + expression().map { it.toAst() }.toTypedArray() -private fun Prog8ANTLRParser.If_stmtContext.toAst(encoding: IStringEncoding): IfStatement { - val condition = expression().toAst(encoding) - val trueStatements = statement_block()?.toAst(encoding) ?: mutableListOf(statement().toAst(encoding)) - val elseStatements = else_part()?.toAst(encoding) ?: mutableListOf() +private fun Prog8ANTLRParser.If_stmtContext.toAst(): IfStatement { + val condition = expression().toAst() + val trueStatements = statement_block()?.toAst() ?: mutableListOf(statement().toAst()) + val elseStatements = else_part()?.toAst() ?: mutableListOf() val trueScope = AnonymousScope(trueStatements, statement_block()?.toPosition() ?: statement().toPosition()) val elseScope = AnonymousScope(elseStatements, else_part()?.toPosition() ?: toPosition()) return IfStatement(condition, trueScope, elseScope, toPosition()) } -private fun Prog8ANTLRParser.Else_partContext.toAst(encoding: IStringEncoding): MutableList { - return statement_block()?.toAst(encoding) ?: mutableListOf(statement().toAst(encoding)) +private fun Prog8ANTLRParser.Else_partContext.toAst(): MutableList { + return statement_block()?.toAst() ?: mutableListOf(statement().toAst()) } -private fun Prog8ANTLRParser.Branch_stmtContext.toAst(encoding: IStringEncoding): BranchStatement { +private fun Prog8ANTLRParser.Branch_stmtContext.toAst(): BranchStatement { val branchcondition = branchcondition().toAst() - val trueStatements = statement_block()?.toAst(encoding) ?: mutableListOf(statement().toAst(encoding)) - val elseStatements = else_part()?.toAst(encoding) ?: mutableListOf() + val trueStatements = statement_block()?.toAst() ?: mutableListOf(statement().toAst()) + val elseStatements = else_part()?.toAst() ?: mutableListOf() val trueScope = AnonymousScope(trueStatements, statement_block()?.toPosition() ?: statement().toPosition()) val elseScope = AnonymousScope(elseStatements, else_part()?.toPosition() ?: toPosition()) @@ -538,65 +528,65 @@ private fun Prog8ANTLRParser.BranchconditionContext.toAst() = BranchCondition.va text.substringAfter('_').uppercase() ) -private fun Prog8ANTLRParser.ForloopContext.toAst(encoding: IStringEncoding): ForLoop { +private fun Prog8ANTLRParser.ForloopContext.toAst(): ForLoop { val loopvar = identifier().toAst() - val iterable = expression()!!.toAst(encoding) + val iterable = expression()!!.toAst() val scope = if(statement()!=null) - AnonymousScope(mutableListOf(statement().toAst(encoding)), statement().toPosition()) + AnonymousScope(mutableListOf(statement().toAst()), statement().toPosition()) else - AnonymousScope(statement_block().toAst(encoding), statement_block().toPosition()) + AnonymousScope(statement_block().toAst(), statement_block().toPosition()) return ForLoop(loopvar, iterable, scope, toPosition()) } private fun Prog8ANTLRParser.BreakstmtContext.toAst() = Break(toPosition()) -private fun Prog8ANTLRParser.WhileloopContext.toAst(encoding: IStringEncoding): WhileLoop { - val condition = expression().toAst(encoding) - val statements = statement_block()?.toAst(encoding) ?: mutableListOf(statement().toAst(encoding)) +private fun Prog8ANTLRParser.WhileloopContext.toAst(): WhileLoop { + val condition = expression().toAst() + val statements = statement_block()?.toAst() ?: mutableListOf(statement().toAst()) val scope = AnonymousScope(statements, statement_block()?.toPosition() ?: statement().toPosition()) return WhileLoop(condition, scope, toPosition()) } -private fun Prog8ANTLRParser.RepeatloopContext.toAst(encoding: IStringEncoding): RepeatLoop { - val iterations = expression()?.toAst(encoding) - val statements = statement_block()?.toAst(encoding) ?: mutableListOf(statement().toAst(encoding)) +private fun Prog8ANTLRParser.RepeatloopContext.toAst(): RepeatLoop { + val iterations = expression()?.toAst() + val statements = statement_block()?.toAst() ?: mutableListOf(statement().toAst()) val scope = AnonymousScope(statements, statement_block()?.toPosition() ?: statement().toPosition()) return RepeatLoop(iterations, scope, toPosition()) } -private fun Prog8ANTLRParser.UntilloopContext.toAst(encoding: IStringEncoding): UntilLoop { - val untilCondition = expression().toAst(encoding) - val statements = statement_block()?.toAst(encoding) ?: mutableListOf(statement().toAst(encoding)) +private fun Prog8ANTLRParser.UntilloopContext.toAst(): UntilLoop { + val untilCondition = expression().toAst() + val statements = statement_block()?.toAst() ?: mutableListOf(statement().toAst()) val scope = AnonymousScope(statements, statement_block()?.toPosition() ?: statement().toPosition()) return UntilLoop(scope, untilCondition, toPosition()) } -private fun Prog8ANTLRParser.WhenstmtContext.toAst(encoding: IStringEncoding): WhenStatement { - val condition = expression().toAst(encoding) - val choices = this.when_choice()?.map { it.toAst(encoding) }?.toMutableList() ?: mutableListOf() +private fun Prog8ANTLRParser.WhenstmtContext.toAst(): WhenStatement { + val condition = expression().toAst() + val choices = this.when_choice()?.map { it.toAst() }?.toMutableList() ?: mutableListOf() return WhenStatement(condition, choices, toPosition()) } -private fun Prog8ANTLRParser.When_choiceContext.toAst(encoding: IStringEncoding): WhenChoice { - val values = expression_list()?.toAst(encoding) - val stmt = statement()?.toAst(encoding) - val stmtBlock = statement_block()?.toAst(encoding)?.toMutableList() ?: mutableListOf() +private fun Prog8ANTLRParser.When_choiceContext.toAst(): WhenChoice { + val values = expression_list()?.toAst() + val stmt = statement()?.toAst() + val stmtBlock = statement_block()?.toAst()?.toMutableList() ?: mutableListOf() if(stmt!=null) stmtBlock.add(stmt) val scope = AnonymousScope(stmtBlock, toPosition()) return WhenChoice(values?.toMutableList(), scope, toPosition()) } -private fun Prog8ANTLRParser.VardeclContext.toAst(encoding: IStringEncoding): VarDecl { +private fun Prog8ANTLRParser.VardeclContext.toAst(): VarDecl { return VarDecl( VarDeclType.VAR, datatype()?.toAst() ?: DataType.UNDEFINED, if(ZEROPAGE() != null) ZeropageWish.PREFER_ZEROPAGE else ZeropageWish.DONTCARE, - arrayindex()?.toAst(encoding), + arrayindex()?.toAst(), varname.text, null, ARRAYSIG() != null || arrayindex() != null, diff --git a/compilerAst/src/prog8/parser/ModuleParsing.kt b/compilerAst/src/prog8/parser/ModuleParsing.kt index d54bc6925..78ac4f003 100644 --- a/compilerAst/src/prog8/parser/ModuleParsing.kt +++ b/compilerAst/src/prog8/parser/ModuleParsing.kt @@ -1,6 +1,5 @@ package prog8.parser -import prog8.ast.IStringEncoding import prog8.ast.Module import prog8.ast.Program import prog8.ast.base.Position @@ -17,7 +16,6 @@ fun moduleName(fileName: Path) = fileName.toString().substringBeforeLast('.') class ModuleImporter(private val program: Program, - private val encoder: IStringEncoding, private val compilationTargetName: String, private val libdirs: List) { diff --git a/compilerAst/src/prog8/parser/Petscii.kt b/compilerAst/src/prog8/parser/Petscii.kt deleted file mode 100644 index c79277af3..000000000 --- a/compilerAst/src/prog8/parser/Petscii.kt +++ /dev/null @@ -1,1171 +0,0 @@ -package prog8.parser - -import prog8.ast.antlr.escape -import java.io.CharConversionException - -object Petscii { - - // decoding: from Petscii/Screencodes (0-255) to unicode - // character tables used from https://github.com/dj51d/cbmcodecs - - private val decodingPetsciiLowercase = arrayOf( - '\u0000', // 0x00 -> \u0000 - '\ufffe', // 0x01 -> UNDEFINED - '\ufffe', // 0x02 -> UNDEFINED - '\ufffe', // 0x03 -> UNDEFINED - '\ufffe', // 0x04 -> UNDEFINED - '\uf100', // 0x05 -> WHITE COLOR SWITCH (CUS) - '\ufffe', // 0x06 -> UNDEFINED - '\ufffe', // 0x07 -> UNDEFINED - '\uf118', // 0x08 -> DISABLE CHARACTER SET SWITCHING (CUS) - '\uf119', // 0x09 -> ENABLE CHARACTER SET SWITCHING (CUS) - '\ufffe', // 0x0A -> UNDEFINED - '\ufffe', // 0x0B -> UNDEFINED - '\ufffe', // 0x0C -> UNDEFINED - '\r' , // 0x0D -> CARRIAGE RETURN - '\u000e', // 0x0E -> SHIFT OUT - '\ufffe', // 0x0F -> UNDEFINED - '\ufffe', // 0x10 -> UNDEFINED - '\uf11c', // 0x11 -> CURSOR DOWN (CUS) - '\uf11a', // 0x12 -> REVERSE VIDEO ON (CUS) - '\uf120', // 0x13 -> HOME (CUS) - '\u007f', // 0x14 -> DELETE - '\ufffe', // 0x15 -> UNDEFINED - '\ufffe', // 0x16 -> UNDEFINED - '\ufffe', // 0x17 -> UNDEFINED - '\ufffe', // 0x18 -> UNDEFINED - '\ufffe', // 0x19 -> UNDEFINED - '\ufffe', // 0x1A -> UNDEFINED - '\ufffe', // 0x1B -> UNDEFINED - '\uf101', // 0x1C -> RED COLOR SWITCH (CUS) - '\uf11d', // 0x1D -> CURSOR RIGHT (CUS) - '\uf102', // 0x1E -> GREEN COLOR SWITCH (CUS) - '\uf103', // 0x1F -> BLUE COLOR SWITCH (CUS) - ' ' , // 0x20 -> SPACE - '!' , // ! 0x21 -> EXCLAMATION MARK - '"' , // " 0x22 -> QUOTATION MARK - '#' , // # 0x23 -> NUMBER SIGN - '$' , // $ 0x24 -> DOLLAR SIGN - '%' , // % 0x25 -> PERCENT SIGN - '&' , // & 0x26 -> AMPERSAND - '\'' , // ' 0x27 -> APOSTROPHE - '(' , // ( 0x28 -> LEFT PARENTHESIS - ')' , // ) 0x29 -> RIGHT PARENTHESIS - '*' , // * 0x2A -> ASTERISK - '+' , // + 0x2B -> PLUS SIGN - ',' , // , 0x2C -> COMMA - '-' , // - 0x2D -> HYPHEN-MINUS - '.' , // . 0x2E -> FULL STOP - '/' , // / 0x2F -> SOLIDUS - '0' , // 0 0x30 -> DIGIT ZERO - '1' , // 1 0x31 -> DIGIT ONE - '2' , // 2 0x32 -> DIGIT TWO - '3' , // 3 0x33 -> DIGIT THREE - '4' , // 4 0x34 -> DIGIT FOUR - '5' , // 5 0x35 -> DIGIT FIVE - '6' , // 6 0x36 -> DIGIT SIX - '7' , // 7 0x37 -> DIGIT SEVEN - '8' , // 8 0x38 -> DIGIT EIGHT - '9' , // 9 0x39 -> DIGIT NINE - ':' , // : 0x3A -> COLON - ';' , // ; 0x3B -> SEMICOLON - '<' , // < 0x3C -> LESS-THAN SIGN - '=' , // = 0x3D -> EQUALS SIGN - '>' , // > 0x3E -> GREATER-THAN SIGN - '?' , // ? 0x3F -> QUESTION MARK - '@' , // @ 0x40 -> COMMERCIAL AT - 'a' , // a 0x41 -> LATIN SMALL LETTER A - 'b' , // b 0x42 -> LATIN SMALL LETTER B - 'c' , // c 0x43 -> LATIN SMALL LETTER C - 'd' , // d 0x44 -> LATIN SMALL LETTER D - 'e' , // e 0x45 -> LATIN SMALL LETTER E - 'f' , // f 0x46 -> LATIN SMALL LETTER F - 'g' , // g 0x47 -> LATIN SMALL LETTER G - 'h' , // h 0x48 -> LATIN SMALL LETTER H - 'i' , // i 0x49 -> LATIN SMALL LETTER I - 'j' , // j 0x4A -> LATIN SMALL LETTER J - 'k' , // k 0x4B -> LATIN SMALL LETTER K - 'l' , // l 0x4C -> LATIN SMALL LETTER L - 'm' , // m 0x4D -> LATIN SMALL LETTER M - 'n' , // n 0x4E -> LATIN SMALL LETTER N - 'o' , // o 0x4F -> LATIN SMALL LETTER O - 'p' , // p 0x50 -> LATIN SMALL LETTER P - 'q' , // q 0x51 -> LATIN SMALL LETTER Q - 'r' , // r 0x52 -> LATIN SMALL LETTER R - 's' , // s 0x53 -> LATIN SMALL LETTER S - 't' , // t 0x54 -> LATIN SMALL LETTER T - 'u' , // u 0x55 -> LATIN SMALL LETTER U - 'v' , // v 0x56 -> LATIN SMALL LETTER V - 'w' , // w 0x57 -> LATIN SMALL LETTER W - 'x' , // x 0x58 -> LATIN SMALL LETTER X - 'y' , // y 0x59 -> LATIN SMALL LETTER Y - 'z' , // z 0x5A -> LATIN SMALL LETTER Z - '[' , // [ 0x5B -> LEFT SQUARE BRACKET - '\u00a3', // £ 0x5C -> POUND SIGN - ']' , // ] 0x5D -> RIGHT SQUARE BRACKET - '\u2191', // ↑ 0x5E -> UPWARDS ARROW - '\u2190', // ← 0x5F -> LEFTWARDS ARROW - '\u2500', // ─ 0x60 -> BOX DRAWINGS LIGHT HORIZONTAL - 'A' , // A 0x61 -> LATIN CAPITAL LETTER A - 'B' , // B 0x62 -> LATIN CAPITAL LETTER B - 'C' , // C 0x63 -> LATIN CAPITAL LETTER C - 'D' , // D 0x64 -> LATIN CAPITAL LETTER D - 'E' , // E 0x65 -> LATIN CAPITAL LETTER E - 'F' , // F 0x66 -> LATIN CAPITAL LETTER F - 'G' , // G 0x67 -> LATIN CAPITAL LETTER G - 'H' , // H 0x68 -> LATIN CAPITAL LETTER H - 'I' , // I 0x69 -> LATIN CAPITAL LETTER I - 'J' , // J 0x6A -> LATIN CAPITAL LETTER J - 'K' , // K 0x6B -> LATIN CAPITAL LETTER K - 'L' , // L 0x6C -> LATIN CAPITAL LETTER L - 'M' , // M 0x6D -> LATIN CAPITAL LETTER M - 'N' , // N 0x6E -> LATIN CAPITAL LETTER N - 'O' , // O 0x6F -> LATIN CAPITAL LETTER O - 'P' , // P 0x70 -> LATIN CAPITAL LETTER P - 'Q' , // Q 0x71 -> LATIN CAPITAL LETTER Q - 'R' , // R 0x72 -> LATIN CAPITAL LETTER R - 'S' , // S 0x73 -> LATIN CAPITAL LETTER S - 'T' , // T 0x74 -> LATIN CAPITAL LETTER T - 'U' , // U 0x75 -> LATIN CAPITAL LETTER U - 'V' , // V 0x76 -> LATIN CAPITAL LETTER V - 'W' , // W 0x77 -> LATIN CAPITAL LETTER W - 'X' , // X 0x78 -> LATIN CAPITAL LETTER X - 'Y' , // Y 0x79 -> LATIN CAPITAL LETTER Y - 'Z' , // Z 0x7A -> LATIN CAPITAL LETTER Z - '\u253c', // ┼ 0x7B -> BOX DRAWINGS LIGHT VERTICAL AND HORIZONTAL - '\uf12e', //  0x7C -> LEFT HALF BLOCK MEDIUM SHADE (CUS) - '\u2502', // │ 0x7D -> BOX DRAWINGS LIGHT VERTICAL - '\u2592', // ▒ 0x7E -> MEDIUM SHADE - '\uf139', //  0x7F -> MEDIUM SHADE SLASHED LEFT (CUS) - '\ufffe', // 0x80 -> UNDEFINED - '\uf104', // 0x81 -> ORANGE COLOR SWITCH (CUS) - '\ufffe', // 0x82 -> UNDEFINED - '\ufffe', // 0x83 -> UNDEFINED - '\ufffe', // 0x84 -> UNDEFINED - '\uf110', //  0x85 -> FUNCTION KEY 1 (CUS) - '\uf112', //  0x86 -> FUNCTION KEY 3 (CUS) - '\uf114', //  0x87 -> FUNCTION KEY 5 (CUS) - '\uf116', //  0x88 -> FUNCTION KEY 7 (CUS) - '\uf111', //  0x89 -> FUNCTION KEY 2 (CUS) - '\uf113', //  0x8A -> FUNCTION KEY 4 (CUS) - '\uf115', //  0x8B -> FUNCTION KEY 6 (CUS) - '\uf117', //  0x8C -> FUNCTION KEY 8 (CUS) - '\n' , // 0x8D -> LINE FEED - '\u000f', //  0x8E -> SHIFT IN - '\ufffe', // 0x8F -> UNDEFINED - '\uf105', // 0x90 -> BLACK COLOR SWITCH (CUS) - '\uf11e', //  0x91 -> CURSOR UP (CUS) - '\uf11b', //  0x92 -> REVERSE VIDEO OFF (CUS) - '\u000c', // 0x93 -> FORM FEED - '\uf121', //  0x94 -> INSERT (CUS) - '\uf106', // 0x95 -> BROWN COLOR SWITCH (CUS) - '\uf107', // 0x96 -> LIGHT RED COLOR SWITCH (CUS) - '\uf108', // 0x97 -> GRAY 1 COLOR SWITCH (CUS) - '\uf109', //  0x98 -> GRAY 2 COLOR SWITCH (CUS) - '\uf10a', //  0x99 -> LIGHT GREEN COLOR SWITCH (CUS) - '\uf10b', //  0x9A -> LIGHT BLUE COLOR SWITCH (CUS) - '\uf10c', //  0x9B -> GRAY 3 COLOR SWITCH (CUS) - '\uf10d', //  0x9C -> PURPLE COLOR SWITCH (CUS) - '\uf11d', //  0x9D -> CURSOR LEFT (CUS) - '\uf10e', //  0x9E -> YELLOW COLOR SWITCH (CUS) - '\uf10f', //  0x9F -> CYAN COLOR SWITCH (CUS) - '\u00a0', // 0xA0 -> NO-BREAK SPACE - '\u258c', // ▌ 0xA1 -> LEFT HALF BLOCK - '\u2584', // ▄ 0xA2 -> LOWER HALF BLOCK - '\u2594', // ▔ 0xA3 -> UPPER ONE EIGHTH BLOCK - '\u2581', // ▁ 0xA4 -> LOWER ONE EIGHTH BLOCK - '\u258f', // ▏ 0xA5 -> LEFT ONE EIGHTH BLOCK - '\u2592', // ▒ 0xA6 -> MEDIUM SHADE - '\u2595', // ▕ 0xA7 -> RIGHT ONE EIGHTH BLOCK - '\uf12f', //  0xA8 -> LOWER HALF BLOCK MEDIUM SHADE (CUS) - '\uf13a', //  0xA9 -> MEDIUM SHADE SLASHED RIGHT (CUS) - '\uf130', //  0xAA -> RIGHT ONE QUARTER BLOCK (CUS) - '\u251c', // ├ 0xAB -> BOX DRAWINGS LIGHT VERTICAL AND RIGHT - '\u2597', // ▗ 0xAC -> QUADRANT LOWER RIGHT - '\u2514', // └ 0xAD -> BOX DRAWINGS LIGHT UP AND RIGHT - '\u2510', // ┐ 0xAE -> BOX DRAWINGS LIGHT DOWN AND LEFT - '\u2582', // ▂ 0xAF -> LOWER ONE QUARTER BLOCK - '\u250c', // ┌ 0xB0 -> BOX DRAWINGS LIGHT DOWN AND RIGHT - '\u2534', // ┴ 0xB1 -> BOX DRAWINGS LIGHT UP AND HORIZONTAL - '\u252c', // ┬ 0xB2 -> BOX DRAWINGS LIGHT DOWN AND HORIZONTAL - '\u2524', // ┤ 0xB3 -> BOX DRAWINGS LIGHT VERTICAL AND LEFT - '\u258e', // ▎ 0xB4 -> LEFT ONE QUARTER BLOCK - '\u258d', // ▍ 0xB5 -> LEFT THREE EIGTHS BLOCK - '\uf131', //  0xB6 -> RIGHT THREE EIGHTHS BLOCK (CUS) - '\uf132', //  0xB7 -> UPPER ONE QUARTER BLOCK (CUS) - '\uf133', //  0xB8 -> UPPER THREE EIGHTS BLOCK (CUS) - '\u2583', // ▃ 0xB9 -> LOWER THREE EIGHTHS BLOCK - '\u2713', // ✓ 0xBA -> CHECK MARK - '\u2596', // ▖ 0xBB -> QUADRANT LOWER LEFT - '\u259d', // ▝ 0xBC -> QUADRANT UPPER RIGHT - '\u2518', // ┘ 0xBD -> BOX DRAWINGS LIGHT UP AND LEFT - '\u2598', // ▘ 0xBE -> QUADRANT UPPER LEFT - '\u259a', // ▚ 0xBF -> QUADRANT UPPER LEFT AND LOWER RIGHT - '\u2500', // ─ 0xC0 -> BOX DRAWINGS LIGHT HORIZONTAL - 'A' , // A 0xC1 -> LATIN CAPITAL LETTER A - 'B' , // B 0xC2 -> LATIN CAPITAL LETTER B - 'C' , // C 0xC3 -> LATIN CAPITAL LETTER C - 'D' , // D 0xC4 -> LATIN CAPITAL LETTER D - 'E' , // E 0xC5 -> LATIN CAPITAL LETTER E - 'F' , // F 0xC6 -> LATIN CAPITAL LETTER F - 'G' , // G 0xC7 -> LATIN CAPITAL LETTER G - 'H' , // H 0xC8 -> LATIN CAPITAL LETTER H - 'I' , // I 0xC9 -> LATIN CAPITAL LETTER I - 'J' , // J 0xCA -> LATIN CAPITAL LETTER J - 'K' , // K 0xCB -> LATIN CAPITAL LETTER K - 'L' , // L 0xCC -> LATIN CAPITAL LETTER L - 'M' , // M 0xCD -> LATIN CAPITAL LETTER M - 'N' , // N 0xCE -> LATIN CAPITAL LETTER N - 'O' , // O 0xCF -> LATIN CAPITAL LETTER O - 'P' , // P 0xD0 -> LATIN CAPITAL LETTER P - 'Q' , // Q 0xD1 -> LATIN CAPITAL LETTER Q - 'R' , // R 0xD2 -> LATIN CAPITAL LETTER R - 'S' , // S 0xD3 -> LATIN CAPITAL LETTER S - 'T' , // T 0xD4 -> LATIN CAPITAL LETTER T - 'U' , // U 0xD5 -> LATIN CAPITAL LETTER U - 'V' , // V 0xD6 -> LATIN CAPITAL LETTER V - 'W' , // W 0xD7 -> LATIN CAPITAL LETTER W - 'X' , // X 0xD8 -> LATIN CAPITAL LETTER X - 'Y' , // Y 0xD9 -> LATIN CAPITAL LETTER Y - 'Z' , // Z 0xDA -> LATIN CAPITAL LETTER Z - '\u253c', // ┼ 0xDB -> BOX DRAWINGS LIGHT VERTICAL AND HORIZONTAL - '\uf12e', //  0xDC -> LEFT HALF BLOCK MEDIUM SHADE (CUS) - '\u2502', // │ 0xDD -> BOX DRAWINGS LIGHT VERTICAL - '\u2592', // ▒ 0xDE -> MEDIUM SHADE - '\uf139', //  0xDF -> MEDIUM SHADE SLASHED LEFT (CUS) - '\u00a0', // 0xE0 -> NO-BREAK SPACE - '\u258c', // ▌ 0xE1 -> LEFT HALF BLOCK - '\u2584', // ▄ 0xE2 -> LOWER HALF BLOCK - '\u2594', // ▔ 0xE3 -> UPPER ONE EIGHTH BLOCK - '\u2581', // ▁ 0xE4 -> LOWER ONE EIGHTH BLOCK - '\u258f', // ▏ 0xE5 -> LEFT ONE EIGHTH BLOCK - '\u2592', // ▒ 0xE6 -> MEDIUM SHADE - '\u2595', // ▕ 0xE7 -> RIGHT ONE EIGHTH BLOCK - '\uf12f', //  0xE8 -> LOWER HALF BLOCK MEDIUM SHADE (CUS) - '\uf13a', //  0xE9 -> MEDIUM SHADE SLASHED RIGHT (CUS) - '\uf130', //  0xEA -> RIGHT ONE QUARTER BLOCK (CUS) - '\u251c', // ├ 0xEB -> BOX DRAWINGS LIGHT VERTICAL AND RIGHT - '\u2597', // ▗ 0xEC -> QUADRANT LOWER RIGHT - '\u2514', // └ 0xED -> BOX DRAWINGS LIGHT UP AND RIGHT - '\u2510', // ┐ 0xEE -> BOX DRAWINGS LIGHT DOWN AND LEFT - '\u2582', // ▂ 0xEF -> LOWER ONE QUARTER BLOCK - '\u250c', // ┌ 0xF0 -> BOX DRAWINGS LIGHT DOWN AND RIGHT - '\u2534', // ┴ 0xF1 -> BOX DRAWINGS LIGHT UP AND HORIZONTAL - '\u252c', // ┬ 0xF2 -> BOX DRAWINGS LIGHT DOWN AND HORIZONTAL - '\u2524', // ┤ 0xF3 -> BOX DRAWINGS LIGHT VERTICAL AND LEFT - '\u258e', // ▎ 0xF4 -> LEFT ONE QUARTER BLOCK - '\u258d', // ▍ 0xF5 -> LEFT THREE EIGTHS BLOCK - '\uf131', //  0xF6 -> RIGHT THREE EIGHTHS BLOCK (CUS) - '\uf132', //  0xF7 -> UPPER ONE QUARTER BLOCK (CUS) - '\uf133', //  0xF8 -> UPPER THREE EIGHTS BLOCK (CUS) - '\u2583', // ▃ 0xF9 -> LOWER THREE EIGHTHS BLOCK - '\u2713', // ✓ 0xFA -> CHECK MARK - '\u2596', // ▖ 0xFB -> QUADRANT LOWER LEFT - '\u259d', // ▝ 0xFC -> QUADRANT UPPER RIGHT - '\u2518', // ┘ 0xFD -> BOX DRAWINGS LIGHT UP AND LEFT - '\u2598', // ▘ 0xFE -> QUADRANT UPPER LEFT - '\u2592' // ▒ 0xFF -> MEDIUM SHADE - ) - - private val decodingPetsciiUppercase = arrayOf( - '\u0000', // 0x00 -> \u0000 - '\ufffe', // 0x01 -> UNDEFINED - '\ufffe', // 0x02 -> UNDEFINED - '\ufffe', // 0x03 -> UNDEFINED - '\ufffe', // 0x04 -> UNDEFINED - '\uf100', // 0x05 -> WHITE COLOR SWITCH (CUS) - '\ufffe', // 0x06 -> UNDEFINED - '\ufffe', // 0x07 -> UNDEFINED - '\uf118', // 0x08 -> DISABLE CHARACTER SET SWITCHING (CUS) - '\uf119', // 0x09 -> ENABLE CHARACTER SET SWITCHING (CUS) - '\ufffe', // 0x0A -> UNDEFINED - '\ufffe', // 0x0B -> UNDEFINED - '\ufffe', // 0x0C -> UNDEFINED - '\r' , // 0x0D -> CARRIAGE RETURN - '\u000e', // 0x0E -> SHIFT OUT - '\ufffe', // 0x0F -> UNDEFINED - '\ufffe', // 0x10 -> UNDEFINED - '\uf11c', // 0x11 -> CURSOR DOWN (CUS) - '\uf11a', // 0x12 -> REVERSE VIDEO ON (CUS) - '\uf120', // 0x13 -> HOME (CUS) - '\u007f', // 0x14 -> DELETE - '\ufffe', // 0x15 -> UNDEFINED - '\ufffe', // 0x16 -> UNDEFINED - '\ufffe', // 0x17 -> UNDEFINED - '\ufffe', // 0x18 -> UNDEFINED - '\ufffe', // 0x19 -> UNDEFINED - '\ufffe', // 0x1A -> UNDEFINED - '\ufffe', // 0x1B -> UNDEFINED - '\uf101', // 0x1C -> RED COLOR SWITCH (CUS) - '\uf11d', // 0x1D -> CURSOR RIGHT (CUS) - '\uf102', // 0x1E -> GREEN COLOR SWITCH (CUS) - '\uf103', // 0x1F -> BLUE COLOR SWITCH (CUS) - ' ' , // 0x20 -> SPACE - '!' , // ! 0x21 -> EXCLAMATION MARK - '"' , // " 0x22 -> QUOTATION MARK - '#' , // # 0x23 -> NUMBER SIGN - '$' , // $ 0x24 -> DOLLAR SIGN - '%' , // % 0x25 -> PERCENT SIGN - '&' , // & 0x26 -> AMPERSAND - '\'' , // ' 0x27 -> APOSTROPHE - '(' , // ( 0x28 -> LEFT PARENTHESIS - ')' , // ) 0x29 -> RIGHT PARENTHESIS - '*' , // * 0x2A -> ASTERISK - '+' , // + 0x2B -> PLUS SIGN - ',' , // , 0x2C -> COMMA - '-' , // - 0x2D -> HYPHEN-MINUS - '.' , // . 0x2E -> FULL STOP - '/' , // / 0x2F -> SOLIDUS - '0' , // 0 0x30 -> DIGIT ZERO - '1' , // 1 0x31 -> DIGIT ONE - '2' , // 2 0x32 -> DIGIT TWO - '3' , // 3 0x33 -> DIGIT THREE - '4' , // 4 0x34 -> DIGIT FOUR - '5' , // 5 0x35 -> DIGIT FIVE - '6' , // 6 0x36 -> DIGIT SIX - '7' , // 7 0x37 -> DIGIT SEVEN - '8' , // 8 0x38 -> DIGIT EIGHT - '9' , // 9 0x39 -> DIGIT NINE - ':' , // : 0x3A -> COLON - ';' , // ; 0x3B -> SEMICOLON - '<' , // < 0x3C -> LESS-THAN SIGN - '=' , // = 0x3D -> EQUALS SIGN - '>' , // > 0x3E -> GREATER-THAN SIGN - '?' , // ? 0x3F -> QUESTION MARK - '@' , // @ 0x40 -> COMMERCIAL AT - 'A' , // A 0x41 -> LATIN CAPITAL LETTER A - 'B' , // B 0x42 -> LATIN CAPITAL LETTER B - 'C' , // C 0x43 -> LATIN CAPITAL LETTER C - 'D' , // D 0x44 -> LATIN CAPITAL LETTER D - 'E' , // E 0x45 -> LATIN CAPITAL LETTER E - 'F' , // F 0x46 -> LATIN CAPITAL LETTER F - 'G' , // G 0x47 -> LATIN CAPITAL LETTER G - 'H' , // H 0x48 -> LATIN CAPITAL LETTER H - 'I' , // I 0x49 -> LATIN CAPITAL LETTER I - 'J' , // J 0x4A -> LATIN CAPITAL LETTER J - 'K' , // K 0x4B -> LATIN CAPITAL LETTER K - 'L' , // L 0x4C -> LATIN CAPITAL LETTER L - 'M' , // M 0x4D -> LATIN CAPITAL LETTER M - 'N' , // N 0x4E -> LATIN CAPITAL LETTER N - 'O' , // O 0x4F -> LATIN CAPITAL LETTER O - 'P' , // P 0x50 -> LATIN CAPITAL LETTER P - 'Q' , // Q 0x51 -> LATIN CAPITAL LETTER Q - 'R' , // R 0x52 -> LATIN CAPITAL LETTER R - 'S' , // S 0x53 -> LATIN CAPITAL LETTER S - 'T' , // T 0x54 -> LATIN CAPITAL LETTER T - 'U' , // U 0x55 -> LATIN CAPITAL LETTER U - 'V' , // V 0x56 -> LATIN CAPITAL LETTER V - 'W' , // W 0x57 -> LATIN CAPITAL LETTER W - 'X' , // X 0x58 -> LATIN CAPITAL LETTER X - 'Y' , // Y 0x59 -> LATIN CAPITAL LETTER Y - 'Z' , // Z 0x5A -> LATIN CAPITAL LETTER Z - '[' , // [ 0x5B -> LEFT SQUARE BRACKET - '\u00a3', // £ 0x5C -> POUND SIGN - ']' , // ] 0x5D -> RIGHT SQUARE BRACKET - '\u2191', // ↑ 0x5E -> UPWARDS ARROW - '\u2190', // ← 0x5F -> LEFTWARDS ARROW - '\u2500', // ─ 0x60 -> BOX DRAWINGS LIGHT HORIZONTAL - '\u2660', // ♠ 0x61 -> BLACK SPADE SUIT - '\u2502', // │ 0x62 -> BOX DRAWINGS LIGHT VERTICAL - '\u2500', // ─ 0x63 -> BOX DRAWINGS LIGHT HORIZONTAL - '\uf122', //  0x64 -> BOX DRAWINGS LIGHT HORIZONTAL ONE QUARTER UP (CUS) - '\uf123', //  0x65 -> BOX DRAWINGS LIGHT HORIZONTAL TWO QUARTERS UP (CUS) - '\uf124', //  0x66 -> BOX DRAWINGS LIGHT HORIZONTAL ONE QUARTER DOWN (CUS) - '\uf126', //  0x67 -> BOX DRAWINGS LIGHT VERTICAL ONE QUARTER LEFT (CUS) - '\uf128', //  0x68 -> BOX DRAWINGS LIGHT VERTICAL ONE QUARTER RIGHT (CUS) - '\u256e', // ╮ 0x69 -> BOX DRAWINGS LIGHT ARC DOWN AND LEFT - '\u2570', // ╰ 0x6A -> BOX DRAWINGS LIGHT ARC UP AND RIGHT - '\u256f', // ╯ 0x6B -> BOX DRAWINGS LIGHT ARC UP AND LEFT - '\uf12a', //  0x6C -> ONE EIGHTH BLOCK UP AND RIGHT (CUS) - '\u2572', // ╲ 0x6D -> BOX DRAWINGS LIGHT DIAGONAL UPPER LEFT TO LOWER RIGHT - '\u2571', // ╱ 0x6E -> BOX DRAWINGS LIGHT DIAGONAL UPPER RIGHT TO LOWER LEFT - '\uf12b', //  0x6F -> ONE EIGHTH BLOCK DOWN AND RIGHT (CUS) - '\uf12c', //  0x70 -> ONE EIGHTH BLOCK DOWN AND LEFT (CUS) - '\u25cf', // ● 0x71 -> BLACK CIRCLE - '\uf125', //  0x72 -> BOX DRAWINGS LIGHT HORIZONTAL TWO QUARTERS DOWN (CUS) - '\u2665', // ♥ 0x73 -> BLACK HEART SUIT - '\uf127', //  0x74 -> BOX DRAWINGS LIGHT VERTICAL TWO QUARTERS LEFT (CUS) - '\u256d', // ╭ 0x75 -> BOX DRAWINGS LIGHT ARC DOWN AND RIGHT - '\u2573', // ╳ 0x76 -> BOX DRAWINGS LIGHT DIAGONAL CROSS - '\u25cb', // ○ 0x77 -> WHITE CIRCLE - '\u2663', // ♣ 0x78 -> BLACK CLUB SUIT - '\uf129', //  0x79 -> BOX DRAWINGS LIGHT VERTICAL TWO QUARTERS RIGHT (CUS) - '\u2666', // ♦ 0x7A -> BLACK DIAMOND SUIT - '\u253c', // ┼ 0x7B -> BOX DRAWINGS LIGHT VERTICAL AND HORIZONTAL - '\uf12e', //  0x7C -> LEFT HALF BLOCK MEDIUM SHADE (CUS) - '\u2502', // │ 0x7D -> BOX DRAWINGS LIGHT VERTICAL - '\u03c0', // π 0x7E -> GREEK SMALL LETTER PI - '\u25e5', // ◥ 0x7F -> BLACK UPPER RIGHT TRIANGLE - '\ufffe', // 0x80 -> UNDEFINED - '\uf104', //  0x81 -> ORANGE COLOR SWITCH (CUS) - '\ufffe', // 0x82 -> UNDEFINED - '\ufffe', // 0x83 -> UNDEFINED - '\ufffe', // 0x84 -> UNDEFINED - '\uf110', // 0x85 -> FUNCTION KEY 1 (CUS) - '\uf112', // 0x86 -> FUNCTION KEY 3 (CUS) - '\uf114', // 0x87 -> FUNCTION KEY 5 (CUS) - '\uf116', // 0x88 -> FUNCTION KEY 7 (CUS) - '\uf111', // 0x89 -> FUNCTION KEY 2 (CUS) - '\uf113', // 0x8A -> FUNCTION KEY 4 (CUS) - '\uf115', // 0x8B -> FUNCTION KEY 6 (CUS) - '\uf117', // 0x8C -> FUNCTION KEY 8 (CUS) - '\n' , // 0x8D -> LINE FEED - '\u000f', // 0x8E -> SHIFT IN - '\ufffe', // 0x8F -> UNDEFINED - '\uf105', // 0x90 -> BLACK COLOR SWITCH (CUS) - '\uf11e', // 0x91 -> CURSOR UP (CUS) - '\uf11b', // 0x92 -> REVERSE VIDEO OFF (CUS) - '\u000c', // 0x93 -> FORM FEED - '\uf121', // 0x94 -> INSERT (CUS) - '\uf106', // 0x95 -> BROWN COLOR SWITCH (CUS) - '\uf107', // 0x96 -> LIGHT RED COLOR SWITCH (CUS) - '\uf108', // 0x97 -> GRAY 1 COLOR SWITCH (CUS) - '\uf109', // 0x98 -> GRAY 2 COLOR SWITCH (CUS) - '\uf10a', // 0x99 -> LIGHT GREEN COLOR SWITCH (CUS) - '\uf10b', // 0x9A -> LIGHT BLUE COLOR SWITCH (CUS) - '\uf10c', // 0x9B -> GRAY 3 COLOR SWITCH (CUS) - '\uf10d', // 0x9C -> PURPLE COLOR SWITCH (CUS) - '\uf11d', // 0x9D -> CURSOR LEFT (CUS) - '\uf10e', // 0x9E -> YELLOW COLOR SWITCH (CUS) - '\uf10f', // 0x9F -> CYAN COLOR SWITCH (CUS) - '\u00a0', // 0xA0 -> NO-BREAK SPACE - '\u258c', // ▌ 0xA1 -> LEFT HALF BLOCK - '\u2584', // ▄ 0xA2 -> LOWER HALF BLOCK - '\u2594', // ▔ 0xA3 -> UPPER ONE EIGHTH BLOCK - '\u2581', // ▁ 0xA4 -> LOWER ONE EIGHTH BLOCK - '\u258f', // ▏ 0xA5 -> LEFT ONE EIGHTH BLOCK - '\u2592', // ▒ 0xA6 -> MEDIUM SHADE - '\u2595', // ▕ 0xA7 -> RIGHT ONE EIGHTH BLOCK - '\uf12f', //  0xA8 -> LOWER HALF BLOCK MEDIUM SHADE (CUS) - '\u25e4', // ◤ 0xA9 -> BLACK UPPER LEFT TRIANGLE - '\uf130', //  0xAA -> RIGHT ONE QUARTER BLOCK (CUS) - '\u251c', // ├ 0xAB -> BOX DRAWINGS LIGHT VERTICAL AND RIGHT - '\u2597', // ▗ 0xAC -> QUADRANT LOWER RIGHT - '\u2514', // └ 0xAD -> BOX DRAWINGS LIGHT UP AND RIGHT - '\u2510', // ┐ 0xAE -> BOX DRAWINGS LIGHT DOWN AND LEFT - '\u2582', // ▂ 0xAF -> LOWER ONE QUARTER BLOCK - '\u250c', // ┌ 0xB0 -> BOX DRAWINGS LIGHT DOWN AND RIGHT - '\u2534', // ┴ 0xB1 -> BOX DRAWINGS LIGHT UP AND HORIZONTAL - '\u252c', // ┬ 0xB2 -> BOX DRAWINGS LIGHT DOWN AND HORIZONTAL - '\u2524', // ┤ 0xB3 -> BOX DRAWINGS LIGHT VERTICAL AND LEFT - '\u258e', // ▎ 0xB4 -> LEFT ONE QUARTER BLOCK - '\u258d', // ▍ 0xB5 -> LEFT THREE EIGTHS BLOCK - '\uf131', //  0xB6 -> RIGHT THREE EIGHTHS BLOCK (CUS) - '\uf132', //  0xB7 -> UPPER ONE QUARTER BLOCK (CUS) - '\uf133', //  0xB8 -> UPPER THREE EIGHTS BLOCK (CUS) - '\u2583', // ▃ 0xB9 -> LOWER THREE EIGHTHS BLOCK - '\uf12d', //  0xBA -> ONE EIGHTH BLOCK UP AND LEFT (CUS) - '\u2596', // ▖ 0xBB -> QUADRANT LOWER LEFT - '\u259d', // ▝ 0xBC -> QUADRANT UPPER RIGHT - '\u2518', // ┘ 0xBD -> BOX DRAWINGS LIGHT UP AND LEFT - '\u2598', // ▘ 0xBE -> QUADRANT UPPER LEFT - '\u259a', // ▚ 0xBF -> QUADRANT UPPER LEFT AND LOWER RIGHT - '\u2500', // ─ 0xC0 -> BOX DRAWINGS LIGHT HORIZONTAL - '\u2660', // ♠ 0xC1 -> BLACK SPADE SUIT - '\u2502', // │ 0xC2 -> BOX DRAWINGS LIGHT VERTICAL - '\u2500', // ─ 0xC3 -> BOX DRAWINGS LIGHT HORIZONTAL - '\uf122', //  0xC4 -> BOX DRAWINGS LIGHT HORIZONTAL ONE QUARTER UP (CUS) - '\uf123', //  0xC5 -> BOX DRAWINGS LIGHT HORIZONTAL TWO QUARTERS UP (CUS) - '\uf124', //  0xC6 -> BOX DRAWINGS LIGHT HORIZONTAL ONE QUARTER DOWN (CUS) - '\uf126', //  0xC7 -> BOX DRAWINGS LIGHT VERTICAL ONE QUARTER LEFT (CUS) - '\uf128', //  0xC8 -> BOX DRAWINGS LIGHT VERTICAL ONE QUARTER RIGHT (CUS) - '\u256e', // ╮ 0xC9 -> BOX DRAWINGS LIGHT ARC DOWN AND LEFT - '\u2570', // ╰ 0xCA -> BOX DRAWINGS LIGHT ARC UP AND RIGHT - '\u256f', // ╯ 0xCB -> BOX DRAWINGS LIGHT ARC UP AND LEFT - '\uf12a', //  0xCC -> ONE EIGHTH BLOCK UP AND RIGHT (CUS) - '\u2572', // ╲ 0xCD -> BOX DRAWINGS LIGHT DIAGONAL UPPER LEFT TO LOWER RIGHT - '\u2571', // ╱ 0xCE -> BOX DRAWINGS LIGHT DIAGONAL UPPER RIGHT TO LOWER LEFT - '\uf12b', //  0xCF -> ONE EIGHTH BLOCK DOWN AND RIGHT (CUS) - '\uf12c', //  0xD0 -> ONE EIGHTH BLOCK DOWN AND LEFT (CUS) - '\u25cf', // ● 0xD1 -> BLACK CIRCLE - '\uf125', //  0xD2 -> BOX DRAWINGS LIGHT HORIZONTAL TWO QUARTERS DOWN (CUS) - '\u2665', // ♥ 0xD3 -> BLACK HEART SUIT - '\uf127', //  0xD4 -> BOX DRAWINGS LIGHT VERTICAL TWO QUARTERS LEFT (CUS) - '\u256d', // ╭ 0xD5 -> BOX DRAWINGS LIGHT ARC DOWN AND LEFT - '\u2573', // ╳ 0xD6 -> BOX DRAWINGS LIGHT DIAGONAL CROSS - '\u25cb', // ○ 0xD7 -> WHITE CIRCLE - '\u2663', // ♣ 0xD8 -> BLACK CLUB SUIT - '\uf129', //  0xD9 -> BOX DRAWINGS LIGHT VERTICAL TWO QUARTERS RIGHT (CUS) - '\u2666', // ♦ 0xDA -> BLACK DIAMOND SUIT - '\u253c', // ┼ 0xDB -> BOX DRAWINGS LIGHT VERTICAL AND HORIZONTAL - '\uf12e', //  0xDC -> LEFT HALF BLOCK MEDIUM SHADE (CUS) - '\u2502', // │ 0xDD -> BOX DRAWINGS LIGHT VERTICAL - '\u03c0', // π 0xDE -> GREEK SMALL LETTER PI - '\u25e5', // ◥ 0xDF -> BLACK UPPER RIGHT TRIANGLE - '\u00a0', // 0xE0 -> NO-BREAK SPACE - '\u258c', // ▌ 0xE1 -> LEFT HALF BLOCK - '\u2584', // ▄ 0xE2 -> LOWER HALF BLOCK - '\u2594', // ▔ 0xE3 -> UPPER ONE EIGHTH BLOCK - '\u2581', // ▁ 0xE4 -> LOWER ONE EIGHTH BLOCK - '\u258f', // ▏ 0xE5 -> LEFT ONE EIGHTH BLOCK - '\u2592', // ▒ 0xE6 -> MEDIUM SHADE - '\u2595', // ▕ 0xE7 -> RIGHT ONE EIGHTH BLOCK - '\uf12f', //  0xE8 -> LOWER HALF BLOCK MEDIUM SHADE (CUS) - '\u25e4', // ◤ 0xE9 -> BLACK UPPER LEFT TRIANGLE - '\uf130', //  0xEA -> RIGHT ONE QUARTER BLOCK (CUS) - '\u251c', // ├ 0xEB -> BOX DRAWINGS LIGHT VERTICAL AND RIGHT - '\u2597', // ▗ 0xEC -> QUADRANT LOWER RIGHT - '\u2514', // └ 0xED -> BOX DRAWINGS LIGHT UP AND RIGHT - '\u2510', // ┐ 0xEE -> BOX DRAWINGS LIGHT DOWN AND LEFT - '\u2582', // ▂ 0xEF -> LOWER ONE QUARTER BLOCK - '\u250c', // ┌ 0xF0 -> BOX DRAWINGS LIGHT DOWN AND RIGHT - '\u2534', // ┴ 0xF1 -> BOX DRAWINGS LIGHT UP AND HORIZONTAL - '\u252c', // ┬ 0xF2 -> BOX DRAWINGS LIGHT DOWN AND HORIZONTAL - '\u2524', // ┤ 0xF3 -> BOX DRAWINGS LIGHT VERTICAL AND LEFT - '\u258e', // ▎ 0xF4 -> LEFT ONE QUARTER BLOCK - '\u258d', // ▍ 0xF5 -> LEFT THREE EIGTHS BLOCK - '\uf131', //  0xF6 -> RIGHT THREE EIGHTHS BLOCK (CUS) - '\uf132', //  0xF7 -> UPPER ONE QUARTER BLOCK (CUS) - '\uf133', //  0xF8 -> UPPER THREE EIGHTS BLOCK (CUS) - '\u2583', // ▃ 0xF9 -> LOWER THREE EIGHTHS BLOCK - '\uf12d', //  0xFA -> ONE EIGHTH BLOCK UP AND LEFT (CUS) - '\u2596', // ▖ 0xFB -> QUADRANT LOWER LEFT - '\u259d', // ▝ 0xFC -> QUADRANT UPPER RIGHT - '\u2518', // ┘ 0xFD -> BOX DRAWINGS LIGHT UP AND LEFT - '\u2598', // ▘ 0xFE -> QUADRANT UPPER LEFT - '\u03c0' // π 0xFF -> GREEK SMALL LETTER PI - ) - - private val decodingScreencodeLowercase = arrayOf( - '@' , // @ 0x00 -> COMMERCIAL AT - 'a' , // a 0x01 -> LATIN SMALL LETTER A - 'b' , // b 0x02 -> LATIN SMALL LETTER B - 'c' , // c 0x03 -> LATIN SMALL LETTER C - 'd' , // d 0x04 -> LATIN SMALL LETTER D - 'e' , // e 0x05 -> LATIN SMALL LETTER E - 'f' , // f 0x06 -> LATIN SMALL LETTER F - 'g' , // g 0x07 -> LATIN SMALL LETTER G - 'h' , // h 0x08 -> LATIN SMALL LETTER H - 'i' , // i 0x09 -> LATIN SMALL LETTER I - 'j' , // j 0x0A -> LATIN SMALL LETTER J - 'k' , // k 0x0B -> LATIN SMALL LETTER K - 'l' , // l 0x0C -> LATIN SMALL LETTER L - 'm' , // m 0x0D -> LATIN SMALL LETTER M - 'n' , // n 0x0E -> LATIN SMALL LETTER N - 'o' , // o 0x0F -> LATIN SMALL LETTER O - 'p' , // p 0x10 -> LATIN SMALL LETTER P - 'q' , // q 0x11 -> LATIN SMALL LETTER Q - 'r' , // r 0x12 -> LATIN SMALL LETTER R - 's' , // s 0x13 -> LATIN SMALL LETTER S - 't' , // t 0x14 -> LATIN SMALL LETTER T - 'u' , // u 0x15 -> LATIN SMALL LETTER U - 'v' , // v 0x16 -> LATIN SMALL LETTER V - 'w' , // w 0x17 -> LATIN SMALL LETTER W - 'x' , // x 0x18 -> LATIN SMALL LETTER X - 'y' , // y 0x19 -> LATIN SMALL LETTER Y - 'z' , // z 0x1A -> LATIN SMALL LETTER Z - '[' , // [ 0x1B -> LEFT SQUARE BRACKET - '\u00a3', // £ 0x1C -> POUND SIGN - ']' , // ] 0x1D -> RIGHT SQUARE BRACKET - '\u2191', // ↑ 0x1E -> UPWARDS ARROW - '\u2190', // ← 0x1F -> LEFTWARDS ARROW - ' ' , // 0x20 -> SPACE - '!' , // ! 0x21 -> EXCLAMATION MARK - '"' , // " 0x22 -> QUOTATION MARK - '#' , // # 0x23 -> NUMBER SIGN - '$' , // $ 0x24 -> DOLLAR SIGN - '%' , // % 0x25 -> PERCENT SIGN - '&' , // & 0x26 -> AMPERSAND - '\'' , // ' 0x27 -> APOSTROPHE - '(' , // ( 0x28 -> LEFT PARENTHESIS - ')' , // ) 0x29 -> RIGHT PARENTHESIS - '*' , // * 0x2A -> ASTERISK - '+' , // + 0x2B -> PLUS SIGN - ',' , // , 0x2C -> COMMA - '-' , // - 0x2D -> HYPHEN-MINUS - '.' , // . 0x2E -> FULL STOP - '/' , // / 0x2F -> SOLIDUS - '0' , // 0 0x30 -> DIGIT ZERO - '1' , // 1 0x31 -> DIGIT ONE - '2' , // 2 0x32 -> DIGIT TWO - '3' , // 3 0x33 -> DIGIT THREE - '4' , // 4 0x34 -> DIGIT FOUR - '5' , // 5 0x35 -> DIGIT FIVE - '6' , // 6 0x36 -> DIGIT SIX - '7' , // 7 0x37 -> DIGIT SEVEN - '8' , // 8 0x38 -> DIGIT EIGHT - '9' , // 9 0x39 -> DIGIT NINE - ':' , // : 0x3A -> COLON - ';' , // ; 0x3B -> SEMICOLON - '<' , // < 0x3C -> LESS-THAN SIGN - '=' , // = 0x3D -> EQUALS SIGN - '>' , // > 0x3E -> GREATER-THAN SIGN - '?' , // ? 0x3F -> QUESTION MARK - '\u2500', // ─ 0x40 -> BOX DRAWINGS LIGHT HORIZONTAL - 'A' , // A 0x41 -> LATIN CAPITAL LETTER A - 'B' , // B 0x42 -> LATIN CAPITAL LETTER B - 'C' , // C 0x43 -> LATIN CAPITAL LETTER C - 'D' , // D 0x44 -> LATIN CAPITAL LETTER D - 'E' , // E 0x45 -> LATIN CAPITAL LETTER E - 'F' , // F 0x46 -> LATIN CAPITAL LETTER F - 'G' , // G 0x47 -> LATIN CAPITAL LETTER G - 'H' , // H 0x48 -> LATIN CAPITAL LETTER H - 'I' , // I 0x49 -> LATIN CAPITAL LETTER I - 'J' , // J 0x4A -> LATIN CAPITAL LETTER J - 'K' , // K 0x4B -> LATIN CAPITAL LETTER K - 'L' , // L 0x4C -> LATIN CAPITAL LETTER L - 'M' , // M 0x4D -> LATIN CAPITAL LETTER M - 'N' , // N 0x4E -> LATIN CAPITAL LETTER N - 'O' , // O 0x4F -> LATIN CAPITAL LETTER O - 'P' , // P 0x50 -> LATIN CAPITAL LETTER P - 'Q' , // Q 0x51 -> LATIN CAPITAL LETTER Q - 'R' , // R 0x52 -> LATIN CAPITAL LETTER R - 'S' , // S 0x53 -> LATIN CAPITAL LETTER S - 'T' , // T 0x54 -> LATIN CAPITAL LETTER T - 'U' , // U 0x55 -> LATIN CAPITAL LETTER U - 'V' , // V 0x56 -> LATIN CAPITAL LETTER V - 'W' , // W 0x57 -> LATIN CAPITAL LETTER W - 'X' , // X 0x58 -> LATIN CAPITAL LETTER X - 'Y' , // Y 0x59 -> LATIN CAPITAL LETTER Y - 'Z' , // Z 0x5A -> LATIN CAPITAL LETTER Z - '\u253c', // ┼ 0x5B -> BOX DRAWINGS LIGHT VERTICAL AND HORIZONTAL - '\uf12e', //  0x5C -> LEFT HALF BLOCK MEDIUM SHADE (CUS) - '\u2502', // │ 0x5D -> BOX DRAWINGS LIGHT VERTICAL - '\u2592', // ▒ 0x5E -> MEDIUM SHADE - '\uf139', //  0x5F -> MEDIUM SHADE SLASHED LEFT (CUS) - '\u00a0', // 0x60 -> NO-BREAK SPACE - '\u258c', // ▌ 0x61 -> LEFT HALF BLOCK - '\u2584', // ▄ 0x62 -> LOWER HALF BLOCK - '\u2594', // ▔ 0x63 -> UPPER ONE EIGHTH BLOCK - '\u2581', // ▁ 0x64 -> LOWER ONE EIGHTH BLOCK - '\u258f', // ▏ 0x65 -> LEFT ONE EIGHTH BLOCK - '\u2592', // ▒ 0x66 -> MEDIUM SHADE - '\u2595', // ▕ 0x67 -> RIGHT ONE EIGHTH BLOCK - '\uf12f', //  0x68 -> LOWER HALF BLOCK MEDIUM SHADE (CUS) - '\uf13a', //  0x69 -> MEDIUM SHADE SLASHED RIGHT (CUS) - '\uf130', //  0x6A -> RIGHT ONE QUARTER BLOCK (CUS) - '\u251c', // ├ 0x6B -> BOX DRAWINGS LIGHT VERTICAL AND RIGHT - '\u2597', // ▗ 0x6C -> QUADRANT LOWER RIGHT - '\u2514', // └ 0x6D -> BOX DRAWINGS LIGHT UP AND RIGHT - '\u2510', // ┐ 0x6E -> BOX DRAWINGS LIGHT DOWN AND LEFT - '\u2582', // ▂ 0x6F -> LOWER ONE QUARTER BLOCK - '\u250c', // ┌ 0x70 -> BOX DRAWINGS LIGHT DOWN AND RIGHT - '\u2534', // ┴ 0x71 -> BOX DRAWINGS LIGHT UP AND HORIZONTAL - '\u252c', // ┬ 0x72 -> BOX DRAWINGS LIGHT DOWN AND HORIZONTAL - '\u2524', // ┤ 0x73 -> BOX DRAWINGS LIGHT VERTICAL AND LEFT - '\u258e', // ▎ 0x74 -> LEFT ONE QUARTER BLOCK - '\u258d', // ▍ 0x75 -> LEFT THREE EIGTHS BLOCK - '\uf131', //  0x76 -> RIGHT THREE EIGHTHS BLOCK (CUS) - '\uf132', //  0x77 -> UPPER ONE QUARTER BLOCK (CUS) - '\uf133', //  0x78 -> UPPER THREE EIGHTS BLOCK (CUS) - '\u2583', // ▃ 0x79 -> LOWER THREE EIGHTHS BLOCK - '\u2713', // ✓ 0x7A -> CHECK MARK - '\u2596', // ▖ 0x7B -> QUADRANT LOWER LEFT - '\u259d', // ▝ 0x7C -> QUADRANT UPPER RIGHT - '\u2518', // ┘ 0x7D -> BOX DRAWINGS LIGHT UP AND LEFT - '\u2598', // ▘ 0x7E -> QUADRANT UPPER LEFT - '\u259a', // ▚ 0x7F -> QUADRANT UPPER LEFT AND LOWER RIGHT - '\ufffe', // 0x80 -> UNDEFINED - '\ufffe', // 0x81 -> UNDEFINED - '\ufffe', // 0x82 -> UNDEFINED - '\ufffe', // 0x83 -> UNDEFINED - '\ufffe', // 0x84 -> UNDEFINED - '\ufffe', // 0x85 -> UNDEFINED - '\ufffe', // 0x86 -> UNDEFINED - '\ufffe', // 0x87 -> UNDEFINED - '\ufffe', // 0x88 -> UNDEFINED - '\ufffe', // 0x89 -> UNDEFINED - '\ufffe', // 0x8A -> UNDEFINED - '\ufffe', // 0x8B -> UNDEFINED - '\ufffe', // 0x8C -> UNDEFINED - '\ufffe', // 0x8D -> UNDEFINED - '\ufffe', // 0x8E -> UNDEFINED - '\ufffe', // 0x8F -> UNDEFINED - '\ufffe', // 0x90 -> UNDEFINED - '\ufffe', // 0x91 -> UNDEFINED - '\ufffe', // 0x92 -> UNDEFINED - '\ufffe', // 0x93 -> UNDEFINED - '\ufffe', // 0x94 -> UNDEFINED - '\ufffe', // 0x95 -> UNDEFINED - '\ufffe', // 0x96 -> UNDEFINED - '\ufffe', // 0x97 -> UNDEFINED - '\ufffe', // 0x98 -> UNDEFINED - '\ufffe', // 0x99 -> UNDEFINED - '\ufffe', // 0x9A -> UNDEFINED - '\ufffe', // 0x9B -> UNDEFINED - '\ufffe', // 0x9C -> UNDEFINED - '\ufffe', // 0x9D -> UNDEFINED - '\ufffe', // 0x9E -> UNDEFINED - '\ufffe', // 0x9F -> UNDEFINED - '\ufffe', // 0xA0 -> UNDEFINED - '\ufffe', // 0xA1 -> UNDEFINED - '\ufffe', // 0xA2 -> UNDEFINED - '\ufffe', // 0xA3 -> UNDEFINED - '\ufffe', // 0xA4 -> UNDEFINED - '\ufffe', // 0xA5 -> UNDEFINED - '\ufffe', // 0xA6 -> UNDEFINED - '\ufffe', // 0xA7 -> UNDEFINED - '\ufffe', // 0xA8 -> UNDEFINED - '\ufffe', // 0xA9 -> UNDEFINED - '\ufffe', // 0xAA -> UNDEFINED - '\ufffe', // 0xAB -> UNDEFINED - '\ufffe', // 0xAC -> UNDEFINED - '\ufffe', // 0xAD -> UNDEFINED - '\ufffe', // 0xAE -> UNDEFINED - '\ufffe', // 0xAF -> UNDEFINED - '\ufffe', // 0xB0 -> UNDEFINED - '\ufffe', // 0xB1 -> UNDEFINED - '\ufffe', // 0xB2 -> UNDEFINED - '\ufffe', // 0xB3 -> UNDEFINED - '\ufffe', // 0xB4 -> UNDEFINED - '\ufffe', // 0xB5 -> UNDEFINED - '\ufffe', // 0xB6 -> UNDEFINED - '\ufffe', // 0xB7 -> UNDEFINED - '\ufffe', // 0xB8 -> UNDEFINED - '\ufffe', // 0xB9 -> UNDEFINED - '\ufffe', // 0xBA -> UNDEFINED - '\ufffe', // 0xBB -> UNDEFINED - '\ufffe', // 0xBC -> UNDEFINED - '\ufffe', // 0xBD -> UNDEFINED - '\ufffe', // 0xBE -> UNDEFINED - '\ufffe', // 0xBF -> UNDEFINED - '\ufffe', // 0xC0 -> UNDEFINED - '\ufffe', // 0xC1 -> UNDEFINED - '\ufffe', // 0xC2 -> UNDEFINED - '\ufffe', // 0xC3 -> UNDEFINED - '\ufffe', // 0xC4 -> UNDEFINED - '\ufffe', // 0xC5 -> UNDEFINED - '\ufffe', // 0xC6 -> UNDEFINED - '\ufffe', // 0xC7 -> UNDEFINED - '\ufffe', // 0xC8 -> UNDEFINED - '\ufffe', // 0xC9 -> UNDEFINED - '\ufffe', // 0xCA -> UNDEFINED - '\ufffe', // 0xCB -> UNDEFINED - '\ufffe', // 0xCC -> UNDEFINED - '\ufffe', // 0xCD -> UNDEFINED - '\ufffe', // 0xCE -> UNDEFINED - '\ufffe', // 0xCF -> UNDEFINED - '\ufffe', // 0xD0 -> UNDEFINED - '\ufffe', // 0xD1 -> UNDEFINED - '\ufffe', // 0xD2 -> UNDEFINED - '\ufffe', // 0xD3 -> UNDEFINED - '\ufffe', // 0xD4 -> UNDEFINED - '\ufffe', // 0xD5 -> UNDEFINED - '\ufffe', // 0xD6 -> UNDEFINED - '\ufffe', // 0xD7 -> UNDEFINED - '\ufffe', // 0xD8 -> UNDEFINED - '\ufffe', // 0xD9 -> UNDEFINED - '\ufffe', // 0xDA -> UNDEFINED - '\ufffe', // 0xDB -> UNDEFINED - '\ufffe', // 0xDC -> UNDEFINED - '\ufffe', // 0xDD -> UNDEFINED - '\ufffe', // 0xDE -> UNDEFINED - '\ufffe', // 0xDF -> UNDEFINED - '\ufffe', // 0xE0 -> UNDEFINED - '\ufffe', // 0xE1 -> UNDEFINED - '\ufffe', // 0xE2 -> UNDEFINED - '\ufffe', // 0xE3 -> UNDEFINED - '\ufffe', // 0xE4 -> UNDEFINED - '\ufffe', // 0xE5 -> UNDEFINED - '\ufffe', // 0xE6 -> UNDEFINED - '\ufffe', // 0xE7 -> UNDEFINED - '\ufffe', // 0xE8 -> UNDEFINED - '\ufffe', // 0xE9 -> UNDEFINED - '\ufffe', // 0xEA -> UNDEFINED - '\ufffe', // 0xEB -> UNDEFINED - '\ufffe', // 0xEC -> UNDEFINED - '\ufffe', // 0xED -> UNDEFINED - '\ufffe', // 0xEE -> UNDEFINED - '\ufffe', // 0xEF -> UNDEFINED - '\ufffe', // 0xF0 -> UNDEFINED - '\ufffe', // 0xF1 -> UNDEFINED - '\ufffe', // 0xF2 -> UNDEFINED - '\ufffe', // 0xF3 -> UNDEFINED - '\ufffe', // 0xF4 -> UNDEFINED - '\ufffe', // 0xF5 -> UNDEFINED - '\ufffe', // 0xF6 -> UNDEFINED - '\ufffe', // 0xF7 -> UNDEFINED - '\ufffe', // 0xF8 -> UNDEFINED - '\ufffe', // 0xF9 -> UNDEFINED - '\ufffe', // 0xFA -> UNDEFINED - '\ufffe', // 0xFB -> UNDEFINED - '\ufffe', // 0xFC -> UNDEFINED - '\ufffe', // 0xFD -> UNDEFINED - '\ufffe', // 0xFE -> UNDEFINED - '\ufffe' // 0xFF -> UNDEFINED - ) - - private val decodingScreencodeUppercase = arrayOf( - '@' , // @ 0x00 -> COMMERCIAL AT - 'A' , // A 0x01 -> LATIN CAPITAL LETTER A - 'B' , // B 0x02 -> LATIN CAPITAL LETTER B - 'C' , // C 0x03 -> LATIN CAPITAL LETTER C - 'D' , // D 0x04 -> LATIN CAPITAL LETTER D - 'E' , // E 0x05 -> LATIN CAPITAL LETTER E - 'F' , // F 0x06 -> LATIN CAPITAL LETTER F - 'G' , // G 0x07 -> LATIN CAPITAL LETTER G - 'H' , // H 0x08 -> LATIN CAPITAL LETTER H - 'I' , // I 0x09 -> LATIN CAPITAL LETTER I - 'J' , // J 0x0A -> LATIN CAPITAL LETTER J - 'K' , // K 0x0B -> LATIN CAPITAL LETTER K - 'L' , // L 0x0C -> LATIN CAPITAL LETTER L - 'M' , // M 0x0D -> LATIN CAPITAL LETTER M - 'N' , // N 0x0E -> LATIN CAPITAL LETTER N - 'O' , // O 0x0F -> LATIN CAPITAL LETTER O - 'P' , // P 0x10 -> LATIN CAPITAL LETTER P - 'Q' , // Q 0x11 -> LATIN CAPITAL LETTER Q - 'R' , // R 0x12 -> LATIN CAPITAL LETTER R - 'S' , // S 0x13 -> LATIN CAPITAL LETTER S - 'T' , // T 0x14 -> LATIN CAPITAL LETTER T - 'U' , // U 0x15 -> LATIN CAPITAL LETTER U - 'V' , // V 0x16 -> LATIN CAPITAL LETTER V - 'W' , // W 0x17 -> LATIN CAPITAL LETTER W - 'X' , // X 0x18 -> LATIN CAPITAL LETTER X - 'Y' , // Y 0x19 -> LATIN CAPITAL LETTER Y - 'Z' , // Z 0x1A -> LATIN CAPITAL LETTER Z - '[' , // [ 0x1B -> LEFT SQUARE BRACKET - '\u00a3', // £ 0x1C -> POUND SIGN - ']' , // ] 0x1D -> RIGHT SQUARE BRACKET - '\u2191', // ↑ 0x1E -> UPWARDS ARROW - '\u2190', // ← 0x1F -> LEFTWARDS ARROW - ' ' , // 0x20 -> SPACE - '!' , // ! 0x21 -> EXCLAMATION MARK - '"' , // " 0x22 -> QUOTATION MARK - '#' , // # 0x23 -> NUMBER SIGN - '$' , // $ 0x24 -> DOLLAR SIGN - '%' , // % 0x25 -> PERCENT SIGN - '&' , // & 0x26 -> AMPERSAND - '\'' , // ' 0x27 -> APOSTROPHE - '(' , // ( 0x28 -> LEFT PARENTHESIS - ')' , // ) 0x29 -> RIGHT PARENTHESIS - '*' , // * 0x2A -> ASTERISK - '+' , // + 0x2B -> PLUS SIGN - ',' , // , 0x2C -> COMMA - '-' , // - 0x2D -> HYPHEN-MINUS - '.' , // . 0x2E -> FULL STOP - '/' , // / 0x2F -> SOLIDUS - '0' , // 0 0x30 -> DIGIT ZERO - '1' , // 1 0x31 -> DIGIT ONE - '2' , // 2 0x32 -> DIGIT TWO - '3' , // 3 0x33 -> DIGIT THREE - '4' , // 4 0x34 -> DIGIT FOUR - '5' , // 5 0x35 -> DIGIT FIVE - '6' , // 6 0x36 -> DIGIT SIX - '7' , // 7 0x37 -> DIGIT SEVEN - '8' , // 8 0x38 -> DIGIT EIGHT - '9' , // 9 0x39 -> DIGIT NINE - ':' , // : 0x3A -> COLON - ';' , // ; 0x3B -> SEMICOLON - '<' , // < 0x3C -> LESS-THAN SIGN - '=' , // = 0x3D -> EQUALS SIGN - '>' , // > 0x3E -> GREATER-THAN SIGN - '?' , // ? 0x3F -> QUESTION MARK - '\u2500', // ─ 0x40 -> BOX DRAWINGS LIGHT HORIZONTAL - '\u2660', // ♠ 0x41 -> BLACK SPADE SUIT - '\u2502', // │ 0x42 -> BOX DRAWINGS LIGHT VERTICAL - '\u2500', // ─ 0x43 -> BOX DRAWINGS LIGHT HORIZONTAL - '\uf122', //  0x44 -> BOX DRAWINGS LIGHT HORIZONTAL ONE QUARTER UP (CUS) - '\uf123', //  0x45 -> BOX DRAWINGS LIGHT HORIZONTAL TWO QUARTERS UP (CUS) - '\uf124', //  0x46 -> BOX DRAWINGS LIGHT HORIZONTAL ONE QUARTER DOWN (CUS) - '\uf126', //  0x47 -> BOX DRAWINGS LIGHT VERTICAL ONE QUARTER LEFT (CUS) - '\uf128', //  0x48 -> BOX DRAWINGS LIGHT VERTICAL ONE QUARTER RIGHT (CUS) - '\u256e', // ╮ 0x49 -> BOX DRAWINGS LIGHT ARC DOWN AND LEFT - '\u2570', // ╰ 0x4A -> BOX DRAWINGS LIGHT ARC UP AND RIGHT - '\u256f', // ╯ 0x4B -> BOX DRAWINGS LIGHT ARC UP AND LEFT - '\uf12a', //  0x4C -> ONE EIGHTH BLOCK UP AND RIGHT (CUS) - '\u2572', // ╲ 0x4D -> BOX DRAWINGS LIGHT DIAGONAL UPPER LEFT TO LOWER RIGHT - '\u2571', // ╱ 0x4E -> BOX DRAWINGS LIGHT DIAGONAL UPPER RIGHT TO LOWER LEFT - '\uf12b', //  0x4F -> ONE EIGHTH BLOCK DOWN AND RIGHT (CUS) - '\uf12c', //  0x50 -> ONE EIGHTH BLOCK DOWN AND LEFT (CUS) - '\u25cf', // ● 0x51 -> BLACK CIRCLE - '\uf125', //  0x52 -> BOX DRAWINGS LIGHT HORIZONTAL TWO QUARTERS DOWN (CUS) - '\u2665', // ♥ 0x53 -> BLACK HEART SUIT - '\uf127', //  0x54 -> BOX DRAWINGS LIGHT VERTICAL TWO QUARTERS LEFT (CUS) - '\u256d', // ╭ 0x55 -> BOX DRAWINGS LIGHT ARC DOWN AND RIGHT - '\u2573', // ╳ 0x56 -> BOX DRAWINGS LIGHT DIAGONAL CROSS - '\u25cb', // ○ 0x57 -> WHITE CIRCLE - '\u2663', // ♣ 0x58 -> BLACK CLUB SUIT - '\uf129', //  0x59 -> BOX DRAWINGS LIGHT VERTICAL TWO QUARTERS RIGHT (CUS) - '\u2666', // ♦ 0x5A -> BLACK DIAMOND SUIT - '\u253c', // ┼ 0x5B -> BOX DRAWINGS LIGHT VERTICAL AND HORIZONTAL - '\uf12e', //  0x5C -> LEFT HALF BLOCK MEDIUM SHADE (CUS) - '\u2502', // │ 0x5D -> BOX DRAWINGS LIGHT VERTICAL - '\u03c0', // π 0x5E -> GREEK SMALL LETTER PI - '\u25e5', // ◥ 0x5F -> BLACK UPPER RIGHT TRIANGLE - '\u00a0', // 0x60 -> NO-BREAK SPACE - '\u258c', // ▌ 0x61 -> LEFT HALF BLOCK - '\u2584', // ▄ 0x62 -> LOWER HALF BLOCK - '\u2594', // ▔ 0x63 -> UPPER ONE EIGHTH BLOCK - '\u2581', // ▁ 0x64 -> LOWER ONE EIGHTH BLOCK - '\u258f', // ▏ 0x65 -> LEFT ONE EIGHTH BLOCK - '\u2592', // ▒ 0x66 -> MEDIUM SHADE - '\u2595', // ▕ 0x67 -> RIGHT ONE EIGHTH BLOCK - '\uf12f', //  0x68 -> LOWER HALF BLOCK MEDIUM SHADE (CUS) - '\u25e4', // ◤ 0x69 -> BLACK UPPER LEFT TRIANGLE - '\uf130', //  0x6A -> RIGHT ONE QUARTER BLOCK (CUS) - '\u251c', // ├ 0x6B -> BOX DRAWINGS LIGHT VERTICAL AND RIGHT - '\u2597', // ▗ 0x6C -> QUADRANT LOWER RIGHT - '\u2514', // └ 0x6D -> BOX DRAWINGS LIGHT UP AND RIGHT - '\u2510', // ┐ 0x6E -> BOX DRAWINGS LIGHT DOWN AND LEFT - '\u2582', // ▂ 0x6F -> LOWER ONE QUARTER BLOCK - '\u250c', // ┌ 0x70 -> BOX DRAWINGS LIGHT DOWN AND RIGHT - '\u2534', // ┴ 0x71 -> BOX DRAWINGS LIGHT UP AND HORIZONTAL - '\u252c', // ┬ 0x72 -> BOX DRAWINGS LIGHT DOWN AND HORIZONTAL - '\u2524', // ┤ 0x73 -> BOX DRAWINGS LIGHT VERTICAL AND LEFT - '\u258e', // ▎ 0x74 -> LEFT ONE QUARTER BLOCK - '\u258d', // ▍ 0x75 -> LEFT THREE EIGTHS BLOCK - '\uf131', //  0x76 -> RIGHT THREE EIGHTHS BLOCK (CUS) - '\uf132', //  0x77 -> UPPER ONE QUARTER BLOCK (CUS) - '\uf133', //  0x78 -> UPPER THREE EIGHTS BLOCK (CUS) - '\u2583', // ▃ 0x79 -> LOWER THREE EIGHTHS BLOCK - '\uf12d', //  0x7A -> ONE EIGHTH BLOCK UP AND LEFT (CUS) - '\u2596', // ▖ 0x7B -> QUADRANT LOWER LEFT - '\u259d', // ▝ 0x7C -> QUADRANT UPPER RIGHT - '\u2518', // ┘ 0x7D -> BOX DRAWINGS LIGHT UP AND LEFT - '\u2598', // ▘ 0x7E -> QUADRANT UPPER LEFT - '\u259a', // ▚ 0x7F -> QUADRANT UPPER LEFT AND LOWER RIGHT - '\ufffe', // 0x80 -> UNDEFINED - '\ufffe', // 0x81 -> UNDEFINED - '\ufffe', // 0x82 -> UNDEFINED - '\ufffe', // 0x83 -> UNDEFINED - '\ufffe', // 0x84 -> UNDEFINED - '\ufffe', // 0x85 -> UNDEFINED - '\ufffe', // 0x86 -> UNDEFINED - '\ufffe', // 0x87 -> UNDEFINED - '\ufffe', // 0x88 -> UNDEFINED - '\ufffe', // 0x89 -> UNDEFINED - '\ufffe', // 0x8A -> UNDEFINED - '\ufffe', // 0x8B -> UNDEFINED - '\ufffe', // 0x8C -> UNDEFINED - '\ufffe', // 0x8D -> UNDEFINED - '\ufffe', // 0x8E -> UNDEFINED - '\ufffe', // 0x8F -> UNDEFINED - '\ufffe', // 0x90 -> UNDEFINED - '\ufffe', // 0x91 -> UNDEFINED - '\ufffe', // 0x92 -> UNDEFINED - '\ufffe', // 0x93 -> UNDEFINED - '\ufffe', // 0x94 -> UNDEFINED - '\ufffe', // 0x95 -> UNDEFINED - '\ufffe', // 0x96 -> UNDEFINED - '\ufffe', // 0x97 -> UNDEFINED - '\ufffe', // 0x98 -> UNDEFINED - '\ufffe', // 0x99 -> UNDEFINED - '\ufffe', // 0x9A -> UNDEFINED - '\ufffe', // 0x9B -> UNDEFINED - '\ufffe', // 0x9C -> UNDEFINED - '\ufffe', // 0x9D -> UNDEFINED - '\ufffe', // 0x9E -> UNDEFINED - '\ufffe', // 0x9F -> UNDEFINED - '\ufffe', // 0xA0 -> UNDEFINED - '\ufffe', // 0xA1 -> UNDEFINED - '\ufffe', // 0xA2 -> UNDEFINED - '\ufffe', // 0xA3 -> UNDEFINED - '\ufffe', // 0xA4 -> UNDEFINED - '\ufffe', // 0xA5 -> UNDEFINED - '\ufffe', // 0xA6 -> UNDEFINED - '\ufffe', // 0xA7 -> UNDEFINED - '\ufffe', // 0xA8 -> UNDEFINED - '\ufffe', // 0xA9 -> UNDEFINED - '\ufffe', // 0xAA -> UNDEFINED - '\ufffe', // 0xAB -> UNDEFINED - '\ufffe', // 0xAC -> UNDEFINED - '\ufffe', // 0xAD -> UNDEFINED - '\ufffe', // 0xAE -> UNDEFINED - '\ufffe', // 0xAF -> UNDEFINED - '\ufffe', // 0xB0 -> UNDEFINED - '\ufffe', // 0xB1 -> UNDEFINED - '\ufffe', // 0xB2 -> UNDEFINED - '\ufffe', // 0xB3 -> UNDEFINED - '\ufffe', // 0xB4 -> UNDEFINED - '\ufffe', // 0xB5 -> UNDEFINED - '\ufffe', // 0xB6 -> UNDEFINED - '\ufffe', // 0xB7 -> UNDEFINED - '\ufffe', // 0xB8 -> UNDEFINED - '\ufffe', // 0xB9 -> UNDEFINED - '\ufffe', // 0xBA -> UNDEFINED - '\ufffe', // 0xBB -> UNDEFINED - '\ufffe', // 0xBC -> UNDEFINED - '\ufffe', // 0xBD -> UNDEFINED - '\ufffe', // 0xBE -> UNDEFINED - '\ufffe', // 0xBF -> UNDEFINED - '\ufffe', // 0xC0 -> UNDEFINED - '\ufffe', // 0xC1 -> UNDEFINED - '\ufffe', // 0xC2 -> UNDEFINED - '\ufffe', // 0xC3 -> UNDEFINED - '\ufffe', // 0xC4 -> UNDEFINED - '\ufffe', // 0xC5 -> UNDEFINED - '\ufffe', // 0xC6 -> UNDEFINED - '\ufffe', // 0xC7 -> UNDEFINED - '\ufffe', // 0xC8 -> UNDEFINED - '\ufffe', // 0xC9 -> UNDEFINED - '\ufffe', // 0xCA -> UNDEFINED - '\ufffe', // 0xCB -> UNDEFINED - '\ufffe', // 0xCC -> UNDEFINED - '\ufffe', // 0xCD -> UNDEFINED - '\ufffe', // 0xCE -> UNDEFINED - '\ufffe', // 0xCF -> UNDEFINED - '\ufffe', // 0xD0 -> UNDEFINED - '\ufffe', // 0xD1 -> UNDEFINED - '\ufffe', // 0xD2 -> UNDEFINED - '\ufffe', // 0xD3 -> UNDEFINED - '\ufffe', // 0xD4 -> UNDEFINED - '\ufffe', // 0xD5 -> UNDEFINED - '\ufffe', // 0xD6 -> UNDEFINED - '\ufffe', // 0xD7 -> UNDEFINED - '\ufffe', // 0xD8 -> UNDEFINED - '\ufffe', // 0xD9 -> UNDEFINED - '\ufffe', // 0xDA -> UNDEFINED - '\ufffe', // 0xDB -> UNDEFINED - '\ufffe', // 0xDC -> UNDEFINED - '\ufffe', // 0xDD -> UNDEFINED - '\ufffe', // 0xDE -> UNDEFINED - '\ufffe', // 0xDF -> UNDEFINED - '\ufffe', // 0xE0 -> UNDEFINED - '\ufffe', // 0xE1 -> UNDEFINED - '\ufffe', // 0xE2 -> UNDEFINED - '\ufffe', // 0xE3 -> UNDEFINED - '\ufffe', // 0xE4 -> UNDEFINED - '\ufffe', // 0xE5 -> UNDEFINED - '\ufffe', // 0xE6 -> UNDEFINED - '\ufffe', // 0xE7 -> UNDEFINED - '\ufffe', // 0xE8 -> UNDEFINED - '\ufffe', // 0xE9 -> UNDEFINED - '\ufffe', // 0xEA -> UNDEFINED - '\ufffe', // 0xEB -> UNDEFINED - '\ufffe', // 0xEC -> UNDEFINED - '\ufffe', // 0xED -> UNDEFINED - '\ufffe', // 0xEE -> UNDEFINED - '\ufffe', // 0xEF -> UNDEFINED - '\ufffe', // 0xF0 -> UNDEFINED - '\ufffe', // 0xF1 -> UNDEFINED - '\ufffe', // 0xF2 -> UNDEFINED - '\ufffe', // 0xF3 -> UNDEFINED - '\ufffe', // 0xF4 -> UNDEFINED - '\ufffe', // 0xF5 -> UNDEFINED - '\ufffe', // 0xF6 -> UNDEFINED - '\ufffe', // 0xF7 -> UNDEFINED - '\ufffe', // 0xF8 -> UNDEFINED - '\ufffe', // 0xF9 -> UNDEFINED - '\ufffe', // 0xFA -> UNDEFINED - '\ufffe', // 0xFB -> UNDEFINED - '\ufffe', // 0xFC -> UNDEFINED - '\ufffe', // 0xFD -> UNDEFINED - '\ufffe', // 0xFE -> UNDEFINED - '\ufffe' // 0xFF -> UNDEFINED - ) - - // encoding: from unicode to Petscii/Screencodes (0-255) - private val encodingPetsciiLowercase = decodingPetsciiLowercase.withIndex().associate{it.value to it.index} - private val encodingPetsciiUppercase = decodingPetsciiUppercase.withIndex().associate{it.value to it.index} - private val encodingScreencodeLowercase = decodingScreencodeLowercase.withIndex().associate{it.value to it.index} - private val encodingScreencodeUppercase = decodingScreencodeUppercase.withIndex().associate{it.value to it.index} - - private fun replaceSpecial(chr: Char): Char = - // characters often used in C like source code can be translated with a little bit of fantasy: - when(chr) { - '^' -> '↑' - '_' -> '▁' - '{' -> '┤' - '}' -> '├' - '|' -> '│' - '\\' -> '╲' - else -> chr - } - - fun encodePetscii(text: String, lowercase: Boolean = false): List { - fun encodeChar(chr3: Char, lowercase: Boolean): Short { - val chr = replaceSpecial(chr3) - val screencode = if(lowercase) encodingPetsciiLowercase[chr] else encodingPetsciiUppercase[chr] - return screencode?.toShort() ?: when (chr) { - '\u0000' -> 0.toShort() - in '\u8000'..'\u80ff' -> { - // special case: take the lower 8 bit hex value directly - (chr.code - 0x8000).toShort() - } - else -> { - val case = if (lowercase) "lower" else "upper" - throw CharConversionException("no ${case}Petscii character for '${escape(chr.toString())}' (${chr.code})") - } - } - } - - return text.map{ - try { - encodeChar(it, lowercase) - } catch (x: CharConversionException) { - encodeChar(it, !lowercase) - } - } - } - - fun decodePetscii(petscii: Iterable, lowercase: Boolean = false): String { - return petscii.map { - val code = it.toInt() - try { - if(lowercase) decodingPetsciiLowercase[code] else decodingPetsciiUppercase[code] - } catch(x: CharConversionException) { - if(lowercase) decodingPetsciiUppercase[code] else decodingPetsciiLowercase[code] - } - }.joinToString("") - } - - fun encodeScreencode(text: String, lowercase: Boolean = false): List { - fun encodeChar(chr3: Char, lowercase: Boolean): Short { - val chr = replaceSpecial(chr3) - val screencode = if(lowercase) encodingScreencodeLowercase[chr] else encodingScreencodeUppercase[chr] - return screencode?.toShort() ?: when (chr) { - '\u0000' -> 0.toShort() - in '\u8000'..'\u80ff' -> { - // special case: take the lower 8 bit hex value directly - (chr.code - 0x8000).toShort() - } - else -> { - val case = if (lowercase) "lower" else "upper" - throw CharConversionException("no ${case}Screencode character for '${escape(chr.toString())}' (${chr.code})") - } - } - } - - return text.map{ - try { - encodeChar(it, lowercase) - } catch (x: CharConversionException) { - encodeChar(it, !lowercase) - } - } - } - - fun decodeScreencode(screencode: Iterable, lowercase: Boolean = false): String { - return screencode.map { - val code = it.toInt() - try { - if (lowercase) decodingScreencodeLowercase[code] else decodingScreencodeUppercase[code] - } catch (x: CharConversionException) { - if (lowercase) decodingScreencodeUppercase[code] else decodingScreencodeLowercase[code] - } - }.joinToString("") - } - - fun petscii2scr(petscii_code: Short, inverseVideo: Boolean): Short { - val code = when { - petscii_code <= 0x1f -> petscii_code + 128 - petscii_code <= 0x3f -> petscii_code.toInt() - petscii_code <= 0x5f -> petscii_code - 64 - petscii_code <= 0x7f -> petscii_code - 32 - petscii_code <= 0x9f -> petscii_code + 64 - petscii_code <= 0xbf -> petscii_code - 64 - petscii_code <= 0xfe -> petscii_code - 128 - petscii_code == 255.toShort() -> 95 - else -> throw CharConversionException("petscii code out of range") - } - if(inverseVideo) - return (code or 0x80).toShort() - return code.toShort() - } - - fun scr2petscii(screencode: Short): Short { - val petscii = when { - screencode <= 0x1f -> screencode + 64 - screencode <= 0x3f -> screencode.toInt() - screencode <= 0x5d -> screencode +123 - screencode == 0x5e.toShort() -> 255 - screencode == 0x5f.toShort() -> 223 - screencode <= 0x7f -> screencode + 64 - screencode <= 0xbf -> screencode - 128 - screencode <= 0xfe -> screencode - 64 - screencode == 255.toShort() -> 191 - else -> throw CharConversionException("screencode out of range") - } - return petscii.toShort() - } -} diff --git a/compilerAst/src/prog8/parser/PetsciiEncoding.kt b/compilerAst/src/prog8/parser/PetsciiEncoding.kt deleted file mode 100644 index 9817003bd..000000000 --- a/compilerAst/src/prog8/parser/PetsciiEncoding.kt +++ /dev/null @@ -1,24 +0,0 @@ -package prog8.parser - -import prog8.ast.IStringEncoding -import java.io.CharConversionException - - -/** - * TODO: remove once [IStringEncoding] has been moved to compiler module - */ -object PetsciiEncoding : IStringEncoding { - override fun encodeString(str: String, altEncoding: Boolean) = - try { - if (altEncoding) Petscii.encodeScreencode(str, true) else Petscii.encodePetscii(str, true) - } catch (x: CharConversionException) { - throw CharConversionException("can't convert string to target machine's char encoding: ${x.message}") - } - - override fun decodeString(bytes: List, altEncoding: Boolean) = - try { - if (altEncoding) Petscii.decodeScreencode(bytes, true) else Petscii.decodePetscii(bytes, true) - } catch (x: CharConversionException) { - throw CharConversionException("can't decode string: ${x.message}") - } -} diff --git a/compilerAst/src/prog8/parser/Prog8Parser.kt b/compilerAst/src/prog8/parser/Prog8Parser.kt index 4d080a8ea..1f783fada 100644 --- a/compilerAst/src/prog8/parser/Prog8Parser.kt +++ b/compilerAst/src/prog8/parser/Prog8Parser.kt @@ -37,7 +37,7 @@ object Prog8Parser { // .linkParents called in ParsedModule.add parseTree.directive().forEach { module.add(it.toAst()) } // TODO: remove Encoding - parseTree.block().forEach { module.add(it.toAst(module.isLibrary(), PetsciiEncoding)) } + parseTree.block().forEach { module.add(it.toAst(module.isLibrary())) } return module } diff --git a/compilerAst/src/prog8/parser/ThrowTodoEncoding.kt b/compilerAst/src/prog8/parser/ThrowTodoEncoding.kt deleted file mode 100644 index 57f48871e..000000000 --- a/compilerAst/src/prog8/parser/ThrowTodoEncoding.kt +++ /dev/null @@ -1,16 +0,0 @@ -package prog8.parser - -import prog8.ast.IStringEncoding - -/** - * TODO: remove once [IStringEncoding] has been moved to compiler module - */ -object ThrowTodoEncoding: IStringEncoding { - override fun encodeString(str: String, altEncoding: Boolean): List { - TODO("move StringEncoding out of compilerAst") - } - - override fun decodeString(bytes: List, altEncoding: Boolean): String { - TODO("move StringEncoding out of compilerAst") - } -} diff --git a/compilerAst/test/Helpers.kt b/compilerAst/test/Helpers.kt index a49aed04a..1a59142a9 100644 --- a/compilerAst/test/Helpers.kt +++ b/compilerAst/test/Helpers.kt @@ -5,7 +5,6 @@ import kotlin.io.path.* import prog8.ast.IBuiltinFunctions import prog8.ast.IMemSizer -import prog8.ast.IStringEncoding import prog8.ast.base.DataType import prog8.ast.base.Position import prog8.ast.expressions.Expression @@ -46,16 +45,6 @@ fun sanityCheckDirectories(workingDirName: String? = null) { } - val DummyEncoding = object : IStringEncoding { - override fun encodeString(str: String, altEncoding: Boolean): List { - TODO("Not yet implemented") - } - - override fun decodeString(bytes: List, altEncoding: Boolean): String { - TODO("Not yet implemented") - } -} - val DummyFunctions = object : IBuiltinFunctions { override val names: Set = emptySet() override val purefunctionNames: Set = emptySet() diff --git a/compilerAst/test/TestModuleImporter.kt b/compilerAst/test/TestModuleImporter.kt index 68ebb41e4..e28a85bb0 100644 --- a/compilerAst/test/TestModuleImporter.kt +++ b/compilerAst/test/TestModuleImporter.kt @@ -19,7 +19,7 @@ class TestModuleImporter { fun testImportModuleWithNonExistingPath() { val program = Program("foo", mutableListOf(), DummyFunctions, DummyMemsizer) val searchIn = "./" + workingDir.relativize(fixturesDir).toString().replace("\\", "/") - val importer = ModuleImporter(program, DummyEncoding, "blah", listOf(searchIn)) + val importer = ModuleImporter(program, "blah", listOf(searchIn)) val srcPath = fixturesDir.resolve("i_do_not_exist") assumeNotExists(srcPath) @@ -31,7 +31,7 @@ class TestModuleImporter { fun testImportModuleWithDirectoryPath() { val program = Program("foo", mutableListOf(), DummyFunctions, DummyMemsizer) val searchIn = "./" + workingDir.relativize(fixturesDir).toString().replace("\\", "/") - val importer = ModuleImporter(program, DummyEncoding, "blah", listOf(searchIn)) + val importer = ModuleImporter(program, "blah", listOf(searchIn)) val srcPath = fixturesDir assumeDirectory(srcPath) @@ -46,7 +46,7 @@ class TestModuleImporter { fun testImportModuleWithSyntaxError() { val program = Program("foo", mutableListOf(), DummyFunctions, DummyMemsizer) val searchIn = "./" + workingDir.relativize(fixturesDir).toString().replace("\\", "/") - val importer = ModuleImporter(program, DummyEncoding, "blah", listOf(searchIn)) + val importer = ModuleImporter(program, "blah", listOf(searchIn)) val filename = "file_with_syntax_error.p8" val path = fixturesDir.resolve(filename) @@ -67,7 +67,7 @@ class TestModuleImporter { fun testImportModuleWithImportingModuleWithSyntaxError() { val program = Program("foo", mutableListOf(), DummyFunctions, DummyMemsizer) val searchIn = "./" + workingDir.relativize(fixturesDir).toString().replace("\\", "/") - val importer = ModuleImporter(program, DummyEncoding, "blah", listOf(searchIn)) + val importer = ModuleImporter(program, "blah", listOf(searchIn)) val importing = fixturesDir.resolve("import_file_with_syntax_error.p8") val imported = fixturesDir.resolve("file_with_syntax_error.p8") @@ -92,7 +92,7 @@ class TestModuleImporter { fun testImportLibraryModuleWithNonExistingName() { val program = Program("foo", mutableListOf(), DummyFunctions, DummyMemsizer) val searchIn = "./" + workingDir.relativize(fixturesDir).toString().replace("\\", "/") - val importer = ModuleImporter(program, DummyEncoding, "blah", listOf(searchIn)) + val importer = ModuleImporter(program, "blah", listOf(searchIn)) val filenameNoExt = "i_do_not_exist" val filenameWithExt = filenameNoExt + ".p8" val srcPathNoExt = fixturesDir.resolve(filenameNoExt) @@ -108,7 +108,7 @@ class TestModuleImporter { fun testImportLibraryModuleWithSyntaxError() { val program = Program("foo", mutableListOf(), DummyFunctions, DummyMemsizer) val searchIn = "./" + workingDir.relativize(fixturesDir).toString().replace("\\", "/") - val importer = ModuleImporter(program, DummyEncoding, "blah", listOf(searchIn)) + val importer = ModuleImporter(program, "blah", listOf(searchIn)) val srcPath = fixturesDir.resolve("file_with_syntax_error.p8") assumeReadableFile(srcPath) @@ -130,7 +130,7 @@ class TestModuleImporter { fun testImportLibraryModuleWithImportingBadModule() { val program = Program("foo", mutableListOf(), DummyFunctions, DummyMemsizer) val searchIn = "./" + workingDir.relativize(fixturesDir).toString().replace("\\", "/") - val importer = ModuleImporter(program, DummyEncoding, "blah", listOf(searchIn)) + val importer = ModuleImporter(program, "blah", listOf(searchIn)) val importing = fixturesDir.resolve("import_file_with_syntax_error.p8") val imported = fixturesDir.resolve("file_with_syntax_error.p8")