fix string literal replacing by identifierref

This commit is contained in:
Irmen de Jong 2019-07-31 00:14:12 +02:00
parent cc9965cc96
commit 6f7322150f
2 changed files with 21 additions and 17 deletions

View File

@ -236,6 +236,7 @@ internal class AstIdentifiersChecker(private val program: Program) : IAstModifyi
override fun visit(refLiteral: ReferenceLiteralValue): Expression {
val litval = super.visit(refLiteral)
if(litval is ReferenceLiteralValue) {
val vardecl = litval.parent as? VarDecl
if (litval.isString) {
// intern the string; move it into the heap
if (litval.str!!.length !in 1..255)
@ -243,8 +244,11 @@ internal class AstIdentifiersChecker(private val program: Program) : IAstModifyi
else {
litval.addToHeap(program.heap)
}
return if(vardecl!=null)
litval
else
makeIdentifierFromRefLv(litval) // replace the literal string by a identifier reference.
} else if (litval.isArray) {
val vardecl = litval.parent as? VarDecl
if (vardecl!=null) {
return fixupArrayDatatype(litval, vardecl, program.heap)
} else {
@ -253,7 +257,7 @@ internal class AstIdentifiersChecker(private val program: Program) : IAstModifyi
val datatype = determineArrayDt(litval.array!!) ?: return litval
val litval2 = litval.cast(datatype)!!
litval2.parent = litval.parent
// finally, replace the literal by a identifier reference.
// finally, replace the literal array by a identifier reference.
return makeIdentifierFromRefLv(litval2)
}
}

View File

@ -5,15 +5,15 @@
main {
sub start() {
; byte bvar
; ubyte var2
;
; for A in "hello" {
; c64scr.print_ub(A)
; c64.CHROUT(',')
; }
; c64.CHROUT('\n')
;
byte bvar
ubyte var2
for A in "hello" {
c64scr.print_ub(A)
c64.CHROUT(',')
}
c64.CHROUT('\n')
; for A in [1,3,5,99] {
; c64scr.print_ub(A)
; c64.CHROUT(',')
@ -26,12 +26,6 @@ main {
; }
; c64.CHROUT('\n')
for float fl in [1.1, 2.2, 5.5, 99.99] {
c64flt.print_f(fl)
c64.CHROUT(',')
}
c64.CHROUT('\n')
; for var2 in 10 to 20 {
; c64scr.print_ub(var2)
; c64.CHROUT(',')
@ -48,6 +42,12 @@ main {
; c64scr.print_b(bvar)
; c64.CHROUT(',')
; }
; c64.CHROUT('\n')
; for float fl in [1.1, 2.2, 5.5, 99.99] {
; c64flt.print_f(fl)
; c64.CHROUT(',')
; }
; c64.CHROUT('\n')
}
}