Commit 3c9a4762 authored by Sander Mathijs van Veen's avatar Sander Mathijs van Veen

Merge branch 'master' of kompiler.org:trs

parents 1a7cebab 805a9166
...@@ -141,8 +141,9 @@ MESSAGES[equalize_denominators] = _('Equalize the denominators of division' ...@@ -141,8 +141,9 @@ MESSAGES[equalize_denominators] = _('Equalize the denominators of division'
def add_nominators(root, args): def add_nominators(root, args):
""" """
a / b + c / b -> (a + c) / b a / b + c / b -> (a + c) / b
a / -b + c / -b -> (a + c) / -b a / b - c / b -> (a - c) / b
a / -b - c / -b -> (a - c) / -b -(a / b) + c / b -> -((a + c) / b)
-(a / b) - c / b -> (c - a) / -b
""" """
# TODO: is 'add' Appropriate when rewriting to "(a + (-c)) / b"? # TODO: is 'add' Appropriate when rewriting to "(a + (-c)) / b"?
ab, cb = args ab, cb = args
......
...@@ -18,7 +18,7 @@ def add_numerics(root, args): ...@@ -18,7 +18,7 @@ def add_numerics(root, args):
n0, n1, c0, c1 = args n0, n1, c0, c1 = args
if c0.is_op(OP_NEG): if c0.is_op(OP_NEG):
c0 = (-c0[0].value) c0 = -c0[0].value
else: else:
c0 = c0.value c0 = c0.value
......
...@@ -34,6 +34,7 @@ class TestNode(RulesTestCase): ...@@ -34,6 +34,7 @@ class TestNode(RulesTestCase):
self.assertTrue(N('+', *self.l[:2]).is_op_or_negated(OP_ADD)) self.assertTrue(N('+', *self.l[:2]).is_op_or_negated(OP_ADD))
self.assertTrue(N('-', N('+', *self.l[:2])).is_op_or_negated(OP_ADD)) self.assertTrue(N('-', N('+', *self.l[:2])).is_op_or_negated(OP_ADD))
self.assertFalse(N('-', *self.l[:2]).is_op_or_negated(OP_ADD)) self.assertFalse(N('-', *self.l[:2]).is_op_or_negated(OP_ADD))
self.assertFalse(self.l[0].is_op_or_negated(OP_ADD))
def test_is_leaf(self): def test_is_leaf(self):
self.assertTrue(L(2).is_leaf()) self.assertTrue(L(2).is_leaf())
......
...@@ -17,6 +17,7 @@ class TestRulesNumerics(RulesTestCase): ...@@ -17,6 +17,7 @@ class TestRulesNumerics(RulesTestCase):
def test_add_numerics_negations(self): def test_add_numerics_negations(self):
l0, a, l1 = tree('1,a,2') l0, a, l1 = tree('1,a,2')
self.assertEqual(add_numerics(-l0 + l1, (-l0, l1, -L(1), L(2))), 1)
self.assertEqual(add_numerics(l0 + -l1, (l0, -l1, L(1), -L(2))), -1) self.assertEqual(add_numerics(l0 + -l1, (l0, -l1, L(1), -L(2))), -1)
self.assertEqual(add_numerics(l0 + a + -l1, (l0, -l1, L(1), -L(2))), self.assertEqual(add_numerics(l0 + a + -l1, (l0, -l1, L(1), -L(2))),
L(-1) + a) L(-1) + a)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment