mirror of
https://github.com/irmen/prog8.git
synced 2024-10-16 18:23:59 +00:00
fix augmentable check to align with what the asmgen understands
This commit is contained in:
parent
7936fc5bd8
commit
eacf8b896a
@ -302,7 +302,7 @@ class ArrayIndex(var indexExpr: Expression,
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun accept(visitor: IAstVisitor) = indexExpr.accept(visitor)
|
fun accept(visitor: IAstVisitor) = indexExpr.accept(visitor)
|
||||||
fun accept(visitor: AstWalker, parent: Node) = indexExpr.accept(visitor, this)
|
fun accept(visitor: AstWalker) = indexExpr.accept(visitor, this)
|
||||||
|
|
||||||
override fun toString(): String {
|
override fun toString(): String {
|
||||||
return("ArrayIndex($indexExpr, pos=$position)")
|
return("ArrayIndex($indexExpr, pos=$position)")
|
||||||
@ -353,13 +353,13 @@ open class Assignment(var target: AssignTarget, var value: Expression, final ove
|
|||||||
|
|
||||||
if(binExpr.operator in "+-") {
|
if(binExpr.operator in "+-") {
|
||||||
val leftBinExpr = binExpr.left as? BinaryExpression
|
val leftBinExpr = binExpr.left as? BinaryExpression
|
||||||
if(leftBinExpr!=null && leftBinExpr.operator in "+-") {
|
val rightBinExpr = binExpr.right as? BinaryExpression
|
||||||
|
if(rightBinExpr==null && leftBinExpr!=null && leftBinExpr.operator in "+-") {
|
||||||
// A = (A +- x) +- y
|
// A = (A +- x) +- y
|
||||||
if(leftBinExpr.left isSameAs target || leftBinExpr.right isSameAs target || binExpr.right isSameAs target)
|
if(leftBinExpr.left isSameAs target || leftBinExpr.right isSameAs target || binExpr.right isSameAs target)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
val rightBinExpr = binExpr.right as? BinaryExpression
|
if(leftBinExpr==null && rightBinExpr!=null && rightBinExpr.operator in "+-") {
|
||||||
if(rightBinExpr!=null && rightBinExpr.operator in "+-") {
|
|
||||||
// A = y +- (A +- x)
|
// A = y +- (A +- x)
|
||||||
if(rightBinExpr.left isSameAs target || rightBinExpr.right isSameAs target || binExpr.left isSameAs target)
|
if(rightBinExpr.left isSameAs target || rightBinExpr.right isSameAs target || binExpr.left isSameAs target)
|
||||||
return true
|
return true
|
||||||
@ -371,15 +371,15 @@ open class Assignment(var target: AssignTarget, var value: Expression, final ove
|
|||||||
return true // A = v <associative-operator> A
|
return true // A = v <associative-operator> A
|
||||||
|
|
||||||
val leftBinExpr = binExpr.left as? BinaryExpression
|
val leftBinExpr = binExpr.left as? BinaryExpression
|
||||||
if(leftBinExpr?.operator == binExpr.operator) {
|
val rightBinExpr = binExpr.right as? BinaryExpression
|
||||||
|
if(leftBinExpr?.operator == binExpr.operator && rightBinExpr==null) {
|
||||||
// one of these?
|
// one of these?
|
||||||
// A = (A <associative-operator> x) <same-operator> y
|
// A = (A <associative-operator> x) <same-operator> y
|
||||||
// A = (x <associative-operator> A) <same-operator> y
|
// A = (x <associative-operator> A) <same-operator> y
|
||||||
// A = (x <associative-operator> y) <same-operator> A
|
// A = (x <associative-operator> y) <same-operator> A
|
||||||
return leftBinExpr.left isSameAs target || leftBinExpr.right isSameAs target || binExpr.right isSameAs target
|
return leftBinExpr.left isSameAs target || leftBinExpr.right isSameAs target || binExpr.right isSameAs target
|
||||||
}
|
}
|
||||||
val rightBinExpr = binExpr.right as? BinaryExpression
|
if(rightBinExpr?.operator == binExpr.operator && leftBinExpr==null) {
|
||||||
if(rightBinExpr?.operator == binExpr.operator) {
|
|
||||||
// one of these?
|
// one of these?
|
||||||
// A = y <associative-operator> (A <same-operator> x)
|
// A = y <associative-operator> (A <same-operator> x)
|
||||||
// A = y <associative-operator> (x <same-operator> y)
|
// A = y <associative-operator> (x <same-operator> y)
|
||||||
|
@ -235,7 +235,7 @@ abstract class AstWalker {
|
|||||||
fun visit(decl: VarDecl, parent: Node) {
|
fun visit(decl: VarDecl, parent: Node) {
|
||||||
track(before(decl, parent), decl, parent)
|
track(before(decl, parent), decl, parent)
|
||||||
decl.value?.accept(this, decl)
|
decl.value?.accept(this, decl)
|
||||||
decl.arraysize?.accept(this, decl)
|
decl.arraysize?.accept(this)
|
||||||
track(after(decl, parent), decl, parent)
|
track(after(decl, parent), decl, parent)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -375,7 +375,7 @@ abstract class AstWalker {
|
|||||||
fun visit(arrayIndexedExpression: ArrayIndexedExpression, parent: Node) {
|
fun visit(arrayIndexedExpression: ArrayIndexedExpression, parent: Node) {
|
||||||
track(before(arrayIndexedExpression, parent), arrayIndexedExpression, parent)
|
track(before(arrayIndexedExpression, parent), arrayIndexedExpression, parent)
|
||||||
arrayIndexedExpression.arrayvar.accept(this, arrayIndexedExpression)
|
arrayIndexedExpression.arrayvar.accept(this, arrayIndexedExpression)
|
||||||
arrayIndexedExpression.indexer.accept(this, arrayIndexedExpression)
|
arrayIndexedExpression.indexer.accept(this)
|
||||||
track(after(arrayIndexedExpression, parent), arrayIndexedExpression, parent)
|
track(after(arrayIndexedExpression, parent), arrayIndexedExpression, parent)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
%import textio
|
%import textio
|
||||||
%import floats
|
|
||||||
|
|
||||||
main {
|
main {
|
||||||
|
|
||||||
@ -7,46 +6,62 @@ main {
|
|||||||
|
|
||||||
ubyte xx = 1
|
ubyte xx = 1
|
||||||
ubyte yy = 2
|
ubyte yy = 2
|
||||||
uword aw
|
|
||||||
byte bb
|
|
||||||
float fl
|
|
||||||
|
|
||||||
;; TODO add these constant folders:
|
;; TODO add these constant folders:
|
||||||
;
|
;
|
||||||
;; (X + C1) + (Y + C2) => (X + Y) + (C1 + C2)
|
;; (X + C1) + (Y + C2) => (X + Y) + (C1 + C2)
|
||||||
;; (X + C1) - (Y + C2) => (X - Y) + (C1 - C2)
|
;; (X + C1) - (Y + C2) => (X - Y) + (C1 - C2)
|
||||||
;; ---> together: (X + C1) <plusmin> (Y + C2) => (X <plusmin> Y) + (C1 <plusmin> C2)
|
;; ---> together: (X + C1) <plusmin> (Y + C2) => (X <plusmin> Y) + (C1 <plusmin> C2)
|
||||||
;
|
|
||||||
|
;; (X * C) + (Y * C) => (X + Y) * C
|
||||||
|
;; (X * C) - (Y * C) => (X - Y) * C
|
||||||
|
;; ---> together: (X * C) <plusmin> (Y * C) => (X <plusmin> Y) * C
|
||||||
|
|
||||||
;
|
;
|
||||||
;; (X - C1) + (Y - C2) => (X + Y) - (C1 + C2)
|
;; (X - C1) + (Y - C2) => (X + Y) - (C1 + C2)
|
||||||
;; (X - C1) - (Y - C2) => (X - Y) - (C1 - C2)
|
;; (X - C1) - (Y - C2) => (X - Y) - (C1 - C2)
|
||||||
;
|
;
|
||||||
; xx=6
|
|
||||||
; yy=8
|
|
||||||
;
|
; result should be: 29 42 40 87 75 35
|
||||||
; yy = (xx+5)+(yy+10)
|
|
||||||
; txt.print_ub(yy) ; 29
|
xx=6
|
||||||
; txt.nl()
|
yy=8
|
||||||
;
|
yy = (xx+5)+(yy+10)
|
||||||
; xx=100
|
txt.print_ub(yy) ; 29
|
||||||
; yy=8
|
txt.nl()
|
||||||
; yy = (xx+5)-(yy+10)
|
|
||||||
; txt.print_ub(yy) ; 87
|
xx=6
|
||||||
; txt.nl()
|
yy=8
|
||||||
;
|
yy = (xx*3)+(yy*3)
|
||||||
; xx=50
|
txt.print_ub(yy) ; 42
|
||||||
; yy=40
|
txt.nl()
|
||||||
; yy = (xx-5)+(yy-10)
|
|
||||||
; txt.print_ub(yy) ; 75
|
xx=13
|
||||||
; txt.nl()
|
yy=5
|
||||||
;
|
yy = (xx*5)-(yy*5)
|
||||||
; xx=50
|
txt.print_ub(yy) ; 40
|
||||||
; yy=20
|
txt.nl()
|
||||||
; yy = (xx-5)-(yy-10)
|
|
||||||
; txt.print_ub(yy) ; 35
|
xx=100
|
||||||
; txt.nl()
|
yy=8
|
||||||
;
|
yy = (xx+5)-(yy+10)
|
||||||
; repeat {
|
txt.print_ub(yy) ; 87
|
||||||
; }
|
txt.nl()
|
||||||
|
|
||||||
|
xx=50
|
||||||
|
yy=40
|
||||||
|
yy = (xx-5)+(yy-10)
|
||||||
|
txt.print_ub(yy) ; 75
|
||||||
|
txt.nl()
|
||||||
|
|
||||||
|
xx=50
|
||||||
|
yy=20
|
||||||
|
yy = (xx-5)-(yy-10)
|
||||||
|
txt.print_ub(yy) ; 35
|
||||||
|
txt.nl()
|
||||||
|
|
||||||
|
repeat {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user