mirror of
https://github.com/irmen/prog8.git
synced 2025-04-09 00:37:15 +00:00
fix a problem with const fold optimization in if expressions, and IR compilation of that
This commit is contained in:
parent
7a6f2ecc8c
commit
db80417bd7
@ -1451,6 +1451,10 @@ class IRCodeGen(
|
||||
}
|
||||
|
||||
when(val cond=ifElse.condition) {
|
||||
is PtBool -> {
|
||||
// normally this will be optimized away, but not with -noopt
|
||||
translateSimple(cond, Opcode.BSTEQ)
|
||||
}
|
||||
is PtTypeCast -> {
|
||||
require(cond.type==DataType.BOOL && cond.value.type in NumericDatatypes)
|
||||
translateSimple(cond, Opcode.BSTEQ)
|
||||
|
@ -458,8 +458,13 @@ private fun optimizeAst(program: Program, compilerOptions: CompilationOptions, e
|
||||
break
|
||||
}
|
||||
removeUnusedCode(program, errors, compilerOptions)
|
||||
if(errors.noErrors())
|
||||
if(errors.noErrors()) {
|
||||
// last round of optimizations because constFold may have enabled more...
|
||||
program.simplifyExpressions(errors, compilerOptions)
|
||||
program.optimizeStatements(errors, functions, compilerOptions)
|
||||
program.constantFold(errors, compilerOptions) // because simplified statements and expressions can result in more constants that can be folded away
|
||||
}
|
||||
|
||||
errors.report()
|
||||
}
|
||||
|
||||
|
@ -1,28 +1,16 @@
|
||||
%import bmx
|
||||
%import diskio
|
||||
%import emudbg
|
||||
%import floats
|
||||
%import gfx2
|
||||
%import graphics
|
||||
%import monogfx
|
||||
%import palette
|
||||
%import psg
|
||||
%import sprites
|
||||
%import syslib
|
||||
%import textio
|
||||
%import verafx
|
||||
%import conv
|
||||
%import cx16logo
|
||||
%import math
|
||||
%import prog8_lib
|
||||
%import string
|
||||
%import test_stack
|
||||
|
||||
%zeropage basicsafe
|
||||
%option no_sysinit
|
||||
|
||||
main {
|
||||
sub start() {
|
||||
const ubyte x=0
|
||||
|
||||
if x==3 {
|
||||
txt.print("three")
|
||||
} else if x==4 {
|
||||
txt.print("four")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user