From ead8c59bda199e670e30eddade7564eb18fc6a6a Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Sat, 2 Dec 2023 20:49:30 +0100 Subject: [PATCH] allow all character encodings on all compilation targets. --- .../src/prog8/code/core/ICompilationTarget.kt | 1 - codeCore/src/prog8/code/target/AtariTarget.kt | 1 - codeCore/src/prog8/code/target/C128Target.kt | 1 - codeCore/src/prog8/code/target/C64Target.kt | 1 - codeCore/src/prog8/code/target/Cx16Target.kt | 1 - codeCore/src/prog8/code/target/PETTarget.kt | 1 - codeCore/src/prog8/code/target/VMTarget.kt | 1 - .../compiler/astprocessing/AstExtensions.kt | 8 ----- .../astprocessing/LiteralsToAutoVars.kt | 9 +++--- docs/source/syntaxreference.rst | 3 +- docs/source/todo.rst | 4 +-- examples/test.p8 | 32 ++----------------- 12 files changed, 9 insertions(+), 54 deletions(-) diff --git a/codeCore/src/prog8/code/core/ICompilationTarget.kt b/codeCore/src/prog8/code/core/ICompilationTarget.kt index 865628139..ea1ad660d 100644 --- a/codeCore/src/prog8/code/core/ICompilationTarget.kt +++ b/codeCore/src/prog8/code/core/ICompilationTarget.kt @@ -3,7 +3,6 @@ package prog8.code.core interface ICompilationTarget: IStringEncoding, IMemSizer { val name: String val machine: IMachineDefinition - val supportedEncodings: Set val defaultEncoding: Encoding override fun encodeString(str: String, encoding: Encoding): List diff --git a/codeCore/src/prog8/code/target/AtariTarget.kt b/codeCore/src/prog8/code/target/AtariTarget.kt index 14c4ad077..19893f9c4 100644 --- a/codeCore/src/prog8/code/target/AtariTarget.kt +++ b/codeCore/src/prog8/code/target/AtariTarget.kt @@ -7,7 +7,6 @@ import prog8.code.target.atari.AtariMachineDefinition class AtariTarget: ICompilationTarget, IStringEncoding by Encoder, IMemSizer { override val name = NAME override val machine = AtariMachineDefinition() - override val supportedEncodings = setOf(Encoding.ATASCII) override val defaultEncoding = Encoding.ATASCII companion object { diff --git a/codeCore/src/prog8/code/target/C128Target.kt b/codeCore/src/prog8/code/target/C128Target.kt index bf39e8083..55e012af3 100644 --- a/codeCore/src/prog8/code/target/C128Target.kt +++ b/codeCore/src/prog8/code/target/C128Target.kt @@ -11,7 +11,6 @@ import prog8.code.target.cbm.CbmMemorySizer class C128Target: ICompilationTarget, IStringEncoding by Encoder, IMemSizer by CbmMemorySizer { override val name = NAME override val machine = C128MachineDefinition() - override val supportedEncodings = setOf(Encoding.PETSCII, Encoding.SCREENCODES) override val defaultEncoding = Encoding.PETSCII companion object { diff --git a/codeCore/src/prog8/code/target/C64Target.kt b/codeCore/src/prog8/code/target/C64Target.kt index 164e4f47c..563b6908f 100644 --- a/codeCore/src/prog8/code/target/C64Target.kt +++ b/codeCore/src/prog8/code/target/C64Target.kt @@ -11,7 +11,6 @@ import prog8.code.target.cbm.CbmMemorySizer class C64Target: ICompilationTarget, IStringEncoding by Encoder, IMemSizer by CbmMemorySizer { override val name = NAME override val machine = C64MachineDefinition() - override val supportedEncodings = setOf(Encoding.PETSCII, Encoding.SCREENCODES) override val defaultEncoding = Encoding.PETSCII companion object { diff --git a/codeCore/src/prog8/code/target/Cx16Target.kt b/codeCore/src/prog8/code/target/Cx16Target.kt index 34b27052a..13c080d46 100644 --- a/codeCore/src/prog8/code/target/Cx16Target.kt +++ b/codeCore/src/prog8/code/target/Cx16Target.kt @@ -11,7 +11,6 @@ import prog8.code.target.cx16.CX16MachineDefinition class Cx16Target: ICompilationTarget, IStringEncoding by Encoder, IMemSizer by CbmMemorySizer { override val name = NAME override val machine = CX16MachineDefinition() - override val supportedEncodings = setOf(Encoding.PETSCII, Encoding.SCREENCODES, Encoding.ISO) override val defaultEncoding = Encoding.PETSCII companion object { diff --git a/codeCore/src/prog8/code/target/PETTarget.kt b/codeCore/src/prog8/code/target/PETTarget.kt index 0b6c67484..1c5f6c0e3 100644 --- a/codeCore/src/prog8/code/target/PETTarget.kt +++ b/codeCore/src/prog8/code/target/PETTarget.kt @@ -11,7 +11,6 @@ import prog8.code.target.pet.PETMachineDefinition class PETTarget: ICompilationTarget, IStringEncoding by Encoder, IMemSizer by CbmMemorySizer { override val name = NAME override val machine = PETMachineDefinition() - override val supportedEncodings = setOf(Encoding.PETSCII, Encoding.SCREENCODES) override val defaultEncoding = Encoding.PETSCII companion object { diff --git a/codeCore/src/prog8/code/target/VMTarget.kt b/codeCore/src/prog8/code/target/VMTarget.kt index 0916a560f..898fb2c81 100644 --- a/codeCore/src/prog8/code/target/VMTarget.kt +++ b/codeCore/src/prog8/code/target/VMTarget.kt @@ -6,7 +6,6 @@ import prog8.code.target.virtual.VirtualMachineDefinition class VMTarget: ICompilationTarget, IStringEncoding by Encoder, IMemSizer { override val name = NAME override val machine = VirtualMachineDefinition() - override val supportedEncodings = setOf(Encoding.ISO) override val defaultEncoding = Encoding.ISO companion object { diff --git a/compiler/src/prog8/compiler/astprocessing/AstExtensions.kt b/compiler/src/prog8/compiler/astprocessing/AstExtensions.kt index e0a4158d3..259f2c49c 100644 --- a/compiler/src/prog8/compiler/astprocessing/AstExtensions.kt +++ b/compiler/src/prog8/compiler/astprocessing/AstExtensions.kt @@ -61,10 +61,6 @@ internal fun Program.charLiteralsToUByteLiterals(target: ICompilationTarget, err val walker = object : AstWalker() { override fun after(char: CharLiteral, parent: Node): Iterable { require(char.encoding != Encoding.DEFAULT) - if(char.encoding != Encoding.DEFAULT && char.encoding !in target.supportedEncodings) { - errors.err("compilation target doesn't support this text encoding", char.position) - return noModifications - } return try { val encoded = target.encodeString(char.value.toString(), char.encoding) listOf(IAstModification.ReplaceNode( @@ -81,10 +77,6 @@ internal fun Program.charLiteralsToUByteLiterals(target: ICompilationTarget, err override fun after(string: StringLiteral, parent: Node): Iterable { // this only *checks* for errors for string encoding. The actual encoding is done much later require(string.encoding != Encoding.DEFAULT) - if(string.encoding != Encoding.DEFAULT && string.encoding !in target.supportedEncodings) { - errors.err("compilation target doesn't support this text encoding", string.position) - return noModifications - } try { target.encodeString(string.value, string.encoding) } catch (x: CharConversionException) { diff --git a/compiler/src/prog8/compiler/astprocessing/LiteralsToAutoVars.kt b/compiler/src/prog8/compiler/astprocessing/LiteralsToAutoVars.kt index 8f1c0407e..e04406b23 100644 --- a/compiler/src/prog8/compiler/astprocessing/LiteralsToAutoVars.kt +++ b/compiler/src/prog8/compiler/astprocessing/LiteralsToAutoVars.kt @@ -12,7 +12,10 @@ import prog8.ast.statements.VarDecl import prog8.ast.statements.WhenChoice import prog8.ast.walk.AstWalker import prog8.ast.walk.IAstModification -import prog8.code.core.* +import prog8.code.core.DataType +import prog8.code.core.ICompilationTarget +import prog8.code.core.IErrorReporter +import prog8.code.core.SplitWordArrayTypes internal class LiteralsToAutoVars(private val program: Program, @@ -21,10 +24,6 @@ internal class LiteralsToAutoVars(private val program: Program, ) : AstWalker() { override fun after(string: StringLiteral, parent: Node): Iterable { - if(string.encoding != Encoding.DEFAULT && string.encoding !in target.supportedEncodings) { - errors.err("compilation target doesn't support this text encoding", string.position) - return noModifications - } if(string.parent !is VarDecl && string.parent !is WhenChoice) { val binExpr = string.parent as? BinaryExpression if(binExpr!=null &&(binExpr.operator=="+" || binExpr.operator=="*")) diff --git a/docs/source/syntaxreference.rst b/docs/source/syntaxreference.rst index 1fe94ea8b..27b42d446 100644 --- a/docs/source/syntaxreference.rst +++ b/docs/source/syntaxreference.rst @@ -160,7 +160,8 @@ Directives The file is located relative to the current working directory! The optional offset and length can be used to select a particular piece of the file. To reference the contents of the included binary data, you can put a label in your prog8 code - just before the %asmbinary. An example program for this can be found below at the description of %asminclude. + just before the %asmbinary. To find out where the included binary data ends, add another label directly after it. + An example program for this can be found below at the description of %asminclude. .. data:: %asminclude "" diff --git a/docs/source/todo.rst b/docs/source/todo.rst index 4685774f0..b682fdbf7 100644 --- a/docs/source/todo.rst +++ b/docs/source/todo.rst @@ -2,9 +2,7 @@ TODO ==== -- get rid of jvmTarget in gradle scripts? -- make sizeof() works with an asmbinary label -- should string encodings not be restricted by the compiler target? (at least, ISO should be everywhere?) +- fix crash on uword[0] = uword[0] or 128 - uword scanline_buf = memory("scanline", 320, 0) different result when inside a sub or outside a sub??! (imageviewer iff module) - [on branch: shortcircuit] investigate McCarthy evaluation again? this may also reduce code size perhaps for things like if a>4 or a<2 .... - once VAL_1 is merged into the kernal properly, remove all the workarounds in cx16 floats.parse_f() diff --git a/examples/test.p8 b/examples/test.p8 index 4dd64a7ba..ae379a977 100644 --- a/examples/test.p8 +++ b/examples/test.p8 @@ -1,40 +1,12 @@ %zeropage basicsafe -%import floats %import textio %option no_sysinit main { sub start() { - floats.print_f(0.0) - txt.nl() - floats.print_f(1.0) - txt.nl() - floats.print_f(11111.0) - txt.nl() - floats.print_f(1e10) - txt.nl() - floats.print_f(1.234) - txt.nl() - floats.print_f(111.234) - txt.nl() - floats.print_f(-111.234) - txt.nl() - floats.print_f(-111.234) - txt.nl() + txt.print(iso:"This is ISO text.\n") - uword zz - const ubyte check = 99 - - when zz { - 1,2,check -> { - cx16.r0++ - } - 9999 -> { - cx16.r0++ - } - else -> { - cx16.r0++ - } + repeat { } } }