diff --git a/codeGenCpu6502/src/prog8/codegen/cpu6502/assignment/AssignmentAsmGen.kt b/codeGenCpu6502/src/prog8/codegen/cpu6502/assignment/AssignmentAsmGen.kt index 1c289852b..fd1b56b40 100644 --- a/codeGenCpu6502/src/prog8/codegen/cpu6502/assignment/AssignmentAsmGen.kt +++ b/codeGenCpu6502/src/prog8/codegen/cpu6502/assignment/AssignmentAsmGen.kt @@ -3758,7 +3758,12 @@ $endLabel""") assignRegisterpairWord(target, RegisterOrPair.AY) return } - require(sourceDt.isWord || sourceDt.isUnsignedByte || sourceDt.isBool || sourceDt.isPointer) { "weird source dt for word variable" } + require(sourceDt.isWord || sourceDt.isUnsignedByte || sourceDt.isBool || sourceDt.isPointer) { + if(sourceDt.isString) + "str source type for word variable should have been uword or ^^ubyte, a && is likely missing on the source variable $sourceDt ${target.position}" + else + "weird source dt for word variable: $sourceDt ${target.position}" + } when(target.kind) { TargetStorageKind.VARIABLE -> { if(sourceDt.isUnsignedByte || sourceDt.isBool) { diff --git a/compiler/src/prog8/compiler/astprocessing/TypecastsAdder.kt b/compiler/src/prog8/compiler/astprocessing/TypecastsAdder.kt index 7678edf51..781e11a04 100644 --- a/compiler/src/prog8/compiler/astprocessing/TypecastsAdder.kt +++ b/compiler/src/prog8/compiler/astprocessing/TypecastsAdder.kt @@ -681,7 +681,7 @@ class TypecastsAdder(val program: Program, val options: CompilationOptions, val addTypecastOrCastedValueModification(modifications, it.second, targetDt, parent) } else if(identifier!=null && targetDt.isUnsignedWord && argDt.isPassByRef) { if(!identifier.isSubroutineParameter()) { - // We allow STR/ARRAY values for UWORD or ^^UBYTE parameters. + // We allow STR/ARRAY values for UWORD or ^^UBYTE parameters, via typed AddressOf. if(!argDt.isString || it.second is IdentifierReference) { modifications += IAstModification.ReplaceNode( identifier, diff --git a/docs/source/todo.rst b/docs/source/todo.rst index be390abb2..071112e1a 100644 --- a/docs/source/todo.rst +++ b/docs/source/todo.rst @@ -16,6 +16,7 @@ Weird Heisenbug Future Things and Ideas ^^^^^^^^^^^^^^^^^^^^^^^ - add a -profile option (for now X16 only) that instruments the start (and returns?) -of every prog8 subroutine with code that dumps to the X16 emulator debug console: name of sub, stack pointer (for call depth!), emudbg cycle count. Save/restore all used registers! Start of program must set cycle count to zero. +- why are (interned) strings stored as initialization value in the SymbolTable AND as string nodes in the interned string block? Something seems redundant here? - add @private to variables and subroutines declared in a scope to make them invisible from outside that scope? - when implementing unsigned longs: remove the (multiple) "TODO "hack" to allow unsigned long constants to be used as values for signed longs, without needing a cast" - structs: properly fix the symbol name prefix hack in StStruct.sameas(), see github issue 198 diff --git a/simpleAst/src/prog8/code/ast/AstBase.kt b/simpleAst/src/prog8/code/ast/AstBase.kt index 2004faefa..716124c2d 100644 --- a/simpleAst/src/prog8/code/ast/AstBase.kt +++ b/simpleAst/src/prog8/code/ast/AstBase.kt @@ -1,8 +1,9 @@ package prog8.code.ast -import prog8.code.core.IMemSizer -import prog8.code.core.IStringEncoding -import prog8.code.core.Position +import prog8.code.INTERNED_STRINGS_MODULENAME +import prog8.code.StStaticVariable +import prog8.code.SymbolTable +import prog8.code.core.* import prog8.code.source.SourceCode import java.nio.file.Path @@ -85,6 +86,17 @@ class PtProgram( allBlocks().firstOrNull { it.name == "main" || it.name=="p8b_main" } ?.children ?.firstOrNull { it is PtSub && (it.name == "start" || it.name=="main.start" || it.name=="p8s_start" || it.name=="p8b_main.p8s_start") } as PtSub? + + fun internString(string: PtString, st: SymbolTable): String { + val internedStringsBlock = children.first { it is PtBlock && it.name == INTERNED_STRINGS_MODULENAME } + val varname = "ptstring_${internedStringsBlock.children.size}" + val internedString = PtVariable(varname, DataType.STR, ZeropageWish.NOT_IN_ZEROPAGE, 0u, false, string, null, string.position) + internedStringsBlock.add(internedString) + val stEntry = StStaticVariable(internedString.scopedName, DataType.STR, string.value to string.encoding, null, string.value.length.toUInt()+1u, + ZeropageWish.NOT_IN_ZEROPAGE, 0u, false, astNode=internedString) + st.add(stEntry) + return internedString.scopedName + } }