fixed string interning to also consider the alt-encoding

This commit is contained in:
Irmen de Jong 2021-02-23 23:27:44 +01:00
parent 6e65cb2c0a
commit c677f0a875
3 changed files with 13 additions and 8 deletions

View File

@ -407,8 +407,9 @@ internal class AsmGen(private val program: Program,
} }
private fun outputStringvar(lastvar: VarDecl, encoded: List<Short>) { private fun outputStringvar(lastvar: VarDecl, encoded: List<Short>) {
val string = (lastvar.value as StringLiteralValue).value val sv = lastvar.value as StringLiteralValue
out("${lastvar.name}\t; ${lastvar.datatype} \"${escape(string).replace("\u0000", "<NULL>")}\"") val altEncoding = if(sv.altEncoding) "@" else ""
out("${lastvar.name}\t; ${lastvar.datatype} $altEncoding\"${escape(sv.value).replace("\u0000", "<NULL>")}\"")
val outputBytes = encoded.map { "$" + it.toString(16).padStart(2, '0') } val outputBytes = encoded.map { "$" + it.toString(16).padStart(2, '0') }
for (chunk in outputBytes.chunked(16)) for (chunk in outputBytes.chunked(16))
out(" .byte " + chunk.joinToString()) out(" .byte " + chunk.joinToString())

View File

@ -268,7 +268,7 @@ class Program(val name: String,
get() = mainModule.loadAddress get() = mainModule.loadAddress
var actualLoadAddress: Int = 0 var actualLoadAddress: Int = 0
private val internedStrings = mutableMapOf<String, List<String>>() private val internedStrings = mutableMapOf<Pair<String, Boolean>, List<String>>()
val internedStringsModuleName = "prog8_interned_strings" val internedStringsModuleName = "prog8_interned_strings"
init { init {
@ -295,7 +295,9 @@ class Program(val name: String,
} }
fun internString(string: StringLiteralValue): List<String> { fun internString(string: StringLiteralValue): List<String> {
val existing = internedStrings[string.value] val key = Pair(string.value, string.altEncoding)
string.heapId
val existing = internedStrings[key]
if(existing!=null) if(existing!=null)
return existing return existing
@ -305,7 +307,7 @@ class Program(val name: String,
(internedStringsBlock as Block).statements.add(decl) (internedStringsBlock as Block).statements.add(decl)
decl.linkParents(internedStringsBlock) decl.linkParents(internedStringsBlock)
val scopedName = listOf(internedStringsModuleName, decl.name) val scopedName = listOf(internedStringsModuleName, decl.name)
internedStrings[string.value] = scopedName internedStrings[key] = scopedName
return scopedName return scopedName
} }

View File

@ -12,7 +12,9 @@ main {
vtui.gotoxy(10,10) vtui.gotoxy(10,10)
vtui.border(1, 40, 6, $47) vtui.border(1, 40, 6, $47)
vtui.gotoxy(12,12) 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 { repeat {
} }
@ -22,7 +24,7 @@ main {
vtui $1000 { 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! ; 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) romsub $1000 = initialize() clobbers(A, X, Y)
@ -35,7 +37,7 @@ vtui $1000 {
romsub $1014 = scan_char() -> ubyte @A, ubyte @X romsub $1014 = scan_char() -> ubyte @A, ubyte @X
romsub $1017 = hline(ubyte char @A, ubyte length @Y, ubyte colors @X) clobbers(A) 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 $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 $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 $1023 = pet2scr(ubyte char @A) -> ubyte @A
romsub $1026 = scr2pet(ubyte char @A) -> ubyte @A romsub $1026 = scr2pet(ubyte char @A) -> ubyte @A