mirror of
https://github.com/irmen/prog8.git
synced 2024-12-22 18:30:01 +00:00
fix boolean expression optimization bug
This commit is contained in:
parent
4d37581694
commit
a7247f5b8b
@ -738,7 +738,6 @@ internal class AssignmentAsmGen(private val program: PtProgram,
|
||||
assignTrue.add(target)
|
||||
assignTrue.add(PtNumber.fromBoolean(true, assign.position))
|
||||
} else {
|
||||
require(assign.target.datatype in ByteDatatypes)
|
||||
when(assign.target.kind) {
|
||||
TargetStorageKind.VARIABLE -> {
|
||||
if(assign.target.datatype in WordDatatypes) {
|
||||
|
@ -240,10 +240,13 @@ class ExpressionSimplifier(private val program: Program, private val options: Co
|
||||
// optimize boolean constant comparisons
|
||||
if(expr.operator=="==") {
|
||||
if(rightDt==DataType.BOOL && leftDt==DataType.BOOL) {
|
||||
if(rightVal?.asBooleanValue==true)
|
||||
return listOf(IAstModification.ReplaceNode(expr, expr.left, parent))
|
||||
val rightConstBool = rightVal?.asBooleanValue
|
||||
if(rightConstBool!=null) {
|
||||
return if(rightConstBool)
|
||||
listOf(IAstModification.ReplaceNode(expr, expr.left, parent))
|
||||
else
|
||||
return listOf(IAstModification.ReplaceNode(expr, PrefixExpression("not", expr.left, expr.position), parent))
|
||||
listOf(IAstModification.ReplaceNode(expr, PrefixExpression("not", expr.left, expr.position), parent))
|
||||
}
|
||||
}
|
||||
if (rightVal?.number == 1.0) {
|
||||
if (options.strictBool) {
|
||||
|
@ -24,6 +24,10 @@ of these library modules automatically as required.
|
||||
The resulting compiled binary program *only works on the target machine it was compiled for*.
|
||||
You must recompile the program for every target you want to run it on.
|
||||
|
||||
.. note::
|
||||
Several algorithms and math routines in Prog8's assembly library files are adapted from
|
||||
code publicly available on https://www.codebase64.org/
|
||||
|
||||
|
||||
Low-fi variable and subroutine definitions in all available library modules
|
||||
---------------------------------------------------------------------------
|
||||
|
@ -1,20 +1,17 @@
|
||||
%zeropage basicsafe
|
||||
%import textio
|
||||
%zeropage basicsafe
|
||||
|
||||
main {
|
||||
sub show_bug(byte a, byte b) {
|
||||
if (a >= 0) == (b > 0) {
|
||||
txt.print("bug!")
|
||||
} else {
|
||||
txt.print("no bug.")
|
||||
}
|
||||
txt.nl()
|
||||
}
|
||||
|
||||
sub start() {
|
||||
uword @shared a,b
|
||||
b = a ; works
|
||||
cx16.r1L = lsb(a) ; works
|
||||
funcw(a) ; works
|
||||
funcb(lsb(a)) ; fails :-(
|
||||
}
|
||||
|
||||
sub funcw(uword arg) {
|
||||
arg++
|
||||
}
|
||||
|
||||
sub funcb(ubyte arg) {
|
||||
arg++
|
||||
show_bug(-1, 4)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user