mirror of
https://github.com/irmen/prog8.git
synced 2024-11-18 19:12:44 +00:00
slightly optimized binexpr evaluation for ==/!= in some cases
This commit is contained in:
parent
5d2dec1803
commit
b62183adcb
@ -45,7 +45,7 @@ X = BinExpr X = LeftExpr
|
||||
|
||||
|
||||
*/
|
||||
if(binExpr.operator in AugmentAssignmentOperators && isSimpleTarget(assignment.target)) {
|
||||
if(binExpr.operator in AugmentAssignmentOperators + listOf("==", "!=") && isSimpleTarget(assignment.target)) {
|
||||
if(assignment.target isSameAs binExpr.right)
|
||||
return noModifications
|
||||
if(assignment.target isSameAs binExpr.left) {
|
||||
@ -73,6 +73,15 @@ X = BinExpr X = LeftExpr
|
||||
// )
|
||||
}
|
||||
|
||||
if(binExpr.operator == "==" || binExpr.operator == "!=") {
|
||||
// don't split if the operand(s) don't fit the type of the resulting variable
|
||||
val targetDt = assignment.target.inferType(program)
|
||||
val leftDt = binExpr.left.inferType(program)
|
||||
val rightDt = binExpr.right.inferType(program)
|
||||
if(leftDt isNotAssignableTo targetDt || rightDt isNotAssignableTo targetDt)
|
||||
return noModifications
|
||||
}
|
||||
|
||||
if(binExpr.right.isSimple) {
|
||||
val firstAssign = Assignment(assignment.target.copy(), binExpr.left, binExpr.left.position)
|
||||
val targetExpr = assignment.target.toExpression()
|
||||
|
@ -66,7 +66,10 @@ fun compileProgram(args: CompilerArguments): CompilationResult {
|
||||
program = programresult
|
||||
importedFiles = imported
|
||||
processAst(program, args.errors, compilationOptions)
|
||||
if (compilationOptions.optimize)
|
||||
if (compilationOptions.optimize) {
|
||||
// println("*********** AST RIGHT BEFORE OPTIMIZING *************")
|
||||
// printProgram(program)
|
||||
|
||||
optimizeAst(
|
||||
program,
|
||||
compilationOptions,
|
||||
@ -74,6 +77,7 @@ fun compileProgram(args: CompilerArguments): CompilationResult {
|
||||
BuiltinFunctionsFacade(BuiltinFunctions),
|
||||
compTarget
|
||||
)
|
||||
}
|
||||
postprocessAst(program, args.errors, compilationOptions)
|
||||
|
||||
// println("*********** AST BEFORE ASSEMBLYGEN *************")
|
||||
|
@ -5,12 +5,21 @@ main {
|
||||
sub start() {
|
||||
ubyte @shared xx
|
||||
ubyte @shared yy
|
||||
ubyte camg
|
||||
|
||||
ubyte @shared interlaced = (camg & $04) != 0
|
||||
|
||||
yy = xx
|
||||
yy = yy==7
|
||||
|
||||
yy++
|
||||
yy = xx==7
|
||||
if xx==99 {
|
||||
xx++
|
||||
yy++
|
||||
}
|
||||
txt.nl()
|
||||
yy++
|
||||
|
||||
; if xx==99 {
|
||||
; xx++
|
||||
; yy++
|
||||
; }
|
||||
; txt.nl()
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user