compiler.iodelay: subtraction certainly shouldn't be commutative.

This commit is contained in:
whitequark 2015-11-20 22:15:03 +08:00
parent cc623c13b4
commit cb9e7d15bf
1 changed files with 11 additions and 6 deletions

View File

@ -158,18 +158,23 @@ class Add(BinOpFixpoint):
_op = lambda a, b: a + b _op = lambda a, b: a + b
_fixpoint = 0 _fixpoint = 0
class Sub(BinOpFixpoint):
_priority = 2
_symbol = "-"
_op = lambda a, b: a - b
_fixpoint = 0
class Mul(BinOpFixpoint): class Mul(BinOpFixpoint):
_priority = 1 _priority = 1
_symbol = "*" _symbol = "*"
_op = lambda a, b: a * b _op = lambda a, b: a * b
_fixpoint = 1 _fixpoint = 1
class Sub(BinOp):
_priority = 2
_symbol = "-"
_op = lambda a, b: a - b
def _fold_binop(self, lhs, rhs):
if isinstance(rhs, Const) and rhs.value == 0:
return lhs
else:
return super()._fold_binop(lhs, rhs)
class Div(BinOp): class Div(BinOp):
def _fold_binop(self, lhs, rhs): def _fold_binop(self, lhs, rhs):
if isinstance(rhs, Const) and rhs.value == 1: if isinstance(rhs, Const) and rhs.value == 1: