From ab7d7c290733aceab25265cc4a71ed5162747cc8 Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Thu, 26 Mar 2020 22:59:42 +0100 Subject: [PATCH] fix comparison of memory expressions (this error prevented some optimizations) --- compiler/src/prog8/ast/statements/AstStatements.kt | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/compiler/src/prog8/ast/statements/AstStatements.kt b/compiler/src/prog8/ast/statements/AstStatements.kt index 61dd10f15..3a18af4e6 100644 --- a/compiler/src/prog8/ast/statements/AstStatements.kt +++ b/compiler/src/prog8/ast/statements/AstStatements.kt @@ -432,7 +432,13 @@ data class AssignTarget(val register: Register?, infix fun isSameAs(value: Expression): Boolean { return when { - this.memoryAddress!=null -> false + this.memoryAddress!=null -> { + // if the target is a memory write, and the value is a memory read, they're the same if the address matches + if(value is DirectMemoryRead) + this.memoryAddress.addressExpression isSameAs value.addressExpression + else + false + } this.register!=null -> value is RegisterExpr && value.register==register this.identifier!=null -> value is IdentifierReference && value.nameInSource==identifier!!.nameInSource this.arrayindexed!=null -> value is ArrayIndexedExpression &&