From c677f0a875ff4b2b6024a6b923dbbf96b6726df9 Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Tue, 23 Feb 2021 23:27:44 +0100 Subject: [PATCH] fixed string interning to also consider the alt-encoding --- compiler/src/prog8/compiler/target/c64/codegen/AsmGen.kt | 5 +++-- compilerAst/src/prog8/ast/AstToplevel.kt | 8 +++++--- examples/cx16/vtui/testvtui.p8 | 8 +++++--- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/compiler/src/prog8/compiler/target/c64/codegen/AsmGen.kt b/compiler/src/prog8/compiler/target/c64/codegen/AsmGen.kt index 197e551d0..712778aba 100644 --- a/compiler/src/prog8/compiler/target/c64/codegen/AsmGen.kt +++ b/compiler/src/prog8/compiler/target/c64/codegen/AsmGen.kt @@ -407,8 +407,9 @@ internal class AsmGen(private val program: Program, } private fun outputStringvar(lastvar: VarDecl, encoded: List) { - val string = (lastvar.value as StringLiteralValue).value - out("${lastvar.name}\t; ${lastvar.datatype} \"${escape(string).replace("\u0000", "")}\"") + val sv = lastvar.value as StringLiteralValue + val altEncoding = if(sv.altEncoding) "@" else "" + out("${lastvar.name}\t; ${lastvar.datatype} $altEncoding\"${escape(sv.value).replace("\u0000", "")}\"") val outputBytes = encoded.map { "$" + it.toString(16).padStart(2, '0') } for (chunk in outputBytes.chunked(16)) out(" .byte " + chunk.joinToString()) diff --git a/compilerAst/src/prog8/ast/AstToplevel.kt b/compilerAst/src/prog8/ast/AstToplevel.kt index 8d2faf0d6..febc6fd5b 100644 --- a/compilerAst/src/prog8/ast/AstToplevel.kt +++ b/compilerAst/src/prog8/ast/AstToplevel.kt @@ -268,7 +268,7 @@ class Program(val name: String, get() = mainModule.loadAddress var actualLoadAddress: Int = 0 - private val internedStrings = mutableMapOf>() + private val internedStrings = mutableMapOf, List>() val internedStringsModuleName = "prog8_interned_strings" init { @@ -295,7 +295,9 @@ class Program(val name: String, } fun internString(string: StringLiteralValue): List { - val existing = internedStrings[string.value] + val key = Pair(string.value, string.altEncoding) + string.heapId + val existing = internedStrings[key] if(existing!=null) return existing @@ -305,7 +307,7 @@ class Program(val name: String, (internedStringsBlock as Block).statements.add(decl) decl.linkParents(internedStringsBlock) val scopedName = listOf(internedStringsModuleName, decl.name) - internedStrings[string.value] = scopedName + internedStrings[key] = scopedName return scopedName } diff --git a/examples/cx16/vtui/testvtui.p8 b/examples/cx16/vtui/testvtui.p8 index 2f660202e..d88e1cb68 100644 --- a/examples/cx16/vtui/testvtui.p8 +++ b/examples/cx16/vtui/testvtui.p8 @@ -12,7 +12,9 @@ main { vtui.gotoxy(10,10) vtui.border(1, 40, 6, $47) vtui.gotoxy(12,12) - vtui.print_str(@"Hello, world! VTUI from Prog8!", $f2, false) + vtui.print_str(@"Hello, world! vtui from Prog8!", $f2, $80) + vtui.gotoxy(12,13) + vtui.print_str("Hello, world! vtui from Prog8!", $f2, $00) repeat { } @@ -22,7 +24,7 @@ main { vtui $1000 { - %asmbinary "VTUI0.4.BIN", 2 ; skip the 2 dummy load address bytes + %asmbinary "VTUI0.5.BIN", 2 ; skip the 2 dummy load address bytes ; NOTE: base address $1000 here must be the same as the block's memory address, for obvious reasons! romsub $1000 = initialize() clobbers(A, X, Y) @@ -35,7 +37,7 @@ vtui $1000 { romsub $1014 = scan_char() -> ubyte @A, ubyte @X romsub $1017 = hline(ubyte char @A, ubyte length @Y, ubyte colors @X) clobbers(A) romsub $101a = vline(ubyte char @A, ubyte length @Y, ubyte colors @X) clobbers(A) - romsub $101d = print_str(str string @R0, ubyte colors @X, ubyte convertchars @Pc) clobbers(A, Y) + romsub $101d = print_str(str string @R0, ubyte colors @X, ubyte convertchars @A) clobbers(A, Y) romsub $1020 = fill_box(ubyte char @A, ubyte width @R1, ubyte height @R2, ubyte colors @X) clobbers(A, Y) romsub $1023 = pet2scr(ubyte char @A) -> ubyte @A romsub $1026 = scr2pet(ubyte char @A) -> ubyte @A