mirror of
https://github.com/irmen/prog8.git
synced 2024-12-24 01:29:28 +00:00
fix compiler error caused by removal of string symbol in txt.print() optimization
This commit is contained in:
parent
2637939e62
commit
f21adaa3ef
@ -45,11 +45,7 @@ class StatementOptimizer(private val program: Program,
|
|||||||
mutableListOf(NumericLiteral(DataType.UBYTE, firstCharEncoded.toDouble(), pos)),
|
mutableListOf(NumericLiteral(DataType.UBYTE, firstCharEncoded.toDouble(), pos)),
|
||||||
functionCallStatement.void, pos
|
functionCallStatement.void, pos
|
||||||
)
|
)
|
||||||
val stringDecl = string.parent as VarDecl
|
return listOf(IAstModification.ReplaceNode(functionCallStatement, chrout, parent))
|
||||||
return listOf(
|
|
||||||
IAstModification.ReplaceNode(functionCallStatement, chrout, parent),
|
|
||||||
IAstModification.Remove(stringDecl, stringDecl.parent as IStatementContainer)
|
|
||||||
)
|
|
||||||
} else if (string.value.length == 2) {
|
} else if (string.value.length == 2) {
|
||||||
val firstTwoCharsEncoded = options.compTarget.encodeString(string.value.take(2), string.encoding)
|
val firstTwoCharsEncoded = options.compTarget.encodeString(string.value.take(2), string.encoding)
|
||||||
val chrout1 = FunctionCallStatement(
|
val chrout1 = FunctionCallStatement(
|
||||||
@ -62,11 +58,9 @@ class StatementOptimizer(private val program: Program,
|
|||||||
mutableListOf(NumericLiteral(DataType.UBYTE, firstTwoCharsEncoded[1].toDouble(), pos)),
|
mutableListOf(NumericLiteral(DataType.UBYTE, firstTwoCharsEncoded[1].toDouble(), pos)),
|
||||||
functionCallStatement.void, pos
|
functionCallStatement.void, pos
|
||||||
)
|
)
|
||||||
val stringDecl = string.parent as VarDecl
|
|
||||||
return listOf(
|
return listOf(
|
||||||
IAstModification.InsertBefore(functionCallStatement, chrout1, parent as IStatementContainer),
|
IAstModification.InsertBefore(functionCallStatement, chrout1, parent as IStatementContainer),
|
||||||
IAstModification.ReplaceNode(functionCallStatement, chrout2, parent),
|
IAstModification.ReplaceNode(functionCallStatement, chrout2, parent)
|
||||||
IAstModification.Remove(stringDecl, stringDecl.parent as IStatementContainer)
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,7 @@ import prog8.code.core.DataType
|
|||||||
import prog8.code.core.Position
|
import prog8.code.core.Position
|
||||||
import prog8.code.target.C64Target
|
import prog8.code.target.C64Target
|
||||||
import prog8.code.target.Cx16Target
|
import prog8.code.target.Cx16Target
|
||||||
|
import prog8.code.target.VMTarget
|
||||||
import prog8tests.helpers.*
|
import prog8tests.helpers.*
|
||||||
|
|
||||||
|
|
||||||
@ -758,4 +759,21 @@ main {
|
|||||||
}"""
|
}"""
|
||||||
compileText(C64Target(), true, text, writeAssembly = false) shouldNotBe null
|
compileText(C64Target(), true, text, writeAssembly = false) shouldNotBe null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test("replacing string print by chrout with referenced string elsewhere shouldn't give string symbol error") {
|
||||||
|
val text="""
|
||||||
|
%import textio
|
||||||
|
|
||||||
|
main {
|
||||||
|
sub start() {
|
||||||
|
str key = "test"
|
||||||
|
txt.print(":")
|
||||||
|
if key != ":" {
|
||||||
|
cx16.r0++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
compileText(VMTarget(), true, text, writeAssembly = false) shouldNotBe null
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
@ -2,8 +2,6 @@
|
|||||||
TODO
|
TODO
|
||||||
====
|
====
|
||||||
|
|
||||||
- fix discord string bug for if key!="." : "ERROR undefined symbol: prog8_interned_strings.string_3"
|
|
||||||
|
|
||||||
- txt.waitkey() should return the pressed key? Also on atari.
|
- txt.waitkey() should return the pressed key? Also on atari.
|
||||||
|
|
||||||
- [on branch: shortcircuit] investigate McCarthy evaluation again? this may also reduce code size perhaps for things like if a>4 or a<2 ....
|
- [on branch: shortcircuit] investigate McCarthy evaluation again? this may also reduce code size perhaps for things like if a>4 or a<2 ....
|
||||||
|
Loading…
Reference in New Issue
Block a user