mirror of
https://github.com/irmen/prog8.git
synced 2025-01-10 20:30:23 +00:00
allow all character encodings on all compilation targets.
This commit is contained in:
parent
db52a9466c
commit
ead8c59bda
@ -3,7 +3,6 @@ package prog8.code.core
|
|||||||
interface ICompilationTarget: IStringEncoding, IMemSizer {
|
interface ICompilationTarget: IStringEncoding, IMemSizer {
|
||||||
val name: String
|
val name: String
|
||||||
val machine: IMachineDefinition
|
val machine: IMachineDefinition
|
||||||
val supportedEncodings: Set<Encoding>
|
|
||||||
val defaultEncoding: Encoding
|
val defaultEncoding: Encoding
|
||||||
|
|
||||||
override fun encodeString(str: String, encoding: Encoding): List<UByte>
|
override fun encodeString(str: String, encoding: Encoding): List<UByte>
|
||||||
|
@ -7,7 +7,6 @@ import prog8.code.target.atari.AtariMachineDefinition
|
|||||||
class AtariTarget: ICompilationTarget, IStringEncoding by Encoder, IMemSizer {
|
class AtariTarget: ICompilationTarget, IStringEncoding by Encoder, IMemSizer {
|
||||||
override val name = NAME
|
override val name = NAME
|
||||||
override val machine = AtariMachineDefinition()
|
override val machine = AtariMachineDefinition()
|
||||||
override val supportedEncodings = setOf(Encoding.ATASCII)
|
|
||||||
override val defaultEncoding = Encoding.ATASCII
|
override val defaultEncoding = Encoding.ATASCII
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
@ -11,7 +11,6 @@ import prog8.code.target.cbm.CbmMemorySizer
|
|||||||
class C128Target: ICompilationTarget, IStringEncoding by Encoder, IMemSizer by CbmMemorySizer {
|
class C128Target: ICompilationTarget, IStringEncoding by Encoder, IMemSizer by CbmMemorySizer {
|
||||||
override val name = NAME
|
override val name = NAME
|
||||||
override val machine = C128MachineDefinition()
|
override val machine = C128MachineDefinition()
|
||||||
override val supportedEncodings = setOf(Encoding.PETSCII, Encoding.SCREENCODES)
|
|
||||||
override val defaultEncoding = Encoding.PETSCII
|
override val defaultEncoding = Encoding.PETSCII
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
@ -11,7 +11,6 @@ import prog8.code.target.cbm.CbmMemorySizer
|
|||||||
class C64Target: ICompilationTarget, IStringEncoding by Encoder, IMemSizer by CbmMemorySizer {
|
class C64Target: ICompilationTarget, IStringEncoding by Encoder, IMemSizer by CbmMemorySizer {
|
||||||
override val name = NAME
|
override val name = NAME
|
||||||
override val machine = C64MachineDefinition()
|
override val machine = C64MachineDefinition()
|
||||||
override val supportedEncodings = setOf(Encoding.PETSCII, Encoding.SCREENCODES)
|
|
||||||
override val defaultEncoding = Encoding.PETSCII
|
override val defaultEncoding = Encoding.PETSCII
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
@ -11,7 +11,6 @@ import prog8.code.target.cx16.CX16MachineDefinition
|
|||||||
class Cx16Target: ICompilationTarget, IStringEncoding by Encoder, IMemSizer by CbmMemorySizer {
|
class Cx16Target: ICompilationTarget, IStringEncoding by Encoder, IMemSizer by CbmMemorySizer {
|
||||||
override val name = NAME
|
override val name = NAME
|
||||||
override val machine = CX16MachineDefinition()
|
override val machine = CX16MachineDefinition()
|
||||||
override val supportedEncodings = setOf(Encoding.PETSCII, Encoding.SCREENCODES, Encoding.ISO)
|
|
||||||
override val defaultEncoding = Encoding.PETSCII
|
override val defaultEncoding = Encoding.PETSCII
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
@ -11,7 +11,6 @@ import prog8.code.target.pet.PETMachineDefinition
|
|||||||
class PETTarget: ICompilationTarget, IStringEncoding by Encoder, IMemSizer by CbmMemorySizer {
|
class PETTarget: ICompilationTarget, IStringEncoding by Encoder, IMemSizer by CbmMemorySizer {
|
||||||
override val name = NAME
|
override val name = NAME
|
||||||
override val machine = PETMachineDefinition()
|
override val machine = PETMachineDefinition()
|
||||||
override val supportedEncodings = setOf(Encoding.PETSCII, Encoding.SCREENCODES)
|
|
||||||
override val defaultEncoding = Encoding.PETSCII
|
override val defaultEncoding = Encoding.PETSCII
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
@ -6,7 +6,6 @@ import prog8.code.target.virtual.VirtualMachineDefinition
|
|||||||
class VMTarget: ICompilationTarget, IStringEncoding by Encoder, IMemSizer {
|
class VMTarget: ICompilationTarget, IStringEncoding by Encoder, IMemSizer {
|
||||||
override val name = NAME
|
override val name = NAME
|
||||||
override val machine = VirtualMachineDefinition()
|
override val machine = VirtualMachineDefinition()
|
||||||
override val supportedEncodings = setOf(Encoding.ISO)
|
|
||||||
override val defaultEncoding = Encoding.ISO
|
override val defaultEncoding = Encoding.ISO
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
@ -61,10 +61,6 @@ internal fun Program.charLiteralsToUByteLiterals(target: ICompilationTarget, err
|
|||||||
val walker = object : AstWalker() {
|
val walker = object : AstWalker() {
|
||||||
override fun after(char: CharLiteral, parent: Node): Iterable<IAstModification> {
|
override fun after(char: CharLiteral, parent: Node): Iterable<IAstModification> {
|
||||||
require(char.encoding != Encoding.DEFAULT)
|
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 {
|
return try {
|
||||||
val encoded = target.encodeString(char.value.toString(), char.encoding)
|
val encoded = target.encodeString(char.value.toString(), char.encoding)
|
||||||
listOf(IAstModification.ReplaceNode(
|
listOf(IAstModification.ReplaceNode(
|
||||||
@ -81,10 +77,6 @@ internal fun Program.charLiteralsToUByteLiterals(target: ICompilationTarget, err
|
|||||||
override fun after(string: StringLiteral, parent: Node): Iterable<IAstModification> {
|
override fun after(string: StringLiteral, parent: Node): Iterable<IAstModification> {
|
||||||
// this only *checks* for errors for string encoding. The actual encoding is done much later
|
// this only *checks* for errors for string encoding. The actual encoding is done much later
|
||||||
require(string.encoding != Encoding.DEFAULT)
|
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 {
|
try {
|
||||||
target.encodeString(string.value, string.encoding)
|
target.encodeString(string.value, string.encoding)
|
||||||
} catch (x: CharConversionException) {
|
} catch (x: CharConversionException) {
|
||||||
|
@ -12,7 +12,10 @@ import prog8.ast.statements.VarDecl
|
|||||||
import prog8.ast.statements.WhenChoice
|
import prog8.ast.statements.WhenChoice
|
||||||
import prog8.ast.walk.AstWalker
|
import prog8.ast.walk.AstWalker
|
||||||
import prog8.ast.walk.IAstModification
|
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,
|
internal class LiteralsToAutoVars(private val program: Program,
|
||||||
@ -21,10 +24,6 @@ internal class LiteralsToAutoVars(private val program: Program,
|
|||||||
) : AstWalker() {
|
) : AstWalker() {
|
||||||
|
|
||||||
override fun after(string: StringLiteral, parent: Node): Iterable<IAstModification> {
|
override fun after(string: StringLiteral, parent: Node): Iterable<IAstModification> {
|
||||||
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) {
|
if(string.parent !is VarDecl && string.parent !is WhenChoice) {
|
||||||
val binExpr = string.parent as? BinaryExpression
|
val binExpr = string.parent as? BinaryExpression
|
||||||
if(binExpr!=null &&(binExpr.operator=="+" || binExpr.operator=="*"))
|
if(binExpr!=null &&(binExpr.operator=="+" || binExpr.operator=="*"))
|
||||||
|
@ -160,7 +160,8 @@ Directives
|
|||||||
The file is located relative to the current working directory!
|
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.
|
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
|
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 "<filename>"
|
.. data:: %asminclude "<filename>"
|
||||||
|
@ -2,9 +2,7 @@
|
|||||||
TODO
|
TODO
|
||||||
====
|
====
|
||||||
|
|
||||||
- get rid of jvmTarget in gradle scripts?
|
- fix crash on uword[0] = uword[0] or 128
|
||||||
- make sizeof() works with an asmbinary label
|
|
||||||
- should string encodings not be restricted by the compiler target? (at least, ISO should be everywhere?)
|
|
||||||
- uword scanline_buf = memory("scanline", 320, 0) different result when inside a sub or outside a sub??! (imageviewer iff module)
|
- 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 ....
|
- [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()
|
- once VAL_1 is merged into the kernal properly, remove all the workarounds in cx16 floats.parse_f()
|
||||||
|
@ -1,40 +1,12 @@
|
|||||||
%zeropage basicsafe
|
%zeropage basicsafe
|
||||||
%import floats
|
|
||||||
%import textio
|
%import textio
|
||||||
%option no_sysinit
|
%option no_sysinit
|
||||||
|
|
||||||
main {
|
main {
|
||||||
sub start() {
|
sub start() {
|
||||||
floats.print_f(0.0)
|
txt.print(iso:"This is ISO text.\n")
|
||||||
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()
|
|
||||||
|
|
||||||
uword zz
|
repeat {
|
||||||
const ubyte check = 99
|
|
||||||
|
|
||||||
when zz {
|
|
||||||
1,2,check -> {
|
|
||||||
cx16.r0++
|
|
||||||
}
|
|
||||||
9999 -> {
|
|
||||||
cx16.r0++
|
|
||||||
}
|
|
||||||
else -> {
|
|
||||||
cx16.r0++
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user