This commit is contained in:
Irmen de Jong
2026-02-27 01:55:53 +01:00
parent 63cba4825a
commit 2a53dbc1f3
4 changed files with 23 additions and 5 deletions

View File

@@ -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) {

View File

@@ -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,

View File

@@ -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

View File

@@ -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
}
}