This commit is contained in:
Irmen de Jong 2021-03-22 01:45:19 +01:00
parent 24b77fb5a5
commit 3626828ceb
3 changed files with 30 additions and 17 deletions

View File

@ -227,8 +227,9 @@ open class VarDecl(val type: VarDeclType,
}
override fun replaceChildNode(node: Node, replacement: Node) {
// TODO the check that node===value is too strict sometimes, but leaving it out allows for bugs to creep through ... :( Perhaps check when adding the replace if there is already a replace on the same node?
require(replacement is Expression)
require(replacement is Expression && node===value)
// NOTE: ideally you also want to check that node===value but this sometimes crashes the optimizer when queueing multiple node replacements
// just accept the risk of having the wrong node specified in the IAstModification object...
value = replacement
replacement.parent = this
}

View File

@ -56,7 +56,7 @@ interface IAstModification {
}
}
class ReplaceNode(private val node: Node, private val replacement: Node, private val parent: Node) :
class ReplaceNode(val node: Node, private val replacement: Node, private val parent: Node) :
IAstModification {
override fun perform() {
parent.replaceChildNode(node, replacement)
@ -158,9 +158,19 @@ abstract class AstWalker {
open fun after(whileLoop: WhileLoop, parent: Node): Iterable<IAstModification> = emptyList()
private val modifications = mutableListOf<Triple<IAstModification, Node, Node>>()
// private val modificationsReplacedNodes = mutableSetOf<Pair<Node, Position>>()
private fun track(mods: Iterable<IAstModification>, node: Node, parent: Node) {
for (it in mods) modifications += Triple(it, node, parent)
for (it in mods) {
// if(it is IAstModification.ReplaceNode) {
// val replaceKey = Pair(it.node, it.node.position)
// if(replaceKey in modificationsReplacedNodes)
// throw FatalAstException("there already is a node replacement for $replaceKey - optimizer can't deal with multiple replacements for same node yet. Split the ast modification?")
// else
// modificationsReplacedNodes.add(replaceKey)
// }
modifications += Triple(it, node, parent)
}
}
fun applyModifications(): Int {
@ -169,6 +179,7 @@ abstract class AstWalker {
}
val amount = modifications.size
modifications.clear()
// modificationsReplacedNodes.clear()
return amount
}

View File

@ -1,23 +1,24 @@
%target cx16
;%target cx16
%import textio
%zeropage basicsafe
main {
sub start() {
txt.print("hello")
str filename = "titlescreen.bin"
ubyte success = cx16.vload(filename, 8, 0, $0000)
if success {
txt.print("load ok")
cx16.VERA_DC_HSCALE = 64
cx16.VERA_DC_VSCALE = 64
cx16.VERA_L1_CONFIG = %00011111 ; 256c bitmap mode
cx16.VERA_L1_MAPBASE = 0
cx16.VERA_L1_TILEBASE = 0
} else {
txt.print("load fail")
}
; str filename = "titlescreen.bin"
; ubyte success = cx16.vload(filename, 8, 0, $0000)
; if success {
; txt.print("load ok")
; cx16.VERA_DC_HSCALE = 64
; cx16.VERA_DC_VSCALE = 64
; cx16.VERA_L1_CONFIG = %00011111 ; 256c bitmap mode
; cx16.VERA_L1_MAPBASE = 0
; cx16.VERA_L1_TILEBASE = 0
; } else {
; txt.print("load fail")
; }
}
}