mirror of
https://github.com/irmen/prog8.git
synced 2024-12-24 16:29:21 +00:00
unsigned>0 now optimized into unsigned!=0
This commit is contained in:
parent
832601b36b
commit
0694a187d7
@ -193,11 +193,15 @@ class ExpressionSimplifier(private val program: Program,
|
|||||||
return listOf(IAstModification.ReplaceNode(expr.right, NumericLiteral.optimalInteger(0, expr.right.position), expr))
|
return listOf(IAstModification.ReplaceNode(expr.right, NumericLiteral.optimalInteger(0, expr.right.position), expr))
|
||||||
}
|
}
|
||||||
|
|
||||||
if(expr.operator == ">=" && rightVal?.number == 0.0) {
|
|
||||||
if (leftDt == DataType.UBYTE || leftDt == DataType.UWORD) {
|
if (leftDt == DataType.UBYTE || leftDt == DataType.UWORD) {
|
||||||
|
if(expr.operator == ">=" && rightVal?.number == 0.0) {
|
||||||
// unsigned >= 0 --> true
|
// unsigned >= 0 --> true
|
||||||
return listOf(IAstModification.ReplaceNode(expr, NumericLiteral.fromBoolean(true, expr.position), parent))
|
return listOf(IAstModification.ReplaceNode(expr, NumericLiteral.fromBoolean(true, expr.position), parent))
|
||||||
}
|
}
|
||||||
|
else if(expr.operator == ">" && rightVal?.number == 0.0) {
|
||||||
|
// unsigned > 0 --> unsigned != 0
|
||||||
|
return listOf(IAstModification.SetExpression({expr.operator="!="}, expr, parent))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(leftDt!=DataType.FLOAT && expr.operator == "<" && rightVal?.number == 1.0) {
|
if(leftDt!=DataType.FLOAT && expr.operator == "<" && rightVal?.number == 1.0) {
|
||||||
@ -206,11 +210,15 @@ class ExpressionSimplifier(private val program: Program,
|
|||||||
return listOf(IAstModification.ReplaceNode(expr.right, NumericLiteral.optimalInteger(0, expr.right.position), expr))
|
return listOf(IAstModification.ReplaceNode(expr.right, NumericLiteral.optimalInteger(0, expr.right.position), expr))
|
||||||
}
|
}
|
||||||
|
|
||||||
if(expr.operator == "<" && rightVal?.number == 0.0) {
|
|
||||||
if (leftDt == DataType.UBYTE || leftDt == DataType.UWORD) {
|
if (leftDt == DataType.UBYTE || leftDt == DataType.UWORD) {
|
||||||
|
if(expr.operator == "<" && rightVal?.number == 0.0) {
|
||||||
// unsigned < 0 --> false
|
// unsigned < 0 --> false
|
||||||
return listOf(IAstModification.ReplaceNode(expr, NumericLiteral.fromBoolean(false, expr.position), parent))
|
return listOf(IAstModification.ReplaceNode(expr, NumericLiteral.fromBoolean(false, expr.position), parent))
|
||||||
}
|
}
|
||||||
|
else if(expr.operator == "<=" && rightVal?.number == 0.0) {
|
||||||
|
// unsigned <= 0 --> unsigned==0
|
||||||
|
return listOf(IAstModification.SetExpression({expr.operator="=="}, expr, parent))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// boolvar & 1 --> boolvar
|
// boolvar & 1 --> boolvar
|
||||||
|
@ -3,6 +3,7 @@ TODO
|
|||||||
|
|
||||||
For next release
|
For next release
|
||||||
^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^
|
||||||
|
- "until not bytearray[index]" creates some pretty silly assembly code. what about while? if?
|
||||||
- regression test the various projects before release
|
- regression test the various projects before release
|
||||||
|
|
||||||
...
|
...
|
||||||
|
Loading…
Reference in New Issue
Block a user