diff options
author | Peter Wu <lekensteyn@gmail.com> | 2011-12-07 08:27:15 +0000 |
---|---|---|
committer | Peter Wu <lekensteyn@gmail.com> | 2011-12-07 08:27:15 +0000 |
commit | 97d67c978678ea6009212ec2b868ebc7bc543585 (patch) | |
tree | 42b731d2c435ef40431947d575b2a128a9fdc07a /pp2cc.py | |
parent | f53bf21c6ad9fb3d2f1a40e2ce06816a6b2e3106 (diff) | |
download | pp2cc-97d67c978678ea6009212ec2b868ebc7bc543585.tar.gz |
Proper fix for calculating negative constants
Diffstat (limited to 'pp2cc.py')
-rwxr-xr-x | pp2cc.py | 10 |
1 files changed, 4 insertions, 6 deletions
@@ -1315,13 +1315,11 @@ class Parse(object): else: operand = self.determineConstValue(LinkedNode(node.expr, linked_node)) - if op == "-": - # negating a value in PP2 is flipping the WORDSIZE-th bit - value = -operand - #(operand ^ (pow(2, self.WORDSIZE) - 1)) + 1 - elif op == "~": - # invert all bits + if op in ("-", "~"): value = operand ^ (pow(2, self.WORDSIZE) - 1) + # negating a value in PP2 is inverting the bits and adding 1 + if op == "-": + value += 1 else: value = int(getattr(operator, op)(operand)) elif linked_node.type == "BinaryOp": |