mirror of
https://github.com/irmen/prog8.git
synced 2024-11-26 11:49:22 +00:00
fixed silly code generated by some NOT-expressions (unused temporary)
This commit is contained in:
parent
0694a187d7
commit
27568c2bef
@ -45,6 +45,21 @@ internal class NotExpressionAndIfComparisonExprChanger(val program: Program, val
|
|||||||
|
|
||||||
override fun after(expr: PrefixExpression, parent: Node): Iterable<IAstModification> {
|
override fun after(expr: PrefixExpression, parent: Node): Iterable<IAstModification> {
|
||||||
if(expr.operator == "not") {
|
if(expr.operator == "not") {
|
||||||
|
|
||||||
|
// first check if we're already part of a "boolean" expresion (i.e. comparing against 0)
|
||||||
|
// if so, simplify THAT whole expression rather than making it more complicated
|
||||||
|
if(parent is BinaryExpression && parent.right.constValue(program)?.number==0.0) {
|
||||||
|
if(parent.operator=="==") {
|
||||||
|
// (NOT X)==0 --> X!=0
|
||||||
|
val replacement = BinaryExpression(expr.expression, "!=", NumericLiteral.optimalInteger(0, expr.position), expr.position)
|
||||||
|
return listOf(IAstModification.ReplaceNode(parent, replacement, parent.parent))
|
||||||
|
} else if(parent.operator=="!=") {
|
||||||
|
// (NOT X)!=0 --> X==0
|
||||||
|
val replacement = BinaryExpression(expr.expression, "==", NumericLiteral.optimalInteger(0, expr.position), expr.position)
|
||||||
|
return listOf(IAstModification.ReplaceNode(parent, replacement, parent.parent))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// not(not(x)) -> x
|
// not(not(x)) -> x
|
||||||
if((expr.expression as? PrefixExpression)?.operator=="not")
|
if((expr.expression as? PrefixExpression)?.operator=="not")
|
||||||
return listOf(IAstModification.ReplaceNode(expr, expr.expression, parent))
|
return listOf(IAstModification.ReplaceNode(expr, expr.expression, parent))
|
||||||
|
@ -3,7 +3,7 @@ TODO
|
|||||||
|
|
||||||
For next release
|
For next release
|
||||||
^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^
|
||||||
- "until not bytearray[index]" creates some pretty silly assembly code. what about while? if?
|
- if epxr goto somewhere creates inefficient code on virt
|
||||||
- regression test the various projects before release
|
- regression test the various projects before release
|
||||||
|
|
||||||
...
|
...
|
||||||
|
Loading…
Reference in New Issue
Block a user